PluginProbe
Event Post / 5.0
Event Post v5.0
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 5.6.1 All 46 releases
← All changes | eventpost.php +1083 -598 4.25.0 View file →
@@ -1,13 +1,13 @@
1 1 <?php
2 2 /*
3 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.2.4
7 - Author: bastho
8 - Contributors: n4thaniel, ecolosites
9 - Author URI: http://ecolosites.eelv.fr/
4 + Plugin URI: http://event-post.com
5 + Description: Add calendar and/or geolocation metadata on posts. For a better experience, we recommand to use it with <a href="https://wordpress.org/plugins/shortcode-ui/" target="_blank">Shortcake (shortcode UI)</a> installed.
6 + Version: 5.0.2
7 + Author: N.O.U.S. Open Useful and Simple
8 + Contributors: bastho, ecolosites
9 + Author URI: http://avecnous.eu
10 10 License: GPLv2
11 11 Text Domain: event-post
12 12 Domain Path: /languages/
13 13 Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda
@@ -12,10 +12,12 @@
12 12 Domain Path: /languages/
13 13 Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda
14 14 */
15 15
16 +global $EventPost;
17 +$EventPost = new EventPost();
16 18
17 -$EventPost = new EventPost();
19 +$EventPost_cache=array();
18 20
19 21 /**
20 22 * The main class where everything begins.
21 23 *
@@ -35,11 +37,12 @@
35 37 public $Week;
36 38 public $settings;
37 39 public $dateformat;
38 40
39 - public $version = '4.2.4';
41 + public $version = '4.5';
40 42
41 43 public $map_interactions;
44 + public $quick_edit_fields;
42 45
43 46 public $Shortcodes;
44 47
45 48 public function __construct() {
@@ -44,14 +47,16 @@
44 47
45 48 public function __construct() {
46 49 load_plugin_textdomain('event-post', false, 'event-post/languages');
47 50
48 - add_action('widgets_init', array(&$this,'init'), 1);
51 + add_action('widgets_init', array(&$this,'init'), 1);
49 52 add_action('save_post', array(&$this, 'save_postdata'));
50 53 add_action('admin_menu', array(&$this, 'manage_options'));
51 - add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
54 + add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
52 55
53 56 // Scripts
57 + add_action( 'admin_init', array(&$this, 'editor_styles'));
58 + add_action( 'admin_init', array(&$this, 'register_settings'));
54 59 add_action('admin_enqueue_scripts', array(&$this, 'admin_head'));
55 60 add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
56 61 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
57 62
@@ -56,9 +61,9 @@
56 61 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
57 62
58 63 // Single
59 64 add_filter('the_content', array(&$this, 'display_single'), 9999);
60 - add_filter('the_title', array(&$this, 'the_title'), 9999);
65 + add_filter('the_title', array(&$this, 'the_title'), 9999, 2);
61 66 add_action('the_event', array(&$this, 'print_single'));
62 67 add_action('wp_head', array(&$this, 'single_header'));
63 68
64 69 // Ajax
@@ -73,21 +78,34 @@
73 78 add_action('wp_ajax_EventPostFeed', array(&$this, 'feed'));
74 79 add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed'));
75 80
76 81 //
77 - add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
82 + add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
78 83
79 84 // Admin
80 - add_action('admin_post_EventPostSaveSettings', array(&$this, 'save_settings'));
85 + add_filter('plugin_action_links_event-post/eventpost.php', array( &$this, 'settings_link' ) );
86 + add_filter('plugin_row_meta', array( &$this, 'row_meta' ), 1, 4);
81 87
82 88 add_action('widgets_init', array(&$this, 'register_widgets'),1,1);
83 89
84 - include_once (plugin_dir_path(__FILE__) . 'widget.php');
85 - include_once (plugin_dir_path(__FILE__) . 'widget.cal.php');
86 - include_once (plugin_dir_path(__FILE__) . 'widget.map.php');
87 - include_once (plugin_dir_path(__FILE__) . 'multisite.php');
88 - include_once (plugin_dir_path(__FILE__) . 'shortcodes.php');
90 + // Quick edit
91 + add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit' ), 10, 2 );
92 + add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit' ), 10, 2 );
93 + add_action( 'admin_print_scripts-edit.php', array(&$this, 'scripts_edit') );
94 + add_action( 'wp_ajax_inline-save', array(&$this, 'inline_save'), 1 );
95 + add_action( 'wp_ajax_eventpost_save_bulk', array(&$this, 'save_bulkdatas') );
96 + add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_color'), 10, 3);
89 97
98 + $inc_path = plugin_dir_path(__FILE__).'inc/';
99 + include_once ($inc_path . 'wrappers.php');
100 + include_once ($inc_path . 'widget.php');
101 + include_once ($inc_path . 'widget.cal.php');
102 + include_once ($inc_path . 'widget.map.php');
103 + include_once ($inc_path . 'multisite.php');
104 + include_once ($inc_path . 'shortcodes.php');
105 + include_once ($inc_path . 'openweathermap.php');
106 + include_once ($inc_path . 'children.php');
107 +
90 108 }
91 109
92 110 /**
93 111 * PHP4 constructor
@@ -97,8 +115,12 @@
97 115 }
98 116
99 117 /**
100 118 * Init all variables when WP is ready
119 + *
120 + * @action evenpost_init
121 + * @filter eventpost_default_list_shema
122 + * @filter eventpost_list_shema
101 123 */
102 124 public function init(){
103 125 $this->META_START = 'event_begin';
104 126 $this->META_END = 'event_end';
@@ -113,8 +135,10 @@
113 135
114 136 $this->maps = $this->get_maps();
115 137 $this->settings = $this->get_settings();
116 138
139 + do_action('evenpost_init', $this);
140 +
117 141 $this->Shortcodes = new EventPost_Shortcodes();
118 142
119 143 // Edit
120 144 add_action('add_meta_boxes', array(&$this, 'add_custom_box'));
@@ -133,25 +157,24 @@
133 157 }
134 158
135 159 $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post'));
136 160
137 - $this->default_list_shema = array(
161 + $this->default_list_shema = apply_filters('eventpost_default_list_shema', array(
138 162 'container' => '
139 - <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>
140 - %list%
141 - </%type%>',
163 + <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>%list%
164 + </%type%><!-- .event_loop -->',
142 165 'item' => '
143 - <%child% class="event_item %class%" data-color="%color%">
144 - <a href="%event_link%">
145 - %event_thumbnail%
146 - <h5>%event_title%</h5>
147 - </a>
148 - %event_date%
149 - %event_cat%
150 - %event_location%
151 - %event_excerpt%
152 - </%child%>'
153 - );
166 + <%child% class="event_item %class%" data-color="%color%">
167 + <a href="%event_link%">
168 + %event_thumbnail%
169 + <h5>%event_title%</h5>
170 + </a>
171 + %event_date%
172 + %event_cat%
173 + %event_location%
174 + %event_excerpt%
175 + </%child%><!-- .event_item -->'
176 + ));
154 177 $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema);
155 178
156 179 $this->map_interactions=array(
157 180 'DragRotate'=>__('Drag Rotate', 'event-post'),
@@ -163,8 +186,29 @@
163 186 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'),
164 187 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'),
165 188 'DragZoom'=>__('Drag Zoom', 'event-post'),
166 189 );
190 +
191 + $this->quick_edit_fields = apply_filters('eventpost_quick_edit_fields', array(
192 + 'event'=>array(
193 + $this->META_START=>__('Begin:', 'event-post'),
194 + $this->META_END=>__('End:', 'event-post'),
195 + $this->META_COLOR=>__('Color:', 'event-post'),
196 + ),
197 + 'location'=>array(
198 + $this->META_ADD=>__('Address:', 'event-post'),
199 + $this->META_LAT=>__('Latitude:', 'event-post'),
200 + $this->META_LONG=>__('Longitude:', 'event-post'),
201 + ),
202 + )
203 + );
204 + $this->bulk_edit_fields = apply_filters('eventpost_bulk_edit_fields', array(
205 + 'event'=>array(
206 + $this->META_COLOR=>__('Color:', 'event-post'),
207 + ),
208 + )
209 + );
210 +
167 211 }
168 212
169 213 public function register_widgets(){
170 214 register_widget('EventPost_List');
@@ -213,9 +257,9 @@
213 257 * Get blog settings, load and saves default settings if needed. Can be filterred using
214 258 *
215 259 * `<?php add_filter('eventpost_getsettings', 'some_function'); ?>`
216 260 *
217 - * @action eventpost_getsettings
261 + * @action eventpost_getsettings_action
218 262 * @filter eventpost_getsettings
219 263 * @return array
220 264 */
221 265 public function get_settings() {
@@ -236,8 +280,12 @@
236 280 $maps = array_keys($this->maps);
237 281 $ep_settings['tile'] = $this->maps[$maps[0]]['id'];
238 282 $reg_settings=true;
239 283 }
284 + if(!isset($ep_settings['zoom']) || !is_numeric($ep_settings['zoom'])){
285 + $ep_settings['zoom']=12;
286 + $reg_settings=true;
287 + }
240 288 if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) {
241 289 $ep_settings['cache'] = 0;
242 290 $reg_settings=true;
243 291 }
@@ -256,8 +304,16 @@
256 304 if (!isset($ep_settings['markpath'])) {
257 305 $ep_settings['markpath'] = '';
258 306 $reg_settings=true;
259 307 }
308 + if (!isset($ep_settings['markurl'])) {
309 + $ep_settings['markurl'] = '';
310 + $reg_settings=true;
311 + }
312 + if (!isset($ep_settings['customcss'])) {
313 + $ep_settings['customcss'] = '';
314 + $reg_settings=true;
315 + }
260 316 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
261 317 $ep_settings['singlepos'] = 'after';
262 318 $reg_settings=true;
263 319 }
@@ -278,10 +334,10 @@
278 334 $ep_settings['item_shema'] = '';
279 335 $reg_settings=true;
280 336 }
281 337
282 - if(!isset($ep_settings['datepicker'])){
283 - $ep_settings['datepicker']='dual';
338 + if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){
339 + $ep_settings['datepicker']='simple';
284 340 $reg_settings=true;
285 341 }
286 342
287 343 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
@@ -288,9 +344,9 @@
288 344 $ep_settings['posttypes']=array('post');
289 345 $reg_settings=true;
290 346 }
291 347
292 - do_action('eventpost_getsettings');
348 + do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings));
293 349
294 350 //Save settings not changed
295 351 if($reg_settings===true){
296 352 update_option('ep_settings', $ep_settings);
@@ -384,25 +440,42 @@
384 440 * Enqueue CSS files
385 441 */
386 442 public function load_styles() {
387 443 //CSS
388 - wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
389 - wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
444 + if(!empty($this->settings['customcss'])){
445 + wp_enqueue_style('event-post-custom', $this->settings['customcss']);
446 + }
447 + elseif(is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')){
448 + wp_enqueue_style('event-post-custom', get_theme_file_uri('event-post.css'));
449 + }
450 + else{
451 + wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
452 + wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
453 + }
454 +
455 + // Lib scripts
390 456 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
391 - wp_enqueue_style('dashicons-css', includes_url('/css/dashicons.min.css'));
457 + wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css'));
392 458 }
459 + /**
460 + * Enqueue Editor style
461 + */
462 + public function editor_styles() {
463 + add_editor_style( plugins_url('/css/eventpost.min.css', __FILE__) );
464 + }
393 465
394 466 /**
395 467 * Enqueue JS files
396 468 */
397 - public function load_scripts() {
469 + public function load_scripts($deps = array('jquery')) {
398 470 // JS
399 471 wp_enqueue_script('jquery', false, false, false, true);
400 - wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), false, $this->version, true);
472 + wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), $deps, $this->version, true);
401 473 wp_localize_script('event-post', 'eventpost_params', array(
402 474 'imgpath' => plugins_url('/img/', __FILE__),
403 475 'maptiles' => $this->maps,
404 476 'defaulttile' => $this->settings['tile'],
477 + 'zoom' => $this->settings['zoom'],
405 478 'ajaxurl' => admin_url() . 'admin-ajax.php',
406 479 'map_interactions'=>$this->map_interactions,
407 480 ));
408 481 }
@@ -411,9 +484,12 @@
411 484 */
412 485 public function load_map_scripts() {
413 486 // JS
414 487 wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true);
415 - $this->load_scripts();
488 + $this->load_scripts(array('jquery', 'openlayers'));
489 + if(is_admin()){
490 + $this->admin_scripts(array('jquery', 'openlayers'));
491 + }
416 492 }
417 493
418 494 /**
419 495 * Enqueue CSS files in admin
@@ -419,45 +495,63 @@
419 495 * Enqueue CSS files in admin
420 496 */
421 497 public function admin_head() {
422 498 $page = basename($_SERVER['SCRIPT_NAME']);
423 - if( $page!='post-new.php' && !($page=='post.php' && isset($_GET['action']) & $_GET['action']=='edit') ){
499 + if( $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){
424 500 return;
425 501 }
426 502 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
427 503 wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version);
428 504 wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version);
429 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
430 - wp_enqueue_style('event-post-datetimepicker', plugins_url('/css/jquery.datetimepicker.css', __FILE__), false, $this->version);
431 - }
432 505 }
433 506
434 507 /**
435 508 * Enqueue JS files in admin
436 509 */
437 - public function admin_scripts() {
510 + public function admin_scripts($deps = array('jquery'), $force=false) {
438 511 $page = basename($_SERVER['SCRIPT_NAME']);
439 - if( $page!='post-new.php' && !($page=='post.php' && isset($_GET['action']) & $_GET['action']=='edit') ){
512 + if(!$force && $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings')){
440 513 return;
441 514 }
442 515 wp_enqueue_script('jquery');
443 - wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), array('jquery'), $this->version, true);
444 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
445 - wp_enqueue_script('event-post-datetimepicker', plugins_url('/js/jquery.datetimepicker.js', __FILE__), array('jquery'), $this->version, true);
516 + wp_enqueue_script('jquery-effects-core');
517 + wp_enqueue_script('jquery-effects-shake');
518 + if(!is_array($deps)){
519 + $deps = array('jquery');
446 520 }
447 - if($this->settings['datepicker']=='separate' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
521 + if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){
448 522 wp_enqueue_script('jquery-ui-datepicker');
523 + $deps[] = 'jquery-ui-datepicker';
449 524 }
525 + wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true);
450 526 $language = get_bloginfo('language');
451 527 if (strpos($language, '-') > -1) {
452 528 $language = strtolower(substr($language, 0, 2));
453 529 }
454 530 wp_localize_script('event-post-admin', 'eventpost', array(
531 + 'ajaxurl' => admin_url('admin-ajax.php'),
455 532 'imgpath' => plugins_url('/img/', __FILE__),
456 - 'date_choose' => __('Choose', 'event-post'),
533 + 'date_choose' => '<span class="screen-reader-text">'.__('Choose', 'event-post').'</span><i class="dashicons dashicons-calendar-alt"></i>',
457 534 'date_format' => __('yy-mm-dd', 'event-post'),
458 535 'more_icons' => __('More icons', 'event-post'),
459 536 'pick_a_date'=>__('Pick a date','event-post'),
537 + 'use_current_location'=>__('Use my current location','event-post'),
538 + 'start_drag'=>__('Click to<br>drag the map<br>and change location','event-post'),
539 + 'empty_address'=>__('Be kind to fill a non empty address :)', 'event-post'),
540 + 'search'=>__('Type an address', 'event-post'),
541 + 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'),
542 + 'datepickeri18n'=>array(
543 + 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'),
544 + 'day'=>__('Day', 'event-post'),
545 + 'month'=>__('Month', 'event-post'),
546 + 'year'=>__('Day', 'event-post'),
547 + 'hour'=>__('Hour', 'event-post'),
548 + 'minute'=>__('Minute', 'event-post'),
549 + 'ok'=>__('OK', 'event-post'),
550 + 'cancel'=>__('Cancel', 'event-post'),
551 + 'edit'=>__('Edit', 'event-post'),
552 + 'months'=>$this->NomDuMois,
553 + ),
460 554 'META_START' => $this->META_START,
461 555 'META_END' => $this->META_END,
462 556 'META_ADD' => $this->META_ADD,
463 557 'META_LAT' => $this->META_LAT,
@@ -466,8 +560,19 @@
466 560 'maptiles' => $this->maps,
467 561 'defaulttile' => $this->settings['tile']
468 562 ));
469 563 }
564 + function scripts_edit() {
565 + // load only when editing a supported post type
566 + $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
567 + if ( in_array( $current_post_type, $this->settings['posttypes'] ) ) {
568 + wp_enqueue_script( 'eventpost-inline-edit', plugins_url( 'js/inline-edit.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), '', true );
569 + wp_localize_script('eventpost-inline-edit', 'eventpost_inline_edit', array(
570 + 'quick'=>$this->quick_edit_fields,
571 + 'bulk'=>$this->bulk_edit_fields
572 + ));
573 + }
574 + }
470 575
471 576 /**
472 577 * Add custom header meta for single events
473 578 */
@@ -478,15 +583,17 @@
478 583 ?>
479 584 <meta name="geo.placename" content="<?php echo $event->address ?>" />
480 585 <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
481 586 <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
482 - <?php
587 +<meta property="place:location:latitude" content="<?php echo $event->lat ?>" />
588 +<meta property="place:location:longitude" content="<?php echo $event->long ?>" />
589 +<?php
483 590 }
484 591 if ($event->start != '' && $event->end != '') {
485 592 ?>
486 593 <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" />
487 594 <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" />
488 - <?php
595 +<?php
489 596 }
490 597 }
491 598 }
492 599
@@ -491,13 +598,23 @@
491 598 }
492 599
493 600 /**
494 601 *
602 + * @param type $str
603 + * @return string
604 + * @since 5.0.1
605 + */
606 + public function date_cleanup($str){
607 + return trim(str_replace(array('0', ' ', ':', '-'), '', $str));
608 + }
609 +
610 + /**
611 + *
495 612 * @param string $str
496 613 * @return boolean
497 614 */
498 615 public function dateisvalid($str) {
499 - return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != '';
616 + return is_string($str) && $this->date_cleanup($str) != '';
500 617 }
501 618
502 619 /**
503 620 *
@@ -543,31 +660,39 @@
543 660 return;
544 661 }
545 662
546 663 //Display dates
547 - $dates='<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">';
548 - if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) {
549 - $dates.= '<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">'
664 + $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">';
665 + if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) { // same day
666 + $dates.= "\n\t\t\t\t\t\t\t".'<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">'
550 667 . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>";
551 668 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') {
552 - $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
553 - <span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>
554 - <span class="linking_word linking_word-t">' . __('to', 'event-post') . '</span>
555 - <span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>';
669 + $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
670 + <span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>
671 + <span class="linking_word linking_word-t">' . __('to', 'event-post') . '</span>
672 + <span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>';
556 673 }
557 674 elseif (date('H:i', $time_start) != '00:00') {
558 - $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span>
559 - <time class="time time-single" itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' . date_i18n($this->settings['timeformat'], $time_start) . '</time>';
675 + $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span>
676 + <time class="time time-single" itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' . date_i18n($this->settings['timeformat'], $time_start) . '</time>';
560 677 }
678 + $dates.="\n\t\t\t\t\t\t\t".'</time>';
679 + } else { // not same day
680 + $dates.= '
681 + <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
682 + <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']);
683 + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00'){
684 + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_start);
685 + }
686 + $dates.='</time>
687 + <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span>
688 + <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']);
689 + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00') {
690 + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_end);
691 + }
561 692 $dates.='</time>';
562 - } else {
563 - $dates.= '
564 - <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
565 - <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']) . '</time>
566 - <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span>
567 - <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']) . '</time>
568 - ';
569 693 }
694 + $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->';
570 695 return $dates;
571 696 }
572 697
573 698 /**
@@ -583,14 +708,9 @@
583 708
584 709 $dates.=$this->delta_date($event->time_start, $event->time_end);
585 710
586 711 $timezone_string = get_option('timezone_string');
587 - $gmt_offset = get_option('gmt_offset ');
588 - $codegmt = 0;
589 - if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
590 - $codegmt = $gmt_offset * -1;
591 - $gmt_offset = '+' . $gmt_offset;
592 - }
712 + $gmt_offset = $gmt = $this->get_gmt_offset();
593 713
594 714 if (!is_admin() && $event->time_end > current_time('timestamp') && (
595 715 $this->settings['export'] == 'both' ||
596 716 ($this->settings['export'] == 'single' && is_single() ) ||
@@ -595,37 +715,63 @@
595 715 $this->settings['export'] == 'both' ||
596 716 ($this->settings['export'] == 'single' && is_single() ) ||
597 717 ($this->settings['export'] == 'list' && !is_single() )
598 718 )) {
719 +
599 720 // Export event
600 721 $title = urlencode($post->post_title);
601 722 $address = urlencode($post->address);
602 723 $url = urlencode($post->guid);
603 -
604 - $mt = strtotime($codegmt . ' Hours', $event->time_start);
605 - $d_s = date("Ymd", $mt) . 'T' . date("His", $mt);
606 - $mte = strtotime($codegmt . ' Hours', $event->time_end);
607 - $d_e = date("Ymd", $mte) . 'T' . date("His", $mte);
724 + $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');
725 + $d_s = date("Ymd", $event->time_start) . ($allday ? '' : 'T' . date("His", $event->time_start));
726 + $d_e = date("Ymd", $event->time_end) . ($allday ? '' : 'T' . date("His", $event->time_end));
608 727 $uid = $post->ID . '-' . $post->blog_id;
609 728
610 729 // format de date ICS
611 - $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);
730 + $ics_url = add_query_arg(array(
731 + 't'=>$title,
732 + 'u'=>$uid,
733 + 'sd'=>$d_s,
734 + 'ed'=>$d_e,
735 + 'a'=>$address,
736 + 'd'=>$url,
737 + 'tz'=>$timezone_string,
738 + 'gmt'=>urlencode($gmt_offset)
739 + ), plugins_url('export/ics.php', __FILE__));
612 740
613 741 // format de date Google cal
614 - $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';
742 + //$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';
743 + $google_url = add_query_arg(array(
744 + 'action'=>'TEMPLATE',
745 + 'trp'=>'false',
746 + 'sprop'=>'name',
747 + 'text'=>$title,
748 + 'dates'=>$d_s.'Z/'.$d_e.'Z',
749 + 'location'=>$address,
750 + 'details'=>$url,
751 + 'ctz'=>$timezone_string,
752 + 'gmt'=> urlencode($gmt_offset)
753 + ), 'https://www.google.com/calendar/event');
615 754
616 755 // format de date VCS
617 - $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);
618 -
756 + $vcs_url = add_query_arg(array(
757 + 't'=>$title,
758 + 'u'=>$uid,
759 + 'sd'=>$d_s,
760 + 'ed'=>$d_e,
761 + 'a'=>$address,
762 + 'd'=>$url,
763 + 'tz'=>$timezone_string,
764 + 'gmt'=>$gmt_offset
765 + ), plugins_url('export/vcs.php', __FILE__));
619 766 $dates.='
620 - <span class="eventpost-date-export">
621 - <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a>
622 - <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a>
623 - <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a>
624 - <i class=" dashicons-before dashicons-calendar"></i>
625 - </span>';
767 + <span class="eventpost-date-export">
768 + <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a>
769 + <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a>
770 + <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a>
771 + <i class="dashicons-before dashicons-calendar"></i>
772 + </span>';
626 773 }
627 - $dates.='</div>';
628 774 }
629 775 return apply_filters('eventpost_printdate', $dates);
630 776 }
631 777
@@ -649,17 +795,20 @@
649 795 $long = $post->long;
650 796 $color = $post->color;
651 797
652 798 if ($address != '' || ($lat != '' && $long != '')) {
653 - $location.='<address';
799 + $location.="\t\t\t\t".'<address';
654 800 if ($lat != '' && $long != '') {
655 801 $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" ';
656 802 }
657 - $location.=' itemprop="adr"><span>' . $address . '</span>';
803 + $location.=' itemprop="adr">'
804 + . "\n\t\t\t\t\t\t\t".'<span>'
805 + . "\n".$address
806 + . "\n\t\t\t\t\t\t\t". '</span>';
658 807 if ($context=='single' && $lat != '' && $long != '') {
659 - $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>';
808 + $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=' . $lat.='&amp;lon=' . $long.='&amp;zoom=13" target="_blank" itemprop="geo">' . __('Map', 'event-post') . '</a>';
660 809 }
661 - $location.='</address>';
810 + $location.="\n\t\t\t\t\t\t".'</address>';
662 811 }
663 812
664 813 return apply_filters('eventpost_printlocation', $location);
665 814 }
@@ -680,9 +829,9 @@
680 829 }
681 830 $cats = '';
682 831 $categories = $post->categories;
683 832 if ($categories) {
684 - $cats.='<span class="event_category"';
833 + $cats.="\t\t\t\t".'<span class="event_category"';
685 834 $color = $post->color;
686 835 if ($color != '') {
687 836 $cats.=' style="color:#' . $color . '"';
688 837 }
@@ -698,8 +847,9 @@
698 847 /**
699 848 * Generate, return or output date event datas
700 849 * @param WP_Post object $post
701 850 * @param string $class
851 + * @filter eventpost_get_single
702 852 * @return string
703 853 */
704 854 public function get_single($post = null, $class = '', $context='') {
705 855 if ($post == null) {
@@ -709,9 +859,11 @@
709 859 $datas_cat = $this->print_categories($post, $context);
710 860 $datas_loc = $this->print_location($post, $context);
711 861 if ($datas_date != '' || $datas_loc != '') {
712 862 $rgb = $this->hex2dec($post->color);
713 - 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>';
863 + 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">'
864 + . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post)
865 + . '</div>';
714 866 }
715 867 return '';
716 868 }
717 869
@@ -721,9 +873,9 @@
721 873 * @param string $class
722 874 * @return string
723 875 */
724 876 public function get_singledate($post = null, $class = '', $context='') {
725 - return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_date($post, null, $context) . '</div>';
877 + 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 -->';
726 878 }
727 879
728 880 /**
729 881 * Displays coloured terms of a given post
@@ -731,9 +883,9 @@
731 883 * @param string $class
732 884 * @return string
733 885 */
734 886 public function get_singlecat($post = null, $class = '', $context='') {
735 - return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_categories($post, $context) . '</div>';
887 + 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 -->';
736 888 }
737 889
738 890 /**
739 891 * Displays location of a given post
@@ -741,9 +893,9 @@
741 893 * @param string $class
742 894 * @return string
743 895 */
744 896 public function get_singleloc($post = null, $class = '', $context='') {
745 - return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_location($post, $context) . '</div>';
897 + 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 -->';
746 898 }
747 899
748 900 /**
749 901 * Uses `the_content` filter to add event details before or after the content of the current post
@@ -750,25 +902,21 @@
750 902 * @param string $content
751 903 * @return string
752 904 */
753 905 public function display_single($content) {
754 - if (is_page() || !is_single() || is_home())
906 + if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){
755 907 return $content;
756 - $post = get_queried_object();
757 - //Prevent from filters applying "the_content" on another thing than the current post content
758 - remove_filter('the_content', array(&$this, 'display_single'), 9999);
759 - $current_content = apply_filters('the_content', $post->post_content);
760 - if ($current_content == $content) {
761 - $post = $this->retreive();
762 - if($this->settings['singlepos']=='before'){
763 - $content=$this->get_single($post, 'event_single', 'single').$content;
764 - }
765 - else{
766 - $content.=$this->get_single($post, 'event_single', 'single');
767 - }
768 - $this->load_map_scripts();
769 908 }
770 - add_filter('the_content', array(&$this, 'display_single'), 9999);
909 +
910 + $post = $this->retreive();
911 + $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post);
912 + if($this->settings['singlepos']=='before'){
913 + $content=$eventbar.$content;
914 + }
915 + elseif($this->settings['singlepos']=='after'){
916 + $content.=$eventbar;
917 + }
918 + $this->load_map_scripts();
771 919 return $content;
772 920 }
773 921
774 922 /**
@@ -785,18 +933,25 @@
785 933 * Alter the post title in order to add icons if needed
786 934 * @param string $title
787 935 * @return string
788 936 */
789 - public function the_title($title){
790 - if(!in_the_loop() || !$this->settings['loopicons']){
937 + public function the_title($title, $post_id = null){
938 + if(!$post_id || !in_the_loop() || !$this->settings['loopicons']){
791 939 return $title;
792 940 }
793 - $event = $this->retreive();
941 + $icons_ = array(
942 + // Emojis
943 + 1=>array('🗓', '🗺'),
944 + // Dashicons
945 + 2=>array('<span class="dashicons dashicons-calendar"></span>', '<span class="dashicons dashicons-location"></span>'),
946 + );
947 +
948 + $event = $this->retreive($post_id);
794 949 if(!empty($event->start)){
795 - $title .= ' <span class="dashicons dashicons-calendar"></span>';
950 + $title .= ' '.$icons_[$this->settings['loopicons']][0];
796 951 }
797 952 if(!empty($event->lat) && !empty($event->long)){
798 - $title .= ' <span class="dashicons dashicons-location"></span>';
953 + $title .= ' '.$icons_[$this->settings['loopicons']][1];
799 954 }
800 955 return $title;
801 956 }
802 957
@@ -802,13 +957,17 @@
802 957
803 958
804 959 /**
805 960 * Return an HTML list of events
806 - * @param array $atts
807 - * @filter eventpost_params
961 + *
962 + * @filter eventpost_params($defaults, 'list_events')
808 963 * @filter eventpost_listevents
809 964 * @filter eventpost_item_scheme_entities
810 965 * @filter eventpost_item_scheme_values
966 + *
967 + * @param array $atts
968 + * @param string $id
969 + * @param string $context
811 970 * @return string
812 971 */
813 972 public function list_events($atts, $id = 'event_list', $context='') {
814 973 $ep_settings = $this->settings;
@@ -819,8 +978,9 @@
819 978 'past' => false,
820 979 'geo' => 0,
821 980 'width' => '',
822 981 'height' => '',
982 + 'zoom' => '',
823 983 'tile' => $ep_settings['tile'],
824 984 'title' => '',
825 985 'before_title' => '<h3>',
826 986 'after_title' => '</h3>',
@@ -849,11 +1009,8 @@
849 1009 }
850 1010 $ret = '';
851 1011 $this->list_id++;
852 1012 if (sizeof($events) > 0) {
853 - if($id=='event_geolist'){
854 - $this->load_map_scripts();
855 - }
856 1013 if (!empty($title)) {
857 1014 $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title);
858 1015 }
859 1016
@@ -860,13 +1017,21 @@
860 1017 $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div';
861 1018
862 1019 $list = '';
863 1020
864 - foreach ($events as $post) { //$post=get_post($item_id);
865 - $class_item = ($post->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past';
866 - if ($ep_settings['emptylink'] == 0 && empty($post->post_content)) {
867 - $post->permalink = '#' . $id . $this->list_id;
1021 + if($id=='event_geolist'){
1022 + $this->load_map_scripts();
1023 + $list.=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);
1024 + }
1025 +
1026 + foreach ($events as $event) {
1027 + $class_item = ($event->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past';
1028 + if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) {
1029 + $event->permalink = '#' . $id . $this->list_id;
868 1030 }
1031 + elseif(empty($ob->permalink)){
1032 + $event->permalink=$event->guid;
1033 + }
869 1034 $list.=str_replace(
870 1035 apply_filters('eventpost_item_scheme_entities', array(
871 1036 '%child%',
872 1037 '%class%',
@@ -880,22 +1045,22 @@
880 1045 '%event_excerpt%'
881 1046 )), apply_filters('eventpost_item_scheme_values', array(
882 1047 $child,
883 1048 $class_item,
884 - $post->color,
885 - $post->permalink,
886 - $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>' : '',
887 - $post->post_title,
888 - $this->get_singledate($post, '', $context),
889 - $this->get_singlecat($post, '', $context),
890 - $this->get_singleloc($post, '', $context),
891 - $excerpt == true && $post->post_excerpt!='' ? '<span class="event_exerpt">'.$post->post_excerpt.'</span>' : '',
892 - )), $item_schema
1049 + $event->color,
1050 + $event->permalink,
1051 + $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>' : '',
1052 + $event->post_title,
1053 + $this->get_singledate($event, '', $context),
1054 + $this->get_singlecat($event, '', $context),
1055 + $this->get_singleloc($event, '', $context),
1056 + $excerpt == true && $event->post_excerpt!='' ? '<span class="event_exerpt">'.$event->post_excerpt.'</span>' : '',
1057 + ), $event), $item_schema
893 1058 );
894 1059 }
895 1060 $attributes = '';
896 1061 if($id == 'event_geolist'){
897 - $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-disabled-interactions="';
1062 + $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-zoom="'.$zoom.'" data-disabled-interactions="';
898 1063 foreach($this->map_interactions as $int_key=>$int_name){
899 1064 $attributes.=$atts[$int_key]==false ? $int_key.', ' : '';
900 1065 }
901 1066 $attributes.='"';
@@ -919,15 +1084,19 @@
919 1084 $list
920 1085 ), $container_schema
921 1086 );
922 1087 }
1088 + elseif(filter_input(INPUT_POST, 'action')=='bulk_do_shortcode'){
1089 + 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>';
1090 + }
923 1091 return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
924 1092 }
925 1093
926 1094 /**
927 1095 * get_events
928 - * @param array $attr
929 - * @filter eventpost_params
1096 + * @param array $atts
1097 + * @filter eventpost_params
1098 + * @filter eventpost_get_items
930 1099 * @return array of post_ids wich are events
931 1100 */
932 1101 public function get_events($atts) {
933 1102 $requete = (shortcode_atts(apply_filters('eventpost_params', array(
@@ -938,8 +1107,9 @@
938 1107 'cat' => '',
939 1108 'tag' => '',
940 1109 'date' => '',
941 1110 'orderby' => 'meta_value',
1111 + 'orderbykey' => $this->META_START,
942 1112 'order' => 'ASC',
943 1113 'tax_name' => '',
944 1114 'tax_term' => '',
945 1115 'post_type'=> $this->settings['posttypes']
@@ -949,9 +1119,9 @@
949 1119
950 1120 $arg = array(
951 1121 'post_type' => $post_type,
952 1122 'posts_per_page' => $nb,
953 - 'meta_key' => $this->META_START,
1123 + 'meta_key' => $orderbykey,
954 1124 'orderby' => $orderby,
955 1125 'order' => $order
956 1126 );
957 1127
@@ -1067,12 +1237,11 @@
1067 1237
1068 1238 $query_md5 = 'eventpost_' . md5(var_export($requete, true));
1069 1239 // Check if cache is activated
1070 1240 if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
1071 - return is_array($cached_events) ? $cached_events : array();
1241 + return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg);
1072 1242 }
1073 1243
1074 -
1075 1244 $events = apply_filters('eventpost_get', '', $requete, $arg);
1076 1245 if ('' === $events) {
1077 1246 global $wpdb;
1078 1247 $query = new WP_Query($arg);
@@ -1084,9 +1253,9 @@
1084 1253 }
1085 1254 if ($this->settings['cache'] == 1){
1086 1255 set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
1087 1256 }
1088 - return $events;
1257 + return apply_filters('eventpost_get_items', $events, $requete, $arg);
1089 1258 }
1090 1259
1091 1260 /**
1092 1261 *
@@ -1093,12 +1262,16 @@
1093 1262 * @param object $event
1094 1263 * @return object
1095 1264 */
1096 1265 public function retreive($event = null) {
1097 - if(isset($event->start)){
1098 - return $event;
1099 - }
1100 - $ob = get_post($event);
1266 + global $EventPost_cache;
1267 + $ob = get_post($event);
1268 + if($ob->start){
1269 + return $ob;
1270 + }
1271 + if(isset($EventPost_cache[$ob->ID])){
1272 + return $EventPost_cache[$ob->ID];
1273 + }
1101 1274 $ob->start = get_post_meta($ob->ID, $this->META_START, true);
1102 1275 $ob->end = get_post_meta($ob->ID, $this->META_END, true);
1103 1276 if (!$this->dateisvalid($ob->start)){
1104 1277 $ob->start = '';
@@ -1104,9 +1277,10 @@
1104 1277 $ob->start = '';
1105 1278 }
1106 1279 if (!$this->dateisvalid($ob->end)){
1107 1280 $ob->end = '';
1108 - }
1281 + }
1282 + $ob->root_ID = $ob->ID;
1109 1283 $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
1110 1284 $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
1111 1285 $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
1112 1286 $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true);
@@ -1117,9 +1291,11 @@
1117 1291 $ob->blog_id = get_current_blog_id();
1118 1292 if ($ob->color == ''){
1119 1293 $ob->color = '000000';
1120 1294 }
1121 - return apply_filters('eventpost_retreive', $ob);
1295 +
1296 + $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob);
1297 + return $EventPost_cache[$ob->ID];
1122 1298 }
1123 1299
1124 1300 /**
1125 1301 *
@@ -1140,9 +1316,11 @@
1140 1316 'post_type'=>$post_type,
1141 1317 'tax_name'=>$term->taxonomy,
1142 1318 'tax_term'=>$term->slug,
1143 1319 'future'=>true,
1144 - 'past'=>true
1320 + 'past'=>true,
1321 + 'nb'=>-1,
1322 + 'order'=>'ASC'
1145 1323 );
1146 1324
1147 1325 $events = $this->get_events($request);
1148 1326
@@ -1153,8 +1331,17 @@
1153 1331 $term->end = $events[$term->events_count-1]->end;
1154 1332 $term->time_end = $events[$term->events_count-1]->time_end;
1155 1333 }
1156 1334
1335 + $request['order']='DESC';
1336 + $request['nb']=1;
1337 + $request['orderbykey']=$this->META_END;
1338 + $events = $this->get_events($request);
1339 + if(count($events)){
1340 + $term->end = $events[0]->end;
1341 + $term->time_end = $events[0]->time_end;
1342 + }
1343 +
1157 1344 return $term;
1158 1345
1159 1346 }
1160 1347
@@ -1164,10 +1351,11 @@
1164 1351 * add custom boxes in posts edit page
1165 1352 */
1166 1353 public function add_custom_box() {
1167 1354 foreach($this->settings['posttypes'] as $posttype){
1168 - add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, $this->settings['adminpos'], 'core');
1169 - add_meta_box('event_post_loc', __('Event location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, $this->settings['adminpos'], 'core');
1355 + add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core');
1356 + add_meta_box('event_post_loc', __('Location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core');
1357 + do_action('eventpost_add_custom_box', $posttype);
1170 1358 }
1171 1359 if(!function_exists('shortcode_ui_register_for_shortcode')){
1172 1360 add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page');
1173 1361 }
@@ -1187,94 +1375,119 @@
1187 1375 if (strpos($language, '-') > -1) {
1188 1376 $language = strtolower(substr($language, 0, 2));
1189 1377 }
1190 1378 $colors = $this->get_colors();
1191 - if (sizeof($colors) > 0):
1192 - ?>
1193 - <div class="misc-pub-section event-color-section">
1194 - <?php _e('Color:', 'event-post'); ?>
1379 + ?>
1380 +
1381 + <div class="eventpost-misc-pub-section">
1382 + <p>
1383 + <label>
1384 + <input type="checkbox" id="event-post-date-all-day" <?php checked( $event->time_start && $event->time_end && date('H:i:s', $event->time_start) == '00:00:00' && date('H:i:s', $event->time_end) == '00:00:00', true, true); ?>>
1385 + <?php _e('All day event', 'event-post') ?>
1386 + </label>
1387 + </p>
1388 + <p>
1389 + <span class="dashicons dashicons-calendar eventpost-edit-icon"></span>
1390 + <label for="<?php echo $this->META_START; ?>_date">
1391 + <?php _e('Begin:', 'event-post') ?>
1392 + <span id="<?php echo $this->META_START; ?>_date_human" class="human_date">
1393 + <?php
1394 + if ($event->time_start != '') {
1395 + echo $this->human_date($event->time_start) . (date('H:i', $event->time_start)=='00:00'?'':date(' H:i', $event->time_start));
1396 + }
1397 + else{
1398 + _e('Pick a date','event-post');
1399 + }
1400 + ?>
1401 + </span>
1402 + <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"/>
1403 + </label>
1404 + </p>
1405 + <p>
1406 + <span class="dashicons dashicons-calendar eventpost-edit-icon"></span>
1407 + <label for="<?php echo $this->META_END; ?>_date">
1408 + <?php _e('End:', 'event-post') ?>
1409 + <span id="<?php echo $this->META_END; ?>_date_human" class="human_date">
1410 + <?php
1411 + if ($event->time_start != '') {
1412 + echo $this->human_date($event->time_end) . (date('H:i', $event->time_end)=='00:00'?'':date(' H:i', $event->time_end));
1413 + }
1414 + else{
1415 + _e('Pick a date','event-post');
1416 + }
1417 + ?>
1418 + </span>
1419 + <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"/>
1420 + </label>
1421 + </p>
1422 + </div>
1423 + <?php if (sizeof($colors) > 0): ?>
1424 + <div class="eventpost-misc-pub-section event-color-section">
1425 + <span class="screen-reader-text"><?php _e('Color:', 'event-post'); ?></span><?php echo $key_color; ?>
1195 1426 <p>
1427 + <img src="<?php echo $this->markurl.$eventcolor.'.png'; ?>" id="eventpost-color-preview" data-url="<?php echo $this->markurl; ?>">
1428 + <span id="eventpost-color-dropdown">
1196 1429 <?php foreach ($colors as $color => $file): ?>
1197 1430 <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>" title="<?php echo $file; ?>">
1198 - <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
1199 - if ($eventcolor == $color) {
1200 - echo 'checked';
1201 - }
1202 - ?>/>
1431 + <img src="<?php echo $this->markurl.$color.'.png'; ?>">
1432 + <input type="radio" value ="<?php echo $color ?>" name="<?php echo $this->META_COLOR; ?>" id="<?php echo $this->META_COLOR; ?><?php echo $color ?>" <?php checked($eventcolor, $color, true); ?>/>
1203 1433 </label>
1204 1434 <?php endforeach; ?>
1435 + </span>
1205 1436 </p>
1206 1437 </div>
1207 1438 <?php endif; ?>
1208 - <div class="misc-pub-section">
1209 - <label for="<?php echo $this->META_START; ?>_date">
1210 - <?php _e('Begin:', 'event-post') ?>
1211 - <span id="<?php echo $this->META_START; ?>_date_human" class="human_date">
1212 - <?php
1213 - if ($event->time_start != '') {
1214 - echo $this->human_date($event->time_start) . date(' H:i', $event->time_start);
1215 - }
1216 - else{
1217 - _e('Pick a date','event-post');
1218 - }
1219 - ?>
1220 - </span>
1221 - <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"/>
1222 - </label>
1223 - <br>
1224 - <label for="<?php echo $this->META_END; ?>_date">
1225 - <?php _e('End:', 'event-post') ?>
1226 - <span id="<?php echo $this->META_END; ?>_date_human" class="human_date">
1227 - <?php
1228 - if ($event->time_start != '') {
1229 - echo $this->human_date($event->time_end) . date(' H:i', $event->time_end);
1230 - }
1231 - else{
1232 - _e('Pick a date','event-post');
1233 - }
1234 - ?>
1235 - </span>
1236 - <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"/>
1237 - </label>
1238 - </div>
1239 1439 <?php
1440 + do_action ('eventpost_custom_box_date', $event);
1240 1441 }
1241 1442 /**
1242 1443 * displays the location custom box
1243 1444 */
1244 - public function inner_custom_box_loc() {
1245 - $post_id = get_the_ID();
1246 - $event = $this->retreive($post_id);
1445 + public function inner_custom_box_loc($post) {
1446 + $event = $this->retreive($post);
1247 1447 ?>
1248 - <div class="misc-pub-section">
1249 - <p><a href="#event_address_search" id="event_address_search">
1250 - <span class="dashicons dashicons-search"></span>
1251 - <?php _e('Look for event\'s GPS coordinates:', 'event-post') ?>
1252 - </a>
1253 - <span id="eventaddress_result"></span>
1254 - </p>
1448 +
1449 + <div class="eventpost-misc-pub-section">
1255 1450 <label for="<?php echo $this->META_ADD; ?>">
1256 - <?php _e('Event address, as it will be displayed:', 'event-post') ?>
1257 - <textarea name="<?php echo $this->META_ADD; ?>" id="<?php echo $this->META_ADD; ?>"><?php echo $event->address ?></textarea>
1451 + <?php _e('Address, as it will be displayed:', 'event-post') ?>
1452 + <textarea name="<?php echo $this->META_ADD; ?>" id="<?php echo $this->META_ADD; ?>" class="widefat"><?php echo $event->address; ?></textarea>
1258 1453 </label>
1454 + </div>
1259 1455
1456 + <div id="event_address_searchwrap">
1457 + <span class="dashicons dashicons-location eventpost-edit-icon"></span>
1458 + <?php _e('GPS coordinates:', 'event-post') ?>
1459 + <a id="event_address_search" title="<?php _e('Search or fill exact coordinates', 'event-post') ?>">
1460 + <?php _e('Search / Edit', 'event-post') ?>
1461 + </a>
1462 +
1463 + <div class="misc-pub-section" id="event_address_coords">
1464 + <p>
1465 + <span id="eventaddress_result"></span>
1466 + </p>
1467 + <label for="<?php echo $this->META_LAT; ?>">
1468 + <?php _e('Latitude:', 'event-post') ?>
1469 + <input type="text" value ="<?php echo $event->lat; ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>" class="widefat"/>
1470 + </label>
1471 +
1472 + <label for="<?php echo $this->META_LONG; ?>">
1473 + <?php _e('Longitude:', 'event-post') ?>
1474 + <input type="text" value ="<?php echo $event->long; ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>" class="widefat"/>
1475 + </label>
1476 + <p>
1477 + <a id="event_address_unsearch" class="button button-small">
1478 + <span class="dashicons dashicons-yes"></span>
1479 + <?php _e('Done', 'event-post') ?>
1480 + </a>
1481 + </p>
1482 + </div>
1260 1483 </div>
1261 - <div class="misc-pub-section">
1262 - <label for="<?php echo $this->META_LAT; ?>">
1263 - <?php _e('Latitude:', 'event-post') ?>
1264 - <input type="text" value ="<?php echo $event->lat ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>"/>
1265 - </label>
1266 - </div>
1267 - <div class="misc-pub-section">
1268 - <label for="<?php echo $this->META_LONG; ?>">
1269 - <?php _e('Longitude:', 'event-post') ?>
1270 - <input type="text" value ="<?php echo $event->long ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>"/>
1271 - </label>
1272 - </div>
1273 - <div class="misc-pub-section">
1484 +
1485 + <div class="eventpost-misc-pub-section">
1274 1486 <div id="event-post-map-preview" data-marker="<?php echo $this->get_marker($event->color); ?>"></div>
1275 1487 </div>
1276 1488 <?php
1489 + do_action ('eventpost_custom_box_loc', $event);
1277 1490 $this->load_map_scripts();
1278 1491 }
1279 1492
1280 1493 /**
@@ -1308,13 +1521,13 @@
1308 1521 <?php
1309 1522 $cats = get_categories();
1310 1523 foreach ($cats as $cat) {
1311 1524 ?>
1312 - <option value="<?= $cat->slug ?>" <?php
1525 + <option value="<?php echo $cat->slug; ?>" <?php
1313 1526 if ($cat->slug == $eventpost_cat) {
1314 1527 echo'selected';
1315 1528 }
1316 - ?>><?= $cat->cat_name ?></option>
1529 + ?>><?php echo $cat->cat_name; ?></option>
1317 1530 <?php } ?>
1318 1531 </select>
1319 1532 </label>
1320 1533 </p>
@@ -1388,8 +1601,95 @@
1388 1601 <?php
1389 1602 }
1390 1603
1391 1604 /**
1605 + *
1606 + * @param string $column_name
1607 + * @param boolean $bulk
1608 + */
1609 + function quick_edit( $column_name, $post_type, $bulk=false) {
1610 +
1611 + if ($bulk) {
1612 + static $eventpostprintNonceBulk = TRUE;
1613 + if ($eventpostprintNonceBulk) {
1614 + $eventpostprintNonceBulk = FALSE;
1615 + }
1616 + $fields = $this->bulk_edit_fields;
1617 + echo '<input type="hidden" name="eventpost-bulk-editor" id="eventpost-bulk-editor" value="eventpost-bulk-editor">';
1618 + }
1619 + else {
1620 + static $eventpostprintNonce = TRUE;
1621 + if ($eventpostprintNonce) {
1622 + $eventpostprintNonce = FALSE;
1623 + }
1624 + $fields = $this->quick_edit_fields;
1625 + }
1626 + wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
1627 + if(isset($fields[$column_name])): ?>
1628 + <fieldset class="inline-edit-col-left inline-edit-<?php echo $column_name; ?>">
1629 + <div class="inline-edit-group">
1630 + <?php foreach ($fields[$column_name] as $fieldname=>$fieldlabel): ?>
1631 + <fieldset class="inline-edit-col inline-edit-<?php echo $fieldname; ?>">
1632 + <div class="inline-edit-col column-<?php echo $fieldname; ?>">
1633 + <label class="inline-edit-group">
1634 + <span class="title"><?php echo $fieldlabel; ?></span>
1635 + <span class="input-text-wrap">
1636 + <?php echo $this->inline_field($fieldname, $bulk); ?>
1637 + </span>
1638 + </label>
1639 + </div>
1640 + </fieldset>
1641 + <?php endforeach; ?>
1642 + </div>
1643 + </fieldset>
1644 + <?php endif;
1645 + }
1646 +
1647 + /**
1648 + *
1649 + * @param type $fieldname
1650 + * @return type
1651 + */
1652 + function inline_field($fieldname, $bulk){
1653 + return apply_filters('eventpost_inline_field', '<input name="'.$fieldname.'" class="eventpost-inline-'.$fieldname.'" value="" type="text">', $fieldname, $bulk);
1654 + }
1655 +
1656 + function inline_field_color($html, $fieldname, $bulk){
1657 + if($fieldname==$this->META_COLOR){
1658 + $colors = $this->get_colors();
1659 + $html='';
1660 + if($bulk){
1661 + $html.= '<span class="eventpost-bulk-colorpicker-button link">'.__('No Change', 'event-post').'</span>';
1662 + }
1663 + $html .= '<select name="'.$fieldname.'" class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'" >';
1664 + if($bulk){
1665 + $html.='<option value="false">— '.__('No Change', 'event-post').' —</option>';
1666 + }
1667 + foreach ($colors as $color=>$image_path){
1668 + $html.='<option value="'.$color.'" data-path="'.$image_path.'">'.$color.'</option>';
1669 + }
1670 + $html.= '</select>';
1671 + }
1672 + return $html;
1673 + }
1674 +
1675 + /**
1676 + *
1677 + * @param type $column_name
1678 + * @param type $post_type
1679 + */
1680 + function bulk_edit($column_name, $post_type){
1681 + $this->quick_edit($column_name, $post_type, true);
1682 + }
1683 +
1684 + /**
1685 + *
1686 + */
1687 + function inline_save(){
1688 + $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT);
1689 + $this->save_postdata($post_id);
1690 + }
1691 + /**
1392 1692 * When the post is saved, saves our custom data
1393 1693 * @param int $post_id
1394 1694 * @return void
1395 1695 */
@@ -1432,10 +1732,33 @@
1432 1732 delete_post_meta($post_id, $this->META_ADD);
1433 1733 delete_post_meta($post_id, $this->META_LAT);
1434 1734 delete_post_meta($post_id, $this->META_LONG);
1435 1735 }
1736 +
1737 + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array();
1436 1738 }
1437 1739
1740 + function save_bulkdatas() {
1741 + $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post';
1742 + if (in_array($current_post_type, $this->settings['posttypes'])) {
1743 + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array();
1744 + if (!empty($post_ids) && is_array($post_ids)) {
1745 + foreach ($this->bulk_edit_fields as $sets) {
1746 + foreach ($sets as $fieldname => $fieldlabel) {
1747 + if ((false != $value = filter_input(INPUT_POST, $fieldname))) {
1748 + foreach ($post_ids as $post_id) {
1749 + update_post_meta($post_id, $fieldname, $value);
1750 + }
1751 + }
1752 + }
1753 + }
1754 + }
1755 + wp_send_json(true);
1756 + exit;
1757 + }
1758 + wp_send_json(false);
1759 + }
1760 +
1438 1761 /**
1439 1762 *
1440 1763 * @param string $date
1441 1764 * @param string $cat
@@ -1452,9 +1775,9 @@
1452 1775 if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
1453 1776 $event->guid = '#';
1454 1777 }
1455 1778 $ret.='<li>'
1456 - . '<a href="' . $event->permalink . '">'
1779 + . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">'
1457 1780 . '<h4>' . $event->post_title . '</h4>'
1458 1781 .$this->get_single($event)
1459 1782 . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
1460 1783 .'</a>'
@@ -1464,9 +1787,9 @@
1464 1787 return $ret;
1465 1788 }
1466 1789 return'';
1467 1790 } else {
1468 - 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);
1791 + return $nb > 0 ? '<button data-date="' . date('Y-m-d', $date) . '" class="eventpost_cal_link"'.($colored?' style="background-color:#'.$events[0]->color.'"':'').' 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']))).'">' . date('j', $date) . '</button>' : date('j', $date);
1469 1792 }
1470 1793 }
1471 1794
1472 1795
@@ -1489,8 +1812,12 @@
1489 1812 $mois = substr($date, 5);
1490 1813
1491 1814 $time = mktime(0, 0, 0, $mois, 1, $annee);
1492 1815
1816 + $prev_year = strtotime('-1 Year', $time);
1817 + $next_year = strtotime('+1 Year', $time);
1818 + $prev_month = strtotime('-1 Month', $time);
1819 + $next_month = strtotime('+1 Month', $time);
1493 1820
1494 1821 $JourMax = date("t", $time);
1495 1822 $NoJour = -date("w", $time);
1496 1823 if ($mondayfirst == 0) {
@@ -1501,22 +1828,25 @@
1501 1828 }
1502 1829 if ($NoJour > 0 && $mondayfirst == 1) {
1503 1830 $NoJour -=7;
1504 1831 }
1505 - $ret = '<table class="event-post-calendar-table">';
1832 + $ret = '<table class="event-post-calendar-table">'
1833 + . '<caption class="screen-reader-text">'
1834 + . __('A calendar of events', 'event-post')
1835 + . '</caption>';
1836 + $ret.='<thead><tr><th colspan="7">';
1506 1837 if ($datepicker == 1) {
1507 - $ret.='<caption>';
1508 - $ret.='<a data-date="' . date('Y-n', strtotime('-1 Year', $time)) . '" class="eventpost_cal_bt">&lt;&lt;</a> ';
1838 + $ret.='<div>';
1839 + $ret.='<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">&lt;&lt;</button> ';
1509 1840 $ret.=$annee;
1510 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Year', $time)) . '" class="eventpost_cal_bt">&gt;&gt;</a> ';
1511 - $ret.='<a data-date="' . date('Y-n', strtotime('-1 Month', $time)) . '" class="eventpost_cal_bt">&lt;</a> ';
1512 - $ret.=$this->NomDuMois[$mois];
1513 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Month', $time)) . '" class="eventpost_cal_bt">&gt;</a> ';
1514 - $ret.='<a data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</a>';
1515 - $ret.='</caption>';
1841 + $ret.='<button data-date="' . date('Y-n', $next_year) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $next_year)).'" class="eventpost_cal_bt">&gt;&gt;</button> ';
1842 + $ret.='<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">&lt;</button> ';
1843 + $ret.=$this->NomDuMois[abs($mois)];
1844 + $ret.='<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">&gt;</button> ';
1845 + $ret.='<button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button>';
1846 + $ret.='</div>';
1516 1847 }
1517 - $ret.='<thead>';
1518 - $ret.='<tr class="event_post_cal_days">';
1848 + $ret.='</th></tr><tr class="event_post_cal_days">';
1519 1849 for ($w = 0; $w < 7; $w++) {
1520 1850 $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>';
1521 1851 }
1522 1852 $ret.='</tr>';
@@ -1529,11 +1859,14 @@
1529 1859 $ret.='<tr>';
1530 1860 for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
1531 1861 if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
1532 1862 $td = '<td class="event_post_day">';
1533 - if ($sqldate . '-' . $NoJour == $cejour) {
1863 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) {
1534 1864 $td = '<td class="event_post_day_now">';
1535 1865 }
1866 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){
1867 + $td = '<td class="event_post_day_over">'; // Patch ahf
1868 + }
1536 1869 $ret.=$td;
1537 1870
1538 1871 $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail);
1539 1872 $ret.='</td>';
@@ -1576,14 +1909,89 @@
1576 1909 */
1577 1910 public function HumanDate() {
1578 1911 if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
1579 1912 $date = strtotime($_REQUEST['date']);
1580 - echo $this->human_date($date, $this->settings['dateformat']) .' '. date($this->settings['timeformat'], $date);
1913 + echo $this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date));
1581 1914 exit();
1582 1915 }
1583 1916 }
1584 1917
1585 1918 /**
1919 + * Displays a search form
1920 + *
1921 + * @param type $atts
1922 + * @return type
1923 + */
1924 + public function search($atts) {
1925 + $params = shortcode_atts(apply_filters('eventpost_params', array(
1926 + 'dates' => true,
1927 + 'q' => true,
1928 + 'tax' => false,
1929 + ), 'search'), $atts);
1930 + $this->list_id++;
1931 +
1932 + $list_id = $this->list_id;
1933 + $q = (false !== $q = filter_input(INPUT_GET, 'q')) ? $q : '';
1934 + $from = (false !== $from = filter_input(INPUT_GET, 'from')) ? $from : '';
1935 + $to = (false !== $to = filter_input(INPUT_GET, 'to')) ? $to : '';
1936 + $tax = (false !== $tax = filter_input(INPUT_GET, 'tax')) ? $tax : '';
1937 +
1938 + $cleaned_from = $this->date_cleanup($from);
1939 + $cleaned_to = $this->date_cleanup($to);
1940 + if(empty($cleaned_from)){
1941 + $from=false;
1942 + }
1943 + if(empty($cleaned_to)){
1944 + $to=false;
1945 + }
1946 +
1947 + // Search form
1948 + $this->admin_scripts(null, true);
1949 + wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version);
1950 + include (plugin_dir_path(__FILE__) . 'views/search-form.php');
1951 +
1952 + // Results
1953 + if ($list_id == filter_input(INPUT_GET, 'evenpost_search')) {
1954 + $arg = array(
1955 + 'post_type' => $this->settings['posttypes'],
1956 + 'meta_key' => $this->META_START,
1957 + 'orderby' => 'meta_value',
1958 + 'order' => 'ASC',
1959 + 's' => $q
1960 + );
1961 + if ($tax) {
1962 + $arg['cat'] = $tax;
1963 + }
1964 +
1965 + if ($from || $to) {
1966 +
1967 + $arg['meta_query'] = array();
1968 + if ($from) {
1969 + $arg['meta_query'][] = array(
1970 + 'key' => $this->META_START,
1971 + 'value' => $from,
1972 + 'compare' => '>=',
1973 + 'type' => 'DATETIME'
1974 + );
1975 + }
1976 + if ($to) {
1977 + $arg['meta_query'][] = $meta_query = array(
1978 + array(
1979 + 'key' => $this->META_END,
1980 + 'value' => $to,
1981 + 'compare' => '<=',
1982 + 'type' => 'DATETIME'
1983 + ),
1984 + );
1985 + }
1986 + }
1987 + $events = new WP_Query($arg);
1988 + include (plugin_dir_path(__FILE__) . 'views/search-results.php');
1989 + wp_reset_query();
1990 + }
1991 + }
1992 +
1993 + /**
1586 1994 * AJAX Get lat long from address
1587 1995 */
1588 1996 public function GetLatLong() {
1589 1997 if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
@@ -1591,14 +1999,17 @@
1591 1999 $q = $_REQUEST['q'];
1592 2000 header('Content-Type: application/json');
1593 2001 $transient_name = 'eventpost_osquery_' . $q;
1594 2002 $val = get_transient($transient_name);
1595 - if (false === $val || empty($val)) {
2003 + if (false === $val || empty($val) || !is_string($val)) {
1596 2004 $language = get_bloginfo('language');
1597 2005 if (strpos($language, '-') > -1) {
1598 2006 $language = strtolower(substr($language, 0, 2));
1599 2007 }
1600 - $val = file_get_contents('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language);
2008 + $remote_val = wp_safe_remote_request('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language);
2009 + if(json_decode($remote_val['body'])){
2010 + $val = $remote_val['body'];
2011 + }
1601 2012 set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
1602 2013 }
1603 2014 echo $val;
1604 2015 exit();
@@ -1608,13 +2019,14 @@
1608 2019 /**
1609 2020 * alters columns
1610 2021 * @param array $defaults
1611 2022 * @return array
2023 + * @filter eventpost_columns_head
1612 2024 */
1613 2025 public function columns_head($defaults) {
1614 2026 $defaults['event'] = __('Event', 'event-post');
1615 2027 $defaults['location'] = __('Location', 'event-post');
1616 - return $defaults;
2028 + return apply_filters('eventpost_columns_head', $defaults);
1617 2029 }
1618 2030
1619 2031 /**
1620 2032 * echoes content of a row in a given column
@@ -1619,8 +2031,9 @@
1619 2031 /**
1620 2032 * echoes content of a row in a given column
1621 2033 * @param string $column_name
1622 2034 * @param int $post_id
2035 + * @action eventpost_columns_content
1623 2036 */
1624 2037 public function columns_content($column_name, $post_id) {
1625 2038 if ($column_name == 'location') {
1626 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
@@ -1626,62 +2039,65 @@
1626 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
1627 2040 $lon = get_post_meta($post_id, $this->META_LONG, true);
1628 2041
1629 2042 if (!empty($lat) && !empty($lon)) {
2043 + add_thickbox();
1630 2044 $color = get_post_meta($post_id, $this->META_COLOR, true);
1631 2045 if ($color == ''){
1632 2046 $color = '777777';
1633 2047 }
1634 - 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>';
2048 + echo '<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">'
2049 + . '<i class="dashicons dashicons-location" style="color:#'.$color.';"></i>'
2050 + . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>'
2051 + . get_post_meta($post_id, $this->META_ADD, true)
2052 + . '</a> ';
1635 2053 }
2054 + $this->column_edit_hidden_fields($post_id, 'location');
1636 2055 }
1637 2056 if ($column_name == 'event') {
1638 2057 echo $this->print_date($post_id, false);
2058 + $this->column_edit_hidden_fields($post_id, 'event');
1639 2059 }
2060 + do_action('eventpost_columns_content', $column_name, $post_id);
1640 2061 }
1641 2062
2063 + function column_edit_hidden_fields($post_id, $set){
2064 + $event = $this->retreive($post_id);
2065 + echo '<div class="hidden">';
2066 + foreach($this->quick_edit_fields[$set] as $fieldname=>$fieldlabel){
2067 + echo'<span class="inline-edit-value '.$fieldname.'">'.esc_attr($event->$fieldname).'</span>';
2068 + }
2069 + echo '</div>';
2070 + }
2071 +
1642 2072 /** ADMIN PAGES **/
1643 2073
1644 2074 /**
1645 - * save settings end redirect
1646 - * @return void
2075 + * Settings link on the plugins page
1647 2076 */
1648 - public function save_settings(){
1649 - if (!current_user_can('manage_options')){
1650 - return;
1651 - }
1652 - if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) {
1653 - wp_die(__('Security error', 'event-post'));
1654 - }
1655 -
1656 - $valid_post = array(
1657 - 'ep_settings'=>array(
1658 - 'filter' => FILTER_SANITIZE_STRING,
1659 - 'flags' => FILTER_REQUIRE_ARRAY
1660 - )
1661 - );
1662 -
1663 - foreach ($this->settings as $item_name=>$item_value){
1664 - $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING;
1665 - }
1666 -
1667 - $post_types=(array) $_POST['ep_settings']['posttypes'];
1668 - $posttypes = get_post_types();
1669 - foreach($post_types as $posttype){
1670 - if(!in_array($posttype, $posttypes)){
1671 - unset($post_types[$posttype]);
1672 - }
2077 + public function settings_link( $links ) {
2078 + $settings_link = '<a href="options-general.php?page=event-settings">' . __( 'Settings', 'event-post' ) . '</a>';
2079 + // place it before other links
2080 + array_unshift( $links, $settings_link );
2081 + return $links;
2082 + }
2083 + /**
2084 + *
2085 + * @param type $plugin_meta
2086 + * @param type $plugin_file
2087 + * @param type $plugin_data
2088 + * @param type $status
2089 + * @return type
2090 + */
2091 + public function row_meta($plugin_meta, $plugin_file, $plugin_data, $status){
2092 + if($plugin_file=='event-post/eventpost.php'){
2093 + $plugin_link = '<a href="http://event-post.com" target="_blank">' . __( 'Plugin site', 'event-post' ) . '</a>';
2094 + $review_link = '<a href="https://wordpress.org/support/plugin/event-post/reviews/#new-post" target="_blank">' . __( 'Give a note', 'event-post' ) . '</a>';
2095 + array_push($plugin_meta, $plugin_link, $review_link);
1673 2096 }
2097 + return $plugin_meta;
2098 + }
1674 2099
1675 - if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) {
1676 - $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']);
1677 - $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']);
1678 - $settings['ep_settings']['posttypes']= array_values($post_types);
1679 - update_option('ep_settings', $settings['ep_settings']);
1680 - }
1681 - wp_redirect('options-general.php?page=event-settings&confirm=options_saved');
1682 - exit;
1683 - }
1684 2100 /**
1685 2101 * adds menu items
1686 2102 */
1687 2103 public function manage_options() {
@@ -1704,307 +2120,332 @@
1704 2120 return $elements;
1705 2121 }
1706 2122
1707 2123 /**
1708 - * output content of the setting page
2124 + * @action eventpost_register_settings
1709 2125 */
1710 - public function manage_settings() {
1711 - if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?>
1712 - <div class="updated"><p><strong><?php _e('Event settings saved !', 'event-post') ?></strong></p></div>
1713 - <?php
1714 - }
1715 - $ep_settings = $this->settings;
1716 - ?>
1717 - <div class="wrap">
1718 - <div class="icon32" id="icon-options-general"><br></div>
1719 - <h1><?php _e('Event settings', 'event-post'); ?></h1>
1720 - <form name="form1" method="post" action="admin-post.php">
1721 - <input type="hidden" name="action" value="EventPostSaveSettings">
1722 - <?php wp_nonce_field('ep_nonce_settings','ep_nonce_settings') ?>
1723 - <h2><?php _e('Global settings', 'event-post'); ?></h2>
1724 - <table class="form-table" id="eventpost-settings-table-global">
1725 - <tbody>
1726 - <tr>
1727 - <th>
1728 - <label for="ep_emptylink">
1729 - <?php _e('Print link for empty posts', 'event-post') ?>
1730 - </label>
1731 - </th>
1732 - <td>
1733 - <select name="ep_settings[emptylink]" id="ep_emptylink">
1734 - <option value="1" <?php selected($ep_settings['emptylink'], 1, true);?>>
1735 - <?php _e('Link all posts', 'event-post'); ?>
1736 - </option>
1737 - <option value="0" <?php selected($ep_settings['emptylink'], 0, true);?>>
1738 - <?php _e('Do not link posts with empty content', 'event-post'); ?>
1739 - </option>
1740 - </select>
1741 - </td>
1742 - </tr>
1743 - <tr>
1744 - <th>
1745 - <label for="ep_singlepos">
1746 - <?php _e('Event bar position for single posts', 'event-post') ?>
1747 - </label>
1748 - </th>
1749 - <td>
1750 - <select name="ep_settings[singlepos]" id="ep_singlepos">
1751 - <option value="before" <?php selected($ep_settings['singlepos'], 'before', true); ?>>
1752 - <?php _e('Before the content', 'event-post'); ?>
1753 - </option>
1754 - <option value="after" <?php selected($ep_settings['singlepos'], 'after', true); ?>>
1755 - <?php _e('After the content', 'event-post'); ?>
1756 - </option>
1757 - </select>
1758 - </td>
1759 - </tr>
1760 - <tr>
1761 - <th>
1762 - <label for="ep_loopicons">
1763 - <?php _e('Add icons for events in the loop', 'event-post') ?>
1764 - </label>
1765 - </th>
1766 - <td>
1767 - <select name="ep_settings[loopicons]" id="ep_loopicons">
1768 - <option value="1" <?php selected($ep_settings['loopicons'],'1', true) ?>>
1769 - <?php _e('Yes', 'event-post'); ?></option>
1770 - <option value="0" <?php selected($ep_settings['loopicons'],'0', true) ?>>
1771 - <?php _e('No', 'event-post'); ?></option>
1772 - </select>
1773 - </td>
1774 - </tr>
1775 - <tr>
1776 - <th>
1777 - <label for="ep_adminpos">
1778 - <?php _e('Position of event details boxes', 'event-post') ?>
1779 - </label>
1780 - </th>
1781 - <td>
1782 - <select name="ep_settings[adminpos]" id="ep_adminpos">
1783 - <option value="side" <?php selected($ep_settings['adminpos'],'side', true) ?>>
1784 - <?php _e('Side', 'event-post'); ?></option>
1785 - <option value="normal" <?php selected($ep_settings['adminpos'],'normal', true) ?>>
1786 - <?php _e('Under the text', 'event-post'); ?></option>
1787 - </select>
1788 - </td>
1789 - </tr>
1790 - </tbody>
1791 - </table><!-- #eventpost-settings-table-global -->
2126 + public function register_settings(){
2127 + register_setting( 'eventpost-settings', 'ep_settings' );
1792 2128
1793 - <h2><?php _e('Date settings', 'event-post'); ?></h2>
1794 - <table class="form-table" id="eventpost-settings-table-event">
1795 - <tbody>
1796 - <tr>
1797 - <th>
1798 - <label for="ep_dateformat">
1799 - <?php _e('Date format', 'event-post') ?>
1800 - </label>
1801 - </th>
1802 - <td>
1803 - <input type="text" name="ep_settings[dateformat]" id="ep_dateformat" value="<?php echo $ep_settings['dateformat']; ?>" size="10">
1804 - </td>
1805 - </tr>
1806 - <tr>
1807 - <th>
1808 - <label for="ep_timeformatformat">
1809 - <?php _e('Time format', 'event-post') ?>
1810 - </label>
1811 - </th>
1812 - <td>
1813 - <input type="text" name="ep_settings[timeformat]" id="ep_dateformat" value="<?php echo $ep_settings['timeformat']; ?>" size="10">
1814 - </td>
1815 - </tr>
1816 - <tr>
1817 - <th>
1818 - <label for="ep_dateexport">
1819 - <?php _e('Show export buttons on:', 'event-post') ?>
1820 - </label>
1821 - </th>
1822 - <td>
1823 - <select name="ep_settings[export]" id="ep_dateexport">
1824 - <option value="list" <?php selected($ep_settings['export'], 'list', true);?>>
1825 - <?php _e('List only', 'event-post') ?>
1826 - </option>
1827 - <option value="single" <?php selected($ep_settings['export'], 'single', true);?>>
1828 - <?php _e('Single only', 'event-post') ?>
1829 - </option>
1830 - <option value="both" <?php selected($ep_settings['export'], 'both', true);?>>
1831 - <?php _e('Both', 'event-post') ?>
1832 - </option>
1833 - <option value="none" <?php selected($ep_settings['export'], 'none', true);?>>
1834 - <?php _e('None', 'event-post') ?>
1835 - </option>
1836 - </select>
1837 - </td>
1838 - </tr>
1839 - <tr>
1840 - <th>
1841 - <label for="ep_dateforhumans">
1842 - <?php _e('Relative human dates:', 'event-post') ?>
1843 - </label>
1844 - </th>
1845 - <td>
1846 - <select name="ep_settings[dateforhumans]" id="ep_dateforhumans">
1847 - <option value="1" <?php selected($ep_settings['dateforhumans'], '1', true);?>>
1848 - <?php _e('Yes', 'event-post') ?>
1849 - </option>
1850 - <option value="0" <?php selected($ep_settings['dateforhumans'], '0', true);?>>
1851 - <?php _e('No', 'event-post') ?>
1852 - </option>
1853 - </select>
1854 - <p class="description"><?php _e('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post') ?></p>
1855 - </td>
1856 - </tr>
1857 - </tbody>
1858 - </table><!-- #eventpost-settings-table-event -->
2129 + // Global
2130 + add_settings_section(
2131 + 'eventpost-settings-general',
2132 + '<span class="dashicons dashicons-admin-appearance"></span>&nbsp;'.__('Global settings', 'event-post'),
2133 + array(&$this, 'settings_section_callback'),
2134 + 'eventpost-settings'
2135 + );
2136 + //--
2137 + add_settings_field(
2138 + 'emptylink',
2139 + __('Print link for empty posts', 'event-post'),
2140 + array(&$this, 'settings_field_select_callback'),
2141 + 'eventpost-settings',
2142 + 'eventpost-settings-general',
2143 + array( 'name' => 'emptylink', 'options'=>array(
2144 + 1=>__('Link all posts', 'event-post'),
2145 + 0=>__('Do not link posts with empty content', 'event-post')
2146 + )
2147 + )
2148 + );
2149 + add_settings_field(
2150 + 'singlepos',
2151 + __('Event bar position for single posts', 'event-post'),
2152 + array(&$this, 'settings_field_select_callback'),
2153 + 'eventpost-settings',
2154 + 'eventpost-settings-general',
2155 + array( 'name' => 'singlepos', 'options'=>array(
2156 + 'before'=>__('Before the content', 'event-post'),
2157 + 'after'=>__('After the content', 'event-post'),
2158 + 'none'=>__('Not displayed', 'event-post')
2159 + ) )
2160 + );
2161 + add_settings_field(
2162 + 'loopicons',
2163 + __('Add icons for events in the loop', 'event-post'),
2164 + array(&$this, 'settings_field_select_callback'),
2165 + 'eventpost-settings',
2166 + 'eventpost-settings-general',
2167 + array( 'name' => 'loopicons', 'options'=>array(
2168 + 1=>__('Emojis', 'event-post'),
2169 + 0=>__('Hide', 'event-post'),
2170 + 2=>__('Icons', 'event-post')
2171 + ) )
2172 + );
2173 + add_settings_field(
2174 + 'customcss',
2175 + __('Use this custom CSS file', 'event-post'),
2176 + array(&$this, 'settings_field_default_callback'),
2177 + 'eventpost-settings',
2178 + 'eventpost-settings-general',
2179 + array( 'name' => 'customcss', 'description'=>sprintf(__('Leave empty to use the <a href="%s" target="_blank">default CSS file</a>.', 'event-post'), plugins_url('/css/eventpost.min.css', __FILE__)).'<br>'
2180 + . (is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')
2181 + ? __('Your theme contains an <code>event-post.css</code> file. It will be used as default stylesheet.', 'event-post')
2182 + : __('You can also add a <code>event-post.css</code> in your theme directory. It will be used as default stylesheet.', 'event-post')))
2183 + );
1859 2184
1860 - <h2><?php _e('List settings', 'event-post'); ?></h2>
1861 - <table class="form-table" id="eventpost-settings-table-list">
1862 - <tbody>
1863 - <tr>
1864 - <th>
1865 - <label for="ep_container_shema">
1866 - <?php _e('Container shema', 'event-post') ?>
1867 - </label>
1868 - </th>
1869 - <td>
1870 - <textarea class="widefat" name="ep_settings[container_shema]" id="ep_container_shema"><?php echo $ep_settings['container_shema']; ?></textarea>
1871 - <p><?php _e('default:','event-post') ?></p>
1872 - <code><?php echo htmlentities($this->default_list_shema['container']) ?></code>
1873 - </td>
1874 - </tr>
1875 - <tr>
1876 - <th>
1877 - <label for="ep_item_shema">
1878 - <?php _e('Item shema', 'event-post') ?>
1879 - </label>
1880 - </th>
1881 - <td>
1882 - <textarea class="widefat" name="ep_settings[item_shema]" id="ep_item_shema"><?php echo $ep_settings['item_shema']; ?></textarea>
1883 - <p><?php _e('default:','event-post') ?></p>
1884 - <code><?php echo htmlentities($this->default_list_shema['item']) ?></code>
1885 - </td>
1886 - </tr>
1887 - </tbody>
1888 - </table><!-- #eventpost-settings-table-list -->
2185 + // Date
2186 + add_settings_section(
2187 + 'eventpost-settings-date',
2188 + '<span class="dashicons dashicons-clock"></span>&nbsp;'.__('Date settings', 'event-post'),
2189 + array(&$this, 'settings_section_callback'),
2190 + 'eventpost-settings'
2191 + );
2192 + //--
2193 + add_settings_field(
2194 + 'dateformat',
2195 + __('Date format', 'event-post'),
2196 + array(&$this, 'settings_field_default_callback'),
2197 + 'eventpost-settings',
2198 + 'eventpost-settings-date',
2199 + array( 'name' => 'dateformat')
2200 + );
2201 + add_settings_field(
2202 + 'timeformat',
2203 + __('Time format', 'event-post'),
2204 + array(&$this, 'settings_field_default_callback'),
2205 + 'eventpost-settings',
2206 + 'eventpost-settings-date',
2207 + array( 'name' => 'timeformat')
2208 + );
2209 + add_settings_field(
2210 + 'export',
2211 + __('Show export buttons on:', 'event-post'),
2212 + array(&$this, 'settings_field_select_callback'),
2213 + 'eventpost-settings',
2214 + 'eventpost-settings-date',
2215 + array( 'name' => 'export', 'options'=>array(
2216 + 'list'=>__('List only', 'event-post'),
2217 + 'single'=>__('Single only', 'event-post'),
2218 + 'both'=>__('Both', 'event-post'),
2219 + 'none'=>__('None', 'event-post'),
2220 + ) )
2221 + );
2222 + add_settings_field(
2223 + 'dateforhumans',
2224 + __('Relative human dates:', 'event-post'),
2225 + array(&$this, 'settings_field_select_callback'),
2226 + 'eventpost-settings',
2227 + 'eventpost-settings-date',
2228 + array( 'name' => 'dateforhumans',
2229 + 'description'=>__('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post'),
2230 + 'options'=>array(
2231 + 1=>__('Yes', 'event-post'),
2232 + 0=>__('No', 'event-post'),
2233 + ) )
2234 + );
1889 2235
1890 - <h2><?php _e('Map settings', 'event-post'); ?></h2>
1891 - <table class="form-table" id="eventpost-settings-table-map">
1892 - <tbody>
1893 - <tr>
1894 - <th>
1895 - <label for="ep_tile">
1896 - <?php _e('Map background', 'event-post') ?>
1897 - </label>
1898 - </th>
1899 - <td>
1900 - <select name="ep_settings[tile]" id="ep_tile">
1901 - <?php foreach ($this->maps as $map): ?>
1902 - <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
1903 - <?php echo $map['name']; ?>
1904 - </option>
1905 - <?php endforeach; ?>
1906 - </select></td>
1907 - </tr>
1908 - <tr>
1909 - <th>
1910 - <?php _e('Makers custom directory (leave empty for default settings)', 'event-post') ?>
1911 - </th>
1912 - <td>
1913 - <label for="ep_markpath">
1914 - <?php _e('Root path:', 'event-post') ?><br>
1915 - ABSPATH/<input name="ep_settings[markpath]" id="ep_markpath" value="<?php echo $this->settings['markpath'] ?>" class="widefat">
1916 - </label><br>
1917 - <label for="ep_markurl">
1918 - <?php _e('URL:', 'event-post') ?><br>
1919 - <input name="ep_settings[markurl]" id="ep_markurl" value="<?php echo $this->settings['markurl'] ?>" class="widefat">
1920 - </label>
1921 - </td>
1922 - </tr>
1923 - </tbody>
1924 - </table><!-- #eventpost-settings-table-map -->
2236 + // List
2237 + add_settings_section(
2238 + 'eventpost-settings-list',
2239 + '<span class="dashicons dashicons-editor-ul"></span>&nbsp;'.__('List settings', 'event-post'),
2240 + array(&$this, 'settings_section_callback'),
2241 + 'eventpost-settings'
2242 + );
2243 + //--
2244 + add_settings_field(
2245 + 'container_shema',
2246 + __('Container shema', 'event-post'),
2247 + array(&$this, 'settings_field_textarea_callback'),
2248 + 'eventpost-settings',
2249 + 'eventpost-settings-list',
2250 + array( 'name' => 'container_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities($this->default_list_shema['container']).'</code>')
2251 + );
2252 + add_settings_field(
2253 + 'item_shema',
2254 + __('Container shema', 'event-post'),
2255 + array(&$this, 'settings_field_textarea_callback'),
2256 + 'eventpost-settings',
2257 + 'eventpost-settings-list',
2258 + array( 'name' => 'item_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities($this->default_list_shema['item']).'</code>')
2259 + );
1925 2260
1926 - <h2><?php _e('Admin UI settings', 'event-post'); ?></h2>
1927 - <table class="form-table" id="eventpost-settings-table-admin">
1928 - <tbody>
1929 - <tr>
1930 - <th>
1931 - <label for="ep_posttypes">
1932 - <?php _e('Wich post types can be events ?', 'event-post') ?>
1933 - </label>
1934 - </th>
1935 - <td><?php $posttypes = get_post_types(array(), 'objects'); ?>
1936 - <?php foreach($posttypes as $posttype): ?>
1937 - <p>
1938 - <label>
1939 - <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) ?>>
1940 - <?php echo $posttype->labels->name; ?>
1941 - </label>
1942 - </p>
1943 - <?php endforeach; ?>
1944 - </td>
1945 - </tr>
1946 - <tr>
1947 - <th>
1948 - <?php _e('Datepicker style', 'event-post') ?>
1949 - <?php $now = current_time('mysql'); ?>
1950 - <?php $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); ?>
1951 - </th>
1952 - <td>
1953 - <p>
1954 - <label>
1955 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="dual" <?php checked($ep_settings['datepicker'],'dual', true) ?>>
1956 - <?php _e('Dual', 'event-post'); ?>
1957 - </label>
1958 - <span id="eventpost_dual_date_human" class="human_date">
1959 - <?php echo $human_date; ?>
1960 - </span>
1961 - <input type="text" class="eventpost-datepicker-dual" id="eventpost_dual_date" value="<?php echo $now; ?>">
1962 - </p>
1963 - <p>
1964 - <label>
1965 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="separate" <?php checked($ep_settings['datepicker'],'separate', true) ?>>
1966 - <?php _e('Separate', 'event-post'); ?>
1967 - </label>
1968 - <span id="eventpost_separate_date_human" class="human_date">
1969 - <?php echo $human_date; ?>
1970 - </span>
1971 - <input type="text" class="eventpost-datepicker-separate" id="eventpost_separate_date" value="<?php echo $now; ?>">
1972 - </p>
1973 - <p>
1974 - <label>
1975 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="browser" <?php checked($ep_settings['datepicker'],'browser', true) ?>>
1976 - <?php _e('Browser\'s style', 'event-post'); ?>
1977 - </label>
1978 - <input type="datetime" class="eventpost-datepicker-browser" value="<?php echo $now; ?>">
1979 - </p>
1980 - </td>
1981 - </tr>
1982 - </tbody>
1983 - </table><!-- #eventpost-settings-table-admin -->
2261 + // Map
2262 + add_settings_section(
2263 + 'eventpost-settings-map',
2264 + '<span class="dashicons dashicons-location-alt"></span>&nbsp;'.__('Map settings', 'event-post'),
2265 + array(&$this, 'settings_section_callback'),
2266 + 'eventpost-settings'
2267 + );
2268 + //--
2269 + $maps = array();
2270 + foreach ($this->maps as $map){
2271 + $maps[$map['id']]=$map['name'].(isset($map['urls_retina']) ? ' '.__('(Retina support)', 'event-post') : '');
2272 + }
2273 + add_settings_field(
2274 + 'tile',
2275 + __('Map background', 'event-post'),
2276 + array(&$this, 'settings_field_select_callback'),
2277 + 'eventpost-settings',
2278 + 'eventpost-settings-map',
2279 + array( 'name' => 'tile', 'options'=>$maps)
2280 + );
2281 + add_settings_field(
2282 + 'zoom',
2283 + __('Default zoom', 'event-post'),
2284 + array(&$this, 'settings_field_default_callback'),
2285 + 'eventpost-settings',
2286 + 'eventpost-settings-map',
2287 + array( 'name' => 'zoom')
2288 + );
2289 + add_settings_field(
2290 + 'markpath',
2291 + __('Makers custom directory after <code>ABSPATH/</code>', 'event-post'),
2292 + array(&$this, 'settings_field_default_callback'),
2293 + 'eventpost-settings',
2294 + 'eventpost-settings-map',
2295 + array( 'name' => 'markpath', 'description'=>__('(leave empty for default settings)','event-post'))
2296 + );
2297 + add_settings_field(
2298 + 'markurl',
2299 + __('Makers custom directory URL', 'event-post'),
2300 + array(&$this, 'settings_field_default_callback'),
2301 + 'eventpost-settings',
2302 + 'eventpost-settings-map',
2303 + array( 'name' => 'markurl', 'description'=>__('(leave empty for default settings)','event-post'))
2304 + );
1984 2305
1985 - <h2><?php _e('Performances settings', 'event-post'); ?></h2>
1986 - <table class="form-table" id="eventpost-settings-table-perfs">
1987 - <tbody>
1988 - <tr>
1989 - <th>
1990 - <?php _e('Use cache', 'event-post') ?>
1991 - </th>
1992 - <td>
1993 - <label for="ep_cache">
1994 - <input type="checkbox" name="ep_settings[cache]" id="ep_cache" <?php if($ep_settings['cache']=='1'){ echo'checked';} ?> value="1">
1995 - <?php _e('Use cache for results','event-post')?>
1996 - </label>
1997 - </td>
1998 - </tr>
1999 - </tbody>
2000 - </table><!-- #eventpost-settings-table-perfs -->
2306 + // Admin
2307 + add_settings_section(
2308 + 'eventpost-settings-admin',
2309 + '<span class="dashicons dashicons-admin-generic"></span>&nbsp;'.__('Admin settings', 'event-post'),
2310 + array(&$this, 'settings_section_callback'),
2311 + 'eventpost-settings'
2312 + );
2313 + //--
2314 + add_settings_field(
2315 + 'adminpos',
2316 + __('Position of event details boxes', 'event-post'),
2317 + array(&$this, 'settings_field_select_callback'),
2318 + 'eventpost-settings',
2319 + 'eventpost-settings-admin',
2320 + array( 'name' => 'adminpos', 'options'=>array(
2321 + 'side'=>__('Side', 'event-post'),
2322 + 'normal'=>__('Under the text', 'event-post'),
2323 + ) )
2324 + );
2325 + $post_types = array();
2326 + $posttypes = apply_filters('eventpost_get_post_types', get_post_types(array(), 'objects'));
2327 + foreach($posttypes as $type=>$posttype){
2328 + $post_types[$posttype->name]=$posttype->labels->name;
2329 + }
2330 + add_settings_field(
2331 + 'posttypes',
2332 + __('Wich post types can be events?', 'event-post'),
2333 + array(&$this, 'settings_field_checkbox_callback'),
2334 + 'eventpost-settings',
2335 + 'eventpost-settings-admin',
2336 + array( 'name' => 'posttypes', 'options'=>$post_types)
2337 + );
2338 + add_settings_field(
2339 + 'datepicker',
2340 + __('Datepicker style', 'event-post'),
2341 + array(&$this, 'settings_field_datepicker_callback'),
2342 + 'eventpost-settings',
2343 + 'eventpost-settings-admin',
2344 + array( 'name' => 'datepicker')
2345 + );
2346 + add_settings_field(
2347 + 'cache',
2348 + __('Use cache', 'event-post'),
2349 + array(&$this, 'settings_field_default_callback'),
2350 + 'eventpost-settings',
2351 + 'eventpost-settings-admin',
2352 + array( 'name' => 'cache', 'description'=>__('Use cache for results','event-post'))
2353 + );
2001 2354
2002 - <p class="submit">
2003 - <input type="submit" value="<?php _e('Apply settings', 'event-post'); ?>" class="button button-primary" id="submit" name="submit">
2004 - </p>
2005 - <?php do_action('eventpost_settings_form'); ?>
2355 + do_action('eventpost_register_settings');
2356 + }
2357 + function settings_section_callback( $arg ) {
2358 + echo '<hr>';
2359 + }
2006 2360
2361 + function settings_field_default_callback($args){
2362 + ?>
2363 + <input name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" value="<?php echo $this->settings[$args['name']]; ?>" class="regular-text"/>
2364 + <?php if(isset($args['description']) && $args['description']): ?>
2365 + <p class="description"><?php echo $args['description']; ?></p>
2366 + <?php endif; ?>
2367 + <?php
2368 + }
2369 + function settings_field_textarea_callback($args){
2370 + ?>
2371 + <textarea name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" class="regular-text"><?php echo $this->settings[$args['name']]; ?></textarea>
2372 + <?php if(isset($args['description']) && $args['description']): ?>
2373 + <p class="description"><?php echo $args['description']; ?></p>
2374 + <?php endif; ?>
2375 + <?php
2376 + }
2377 + function settings_field_select_callback($args){
2378 + ?>
2379 + <select name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" class="">
2380 + <?php foreach($args['options'] as $value=>$label) : ?>
2381 + <option value="<?php echo $value; ?>" <?php selected($value, $this->settings[$args['name']], true);?>><?php echo $label; ?></option>
2382 + <?php endforeach; ?>
2383 + </select>
2384 + <?php if(isset($args['description']) && $args['description']): ?>
2385 + <p class="description"><?php echo $args['description']; ?></p>
2386 + <?php endif; ?>
2387 + <?php
2388 + }
2389 + function settings_field_checkbox_callback($args){
2390 + ?>
2391 + <?php foreach($args['options'] as $value=>$label) : ?>
2392 + <p>
2393 + <label>
2394 + <input type="checkbox" name="ep_settings[<?php echo $args['name']; ?>][<?php echo $value; ?>]" value="<?php echo $value; ?>" <?php checked(in_array($value, $this->settings[$args['name']]),true, true) ?>>
2395 + <?php echo $label; ?>
2396 + </label>
2397 + </p>
2398 + <?php endforeach; ?>
2399 + <?php if(isset($args['description']) && $args['description']): ?>
2400 + <p class="description"><?php echo $args['description']; ?></p>
2401 + <?php endif; ?>
2402 + <?php
2403 + }
2404 + function settings_field_datepicker_callback($args){
2405 + $now = current_time('mysql');
2406 + $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp'));
2407 + ?>
2408 + <div>
2409 + <label>
2410 + <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_simple" value="simple" <?php checked($this->settings['datepicker'],'simple', true) ?>>
2411 + <?php _e('Simple', 'event-post'); ?>
2412 + </label>
2413 + <p>
2414 + <span id="eventpost_simple_date_human" class="human_date">
2415 + <?php echo $human_date; ?>
2416 + </span>
2417 + <input type="text" class="eventpost-datepicker-simple" id="eventpost_simple_date" value="<?php echo $now; ?>">
2418 + </p>
2419 + </div>
2420 + <div>
2421 + <label>
2422 + <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_native" value="native" <?php checked($this->settings['datepicker'],'native', true) ?>>
2423 + <?php _e('Native WordPress style', 'event-post'); ?>
2424 + </label>
2425 + <p>
2426 + <span id="eventpost_native_date_human" class="human_date">
2427 + <?php echo $human_date; ?>
2428 + </span>
2429 + <input type="text" class="eventpost-datepicker-native" id="eventpost_native_date" value="<?php echo $now; ?>">
2430 + </p>
2431 + </div>
2432 + <?php
2433 + }
2434 + /**
2435 + * output content of the setting page
2436 + */
2437 + public function manage_settings() {
2438 + $ep_settings = $this->settings;
2439 + ?>
2440 + <div class="wrap">
2441 + <?php screen_icon(); ?>
2442 + <h2><?php _e('Event settings', 'event-post'); ?></h2>
2443 + <form action="options.php" method="post">
2444 + <?php settings_fields( 'eventpost-settings' ); ?>
2445 + <?php do_settings_sections('eventpost-settings'); ?>
2446 + <?php do_action('eventpost_settings_form', $ep_settings); ?>
2447 + <?php submit_button(); ?>
2007 2448 </form>
2008 2449 </div>
2009 2450 <?php
2010 2451 do_action('eventpost_after_settings_form');
@@ -2020,47 +2461,91 @@
2020 2461 * @param timestamp $timestamp
2021 2462 * @return string
2022 2463 */
2023 2464 public function ics_date($timestamp){
2024 - return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z';
2465 + return date("Ymd",$timestamp).'T'.date("His",$timestamp);
2025 2466 }
2026 2467
2468 + public function get_gmt_offset(){
2469 + $gmt_offset = get_option('gmt_offset ');
2470 + $codegmt = 0;
2471 + if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
2472 + $codegmt = $gmt_offset * -1;
2473 + $gmt_offset = '+' . $gmt_offset;
2474 + }
2475 + if(abs($gmt_offset < 10)){
2476 + $gmt_offset = substr($gmt_offset, 0, 1).'0'.substr($gmt_offset, 1);
2477 + }
2478 + return $gmt_offset;
2479 + }
2480 +
2027 2481 /**
2028 - * outputs an RSS document
2482 + * outputs an ICS document
2029 2483 */
2030 2484 public function feed(){
2031 2485 if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){
2032 - $timezone_string = get_option('timezone_string');
2033 - date_default_timezone_set($timezone_string);
2486 + $vtz = get_option('timezone_string');
2487 + $gmt = $this->get_gmt_offset();
2488 + date_default_timezone_set($vtz);
2489 + $separator = "\n";
2034 2490
2035 - header("content-type:text/calendar");
2491 + header("content-type:text/x-icalendar");
2036 2492 header("Pragma: public");
2037 2493 header("Expires: 0");
2038 2494 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
2039 2495 header("Cache-Control: public");
2040 2496 header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" );
2041 - echo"BEGIN:VCALENDAR\r\n"
2042 - . "PRODID:EventPost\r\n"
2043 - . "VERSION:2.0\r\n"
2044 - . "BEGIN:VTIMEZONE\r\n"
2045 - . "TZID:$timezone_string\r\n"
2046 - . "X-LIC-LOCATION:$timezone_string\r\n"
2047 - . "END:VTIMEZONE";
2048 2497
2049 - $events=$this->get_events(array('cat'=>$cat,'nb'=>-1));
2498 + $props = array();
2499 +
2500 + // General
2501 + $props[] = 'BEGIN:VCALENDAR';
2502 + $props[] = 'PRODID://WordPress//Event-Post V'. file_get_contents(('VERSION')).'//EN';
2503 + $props[] = 'VERSION:2.0';
2504 +
2505 + // Timezone
2506 + if(!empty($vtz)){
2507 + array_push($props,
2508 + 'BEGIN:VTIMEZONE',
2509 + 'TZID:'.$vtz,
2510 + 'BEGIN:DAYLIGHT',
2511 + 'TZOFFSETFROM:+0100',
2512 + 'TZOFFSETTO:'.($gmt).'00',
2513 + 'DTSTART:19700329T020000',
2514 + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3',
2515 + 'END:DAYLIGHT',
2516 + 'BEGIN:STANDARD',
2517 + 'TZOFFSETFROM:'.($gmt).'00',
2518 + 'TZOFFSETTO:+0100',
2519 + 'TZNAME:CET',
2520 + 'DTSTART:19701025T030000',
2521 + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10',
2522 + 'END:STANDARD',
2523 + 'END:VTIMEZONE'
2524 + );
2525 + }
2526 +
2527 + // Events
2528 + $events=$this->get_events(array('cat'=>$cat,'nb'=>-1));
2050 2529 foreach ($events as $event) {
2051 - echo"BEGIN:VEVENT\r\n"
2052 - . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n"
2053 - . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n"
2054 - . "SUMMARY:".$event->post_title."\r\n"
2055 - . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n"
2056 - . "LOCATION:".str_replace(',','\,',$event->address)."\r\n"
2057 - . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n"
2058 - . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n"
2059 - . "DESCRIPTION:".$event->guid."\r\n"
2060 - . "END:VEVENT\r\n";
2061 - }
2062 - echo"END:VCALENDAR\r\n";
2063 - exit;
2530 + array_push($props,
2531 + 'BEGIN:VEVENT',
2532 + 'CREATED:'.$this->ics_date(strtotime($event->post_date)).'Z',
2533 + 'LAST-MODIFIED:'.$this->ics_date(strtotime($event->post_modified)).'Z',
2534 + 'SUMMARY:'.$event->post_title,
2535 + 'UID:'.md5(site_url()."_eventpost_".$event->ID),
2536 + 'LOCATION:'.str_replace(',','\,',$event->address),
2537 + 'DTSTART'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'),
2538 + 'DTEND'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_end).(!empty($vtz)?'':'Z'),
2539 + 'DESCRIPTION:'.$event->guid,
2540 + 'END:VEVENT'
2541 + );
2542 + }
2543 +
2544 + // End
2545 + $props[] = 'END:VCALENDAR';
2546 +
2547 + echo implode($separator, $props);
2548 + exit;
2064 2549 }
2065 2550 }
2066 -}
2551 +}