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 +1268 -999 4.05.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.0.0
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,11 +12,18 @@
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
21 +/**
22 + * The main class where everything begins.
23 + *
24 + * Add calendar and/or geolocation metadata on posts
25 + */
19 26 class EventPost {
20 27 const META_START = 'event_begin';
21 28 const META_END = 'event_end';
22 29 const META_COLOR = 'event_color';
@@ -30,20 +37,26 @@
30 37 public $Week;
31 38 public $settings;
32 39 public $dateformat;
33 40
34 - public $version = '4.0.0';
41 + public $version = '4.5';
35 42
36 43 public $map_interactions;
44 + public $quick_edit_fields;
37 45
46 + public $Shortcodes;
47 +
38 48 public function __construct() {
39 49 load_plugin_textdomain('event-post', false, 'event-post/languages');
40 50
51 + add_action('widgets_init', array(&$this,'init'), 1);
41 52 add_action('save_post', array(&$this, 'save_postdata'));
42 53 add_action('admin_menu', array(&$this, 'manage_options'));
43 - add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
54 + add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
44 55
45 56 // Scripts
57 + add_action( 'admin_init', array(&$this, 'editor_styles'));
58 + add_action( 'admin_init', array(&$this, 'register_settings'));
46 59 add_action('admin_enqueue_scripts', array(&$this, 'admin_head'));
47 60 add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
48 61 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
49 62
@@ -48,9 +61,9 @@
48 61 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
49 62
50 63 // Single
51 64 add_filter('the_content', array(&$this, 'display_single'), 9999);
52 - add_filter('the_title', array(&$this, 'the_title'), 9999);
65 + add_filter('the_title', array(&$this, 'the_title'), 9999, 2);
53 66 add_action('the_event', array(&$this, 'print_single'));
54 67 add_action('wp_head', array(&$this, 'single_header'));
55 68
56 69 // Ajax
@@ -64,26 +77,53 @@
64 77 // Calendar publishing
65 78 add_action('wp_ajax_EventPostFeed', array(&$this, 'feed'));
66 79 add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed'));
67 80
68 - //Shortcodes
69 - add_action('init', array(&$this,'init'));
70 - add_shortcode('events_list', array(&$this, 'shortcode_list'));
71 - add_shortcode('events_map', array(&$this, 'shortcode_map'));
72 - add_shortcode('events_cal', array(&$this, 'shortcode_cal'));
73 - add_shortcode('event_details', array(&$this, 'shortcode_single'));
74 81 //
75 - add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
82 + add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
76 83
77 84 // Admin
78 - 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);
79 87
80 - include_once (plugin_dir_path(__FILE__) . 'widget.php');
81 - include_once (plugin_dir_path(__FILE__) . 'widget.cal.php');
82 - include_once (plugin_dir_path(__FILE__) . 'widget.map.php');
83 - include_once (plugin_dir_path(__FILE__) . 'multisite.php');
88 + add_action('widgets_init', array(&$this, 'register_widgets'),1,1);
84 89
85 - $this->META_START = 'event_begin';
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);
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 +
108 + }
109 +
110 + /**
111 + * PHP4 constructor
112 + */
113 + public function EventPost(){
114 + $this->__construct();
115 + }
116 +
117 + /**
118 + * Init all variables when WP is ready
119 + *
120 + * @action evenpost_init
121 + * @filter eventpost_default_list_shema
122 + * @filter eventpost_list_shema
123 + */
124 + public function init(){
125 + $this->META_START = 'event_begin';
86 126 $this->META_END = 'event_end';
87 127 $this->META_COLOR = 'event_color';
88 128 // http://codex.wordpress.org/Geodata
89 129 $this->META_ADD = 'geo_address';
@@ -95,9 +135,12 @@
95 135
96 136 $this->maps = $this->get_maps();
97 137 $this->settings = $this->get_settings();
98 138
139 + do_action('evenpost_init', $this);
99 140
141 + $this->Shortcodes = new EventPost_Shortcodes();
142 +
100 143 // Edit
101 144 add_action('add_meta_boxes', array(&$this, 'add_custom_box'));
102 145 foreach($this->settings['posttypes'] as $posttype){
103 146 add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2);
@@ -114,25 +157,24 @@
114 157 }
115 158
116 159 $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post'));
117 160
118 - $this->default_list_shema = array(
161 + $this->default_list_shema = apply_filters('eventpost_default_list_shema', array(
119 162 'container' => '
120 - <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>
121 - %list%
122 - </%type%>',
163 + <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>%list%
164 + </%type%><!-- .event_loop -->',
123 165 'item' => '
124 - <%child% class="event_item %class%" data-color="%color%">
125 - <a href="%event_link%">
126 - %event_thumbnail%
127 - <h5>%event_title%</h5>
128 - </a>
129 - %event_date%
130 - %event_cat%
131 - %event_location%
132 - %event_excerpt%
133 - </%child%>'
134 - );
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 + ));
135 177 $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema);
136 178
137 179 $this->map_interactions=array(
138 180 'DragRotate'=>__('Drag Rotate', 'event-post'),
@@ -145,26 +187,38 @@
145 187 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'),
146 188 'DragZoom'=>__('Drag Zoom', 'event-post'),
147 189 );
148 190
149 - }
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 + );
150 210
151 - /**
152 - * PHP4 constructor
153 - */
154 - public function EventPost(){
155 - $this->__construct();
156 211 }
157 212
158 - /**
159 - * Call functions when WP is ready
160 - */
161 - public function init(){
162 - $this->shortcode_ui();
213 + public function register_widgets(){
214 + register_widget('EventPost_List');
215 + register_widget('EventPost_Map');
216 + register_widget('EventPost_Cal');
163 217 }
164 218
165 219 /**
166 - * @desc Usefull hexadecimal to decimal converter
220 + * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color.
167 221 * @param string $color
168 222 * @return array $color($R, $G, $B)
169 223 */
170 224 public function hex2dec($color = '000000') {
@@ -177,9 +231,9 @@
177 231 $tbl_color['B'] = hexdec(substr($color, 5, 2));
178 232 return $tbl_color;
179 233 }
180 234 /**
181 - *
235 + * Fetch all registered image sizes
182 236 * @global array $_wp_additional_image_sizes
183 237 * @return array
184 238 */
185 239 function get_thumbnail_sizes(){
@@ -184,9 +238,9 @@
184 238 */
185 239 function get_thumbnail_sizes(){
186 240 global $_wp_additional_image_sizes;
187 241 $sizes = array('thumbnail', 'medium', 'large', 'full');
188 - foreach($_wp_additional_image_sizes as $size=>$attrs){
242 + foreach(array_keys($_wp_additional_image_sizes) as $size){
189 243 $sizes[]=$size;
190 244 }
191 245 return $sizes;
192 246 }
@@ -191,9 +245,9 @@
191 245 return $sizes;
192 246 }
193 247
194 248 /**
195 - * Just for localisation
249 + * Just for localization
196 250 */
197 251 private function no_use() {
198 252 __('Add calendar and/or geolocation metadata on posts', 'event-post');
199 253 __('Event Post', 'event-post');
@@ -199,10 +253,13 @@
199 253 __('Event Post', 'event-post');
200 254 }
201 255
202 256 /**
203 - * @desc get blog settings, load and saves default settings id needed
204 - * @action eventpost_getsettings
257 + * Get blog settings, load and saves default settings if needed. Can be filterred using
258 + *
259 + * `<?php add_filter('eventpost_getsettings', 'some_function'); ?>`
260 + *
261 + * @action eventpost_getsettings_action
205 262 * @filter eventpost_getsettings
206 263 * @return array
207 264 */
208 265 public function get_settings() {
@@ -223,8 +280,12 @@
223 280 $maps = array_keys($this->maps);
224 281 $ep_settings['tile'] = $this->maps[$maps[0]]['id'];
225 282 $reg_settings=true;
226 283 }
284 + if(!isset($ep_settings['zoom']) || !is_numeric($ep_settings['zoom'])){
285 + $ep_settings['zoom']=12;
286 + $reg_settings=true;
287 + }
227 288 if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) {
228 289 $ep_settings['cache'] = 0;
229 290 $reg_settings=true;
230 291 }
@@ -243,8 +304,16 @@
243 304 if (!isset($ep_settings['markpath'])) {
244 305 $ep_settings['markpath'] = '';
245 306 $reg_settings=true;
246 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 + }
247 316 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
248 317 $ep_settings['singlepos'] = 'after';
249 318 $reg_settings=true;
250 319 }
@@ -265,10 +334,10 @@
265 334 $ep_settings['item_shema'] = '';
266 335 $reg_settings=true;
267 336 }
268 337
269 - if(!isset($ep_settings['datepicker'])){
270 - $ep_settings['datepicker']='dual';
338 + if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){
339 + $ep_settings['datepicker']='simple';
271 340 $reg_settings=true;
272 341 }
273 342
274 343 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
@@ -275,9 +344,9 @@
275 344 $ep_settings['posttypes']=array('post');
276 345 $reg_settings=true;
277 346 }
278 347
279 - do_action('eventpost_getsettings');
348 + do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings));
280 349
281 350 //Save settings not changed
282 351 if($reg_settings===true){
283 352 update_option('ep_settings', $ep_settings);
@@ -285,9 +354,9 @@
285 354 return apply_filters('eventpost_getsettings', $ep_settings);
286 355 }
287 356
288 357 /**
289 - *
358 + * Checks if HTML schemas are not empty
290 359 * @param array $shema
291 360 * @return array
292 361 */
293 362 public function custom_shema($shema){
@@ -300,26 +369,41 @@
300 369 return $shema;
301 370 }
302 371
303 372 /**
373 + * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example:
304 374 *
305 - * @return array
375 + * ```
376 + * <?php
377 + * add_filter('eventpost_getsettings', 'map_function');
378 + * function map_function($maps){
379 + * array_push($maps, array(
380 + * 'name'=>'Myt custom map',
381 + * 'id'=>'custom_map',
382 + * 'urls'=>array(
383 + * 'http://a.customurl.org/{z}/{x}/{y}.png',
384 + * 'http://b.customurl.org/{z}/{x}/{y}.png',
385 + * 'http://c.customurl.org/{z}/{x}/{y}.png',
386 + * )
387 + * ));
388 + * return $maps;
389 + * }
390 + * ?>
391 + * ```
392 + *
393 + * @filter eventpost_maps
394 + * @return array of map arrays ['name', 'id', 'urls']
306 395 */
307 396 public function get_maps() {
308 397 $maps = array();
309 - if (is_file(plugin_dir_path(__FILE__) . 'maps.csv')) {
310 - $map_f = fopen(plugin_dir_path(__FILE__) . 'maps.csv', 'r');
311 - $map_s = explode("\n", fread($map_f, filesize(plugin_dir_path(__FILE__) . 'maps.csv')));
312 - foreach ($map_s as $map) {
313 - $map = explode(';', $map);
314 - if (sizeof($map >= 5)) {
315 - $maps[$map[1]] = array(
316 - 'name' => $map[0],
317 - 'id' => $map[1],
318 - 'urls' => array($map[2], $map[3], $map[4]),
319 - );
320 - }
398 + $filename = plugin_dir_path(__FILE__) . 'maps.json';
399 + if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) {
400 + // Convert objects to array to ensure retrocompatibility
401 + $arrays = array();
402 + foreach($json as $map){
403 + $arrays[$map->id] = (array) $map;
321 404 }
405 + $maps = apply_filters('eventpost_maps', $arrays);
322 406 }
323 407 return $maps;
324 408 }
325 409
@@ -356,25 +440,42 @@
356 440 * Enqueue CSS files
357 441 */
358 442 public function load_styles() {
359 443 //CSS
360 - wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
361 - wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
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
362 456 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
363 - wp_enqueue_style('dashicons-css', includes_url('/css/dashicons.min.css'));
457 + wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css'));
364 458 }
459 + /**
460 + * Enqueue Editor style
461 + */
462 + public function editor_styles() {
463 + add_editor_style( plugins_url('/css/eventpost.min.css', __FILE__) );
464 + }
365 465
366 466 /**
367 467 * Enqueue JS files
368 468 */
369 - public function load_scripts() {
469 + public function load_scripts($deps = array('jquery')) {
370 470 // JS
371 471 wp_enqueue_script('jquery', false, false, false, true);
372 - wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), false, $this->version, true);
472 + wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), $deps, $this->version, true);
373 473 wp_localize_script('event-post', 'eventpost_params', array(
374 474 'imgpath' => plugins_url('/img/', __FILE__),
375 475 'maptiles' => $this->maps,
376 476 'defaulttile' => $this->settings['tile'],
477 + 'zoom' => $this->settings['zoom'],
377 478 'ajaxurl' => admin_url() . 'admin-ajax.php',
378 479 'map_interactions'=>$this->map_interactions,
379 480 ));
380 481 }
@@ -382,10 +483,13 @@
382 483 * Enqueue JS files for maps
383 484 */
384 485 public function load_map_scripts() {
385 486 // JS
386 - $this->load_scripts();
387 487 wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true);
488 + $this->load_scripts(array('jquery', 'openlayers'));
489 + if(is_admin()){
490 + $this->admin_scripts(array('jquery', 'openlayers'));
491 + }
388 492 }
389 493
390 494 /**
391 495 * Enqueue CSS files in admin
@@ -390,37 +494,64 @@
390 494 /**
391 495 * Enqueue CSS files in admin
392 496 */
393 497 public function admin_head() {
498 + $page = basename($_SERVER['SCRIPT_NAME']);
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') ){
500 + return;
501 + }
502 + wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
394 503 wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version);
395 - wp_enqueue_style('eventpostadmin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version);
396 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
397 - wp_enqueue_style('eventpost-datetimepicker', plugins_url('/css/jquery.datetimepicker.css', __FILE__), false, $this->version);
398 - }
504 + wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version);
399 505 }
400 506
401 507 /**
402 508 * Enqueue JS files in admin
403 509 */
404 - public function admin_scripts() {
510 + public function admin_scripts($deps = array('jquery'), $force=false) {
511 + $page = basename($_SERVER['SCRIPT_NAME']);
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')){
513 + return;
514 + }
405 515 wp_enqueue_script('jquery');
406 - wp_enqueue_script('eventpost-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), array('jquery'), $this->version, true);
407 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
408 - wp_enqueue_script('eventpost-datetimepicker', plugins_url('/js/jquery.datetimepicker.js', __FILE__), array('jquery'), $this->version, true);
516 + wp_enqueue_script('jquery-effects-core');
517 + wp_enqueue_script('jquery-effects-shake');
518 + if(!is_array($deps)){
519 + $deps = array('jquery');
409 520 }
410 - 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')){
411 522 wp_enqueue_script('jquery-ui-datepicker');
523 + $deps[] = 'jquery-ui-datepicker';
412 524 }
525 + wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true);
413 526 $language = get_bloginfo('language');
414 527 if (strpos($language, '-') > -1) {
415 528 $language = strtolower(substr($language, 0, 2));
416 529 }
417 - wp_localize_script('eventpost-admin', 'eventpost', array(
530 + wp_localize_script('event-post-admin', 'eventpost', array(
531 + 'ajaxurl' => admin_url('admin-ajax.php'),
418 532 'imgpath' => plugins_url('/img/', __FILE__),
419 - 'date_choose' => __('Choose', 'event-post'),
533 + 'date_choose' => '<span class="screen-reader-text">'.__('Choose', 'event-post').'</span><i class="dashicons dashicons-calendar-alt"></i>',
420 534 'date_format' => __('yy-mm-dd', 'event-post'),
421 535 'more_icons' => __('More icons', 'event-post'),
422 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 + ),
423 554 'META_START' => $this->META_START,
424 555 'META_END' => $this->META_END,
425 556 'META_ADD' => $this->META_ADD,
426 557 'META_LAT' => $this->META_LAT,
@@ -425,13 +556,26 @@
425 556 'META_ADD' => $this->META_ADD,
426 557 'META_LAT' => $this->META_LAT,
427 558 'META_LONG' => $this->META_LONG,
428 559 'lang'=>$language,
560 + 'maptiles' => $this->maps,
561 + 'defaulttile' => $this->settings['tile']
429 562 ));
430 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 + }
431 575
432 576 /**
433 - * @desc Add custom header meta for single events
577 + * Add custom header meta for single events
434 578 */
435 579 public function single_header() {
436 580 if (is_single()) {
437 581 $event = $this->retreive();
@@ -439,15 +583,17 @@
439 583 ?>
440 584 <meta name="geo.placename" content="<?php echo $event->address ?>" />
441 585 <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
442 586 <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
443 - <?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
444 590 }
445 591 if ($event->start != '' && $event->end != '') {
446 592 ?>
447 593 <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" />
448 594 <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" />
449 - <?php
595 +<?php
450 596 }
451 597 }
452 598 }
453 599
@@ -452,13 +598,23 @@
452 598 }
453 599
454 600 /**
455 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 + *
456 612 * @param string $str
457 613 * @return boolean
458 614 */
459 615 public function dateisvalid($str) {
460 - return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != '';
616 + return is_string($str) && $this->date_cleanup($str) != '';
461 617 }
462 618
463 619 /**
464 620 *
@@ -494,8 +650,54 @@
494 650 }
495 651
496 652 /**
497 653 *
654 + * @param timestamp $time_start
655 + * @param timestamp $time_end
656 + * @return string
657 + */
658 + public function delta_date($time_start, $time_end){
659 + if(!$time_start || !$time_end){
660 + return;
661 + }
662 +
663 + //Display dates
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) . '">'
667 + . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>";
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') {
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>';
673 + }
674 + elseif (date('H:i', $time_start) != '00:00') {
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>';
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 + }
692 + $dates.='</time>';
693 + }
694 + $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->';
695 + return $dates;
696 + }
697 +
698 + /**
699 + *
498 700 * @param WP_Post object $post
499 701 * @param mixed $links
500 702 * @return string
501 703 */
@@ -501,41 +703,14 @@
501 703 */
502 704 public function print_date($post = null, $links = 'deprecated', $context='') {
503 705 $dates = '';
504 706 $event = $this->retreive($post);
505 - $start_date = $event->start;
506 - $end_date = $post->end;
507 707 if ($event->start != '' && $event->end != '') {
508 - $gmt_offset = get_option('gmt_offset ');
708 +
709 + $dates.=$this->delta_date($event->time_start, $event->time_end);
710 +
509 711 $timezone_string = get_option('timezone_string');
510 - $codegmt = 0;
511 - if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
512 - $codegmt = $gmt_offset * -1;
513 - $gmt_offset = '+' . $gmt_offset;
514 - }
515 - //Display dates
516 - $dates.='<div class="event_date" data-start="' . $this->human_date($event->time_start) . '" data-end="' . $this->human_date($event->time_end) . '">';
517 - if (date('d/m/Y', $event->time_start) == date('d/m/Y', $event->time_end)) {
518 - $dates.= '<time itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">'
519 - . '<span class="date date-single">' . $this->human_date($event->time_end, $this->settings['dateformat']) . "</span>";
520 - if (date('H:i', $event->time_start) != date('H:i', $event->time_end) && date('H:i', $event->time_start) != '00:00' && date('H:i', $event->time_end) != '00:00') {
521 - $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
522 - <span class="time time-start">' . date($this->settings['timeformat'], $event->time_start) . '</span>
523 - <span class="linking_word linking_word-t">' . __('to', 'event-post') . '</span>
524 - <span class="time time-end">' . date($this->settings['timeformat'], $event->time_end) . '</span>';
525 - } elseif (date('H:i', $event->time_start) != '00:00') {
526 - $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span>
527 - <span class="time time-single" itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">' . date($this->settings['timeformat'], $event->time_start) . '</span>';
528 - }
529 - $dates.='</time>';
530 - } else {
531 - $dates.= '
532 - <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
533 - <span class="date date-start" itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">' . $this->human_date($event->time_start, $this->settings['dateformat']) . '</span>
534 - <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span>
535 - <span class="date date-end" itemprop="dtend" datetime="' . date('c', $event->time_end) . '">' . $this->human_date($event->time_end, $this->settings['dateformat']) . '</span>
536 - ';
537 - }
712 + $gmt_offset = $gmt = $this->get_gmt_offset();
538 713
539 714 if (!is_admin() && $event->time_end > current_time('timestamp') && (
540 715 $this->settings['export'] == 'both' ||
541 716 ($this->settings['export'] == 'single' && is_single() ) ||
@@ -540,37 +715,63 @@
540 715 $this->settings['export'] == 'both' ||
541 716 ($this->settings['export'] == 'single' && is_single() ) ||
542 717 ($this->settings['export'] == 'list' && !is_single() )
543 718 )) {
719 +
544 720 // Export event
545 721 $title = urlencode($post->post_title);
546 722 $address = urlencode($post->address);
547 723 $url = urlencode($post->guid);
548 -
549 - $mt = strtotime($codegmt . ' Hours', $event->time_start);
550 - $d_s = date("Ymd", $mt) . 'T' . date("His", $mt);
551 - $mte = strtotime($codegmt . ' Hours', $event->time_end);
552 - $d_e = date("Ymd", $mte) . 'T' . date("His", $mte);
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));
553 727 $uid = $post->ID . '-' . $post->blog_id;
554 728
555 729 // format de date ICS
556 - $ics_url = plugins_url('export/ics.php', __FILE__) . '?t=' . $title . '&amp;u=' . $uid . '&amp;sd=' . $d_s . '&amp;ed=' . $d_e . '&amp;a=' . $address . '&amp;d=' . $url . '&amp;tz=%3BTZID%3D' . urlencode($timezone_string);
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__));
557 740
558 741 // format de date Google cal
559 - $google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&amp;text=' . $title . '&amp;dates=' . $d_s . 'Z/' . $d_e . 'Z&amp;details=' . $url . '&amp;location=' . $address . '&amp;trp=false&amp;sprop=&amp;sprop=name';
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');
560 754
561 755 // format de date VCS
562 - $vcs_url = plugins_url('export/vcs.php', __FILE__) . '?t=' . $title . '&amp;u=' . $uid . '&amp;sd=' . $d_s . '&amp;ed=' . $d_e . '&amp;a=' . $address . '&amp;d=' . $url . '&amp;tz=%3BTZID%3D' . urlencode($timezone_string);
563 -
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__));
564 766 $dates.='
565 - <span class="eventpost-date-export">
566 - <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a>
567 - <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a>
568 - <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a>
569 - <i class=" dashicons-before dashicons-calendar"></i>
570 - </span>';
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>';
571 773 }
572 - $dates.='</div>';
573 774 }
574 775 return apply_filters('eventpost_printdate', $dates);
575 776 }
576 777
@@ -594,17 +795,20 @@
594 795 $long = $post->long;
595 796 $color = $post->color;
596 797
597 798 if ($address != '' || ($lat != '' && $long != '')) {
598 - $location.='<address';
799 + $location.="\t\t\t\t".'<address';
599 800 if ($lat != '' && $long != '') {
600 801 $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" ';
601 802 }
602 - $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>';
603 807 if ($context=='single' && $lat != '' && $long != '') {
604 - $location.='<a class="event_link gps dashicons-before dashicons-location-alt" href="https://www.openstreetmap.org/?lat=' . $lat.='&amp;lon=' . $long.='&amp;zoom=13" target="_blank" itemprop="geo">' . __('Map', 'event-post') . '</a>';
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>';
605 809 }
606 - $location.='</address>';
810 + $location.="\n\t\t\t\t\t\t".'</address>';
607 811 }
608 812
609 813 return apply_filters('eventpost_printlocation', $location);
610 814 }
@@ -625,9 +829,9 @@
625 829 }
626 830 $cats = '';
627 831 $categories = $post->categories;
628 832 if ($categories) {
629 - $cats.='<span class="event_category"';
833 + $cats.="\t\t\t\t".'<span class="event_category"';
630 834 $color = $post->color;
631 835 if ($color != '') {
632 836 $cats.=' style="color:#' . $color . '"';
633 837 }
@@ -640,11 +844,12 @@
640 844 return $cats;
641 845 }
642 846
643 847 /**
644 - * @desc Generate, return or output date event datas
848 + * Generate, return or output date event datas
645 849 * @param WP_Post object $post
646 850 * @param string $class
851 + * @filter eventpost_get_single
647 852 * @return string
648 853 */
649 854 public function get_single($post = null, $class = '', $context='') {
650 855 if ($post == null) {
@@ -654,71 +859,69 @@
654 859 $datas_cat = $this->print_categories($post, $context);
655 860 $datas_loc = $this->print_location($post, $context);
656 861 if ($datas_date != '' || $datas_loc != '') {
657 862 $rgb = $this->hex2dec($post->color);
658 - return '<div class="event_data ' . $class . '" style="border-left-color:#' . $post->color . ';background:rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ',0.1)" itemscope itemtype="http://microformats.org/profile/hcard">' . $datas_date . $datas_cat . $datas_loc . '</div>';
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>';
659 866 }
660 867 return '';
661 868 }
662 869
663 870 /**
664 - *
871 + * Displays dates of a gieven post
665 872 * @param WP_Post object $post
666 873 * @param string $class
667 874 * @return string
668 875 */
669 876 public function get_singledate($post = null, $class = '', $context='') {
670 - return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_date($post, null, $context) . '</div>';
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 -->';
671 878 }
672 879
673 880 /**
674 - *
881 + * Displays coloured terms of a given post
675 882 * @param WP_Post object $post
676 883 * @param string $class
677 884 * @return string
678 885 */
679 886 public function get_singlecat($post = null, $class = '', $context='') {
680 - return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_categories($post, $context) . '</div>';
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 -->';
681 888 }
682 889
683 890 /**
684 - *
891 + * Displays location of a given post
685 892 * @param WP_Post object $post
686 893 * @param string $class
687 894 * @return string
688 895 */
689 896 public function get_singleloc($post = null, $class = '', $context='') {
690 - return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_location($post, $context) . '</div>';
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 -->';
691 898 }
692 899
693 900 /**
694 - *
901 + * Uses `the_content` filter to add event details before or after the content of the current post
695 902 * @param string $content
696 903 * @return string
697 904 */
698 905 public function display_single($content) {
699 - if (is_page() || !is_single() || is_home())
906 + if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){
700 907 return $content;
701 - $post = get_queried_object();
702 - //Prevent from filters applying "the_content" on another thing than the current post content
703 - remove_filter('the_content', array(&$this, 'display_single'), 9999);
704 - $current_content = apply_filters('the_content', $post->post_content);
705 - if ($current_content == $content) {
706 - $post = $this->retreive();
707 - if($this->settings['singlepos']=='before'){
708 - $content=$this->get_single($post, 'event_single', 'single').$content;
709 - }
710 - else{
711 - $content.=$this->get_single($post, 'event_single', 'single');
712 - }
713 - $this->load_map_scripts();
714 908 }
715 - 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();
716 919 return $content;
717 920 }
718 921
719 922 /**
720 - *
923 + * Outputs events details (dates, geoloc, terms) of given post
721 924 * @param WP_Post object $post
722 925 * @echoes string
723 926 * @return void
724 927 */
@@ -726,169 +929,45 @@
726 929 echo $this->get_single($post);
727 930 }
728 931
729 932 /**
730 - * the_title
731 - * @desc alter the post title in order to add icons if needed
933 + * Alter the post title in order to add icons if needed
732 934 * @param string $title
733 935 * @return string
734 936 */
735 - public function the_title($title){
736 - 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']){
737 939 return $title;
738 940 }
739 - $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);
740 949 if(!empty($event->start)){
741 - $title .= ' <span class="dashicons dashicons-calendar"></span>';
950 + $title .= ' '.$icons_[$this->settings['loopicons']][0];
742 951 }
743 952 if(!empty($event->lat) && !empty($event->long)){
744 - $title .= ' <span class="dashicons dashicons-location"></span>';
953 + $title .= ' '.$icons_[$this->settings['loopicons']][1];
745 954 }
746 955 return $title;
747 956 }
748 957
749 - /**
750 - * shortcode_single
751 - * @param array $atts
752 - * @filter : eventpost_params
753 - * @return string
754 - */
755 - public function shortcode_single($atts){
756 - extract(shortcode_atts(apply_filters('eventpost_params', array(
757 - 'attribute' => '',
758 - ), 'shortcode_single'), $atts));
759 - $event = $this->retreive();
760 - switch($attribute){
761 - case 'start':
762 - return $this->human_date($event->time_start);
763 - case 'end':
764 - return $this->human_date($event->time_end);
765 - case 'address':
766 - return $event->address;
767 - case 'location':
768 - return $this->get_singleloc($event, '', 'single');
769 - case 'date':
770 - return $this->get_singledate($event, '', 'single');
771 - default:
772 - return $this->get_single($event, '', 'single');
773 - }
774 - }
775 958
776 959 /**
777 - * @desc Shortcode to display a list of events
778 - * @param array $atts
779 - * @filter eventpost_params
780 - * @return string
781 - */
782 - public function shortcode_list($atts) {
783 - $atts = shortcode_atts(apply_filters('eventpost_params', array(
784 - 'nb' => 0,
785 - 'type' => 'div',
786 - 'future' => true,
787 - 'past' => false,
788 - 'geo' => 0,
789 - 'width' => '',
790 - 'height' => 'auto',
791 - 'title' => '',
792 - 'before_title' => '<h3>',
793 - 'after_title' => '</h3>',
794 - 'cat' => '',
795 - 'tag' => '',
796 - 'thumbnail' => '',
797 - 'thumbnail_size' => '',
798 - 'excerpt' => '',
799 - 'style' => '',
800 - 'orderby' => 'meta_value',
801 - 'order' => 'ASC',
802 - 'container_schema' => $this->list_shema['container'],
803 - 'item_schema' => $this->list_shema['item'],
804 - ), 'shortcode_list'), $atts);
805 -
806 - if ($atts['container_schema'] != $this->list_shema['container'])
807 - $atts['container_schema'] = html_entity_decode($atts['container_schema']);
808 - if ($atts['item_schema'] != $this->list_shema['item'])
809 - $atts['item_schema'] = html_entity_decode($atts['item_schema']);
810 - return $this->list_events($atts, 'event_list', 'shortcode');
811 - }
812 -
813 - /**
814 - * @desc Shortcode to display a map of events
815 - * @param array $atts
816 - * @filter eventpost_params
817 - * @return string
818 - */
819 - public function shortcode_map($atts) {
820 - $ep_settings = $this->settings;
821 -
822 - $defaults = array(
823 - // Display
824 - 'width' => '',
825 - 'height' => '',
826 - 'tile' => $ep_settings['tile'],
827 - 'title' => '',
828 - 'before_title' => '<h3>',
829 - 'after_title' => '</h3>',
830 - 'style' => '',
831 - 'thumbnail' => '',
832 - 'thumbnail_size' => '',
833 - 'excerpt' => '',
834 - // Filters
835 - 'nb' => 0,
836 - 'future' => true,
837 - 'past' => false,
838 - 'cat' => '',
839 - 'tag' => '',
840 - 'orderby' => 'meta_value',
841 - 'order' => 'ASC',
842 - );
843 - // UI options
844 - foreach($this->map_interactions as $int_key=>$int_name){
845 - $defaults[$int_key]=true;
846 - }
847 - // - UI options
848 - foreach($this->map_interactions as $int_key=>$int_name){
849 - $defaults['disable_'.strtolower($int_key)]=false;
850 - }
851 -
852 - $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $atts);
853 - // UI options
854 - foreach($this->map_interactions as $int_key=>$int_name){
855 - if($atts['disable_'.strtolower($int_key)]==true){
856 - $atts[$int_key]=false;
857 - }
858 - unset($atts['disable_'.strtolower($int_key)]);
859 - }
860 - $atts['geo'] = 1;
861 - $atts['type'] = 'div';
862 - return $this->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
863 - }
864 -
865 - /**
866 - * @desc Shortcode to display a calendar of events
867 - * @param array $atts
868 - * @filter eventpost_params
869 - * @return string
870 - */
871 - public function shortcode_cal($atts) {
872 - $this->load_scripts();
873 - $ep_settings = $this->settings;
874 - $atts = shortcode_atts(apply_filters('eventpost_params', array(
875 - 'date' => date('Y-n'),
876 - 'cat' => '',
877 - 'mondayfirst' => 0, //1 : weeks starts on monday
878 - 'datepicker' => 1
879 - ), 'shortcode_cal'), $atts);
880 - extract($atts);
881 - return '<div class="eventpost_calendar" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '">' . $this->calendar($atts) . '</div>';
882 - }
883 -
884 - /**
885 - * @desc Return an HTML list of events
886 - * @param array $atts
887 - * @filter eventpost_params
960 + * Return an HTML list of events
961 + *
962 + * @filter eventpost_params($defaults, 'list_events')
888 963 * @filter eventpost_listevents
889 964 * @filter eventpost_item_scheme_entities
890 965 * @filter eventpost_item_scheme_values
966 + *
967 + * @param array $atts
968 + * @param string $id
969 + * @param string $context
891 970 * @return string
892 971 */
893 972 public function list_events($atts, $id = 'event_list', $context='') {
894 973 $ep_settings = $this->settings;
@@ -899,8 +978,9 @@
899 978 'past' => false,
900 979 'geo' => 0,
901 980 'width' => '',
902 981 'height' => '',
982 + 'zoom' => '',
903 983 'tile' => $ep_settings['tile'],
904 984 'title' => '',
905 985 'before_title' => '<h3>',
906 986 'after_title' => '</h3>',
@@ -929,11 +1009,8 @@
929 1009 }
930 1010 $ret = '';
931 1011 $this->list_id++;
932 1012 if (sizeof($events) > 0) {
933 - if($id=='event_geolist'){
934 - $this->load_map_scripts();
935 - }
936 1013 if (!empty($title)) {
937 1014 $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title);
938 1015 }
939 1016
@@ -940,14 +1017,21 @@
940 1017 $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div';
941 1018
942 1019 $list = '';
943 1020
944 - foreach ($events as $post) { //$post=get_post($item_id);
945 - $item_id = $post->ID;
946 - $class_item = ($post->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past';
947 - if ($ep_settings['emptylink'] == 0 && empty($post->post_content)) {
948 - $post->permalink = '#' . $id . $this->list_id;
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;
949 1030 }
1031 + elseif(empty($ob->permalink)){
1032 + $event->permalink=$event->guid;
1033 + }
950 1034 $list.=str_replace(
951 1035 apply_filters('eventpost_item_scheme_entities', array(
952 1036 '%child%',
953 1037 '%class%',
@@ -961,22 +1045,22 @@
961 1045 '%event_excerpt%'
962 1046 )), apply_filters('eventpost_item_scheme_values', array(
963 1047 $child,
964 1048 $class_item,
965 - $post->color,
966 - $post->permalink,
967 - $thumbnail == true ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($post->ID, !empty($thumbnail_size) ? $thumbnail_size : 'thumbnail', array('class' => 'attachment-thumbnail wp-post-image event_thumbnail')) . '</span>' : '',
968 - $post->post_title,
969 - $this->get_singledate($post, '', $context),
970 - $this->get_singlecat($post, '', $context),
971 - $this->get_singleloc($post, '', $context),
972 - $excerpt == true && $post->post_excerpt!='' ? '<span class="event_exerpt">'.$post->post_excerpt.'</span>' : '',
973 - )), $item_schema
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
974 1058 );
975 1059 }
976 1060 $attributes = '';
977 1061 if($id == 'event_geolist'){
978 - $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="';
979 1063 foreach($this->map_interactions as $int_key=>$int_name){
980 1064 $attributes.=$atts[$int_key]==false ? $int_key.', ' : '';
981 1065 }
982 1066 $attributes.='"';
@@ -1000,15 +1084,19 @@
1000 1084 $list
1001 1085 ), $container_schema
1002 1086 );
1003 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 + }
1004 1091 return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
1005 1092 }
1006 1093
1007 1094 /**
1008 1095 * get_events
1009 - * @param array $attr
1010 - * @filter eventpost_params
1096 + * @param array $atts
1097 + * @filter eventpost_params
1098 + * @filter eventpost_get_items
1011 1099 * @return array of post_ids wich are events
1012 1100 */
1013 1101 public function get_events($atts) {
1014 1102 $requete = (shortcode_atts(apply_filters('eventpost_params', array(
@@ -1019,9 +1107,12 @@
1019 1107 'cat' => '',
1020 1108 'tag' => '',
1021 1109 'date' => '',
1022 1110 'orderby' => 'meta_value',
1111 + 'orderbykey' => $this->META_START,
1023 1112 'order' => 'ASC',
1113 + 'tax_name' => '',
1114 + 'tax_term' => '',
1024 1115 'post_type'=> $this->settings['posttypes']
1025 1116 ), 'get_events'), $atts));
1026 1117 extract($requete);
1027 1118 wp_reset_query();
@@ -1028,13 +1119,26 @@
1028 1119
1029 1120 $arg = array(
1030 1121 'post_type' => $post_type,
1031 1122 'posts_per_page' => $nb,
1032 - 'meta_key' => $this->META_START,
1123 + 'meta_key' => $orderbykey,
1033 1124 'orderby' => $orderby,
1034 1125 'order' => $order
1035 1126 );
1036 1127
1128 + if($tax_name=='category'){
1129 + $tax_name='';
1130 + $cat=$tax_term;
1131 + }
1132 + elseif($tax_name=='post-tag'){
1133 + $tax_name='';
1134 + $tag=$tax_term;
1135 + }
1136 +
1137 + // CUSTOM TAXONOMY
1138 + if ($tax_name != '' && $tax_term != '') {
1139 + $arg[$tax_name] = $tax_term;
1140 + }
1037 1141 // CAT
1038 1142 if ($cat != '') {
1039 1143 if (preg_match('/[a-zA-Z]/i', $cat)) {
1040 1144 $arg['category_name'] = $cat;
@@ -1133,12 +1237,11 @@
1133 1237
1134 1238 $query_md5 = 'eventpost_' . md5(var_export($requete, true));
1135 1239 // Check if cache is activated
1136 1240 if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
1137 - return is_array($cached_events) ? $cached_events : array();
1241 + return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg);
1138 1242 }
1139 1243
1140 -
1141 1244 $events = apply_filters('eventpost_get', '', $requete, $arg);
1142 1245 if ('' === $events) {
1143 1246 global $wpdb;
1144 1247 $query = new WP_Query($arg);
@@ -1150,9 +1253,9 @@
1150 1253 }
1151 1254 if ($this->settings['cache'] == 1){
1152 1255 set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
1153 1256 }
1154 - return $events;
1257 + return apply_filters('eventpost_get_items', $events, $requete, $arg);
1155 1258 }
1156 1259
1157 1260 /**
1158 1261 *
@@ -1159,12 +1262,16 @@
1159 1262 * @param object $event
1160 1263 * @return object
1161 1264 */
1162 1265 public function retreive($event = null) {
1163 - if(isset($event->start)){
1164 - return $event;
1165 - }
1166 - $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 + }
1167 1274 $ob->start = get_post_meta($ob->ID, $this->META_START, true);
1168 1275 $ob->end = get_post_meta($ob->ID, $this->META_END, true);
1169 1276 if (!$this->dateisvalid($ob->start)){
1170 1277 $ob->start = '';
@@ -1170,9 +1277,10 @@
1170 1277 $ob->start = '';
1171 1278 }
1172 1279 if (!$this->dateisvalid($ob->end)){
1173 1280 $ob->end = '';
1174 - }
1281 + }
1282 + $ob->root_ID = $ob->ID;
1175 1283 $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
1176 1284 $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
1177 1285 $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
1178 1286 $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true);
@@ -1183,205 +1291,71 @@
1183 1291 $ob->blog_id = get_current_blog_id();
1184 1292 if ($ob->color == ''){
1185 1293 $ob->color = '000000';
1186 1294 }
1187 - return apply_filters('eventpost_retreive', $ob);
1295 +
1296 + $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob);
1297 + return $EventPost_cache[$ob->ID];
1188 1298 }
1189 1299
1190 - /** ADMIN ISSUES * */
1191 -
1192 1300 /**
1193 - * set_shortcode_ui
1194 - * needs Shortcake (shortcode UI) plugin
1195 - * https://wordpress.org/plugins/shortcode-ui/
1301 + *
1302 + * @param mixte $_term
1303 + * @param string $taxonomy
1304 + * @param string $post_type
1196 1305 */
1197 - public function shortcode_ui(){
1198 - if(!function_exists('shortcode_ui_register_for_shortcode')){
1199 - return;
1200 - }
1201 - $shortcodes_list_atts=array(
1202 - 'label' => __('Events list','event-post'),
1203 - 'listItemImage' => 'dashicons-calendar',
1204 - 'post_type'=>array('page','post'),
1205 - 'attrs' => array(
1206 - 0=>array(
1207 - 'label' => __('Number of posts','event-post'),
1208 - 'attr' => 'nb',
1209 - 'type' => 'number',
1210 - 'description' => __('-1 is for: no limit','event-post')
1211 - ),
1212 - 1=>array(
1213 - 'label' => __('Categories','event-post'),
1214 - 'attr' => 'cat',
1215 - 'type' => 'text',
1216 - ),
1217 - 2=>array(
1218 - 'label' => __('Tags','event-post'),
1219 - 'attr' => 'tag',
1220 - 'type' => 'text',
1221 - ),
1222 - 3=>array(
1223 - 'label' => __('Future events:','event-post'),
1224 - 'attr' => 'future',
1225 - 'type' => 'select',
1226 - 'options' => array(
1227 - '1' => __('Yes','event-post'),
1228 - '0' => __('No','event-post'),
1229 - ),
1230 - ),
1231 - 4=>array(
1232 - 'label' => __('Past events:','event-post'),
1233 - 'attr' => 'past',
1234 - 'type' => 'select',
1235 - 'options' => array(
1236 - '1' => __('Yes','event-post'),
1237 - '0' => __('No','event-post'),
1238 - ),
1239 - ),
1240 - 5=>array(
1241 - 'label' => __('Only geotagged events:','event-post'),
1242 - 'attr' => 'geo',
1243 - 'type' => 'select',
1244 - 'options' => array(
1245 - '1' => __('Yes','event-post'),
1246 - '0' => __('No','event-post'),
1247 - ),
1248 - ),
1249 - 6=>array(
1250 - 'label' => __('Thumbnail:','event-post'),
1251 - 'attr' => 'thumbnail',
1252 - 'type' => 'select',
1253 - 'options' => array(
1254 - '1' => __('Yes','event-post'),
1255 - '0' => __('No','event-post'),
1256 - ),
1257 - ),
1258 - 7=>array(
1259 - 'label' => __('Thumbnail size:','event-post'),
1260 - 'attr' => 'thumbnail_size',
1261 - 'type' => 'select',
1262 - 'options' => array(
1263 - 'thumbnail' => __('Thumbnail'),
1264 - 'medium' => __('Medium'),
1265 - 'large' => __('Large'),
1266 - ),
1267 - ),
1268 - 8=>array(
1269 - 'label' => __('Order by:','event-post'),
1270 - 'attr' => 'orderby',
1271 - 'type' => 'select',
1272 - 'options' => array(
1273 - 'meta_value' => __('Date'),
1274 - 'title' => __('Title'),
1275 - ),
1276 - ),
1277 - 9=>array(
1278 - 'label' => __('Order:','event-post'),
1279 - 'attr' => 'order',
1280 - 'type' => 'select',
1281 - 'options' => array(
1282 - 'ASC' => __('Asc.'),
1283 - 'DESC' => __('Desc.'),
1284 - ),
1285 - ),
1286 - ),
1306 + public function retreive_term($_term=null, $taxonomy='category', $post_type='post') {
1307 + $term = get_term($_term, $taxonomy);
1308 +
1309 + if(!$term){
1310 + return $term;
1311 + }
1312 +
1313 + $term->start = $term->end = $term->time_start = $term->time_end = Null;
1314 +
1315 + $request = array(
1316 + 'post_type'=>$post_type,
1317 + 'tax_name'=>$term->taxonomy,
1318 + 'tax_term'=>$term->slug,
1319 + 'future'=>true,
1320 + 'past'=>true,
1321 + 'nb'=>-1,
1322 + 'order'=>'ASC'
1287 1323 );
1288 - /*
1289 - * Map
1290 - */
1291 - $shortcodes_map_atts = $shortcodes_list_atts;
1292 - unset($shortcodes_map_atts['attrs'][5]); // Remove geotagged attr
1293 - unset($shortcodes_map_atts['attrs'][8]); // Remove orderby attr
1294 - unset($shortcodes_map_atts['attrs'][9]); // Remove order attr
1295 - array_unshift($shortcodes_map_atts['attrs'],
1296 - array(
1297 - 'label' => __('Width','event-post'),
1298 - 'attr' => 'width',
1299 - 'type' => 'text',
1300 - ),
1301 - array(
1302 - 'label' => __('Height','event-post'),
1303 - 'attr' => 'height',
1304 - 'type' => 'text',
1305 - )
1306 - );
1307 - $shortcodes_map_atts['label']=__('Events map','event-post');
1308 - $shortcodes_map_atts['listItemImage']='dashicons-location-alt';
1309 - foreach($this->map_interactions as $int_key=>$int_name){
1310 - $shortcodes_map_atts['attrs'][]=array(
1311 - 'label' => sprintf(__('Disable %s interaction','event-post'), $int_name),
1312 - 'attr' => 'disable_'.$int_key,
1313 - 'type' => 'checkbox'
1314 - );
1324 +
1325 + $events = $this->get_events($request);
1326 +
1327 + $term->events_count = count($events);
1328 + if($term->events_count){
1329 + $term->start = $events[0]->start;
1330 + $term->time_start = $events[0]->time_start;
1331 + $term->end = $events[$term->events_count-1]->end;
1332 + $term->time_end = $events[$term->events_count-1]->time_end;
1315 1333 }
1316 - shortcode_ui_register_for_shortcode('events_list', apply_filters('eventpost_shortcodeui_list',$shortcodes_list_atts));
1317 - shortcode_ui_register_for_shortcode('events_map', apply_filters('eventpost_shortcodeui_map',$shortcodes_map_atts));
1318 1334
1319 - /*
1320 - * Calendar
1321 - */
1322 - $shortcodes_cal_atts=array(
1323 - 'label' => __('Events calendar','event-post'),
1324 - 'listItemImage' => 'dashicons-calendar-alt',
1325 - 'post_type'=>array('page','post'),
1326 - 'attrs' => array(
1327 - array(
1328 - 'label' => __('Default date','event-post'),
1329 - 'attr' => 'date',
1330 - 'type' => 'text',
1331 - 'description' => date('Y-n')
1332 - ),
1333 - array(
1334 - 'label' => __('Categories','event-post'),
1335 - 'attr' => 'cat',
1336 - 'type' => 'text',
1337 - ),
1338 - array(
1339 - 'label' => __('Monday first','event-post'),
1340 - 'attr' => 'mondayfirst',
1341 - 'type' => 'checkbox',
1342 - ),
1343 - array(
1344 - 'label' => __('Date selector','event-post'),
1345 - 'attr' => 'datepicker',
1346 - 'type' => 'checkbox',
1347 - )
1348 - )
1349 - );
1350 - shortcode_ui_register_for_shortcode('events_cal', apply_filters('eventpost_shortcodeui_cal',$shortcodes_cal_atts));
1351 - /*
1352 - * Details
1353 - */
1354 - $shortcodes_details_atts=array(
1355 - 'label' => __('Event details','event-post'),
1356 - 'listItemImage' => 'dashicons-clock',
1357 - 'attrs' => array(
1358 - array(
1359 - 'label' => __('Attribute','event-post'),
1360 - 'attr' => 'attribute',
1361 - 'type' => 'select',
1362 - 'options' => array(
1363 - '' => __('Full details','event-post'),
1364 - 'date' => __('Full date','event-post'),
1365 - 'start' => __('Begin date','event-post'),
1366 - 'end' => __('End date','event-post'),
1367 - 'address' => __('Address text','event-post'),
1368 - 'location' => __('Location','event-post'),
1369 - ),
1370 - ),
1371 - )
1372 - );
1373 - shortcode_ui_register_for_shortcode('event_details', apply_filters('eventpost_shortcodeui_details',$shortcodes_details_atts));
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 + }
1374 1343
1344 + return $term;
1345 +
1375 1346 }
1376 1347
1348 + /** ADMIN ISSUES * */
1349 +
1377 1350 /**
1378 - * @desc add custom boxes in posts edit page
1351 + * add custom boxes in posts edit page
1379 1352 */
1380 1353 public function add_custom_box() {
1381 1354 foreach($this->settings['posttypes'] as $posttype){
1382 - add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, $this->settings['adminpos'], 'core');
1383 - add_meta_box('event_post_loc', __('Event location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, $this->settings['adminpos'], 'core');
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);
1384 1358 }
1385 1359 if(!function_exists('shortcode_ui_register_for_shortcode')){
1386 1360 add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page');
1387 1361 }
@@ -1386,9 +1360,9 @@
1386 1360 add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page');
1387 1361 }
1388 1362 }
1389 1363 /**
1390 - * @desc disokay the date custom box
1364 + * display the date custom box
1391 1365 */
1392 1366 public function inner_custom_box_date() {
1393 1367 wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
1394 1368 $post_id = get_the_ID();
@@ -1401,95 +1375,124 @@
1401 1375 if (strpos($language, '-') > -1) {
1402 1376 $language = strtolower(substr($language, 0, 2));
1403 1377 }
1404 1378 $colors = $this->get_colors();
1405 - if (sizeof($colors) > 0):
1406 - ?>
1407 - <div class="misc-pub-section event-color-section">
1408 - <?php _e('Color:', 'event-post'); ?>
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; ?>
1409 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">
1410 1429 <?php foreach ($colors as $color => $file): ?>
1411 - <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>">
1412 - <img src="<?=$this->markurl.$color.'.png' ?>"><input type="radio" value ="<?php echo $color ?>" name="<?php echo $this->META_COLOR; ?>" id="<?php echo $this->META_COLOR; ?><?php echo $color ?>" <?php
1413 - if ($eventcolor == $color) {
1414 - echo 'checked';
1415 - }
1416 - ?>/>
1430 + <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>" title="<?php echo $file; ?>">
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); ?>/>
1417 1433 </label>
1418 1434 <?php endforeach; ?>
1435 + </span>
1419 1436 </p>
1420 1437 </div>
1421 1438 <?php endif; ?>
1422 - <div class="misc-pub-section">
1423 - <label for="<?php echo $this->META_START; ?>_date">
1424 - <?php _e('Begin:', 'event-post') ?>
1425 - <span id="<?php echo $this->META_START; ?>_date_human" class="human_date">
1426 - <?php
1427 - if ($event->time_start != '') {
1428 - echo $this->human_date($event->time_start) . date(' H:i', $event->time_start);
1429 - }
1430 - else{
1431 - _e('Pick a date','event-post');
1432 - }
1433 - ?>
1434 - </span>
1435 - <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value="<?php echo substr($start_date,0,16) ?>" name="<?php echo $this->META_START; ?>" id="<?php echo $this->META_START; ?>_date"/>
1436 - </label>
1437 - <br>
1438 - <label for="<?php echo $this->META_END; ?>_date">
1439 - <?php _e('End:', 'event-post') ?>
1440 - <span id="<?php echo $this->META_END; ?>_date_human" class="human_date">
1441 - <?php
1442 - if ($event->time_start != '') {
1443 - echo $this->human_date($event->time_end) . date(' H:i', $event->time_end);
1444 - }
1445 - else{
1446 - _e('Pick a date','event-post');
1447 - }
1448 - ?>
1449 - </span>
1450 - <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value ="<?php echo substr($end_date,0,16) ?>" name="<?php echo $this->META_END; ?>" id="<?php echo $this->META_END; ?>_date"/>
1451 - </label>
1452 - </div>
1453 1439 <?php
1440 + do_action ('eventpost_custom_box_date', $event);
1454 1441 }
1455 1442 /**
1456 - * @desc displays the location custom box
1443 + * displays the location custom box
1457 1444 */
1458 - public function inner_custom_box_loc() {
1459 - $post_id = get_the_ID();
1460 - $event = $this->retreive($post_id);
1445 + public function inner_custom_box_loc($post) {
1446 + $event = $this->retreive($post);
1461 1447 ?>
1462 - <div class="misc-pub-section">
1463 - <p><a href="#event_address_search" id="event_address_search">
1464 - <span class="dashicons dashicons-search"></span>
1465 - <?php _e('Look for event\'s GPS coordinates:', 'event-post') ?>
1466 - </a>
1467 - <span id="eventaddress_result"></span>
1468 - </p>
1448 +
1449 + <div class="eventpost-misc-pub-section">
1469 1450 <label for="<?php echo $this->META_ADD; ?>">
1470 - <?php _e('Event address, as it will be displayed:', 'event-post') ?>
1471 - <textarea name="<?php echo $this->META_ADD; ?>" id="<?php echo $this->META_ADD; ?>"><?php echo $event->address ?></textarea>
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>
1472 1453 </label>
1454 + </div>
1473 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>
1474 1483 </div>
1475 - <div class="misc-pub-section">
1476 - <label for="<?php echo $this->META_LAT; ?>">
1477 - <?php _e('Latitude:', 'event-post') ?>
1478 - <input type="text" value ="<?php echo $event->lat ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>"/>
1479 - </label>
1484 +
1485 + <div class="eventpost-misc-pub-section">
1486 + <div id="event-post-map-preview" data-marker="<?php echo $this->get_marker($event->color); ?>"></div>
1480 1487 </div>
1481 - <div class="misc-pub-section">
1482 - <label for="<?php echo $this->META_LONG; ?>">
1483 - <?php _e('Longitude:', 'event-post') ?>
1484 - <input type="text" value ="<?php echo $event->long ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>"/>
1485 - </label>
1486 - </div>
1487 1488 <?php
1489 + do_action ('eventpost_custom_box_loc', $event);
1490 + $this->load_map_scripts();
1488 1491 }
1489 1492
1490 1493 /**
1491 - * @desc display custombox containing shortcode wizard
1494 + * display custombox containing shortcode wizard
1492 1495 */
1493 1496 public function inner_custom_box_edit() {
1494 1497 $ep_settings = $this->settings;
1495 1498 ?>
@@ -1518,13 +1521,13 @@
1518 1521 <?php
1519 1522 $cats = get_categories();
1520 1523 foreach ($cats as $cat) {
1521 1524 ?>
1522 - <option value="<?= $cat->slug ?>" <?php
1525 + <option value="<?php echo $cat->slug; ?>" <?php
1523 1526 if ($cat->slug == $eventpost_cat) {
1524 1527 echo'selected';
1525 1528 }
1526 - ?>><?= $cat->cat_name ?></option>
1529 + ?>><?php echo $cat->cat_name; ?></option>
1527 1530 <?php } ?>
1528 1531 </select>
1529 1532 </label>
1530 1533 </p>
@@ -1557,26 +1560,20 @@
1557 1560 <div id="ep_sce_maponly" class="map">
1558 1561 <p>
1559 1562 <label for="ep_sce_tile"><?php _e('Map background', 'event-post'); ?>
1560 1563 <select id="ep_sce_tile" data-att="tile">
1561 - <?php
1562 - foreach ($this->maps as $id => $map):
1563 - ?>
1564 - <option value="<?php
1565 - if ($ep_settings['tile'] != $map['id']) {
1566 - echo $map['id'];
1567 - }
1568 - ?>" <?php
1569 - if ($ep_settings['tile'] == $map['id']) {
1570 - echo'selected';
1571 - }
1572 - ?>>
1573 - <?php echo $map['name']; ?><?php
1574 - if ($ep_settings['tile'] == $map['id']) {
1575 - echo' (default)';
1576 - }
1577 - ?>
1578 - </option>
1564 + <?php foreach ($this->maps as $map): ?>
1565 + <option value="<?php
1566 + if ($ep_settings['tile'] != $map['id']) {
1567 + echo $map['id'];
1568 + }
1569 + ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
1570 + <?php echo $map['name']; ?><?php
1571 + if ($ep_settings['tile'] == $map['id']) {
1572 + echo' (default)';
1573 + }
1574 + ?>
1575 + </option>
1579 1576 <?php endforeach; ?>
1580 1577 </select>
1581 1578 </label>
1582 1579 </p>
@@ -1604,9 +1601,96 @@
1604 1601 <?php
1605 1602 }
1606 1603
1607 1604 /**
1608 - * @desc When the post is saved, saves our custom data
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 + /**
1692 + * When the post is saved, saves our custom data
1609 1693 * @param int $post_id
1610 1694 * @return void
1611 1695 */
1612 1696 public function save_postdata($post_id) {
@@ -1648,10 +1732,33 @@
1648 1732 delete_post_meta($post_id, $this->META_ADD);
1649 1733 delete_post_meta($post_id, $this->META_LAT);
1650 1734 delete_post_meta($post_id, $this->META_LONG);
1651 1735 }
1736 +
1737 + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array();
1652 1738 }
1653 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 +
1654 1761 /**
1655 1762 *
1656 1763 * @param string $date
1657 1764 * @param string $cat
@@ -1668,9 +1775,9 @@
1668 1775 if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
1669 1776 $event->guid = '#';
1670 1777 }
1671 1778 $ret.='<li>'
1672 - . '<a href="' . $event->guid . '">'
1779 + . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">'
1673 1780 . '<h4>' . $event->post_title . '</h4>'
1674 1781 .$this->get_single($event)
1675 1782 . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
1676 1783 .'</a>'
@@ -1680,9 +1787,9 @@
1680 1787 return $ret;
1681 1788 }
1682 1789 return'';
1683 1790 } else {
1684 - return $nb > 0 ? '<a data-date="' . date('Y-m-d', $date) . '" class="eventpost_cal_link"'.($colored?' style="background-color:#'.$events[0]->color.'"':'').'>' . date('j', $date) . '</a>' : date('j', $date);
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);
1685 1792 }
1686 1793 }
1687 1794
1688 1795
@@ -1705,8 +1812,12 @@
1705 1812 $mois = substr($date, 5);
1706 1813
1707 1814 $time = mktime(0, 0, 0, $mois, 1, $annee);
1708 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);
1709 1820
1710 1821 $JourMax = date("t", $time);
1711 1822 $NoJour = -date("w", $time);
1712 1823 if ($mondayfirst == 0) {
@@ -1717,27 +1828,32 @@
1717 1828 }
1718 1829 if ($NoJour > 0 && $mondayfirst == 1) {
1719 1830 $NoJour -=7;
1720 1831 }
1721 - $ret = '<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">';
1722 1837 if ($datepicker == 1) {
1723 - $ret.='<thead><tr><td colspan="7">';
1724 - $ret.='<a data-date="' . date('Y-n', strtotime('-1 Year', $time)) . '" class="eventpost_cal_bt">&lt;&lt;</a> ';
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> ';
1725 1840 $ret.=$annee;
1726 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Year', $time)) . '" class="eventpost_cal_bt">&gt;&gt;</a> ';
1727 - $ret.='<a data-date="' . date('Y-n', strtotime('-1 Month', $time)) . '" class="eventpost_cal_bt">&lt;</a> ';
1728 - $ret.=$this->NomDuMois[$mois];
1729 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Month', $time)) . '" class="eventpost_cal_bt">&gt;</a> ';
1730 - $ret.='<a data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</a> </td></tr></thead>';
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>';
1731 1847 }
1732 - $ret.='<tbody>';
1733 - $ret.='<tr class="event_post_cal_days">';
1848 + $ret.='</th></tr><tr class="event_post_cal_days">';
1734 1849 for ($w = 0; $w < 7; $w++) {
1735 - $ret.='<td>' . strtoupper(substr($this->Week[$w], 0, 1)) . '</td>';
1850 + $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>';
1736 1851 }
1737 1852 $ret.='</tr>';
1853 + $ret.='</thead>';
1738 1854
1739 -
1855 + $ret.='<tbody>';
1740 1856 $sqldate = date('Y-m', $time);
1741 1857 $cejour = date('Y-m-d');
1742 1858 for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois
1743 1859 $ret.='<tr>';
@@ -1743,11 +1859,14 @@
1743 1859 $ret.='<tr>';
1744 1860 for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
1745 1861 if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
1746 1862 $td = '<td class="event_post_day">';
1747 - if ($sqldate . '-' . $NoJour == $cejour) {
1863 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) {
1748 1864 $td = '<td class="event_post_day_now">';
1749 1865 }
1866 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){
1867 + $td = '<td class="event_post_day_over">'; // Patch ahf
1868 + }
1750 1869 $ret.=$td;
1751 1870
1752 1871 $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail);
1753 1872 $ret.='</td>';
@@ -1762,9 +1881,9 @@
1762 1881 return $ret;
1763 1882 }
1764 1883
1765 1884 /**
1766 - * @desc echoes the content of the calendar in ajax context
1885 + * echoes the content of the calendar in ajax context
1767 1886 */
1768 1887 public function ajaxcal() {
1769 1888 echo $this->calendar(array(
1770 1889 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')),
@@ -1777,9 +1896,9 @@
1777 1896 exit();
1778 1897 }
1779 1898
1780 1899 /**
1781 - * @desc echoes the date of the calendar in ajax context
1900 + * echoes the date of the calendar in ajax context
1782 1901 */
1783 1902 public function ajaxdate() {
1784 1903 echo $this->display_caldate(strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))), esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), true, esc_attr(FILTER_INPUT(INPUT_GET, 'color')), esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')));
1785 1904 exit();
@@ -1785,21 +1904,96 @@
1785 1904 exit();
1786 1905 }
1787 1906
1788 1907 /**
1789 - * @desc echoes a date in ajax context
1908 + * echoes a date in ajax context
1790 1909 */
1791 1910 public function HumanDate() {
1792 1911 if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
1793 1912 $date = strtotime($_REQUEST['date']);
1794 - 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));
1795 1914 exit();
1796 1915 }
1797 1916 }
1798 1917
1799 1918 /**
1800 - * @desc AJAX Get lat long from address
1919 + * Displays a search form
1920 + *
1921 + * @param type $atts
1922 + * @return type
1801 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 + /**
1994 + * AJAX Get lat long from address
1995 + */
1802 1996 public function GetLatLong() {
1803 1997 if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
1804 1998 // verifier le cache
1805 1999 $q = $_REQUEST['q'];
@@ -1805,14 +1999,17 @@
1805 1999 $q = $_REQUEST['q'];
1806 2000 header('Content-Type: application/json');
1807 2001 $transient_name = 'eventpost_osquery_' . $q;
1808 2002 $val = get_transient($transient_name);
1809 - if (false === $val || empty($val)) {
2003 + if (false === $val || empty($val) || !is_string($val)) {
1810 2004 $language = get_bloginfo('language');
1811 2005 if (strpos($language, '-') > -1) {
1812 2006 $language = strtolower(substr($language, 0, 2));
1813 2007 }
1814 - $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 + }
1815 2012 set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
1816 2013 }
1817 2014 echo $val;
1818 2015 exit();
@@ -1819,22 +2016,24 @@
1819 2016 }
1820 2017 }
1821 2018
1822 2019 /**
1823 - * @desc alters columns
2020 + * alters columns
1824 2021 * @param array $defaults
1825 2022 * @return array
2023 + * @filter eventpost_columns_head
1826 2024 */
1827 2025 public function columns_head($defaults) {
1828 2026 $defaults['event'] = __('Event', 'event-post');
1829 2027 $defaults['location'] = __('Location', 'event-post');
1830 - return $defaults;
2028 + return apply_filters('eventpost_columns_head', $defaults);
1831 2029 }
1832 2030
1833 2031 /**
1834 - * @desc echoes content of a row in a given column
2032 + * echoes content of a row in a given column
1835 2033 * @param string $column_name
1836 2034 * @param int $post_id
2035 + * @action eventpost_columns_content
1837 2036 */
1838 2037 public function columns_content($column_name, $post_id) {
1839 2038 if ($column_name == 'location') {
1840 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
@@ -1840,70 +2039,73 @@
1840 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
1841 2040 $lon = get_post_meta($post_id, $this->META_LONG, true);
1842 2041
1843 2042 if (!empty($lat) && !empty($lon)) {
2043 + add_thickbox();
1844 2044 $color = get_post_meta($post_id, $this->META_COLOR, true);
1845 2045 if ($color == ''){
1846 2046 $color = '777777';
1847 2047 }
1848 - echo'<a href="https://www.openstreetmap.org/?lat=' . $lat.='&amp;lon=' . $lon.='&amp;zoom=13" target="_blank"><img src="' . plugins_url('/markers/', __FILE__) . $color . '.png" alt="' . get_post_meta($post_id, $this->META_ADD, true) . '"/></a>';
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> ';
1849 2053 }
2054 + $this->column_edit_hidden_fields($post_id, 'location');
1850 2055 }
1851 2056 if ($column_name == 'event') {
1852 2057 echo $this->print_date($post_id, false);
2058 + $this->column_edit_hidden_fields($post_id, 'event');
1853 2059 }
2060 + do_action('eventpost_columns_content', $column_name, $post_id);
1854 2061 }
1855 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 +
1856 2072 /** ADMIN PAGES **/
1857 2073
1858 2074 /**
1859 - * @desc save settings end redirect
1860 - * @return void
2075 + * Settings link on the plugins page
1861 2076 */
1862 - public function save_settings(){
1863 - if (!current_user_can('manage_options')){
1864 - return;
1865 - }
1866 - if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) {
1867 - wp_die(__('Security error', 'event-post'));
1868 - }
1869 -
1870 - $valid_post = array(
1871 - 'ep_settings'=>array(
1872 - 'filter' => FILTER_SANITIZE_STRING,
1873 - 'flags' => FILTER_REQUIRE_ARRAY
1874 - )
1875 - );
1876 -
1877 - foreach ($this->settings as $item_name=>$item_value){
1878 - $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING;
1879 - }
1880 -
1881 - $post_types=(array) $_POST['ep_settings']['posttypes'];
1882 - $posttypes = get_post_types();
1883 - foreach($post_types as $posttype){
1884 - if(!in_array($posttype, $posttypes)){
1885 - unset($post_types[$posttype]);
1886 - }
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);
1887 2096 }
2097 + return $plugin_meta;
2098 + }
1888 2099
1889 - if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) {
1890 - $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']);
1891 - $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']);
1892 - $settings['ep_settings']['posttypes']= array_values($post_types);
1893 - update_option('ep_settings', $settings['ep_settings']);
1894 - }
1895 - wp_redirect('options-general.php?page=event-settings&confirm=options_saved');
1896 - exit;
1897 - }
1898 2100 /**
1899 - * @desc adds menu items
2101 + * adds menu items
1900 2102 */
1901 2103 public function manage_options() {
1902 2104 add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings'));
1903 2105 }
1904 2106 /**
1905 - * @desc adds items to the native "right now" dashboard widget
2107 + * adds items to the native "right now" dashboard widget
1906 2108 * @param array $elements
1907 2109 * @return array
1908 2110 */
1909 2111 public function dashboard_right_now($elements){
@@ -1918,307 +2120,332 @@
1918 2120 return $elements;
1919 2121 }
1920 2122
1921 2123 /**
1922 - * @desc output content of the setting page
2124 + * @action eventpost_register_settings
1923 2125 */
1924 - public function manage_settings() {
1925 - if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?>
1926 - <div class="updated"><p><strong><?php _e('Event settings saved !', 'event-post') ?></strong></p></div>
1927 - <?php
1928 - }
1929 - $ep_settings = $this->settings;
1930 - ?>
1931 - <div class="wrap">
1932 - <div class="icon32" id="icon-options-general"><br></div>
1933 - <h1><?php _e('Event settings', 'event-post'); ?></h1>
1934 - <form name="form1" method="post" action="admin-post.php">
1935 - <input type="hidden" name="action" value="EventPostSaveSettings">
1936 - <?php wp_nonce_field('ep_nonce_settings','ep_nonce_settings') ?>
1937 - <h2><?php _e('Global settings', 'event-post'); ?></h2>
1938 - <table class="form-table" id="eventpost-settings-table-global">
1939 - <tbody>
1940 - <tr>
1941 - <th>
1942 - <label for="ep_emptylink">
1943 - <?php _e('Print link for empty posts', 'event-post') ?>
1944 - </label>
1945 - </th>
1946 - <td>
1947 - <select name="ep_settings[emptylink]" id="ep_emptylink">
1948 - <option value="1" <?php selected($ep_settings['emptylink'], 1, true);?>>
1949 - <?php _e('Link all posts', 'event-post'); ?>
1950 - </option>
1951 - <option value="0" <?php selected($ep_settings['emptylink'], 0, true);?>>
1952 - <?php _e('Do not link posts with empty content', 'event-post'); ?>
1953 - </option>
1954 - </select>
1955 - </td>
1956 - </tr>
1957 - <tr>
1958 - <th>
1959 - <label for="ep_singlepos">
1960 - <?php _e('Event bar position for single posts', 'event-post') ?>
1961 - </label>
1962 - </th>
1963 - <td>
1964 - <select name="ep_settings[singlepos]" id="ep_singlepos">
1965 - <option value="before" <?php selected($ep_settings['singlepos'], 'before', true); ?>>
1966 - <?php _e('Before the content', 'event-post'); ?>
1967 - </option>
1968 - <option value="after" <?php selected($ep_settings['singlepos'], 'after', true); ?>>
1969 - <?php _e('After the content', 'event-post'); ?>
1970 - </option>
1971 - </select>
1972 - </td>
1973 - </tr>
1974 - <tr>
1975 - <th>
1976 - <label for="ep_loopicons">
1977 - <?php _e('Add icons for events in the loop', 'event-post') ?>
1978 - </label>
1979 - </th>
1980 - <td>
1981 - <select name="ep_settings[loopicons]" id="ep_loopicons">
1982 - <option value="1" <?php selected($ep_settings['loopicons'],'1', true) ?>>
1983 - <?php _e('Yes', 'event-post'); ?></option>
1984 - <option value="0" <?php selected($ep_settings['loopicons'],'0', true) ?>>
1985 - <?php _e('No', 'event-post'); ?></option>
1986 - </select>
1987 - </td>
1988 - </tr>
1989 - <tr>
1990 - <th>
1991 - <label for="ep_adminpos">
1992 - <?php _e('Position of event details boxes', 'event-post') ?>
1993 - </label>
1994 - </th>
1995 - <td>
1996 - <select name="ep_settings[adminpos]" id="ep_adminpos">
1997 - <option value="side" <?php selected($ep_settings['adminpos'],'side', true) ?>>
1998 - <?php _e('Side', 'event-post'); ?></option>
1999 - <option value="normal" <?php selected($ep_settings['adminpos'],'normal', true) ?>>
2000 - <?php _e('Under the text', 'event-post'); ?></option>
2001 - </select>
2002 - </td>
2003 - </tr>
2004 - </tbody>
2005 - </table><!-- #eventpost-settings-table-global -->
2126 + public function register_settings(){
2127 + register_setting( 'eventpost-settings', 'ep_settings' );
2006 2128
2007 - <h2><?php _e('Date settings', 'event-post'); ?></h2>
2008 - <table class="form-table" id="eventpost-settings-table-event">
2009 - <tbody>
2010 - <tr>
2011 - <th>
2012 - <label for="ep_dateformat">
2013 - <?php _e('Date format', 'event-post') ?>
2014 - </label>
2015 - </th>
2016 - <td>
2017 - <input type="text" name="ep_settings[dateformat]" id="ep_dateformat" value="<?php echo $ep_settings['dateformat']; ?>" size="10">
2018 - </td>
2019 - </tr>
2020 - <tr>
2021 - <th>
2022 - <label for="ep_timeformatformat">
2023 - <?php _e('Time format', 'event-post') ?>
2024 - </label>
2025 - </th>
2026 - <td>
2027 - <input type="text" name="ep_settings[timeformat]" id="ep_dateformat" value="<?php echo $ep_settings['timeformat']; ?>" size="10">
2028 - </td>
2029 - </tr>
2030 - <tr>
2031 - <th>
2032 - <label for="ep_dateexport">
2033 - <?php _e('Show export buttons on:', 'event-post') ?>
2034 - </label>
2035 - </th>
2036 - <td>
2037 - <select name="ep_settings[export]" id="ep_dateexport">
2038 - <option value="list" <?php selected($ep_settings['export'], 'list', true);?>>
2039 - <?php _e('List only', 'event-post') ?>
2040 - </option>
2041 - <option value="single" <?php selected($ep_settings['export'], 'single', true);?>>
2042 - <?php _e('Single only', 'event-post') ?>
2043 - </option>
2044 - <option value="both" <?php selected($ep_settings['export'], 'both', true);?>>
2045 - <?php _e('Both', 'event-post') ?>
2046 - </option>
2047 - <option value="none" <?php selected($ep_settings['export'], 'none', true);?>>
2048 - <?php _e('None', 'event-post') ?>
2049 - </option>
2050 - </select>
2051 - </td>
2052 - </tr>
2053 - <tr>
2054 - <th>
2055 - <label for="ep_dateforhumans">
2056 - <?php _e('Relative human dates:', 'event-post') ?>
2057 - </label>
2058 - </th>
2059 - <td>
2060 - <select name="ep_settings[dateforhumans]" id="ep_dateforhumans">
2061 - <option value="1" <?php selected($ep_settings['dateforhumans'], '1', true);?>>
2062 - <?php _e('Yes', 'event-post') ?>
2063 - </option>
2064 - <option value="0" <?php selected($ep_settings['dateforhumans'], '0', true);?>>
2065 - <?php _e('No', 'event-post') ?>
2066 - </option>
2067 - </select>
2068 - <p class="description"><?php _e('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post') ?></p>
2069 - </td>
2070 - </tr>
2071 - </tbody>
2072 - </table><!-- #eventpost-settings-table-event -->
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 + );
2073 2184
2074 - <h2><?php _e('List settings', 'event-post'); ?></h2>
2075 - <table class="form-table" id="eventpost-settings-table-list">
2076 - <tbody>
2077 - <tr>
2078 - <th>
2079 - <label for="ep_container_shema">
2080 - <?php _e('Container shema', 'event-post') ?>
2081 - </label>
2082 - </th>
2083 - <td>
2084 - <textarea class="widefat" name="ep_settings[container_shema]" id="ep_container_shema"><?php echo $ep_settings['container_shema']; ?></textarea>
2085 - <p><?php _e('default:','event-post') ?></p>
2086 - <code><?php echo htmlentities($this->default_list_shema['container']) ?></code>
2087 - </td>
2088 - </tr>
2089 - <tr>
2090 - <th>
2091 - <label for="ep_item_shema">
2092 - <?php _e('Item shema', 'event-post') ?>
2093 - </label>
2094 - </th>
2095 - <td>
2096 - <textarea class="widefat" name="ep_settings[item_shema]" id="ep_item_shema"><?php echo $ep_settings['item_shema']; ?></textarea>
2097 - <p><?php _e('default:','event-post') ?></p>
2098 - <code><?php echo htmlentities($this->default_list_shema['item']) ?></code>
2099 - </td>
2100 - </tr>
2101 - </tbody>
2102 - </table><!-- #eventpost-settings-table-list -->
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 + );
2103 2235
2104 - <h2><?php _e('Map settings', 'event-post'); ?></h2>
2105 - <table class="form-table" id="eventpost-settings-table-map">
2106 - <tbody>
2107 - <tr>
2108 - <th>
2109 - <label for="ep_tile">
2110 - <?php _e('Map background', 'event-post') ?>
2111 - </label>
2112 - </th>
2113 - <td>
2114 - <select name="ep_settings[tile]" id="ep_tile">
2115 - <?php foreach ($this->maps as $id => $map): ?>
2116 - <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
2117 - <?php echo $map['name']; ?>
2118 - </option>
2119 - <?php endforeach; ?>
2120 - </select></td>
2121 - </tr>
2122 - <tr>
2123 - <th>
2124 - <?php _e('Makers custom directory (leave empty for default settings)', 'event-post') ?>
2125 - </th>
2126 - <td>
2127 - <label for="ep_markpath">
2128 - <?php _e('Root path:', 'event-post') ?><br>
2129 - ABSPATH/<input name="ep_settings[markpath]" id="ep_markpath" value="<?php echo $this->settings['markpath'] ?>" class="widefat">
2130 - </label><br>
2131 - <label for="ep_markurl">
2132 - <?php _e('URL:', 'event-post') ?><br>
2133 - <input name="ep_settings[markurl]" id="ep_markurl" value="<?php echo $this->settings['markurl'] ?>" class="widefat">
2134 - </label>
2135 - </td>
2136 - </tr>
2137 - </tbody>
2138 - </table><!-- #eventpost-settings-table-map -->
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 + );
2139 2260
2140 - <h2><?php _e('Admin UI settings', 'event-post'); ?></h2>
2141 - <table class="form-table" id="eventpost-settings-table-admin">
2142 - <tbody>
2143 - <tr>
2144 - <th>
2145 - <label for="ep_posttypes">
2146 - <?php _e('Wich post types can be events ?', 'event-post') ?>
2147 - </label>
2148 - </th>
2149 - <td><?php $posttypes = get_post_types(array(), 'objects'); ?>
2150 - <?php foreach($posttypes as $posttype): ?>
2151 - <p>
2152 - <label>
2153 - <input type="checkbox" name="ep_settings[posttypes][<?php echo $posttype->name; ?>]" value="<?php echo $posttype->name; ?>" <?php checked(in_array($posttype->name, $ep_settings['posttypes']),true, true) ?>>
2154 - <?php echo $posttype->labels->name; ?>
2155 - </label>
2156 - </p>
2157 - <?php endforeach; ?>
2158 - </td>
2159 - </tr>
2160 - <tr>
2161 - <th>
2162 - <?php _e('Datepicker style', 'event-post') ?>
2163 - <?php $now = current_time('mysql'); ?>
2164 - <?php $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); ?>
2165 - </th>
2166 - <td>
2167 - <p>
2168 - <label>
2169 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="dual" <?php checked($ep_settings['datepicker'],'dual', true) ?>>
2170 - <?php _e('Dual', 'event-post'); ?>
2171 - </label>
2172 - <span id="eventpost_dual_date_human" class="human_date">
2173 - <?php echo $human_date; ?>
2174 - </span>
2175 - <input type="text" class="eventpost-datepicker-dual" id="eventpost_dual_date" value="<?php echo $now; ?>">
2176 - </p>
2177 - <p>
2178 - <label>
2179 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="separate" <?php checked($ep_settings['datepicker'],'separate', true) ?>>
2180 - <?php _e('Separate', 'event-post'); ?>
2181 - </label>
2182 - <span id="eventpost_separate_date_human" class="human_date">
2183 - <?php echo $human_date; ?>
2184 - </span>
2185 - <input type="text" class="eventpost-datepicker-separate" id="eventpost_separate_date" value="<?php echo $now; ?>">
2186 - </p>
2187 - <p>
2188 - <label>
2189 - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="browser" <?php checked($ep_settings['datepicker'],'browser', true) ?>>
2190 - <?php _e('Browser\'s style', 'event-post'); ?>
2191 - </label>
2192 - <input type="datetime" class="eventpost-datepicker-browser" value="<?php echo $now; ?>">
2193 - </p>
2194 - </td>
2195 - </tr>
2196 - </tbody>
2197 - </table><!-- #eventpost-settings-table-admin -->
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 + );
2198 2305
2199 - <h2><?php _e('Performances settings', 'event-post'); ?></h2>
2200 - <table class="form-table" id="eventpost-settings-table-perfs">
2201 - <tbody>
2202 - <tr>
2203 - <th>
2204 - <?php _e('Use cache', 'event-post') ?>
2205 - </th>
2206 - <td>
2207 - <label for="ep_cache">
2208 - <input type="checkbox" name="ep_settings[cache]" id="ep_cache" <?php if($ep_settings['cache']=='1'){ echo'checked';} ?> value="1">
2209 - <?php _e('Use cache for results','event-post')?>
2210 - </label>
2211 - </td>
2212 - </tr>
2213 - </tbody>
2214 - </table><!-- #eventpost-settings-table-perfs -->
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 + );
2215 2354
2216 - <p class="submit">
2217 - <input type="submit" value="<?php _e('Apply settings', 'event-post'); ?>" class="button button-primary" id="submit" name="submit">
2218 - </p>
2219 - <?php do_action('eventpost_settings_form'); ?>
2355 + do_action('eventpost_register_settings');
2356 + }
2357 + function settings_section_callback( $arg ) {
2358 + echo '<hr>';
2359 + }
2220 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(); ?>
2221 2448 </form>
2222 2449 </div>
2223 2450 <?php
2224 2451 do_action('eventpost_after_settings_form');
@@ -2234,49 +2461,91 @@
2234 2461 * @param timestamp $timestamp
2235 2462 * @return string
2236 2463 */
2237 2464 public function ics_date($timestamp){
2238 - return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z';
2465 + return date("Ymd",$timestamp).'T'.date("His",$timestamp);
2239 2466 }
2240 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 +
2241 2481 /**
2242 - * @desc outputs an RSS document
2482 + * outputs an ICS document
2243 2483 */
2244 2484 public function feed(){
2245 2485 if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){
2246 - $timezone_string = get_option('timezone_string');
2247 - date_default_timezone_set($timezone_string);
2486 + $vtz = get_option('timezone_string');
2487 + $gmt = $this->get_gmt_offset();
2488 + date_default_timezone_set($vtz);
2489 + $separator = "\n";
2248 2490
2249 - header("content-type:text/calendar");
2491 + header("content-type:text/x-icalendar");
2250 2492 header("Pragma: public");
2251 2493 header("Expires: 0");
2252 2494 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
2253 2495 header("Cache-Control: public");
2254 2496 header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" );
2255 - echo"BEGIN:VCALENDAR\r\n"
2256 - . "PRODID:EventPost\r\n"
2257 - . "VERSION:2.0\r\n";
2258 - /*
2259 - . "BEGIN:VTIMEZONE\r\n"
2260 - . "TZID:$timezone_string\r\n"
2261 - . "X-LIC-LOCATION:$timezone_string\r\n"
2262 - . "END:VTIMEZONE";
2263 - *
2264 - */
2265 - $events=$this->get_events(array('cat'=>$cat,'nb'=>-1));
2497 +
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));
2266 2529 foreach ($events as $event) {
2267 - echo"BEGIN:VEVENT\r\n"
2268 - . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n"
2269 - . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n"
2270 - . "SUMMARY:".$event->post_title."\r\n"
2271 - . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n"
2272 - . "LOCATION:".str_replace(',','\,',$event->address)."\r\n"
2273 - . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n"
2274 - . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n"
2275 - . "DESCRIPTION:".$event->guid."\r\n"
2276 - . "END:VEVENT\r\n";
2277 - }
2278 - echo"END:VCALENDAR\r\n";
2279 - exit;
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;
2280 2549 }
2281 2550 }
2282 -}
2551 +}