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 +1345 -1000 3.95.0 View file →
@@ -1,22 +1,29 @@
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: 3.9.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 - Text Domain: eventpost
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
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 = '3.8.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 - load_plugin_textdomain('eventpost', false, 'event-post/languages');
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';
@@ -89,15 +129,18 @@
89 129 $this->META_ADD = 'geo_address';
90 130 $this->META_LAT = 'geo_latitude';
91 131 $this->META_LONG = 'geo_longitude';
92 132 $this->list_id = 0;
93 - $this->NomDuMois = array('', __('Jan', 'eventpost'), __('Feb', 'eventpost'), __('Mar', 'eventpost'), __('Apr', 'eventpost'), __('May', 'eventpost'), __('Jun', 'eventpost'), __('Jul', 'eventpost'), __('Aug', 'eventpost'), __('Sept', 'eventpost'), __('Oct', 'eventpost'), __('Nov', 'eventpost'), __('Dec', 'eventpost'));
94 - $this->Week = array(__('Sunday', 'eventpost'), __('Monday', 'eventpost'), __('Tuesday', 'eventpost'), __('Wednesday', 'eventpost'), __('Thursday', 'eventpost'), __('Friday', 'eventpost'), __('Saturday', 'eventpost'));
133 + $this->NomDuMois = array('', __('Jan', 'event-post'), __('Feb', 'event-post'), __('Mar', 'event-post'), __('Apr', 'event-post'), __('May', 'event-post'), __('Jun', 'event-post'), __('Jul', 'event-post'), __('Aug', 'event-post'), __('Sept', 'event-post'), __('Oct', 'event-post'), __('Nov', 'event-post'), __('Dec', 'event-post'));
134 + $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post'));
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);
@@ -112,59 +155,70 @@
112 155 $this->markpath = plugin_dir_path(__FILE__) . 'markers/';
113 156 $this->markurl = plugins_url('/markers/', __FILE__);
114 157 }
115 158
116 - $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'eventpost'));
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 - 'DragRotate'=>__('Drag Rotate', 'eventpost'),
139 - 'DoubleClickZoom'=>__('Double Click Zoom', 'eventpost'),
140 - 'DragPan'=>__('Drag Pan', 'eventpost'),
141 - 'PinchRotate'=>__('Pinch Rotate', 'eventpost'),
142 - 'PinchZoom'=>__('Pinch Zoom', 'eventpost'),
143 - 'KeyboardPan'=>__('Keyboard Pan', 'eventpost'),
144 - 'KeyboardZoom'=>__('Keyboard Zoom', 'eventpost'),
145 - 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'eventpost'),
146 - 'DragZoom'=>__('Drag Zoom', 'eventpost'),
180 + 'DragRotate'=>__('Drag Rotate', 'event-post'),
181 + 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'),
182 + 'DragPan'=>__('Drag Pan', 'event-post'),
183 + 'PinchRotate'=>__('Pinch Rotate', 'event-post'),
184 + 'PinchZoom'=>__('Pinch Zoom', 'event-post'),
185 + 'KeyboardPan'=>__('Keyboard Pan', 'event-post'),
186 + 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'),
187 + 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'),
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,18 +245,21 @@
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 - __('Add calendar and/or geolocation metadata on posts', 'eventpost');
199 - __('Event Post', 'eventpost');
252 + __('Add calendar and/or geolocation metadata on posts', 'event-post');
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 }
@@ -231,8 +292,12 @@
231 292 if (!isset($ep_settings['export']) || empty($ep_settings['export'])) {
232 293 $ep_settings['export'] = 'both';
233 294 $reg_settings=true;
234 295 }
296 + if (!isset($ep_settings['dateforhumans'])) {
297 + $ep_settings['dateforhumans'] = 1;
298 + $reg_settings=true;
299 + }
235 300 if (!isset($ep_settings['emptylink'])) {
236 301 $ep_settings['emptylink'] = 1;
237 302 $reg_settings=true;
238 303 }
@@ -239,8 +304,16 @@
239 304 if (!isset($ep_settings['markpath'])) {
240 305 $ep_settings['markpath'] = '';
241 306 $reg_settings=true;
242 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 + }
243 316 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
244 317 $ep_settings['singlepos'] = 'after';
245 318 $reg_settings=true;
246 319 }
@@ -261,10 +334,10 @@
261 334 $ep_settings['item_shema'] = '';
262 335 $reg_settings=true;
263 336 }
264 337
265 - if(!isset($ep_settings['datepicker'])){
266 - $ep_settings['datepicker']='dual';
338 + if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){
339 + $ep_settings['datepicker']='simple';
267 340 $reg_settings=true;
268 341 }
269 342
270 343 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
@@ -271,9 +344,9 @@
271 344 $ep_settings['posttypes']=array('post');
272 345 $reg_settings=true;
273 346 }
274 347
275 - do_action('eventpost_getsettings');
348 + do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings));
276 349
277 350 //Save settings not changed
278 351 if($reg_settings===true){
279 352 update_option('ep_settings', $ep_settings);
@@ -281,9 +354,9 @@
281 354 return apply_filters('eventpost_getsettings', $ep_settings);
282 355 }
283 356
284 357 /**
285 - *
358 + * Checks if HTML schemas are not empty
286 359 * @param array $shema
287 360 * @return array
288 361 */
289 362 public function custom_shema($shema){
@@ -296,26 +369,41 @@
296 369 return $shema;
297 370 }
298 371
299 372 /**
373 + * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example:
300 374 *
301 - * @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']
302 395 */
303 396 public function get_maps() {
304 397 $maps = array();
305 - if (is_file(plugin_dir_path(__FILE__) . 'maps.csv')) {
306 - $map_f = fopen(plugin_dir_path(__FILE__) . 'maps.csv', 'r');
307 - $map_s = explode("\n", fread($map_f, filesize(plugin_dir_path(__FILE__) . 'maps.csv')));
308 - foreach ($map_s as $map) {
309 - $map = explode(';', $map);
310 - if (sizeof($map >= 5)) {
311 - $maps[$map[1]] = array(
312 - 'name' => $map[0],
313 - 'id' => $map[1],
314 - 'urls' => array($map[2], $map[3], $map[4]),
315 - );
316 - }
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;
317 404 }
405 + $maps = apply_filters('eventpost_maps', $arrays);
318 406 }
319 407 return $maps;
320 408 }
321 409
@@ -352,25 +440,42 @@
352 440 * Enqueue CSS files
353 441 */
354 442 public function load_styles() {
355 443 //CSS
356 - wp_register_style('eventpost', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
357 - wp_enqueue_style('eventpost', 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
358 456 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
359 - wp_enqueue_style('dashicons-css', includes_url('/css/dashicons.min.css'));
457 + wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css'));
360 458 }
459 + /**
460 + * Enqueue Editor style
461 + */
462 + public function editor_styles() {
463 + add_editor_style( plugins_url('/css/eventpost.min.css', __FILE__) );
464 + }
361 465
362 466 /**
363 467 * Enqueue JS files
364 468 */
365 - public function load_scripts() {
469 + public function load_scripts($deps = array('jquery')) {
366 470 // JS
367 471 wp_enqueue_script('jquery', false, false, false, true);
368 - wp_enqueue_script('eventpost', plugins_url('/js/eventpost.min.js', __FILE__), false, $this->version, true);
369 - wp_localize_script('eventpost', 'eventpost_params', array(
472 + wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), $deps, $this->version, true);
473 + wp_localize_script('event-post', 'eventpost_params', array(
370 474 'imgpath' => plugins_url('/img/', __FILE__),
371 475 'maptiles' => $this->maps,
372 476 'defaulttile' => $this->settings['tile'],
477 + 'zoom' => $this->settings['zoom'],
373 478 'ajaxurl' => admin_url() . 'admin-ajax.php',
374 479 'map_interactions'=>$this->map_interactions,
375 480 ));
376 481 }
@@ -378,10 +483,13 @@
378 483 * Enqueue JS files for maps
379 484 */
380 485 public function load_map_scripts() {
381 486 // JS
382 - $this->load_scripts();
383 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 + }
384 492 }
385 493
386 494 /**
387 495 * Enqueue CSS files in admin
@@ -386,37 +494,64 @@
386 494 /**
387 495 * Enqueue CSS files in admin
388 496 */
389 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);
390 503 wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version);
391 - wp_enqueue_style('eventpostadmin', plugins_url('/css/eventpostadmin.css', __FILE__), false, $this->version);
392 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
393 - wp_enqueue_style('eventpost-datetimepicker', plugins_url('/css/jquery.datetimepicker.css', __FILE__), false, $this->version);
394 - }
504 + wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version);
395 505 }
396 506
397 507 /**
398 508 * Enqueue JS files in admin
399 509 */
400 - 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 + }
401 515 wp_enqueue_script('jquery');
402 - wp_enqueue_script('eventpost-admin', plugins_url('/js/osm-admin.min.js', __FILE__), false, $this->version, true);
403 - if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
404 - wp_enqueue_script('eventpost-datetimepicker', plugins_url('/js/jquery.datetimepicker.js', __FILE__), false, $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');
405 520 }
406 - 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')){
407 522 wp_enqueue_script('jquery-ui-datepicker');
523 + $deps[] = 'jquery-ui-datepicker';
408 524 }
525 + wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true);
409 526 $language = get_bloginfo('language');
410 527 if (strpos($language, '-') > -1) {
411 528 $language = strtolower(substr($language, 0, 2));
412 529 }
413 - wp_localize_script('eventpost-admin', 'eventpost', array(
530 + wp_localize_script('event-post-admin', 'eventpost', array(
531 + 'ajaxurl' => admin_url('admin-ajax.php'),
414 532 'imgpath' => plugins_url('/img/', __FILE__),
415 - 'date_choose' => __('Choose', 'eventpost'),
416 - 'date_format' => __('yy-mm-dd', 'eventpost'),
417 - 'more_icons' => __('More icons', 'eventpost'),
418 - 'pick_a_date'=>__('Pick a date','eventpost'),
533 + 'date_choose' => '<span class="screen-reader-text">'.__('Choose', 'event-post').'</span><i class="dashicons dashicons-calendar-alt"></i>',
534 + 'date_format' => __('yy-mm-dd', 'event-post'),
535 + 'more_icons' => __('More icons', 'event-post'),
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 + ),
419 554 'META_START' => $this->META_START,
420 555 'META_END' => $this->META_END,
421 556 'META_ADD' => $this->META_ADD,
422 557 'META_LAT' => $this->META_LAT,
@@ -421,13 +556,26 @@
421 556 'META_ADD' => $this->META_ADD,
422 557 'META_LAT' => $this->META_LAT,
423 558 'META_LONG' => $this->META_LONG,
424 559 'lang'=>$language,
560 + 'maptiles' => $this->maps,
561 + 'defaulttile' => $this->settings['tile']
425 562 ));
426 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 + }
427 575
428 576 /**
429 - * @desc Add custom header meta for single events
577 + * Add custom header meta for single events
430 578 */
431 579 public function single_header() {
432 580 if (is_single()) {
433 581 $event = $this->retreive();
@@ -435,15 +583,17 @@
435 583 ?>
436 584 <meta name="geo.placename" content="<?php echo $event->address ?>" />
437 585 <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
438 586 <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
439 - <?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
440 590 }
441 591 if ($event->start != '' && $event->end != '') {
442 592 ?>
443 593 <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" />
444 594 <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" />
445 - <?php
595 +<?php
446 596 }
447 597 }
448 598 }
449 599
@@ -448,13 +598,23 @@
448 598 }
449 599
450 600 /**
451 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 + *
452 612 * @param string $str
453 613 * @return boolean
454 614 */
455 615 public function dateisvalid($str) {
456 - return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != '';
616 + return is_string($str) && $this->date_cleanup($str) != '';
457 617 }
458 618
459 619 /**
460 620 *
@@ -476,14 +636,16 @@
476 636 * @param string $format
477 637 * @return type
478 638 */
479 639 public function human_date($date, $format = 'l j F Y') {
480 - if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) {
481 - return __('today', 'eventpost');
482 - } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) {
483 - return __('tomorrow', 'eventpost');
484 - } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) {
485 - return __('yesterday', 'eventpost');
640 + if($this->settings['dateforhumans']){
641 + if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) {
642 + return __('today', 'event-post');
643 + } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) {
644 + return __('tomorrow', 'event-post');
645 + } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) {
646 + return __('yesterday', 'event-post');
647 + }
486 648 }
487 649 return date_i18n($format, $date);
488 650 }
489 651
@@ -488,48 +650,67 @@
488 650 }
489 651
490 652 /**
491 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 + *
492 700 * @param WP_Post object $post
493 701 * @param mixed $links
494 702 * @return string
495 703 */
496 - public function print_date($post = null, $links = 'deprecated') {
704 + public function print_date($post = null, $links = 'deprecated', $context='') {
497 705 $dates = '';
498 706 $event = $this->retreive($post);
499 - $start_date = $event->start;
500 - $end_date = $post->end;
501 707 if ($event->start != '' && $event->end != '') {
502 - $gmt_offset = get_option('gmt_offset ');
708 +
709 + $dates.=$this->delta_date($event->time_start, $event->time_end);
710 +
503 711 $timezone_string = get_option('timezone_string');
504 - $codegmt = 0;
505 - if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
506 - $codegmt = $gmt_offset * -1;
507 - $gmt_offset = '+' . $gmt_offset;
508 - }
509 - //Display dates
510 - $dates.='<div class="event_date" data-start="' . $this->human_date($event->time_start) . '" data-end="' . $this->human_date($event->time_end) . '">';
511 - if (date('d/m/Y', $event->time_start) == date('d/m/Y', $event->time_end)) {
512 - $dates.= '<time itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">'
513 - . '<span class="date date-single">' . $this->human_date($event->time_end, $this->settings['dateformat']) . "</span>";
514 - 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') {
515 - $dates.=' <span class="linking_word linking_word-from">' . __('from', 'eventpost') . '</span>
516 - <span class="time time-start">' . date($this->settings['timeformat'], $event->time_start) . '</span>
517 - <span class="linking_word linking_word-t">' . __('to', 'eventpost') . '</span>
518 - <span class="time time-end">' . date($this->settings['timeformat'], $event->time_end) . '</span>';
519 - } elseif (date('H:i', $event->time_start) != '00:00') {
520 - $dates.=' <span class="linking_word">' . __('at', 'eventpost') . '</span>
521 - <span class="time time-single" itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">' . date($this->settings['timeformat'], $event->time_start) . '</span>';
522 - }
523 - $dates.='</time>';
524 - } else {
525 - $dates.= '
526 - <span class="linking_word linking_word-from">' . __('from', 'eventpost') . '</span>
527 - <span class="date date-start" itemprop="dtstart" datetime="' . date('c', $event->time_start) . '">' . $this->human_date($event->time_start, $this->settings['dateformat']) . '</span>
528 - <span class="linking_word linking_word-to">' . __('to', 'eventpost') . '</span>
529 - <span class="date date-end" itemprop="dtend" datetime="' . date('c', $event->time_end) . '">' . $this->human_date($event->time_end, $this->settings['dateformat']) . '</span>
530 - ';
531 - }
712 + $gmt_offset = $gmt = $this->get_gmt_offset();
532 713
533 714 if (!is_admin() && $event->time_end > current_time('timestamp') && (
534 715 $this->settings['export'] == 'both' ||
535 716 ($this->settings['export'] == 'single' && is_single() ) ||
@@ -534,37 +715,63 @@
534 715 $this->settings['export'] == 'both' ||
535 716 ($this->settings['export'] == 'single' && is_single() ) ||
536 717 ($this->settings['export'] == 'list' && !is_single() )
537 718 )) {
719 +
538 720 // Export event
539 721 $title = urlencode($post->post_title);
540 722 $address = urlencode($post->address);
541 723 $url = urlencode($post->guid);
542 -
543 - $mt = strtotime($codegmt . ' Hours', $event->time_start);
544 - $d_s = date("Ymd", $mt) . 'T' . date("His", $mt);
545 - $mte = strtotime($codegmt . ' Hours', $event->time_end);
546 - $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));
547 727 $uid = $post->ID . '-' . $post->blog_id;
548 728
549 729 // format de date ICS
550 - $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__));
551 740
552 741 // format de date Google cal
553 - $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');
554 754
555 755 // format de date VCS
556 - $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);
557 -
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__));
558 766 $dates.='
559 - <span class="eventpost-date-export">
560 - <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'eventpost') . '">ical</a>
561 - <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'eventpost') . '">Google</a>
562 - <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'eventpost') . '">outlook</a>
563 - <i class=" dashicons-before dashicons-calendar"></i>
564 - </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>';
565 773 }
566 - $dates.='</div>';
567 774 }
568 775 return apply_filters('eventpost_printdate', $dates);
569 776 }
570 777
@@ -572,9 +779,9 @@
572 779 *
573 780 * @param WP_Post object $post
574 781 * @return string
575 782 */
576 - public function print_location($post = null) {
783 + public function print_location($post=null, $context='') {
577 784 $location = '';
578 785 if ($post == null)
579 786 $post = get_post();
580 787 elseif (is_numeric($post)) {
@@ -588,17 +795,20 @@
588 795 $long = $post->long;
589 796 $color = $post->color;
590 797
591 798 if ($address != '' || ($lat != '' && $long != '')) {
592 - $location.='<address';
799 + $location.="\t\t\t\t".'<address';
593 800 if ($lat != '' && $long != '') {
594 801 $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" ';
595 802 }
596 - $location.=' itemprop="adr"><span>' . $address . '</span>';
597 - if (is_single() && $lat != '' && $long != '') {
598 - $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', 'eventpost') . '</a>';
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>';
807 + if ($context=='single' && $lat != '' && $long != '') {
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>';
599 809 }
600 - $location.='</address>';
810 + $location.="\n\t\t\t\t\t\t".'</address>';
601 811 }
602 812
603 813 return apply_filters('eventpost_printlocation', $location);
604 814 }
@@ -607,9 +817,9 @@
607 817 *
608 818 * @param WP_Post object $post
609 819 * @return string
610 820 */
611 - public function print_categories($post = null) {
821 + public function print_categories($post=null, $context='') {
612 822 if ($post == null)
613 823 $post = get_post();
614 824 elseif (is_numeric($post)) {
615 825 $post = get_post($post);
@@ -619,9 +829,9 @@
619 829 }
620 830 $cats = '';
621 831 $categories = $post->categories;
622 832 if ($categories) {
623 - $cats.='<span class="event_category"';
833 + $cats.="\t\t\t\t".'<span class="event_category"';
624 834 $color = $post->color;
625 835 if ($color != '') {
626 836 $cats.=' style="color:#' . $color . '"';
627 837 }
@@ -634,85 +844,84 @@
634 844 return $cats;
635 845 }
636 846
637 847 /**
638 - * @desc Generate, return or output date event datas
848 + * Generate, return or output date event datas
639 849 * @param WP_Post object $post
640 850 * @param string $class
851 + * @filter eventpost_get_single
641 852 * @return string
642 853 */
643 - public function get_single($post = null, $class = '') {
854 + public function get_single($post = null, $class = '', $context='') {
644 855 if ($post == null) {
645 856 $post = $this->retreive();
646 857 }
647 - $datas_date = $this->print_date($post);
648 - $datas_cat = $this->print_categories($post);
649 - $datas_loc = $this->print_location($post);
858 + $datas_date = $this->print_date($post, null, $context);
859 + $datas_cat = $this->print_categories($post, $context);
860 + $datas_loc = $this->print_location($post, $context);
650 861 if ($datas_date != '' || $datas_loc != '') {
651 862 $rgb = $this->hex2dec($post->color);
652 - 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>';
653 866 }
654 867 return '';
655 868 }
656 869
657 870 /**
658 - *
871 + * Displays dates of a gieven post
659 872 * @param WP_Post object $post
660 873 * @param string $class
661 874 * @return string
662 875 */
663 - public function get_singledate($post = null, $class = '') {
664 - return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_date($post) . '</div>';
876 + public function get_singledate($post = null, $class = '', $context='') {
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 -->';
665 878 }
666 879
667 880 /**
668 - *
881 + * Displays coloured terms of a given post
669 882 * @param WP_Post object $post
670 883 * @param string $class
671 884 * @return string
672 885 */
673 - public function get_singlecat($post = null, $class = '') {
674 - return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_categories($post) . '</div>';
886 + public function get_singlecat($post = null, $class = '', $context='') {
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 -->';
675 888 }
676 889
677 890 /**
678 - *
891 + * Displays location of a given post
679 892 * @param WP_Post object $post
680 893 * @param string $class
681 894 * @return string
682 895 */
683 - public function get_singleloc($post = null, $class = '') {
684 - return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_location($post) . '</div>';
896 + public function get_singleloc($post = null, $class = '', $context='') {
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 -->';
685 898 }
686 899
687 900 /**
688 - *
901 + * Uses `the_content` filter to add event details before or after the content of the current post
689 902 * @param string $content
690 903 * @return string
691 904 */
692 905 public function display_single($content) {
693 - if (is_page() || !is_single() || is_home())
906 + if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){
694 907 return $content;
695 - $post = get_queried_object();
696 - //Prevent from filters applying "the_content" on another thing than the current post content
697 - remove_filter('the_content', array(&$this, 'display_single'), 9999);
698 - $current_content = apply_filters('the_content', $post->post_content);
699 - if ($current_content == $content) {
700 - $post = $this->retreive();
701 - if($this->settings['singlepos']=='before'){
702 - $content=$this->get_single($post, 'event_single').$content;
703 - }
704 - else{
705 - $content.=$this->get_single($post, 'event_single');
706 - }
707 - $this->load_map_scripts();
708 908 }
709 - 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();
710 919 return $content;
711 920 }
712 921
713 922 /**
714 - *
923 + * Outputs events details (dates, geoloc, terms) of given post
715 924 * @param WP_Post object $post
716 925 * @echoes string
717 926 * @return void
718 927 */
@@ -720,169 +929,45 @@
720 929 echo $this->get_single($post);
721 930 }
722 931
723 932 /**
724 - * the_title
725 - * @desc alter the post title in order to add icons if needed
933 + * Alter the post title in order to add icons if needed
726 934 * @param string $title
727 935 * @return string
728 936 */
729 - public function the_title($title){
730 - 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']){
731 939 return $title;
732 940 }
733 - $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);
734 949 if(!empty($event->start)){
735 - $title .= ' <span class="dashicons dashicons-calendar"></span>';
950 + $title .= ' '.$icons_[$this->settings['loopicons']][0];
736 951 }
737 952 if(!empty($event->lat) && !empty($event->long)){
738 - $title .= ' <span class="dashicons dashicons-location"></span>';
953 + $title .= ' '.$icons_[$this->settings['loopicons']][1];
739 954 }
740 955 return $title;
741 956 }
742 957
743 - /**
744 - * shortcode_single
745 - * @param array $atts
746 - * @filter : eventpost_params
747 - * @return string
748 - */
749 - public function shortcode_single($atts){
750 - extract(shortcode_atts(apply_filters('eventpost_params', array(
751 - 'attribute' => '',
752 - ), 'shortcode_single'), $atts));
753 - $event = $this->retreive();
754 - switch($attribute){
755 - case 'start':
756 - return $this->human_date($event->time_start);
757 - case 'end':
758 - return $this->human_date($event->time_end);
759 - case 'address':
760 - return $event->address;
761 - case 'location':
762 - return $this->get_singleloc($event);
763 - case 'date':
764 - return $this->get_singledate($event);
765 - default:
766 - return $this->get_single($event);
767 - }
768 - }
769 958
770 959 /**
771 - * @desc Shortcode to display a list of events
772 - * @param array $atts
773 - * @filter eventpost_params
774 - * @return string
775 - */
776 - public function shortcode_list($atts) {
777 - $atts = shortcode_atts(apply_filters('eventpost_params', array(
778 - 'nb' => 0,
779 - 'type' => 'div',
780 - 'future' => true,
781 - 'past' => false,
782 - 'geo' => 0,
783 - 'width' => '',
784 - 'height' => 'auto',
785 - 'title' => '',
786 - 'before_title' => '<h3>',
787 - 'after_title' => '</h3>',
788 - 'cat' => '',
789 - 'tag' => '',
790 - 'thumbnail' => '',
791 - 'thumbnail_size' => '',
792 - 'excerpt' => '',
793 - 'style' => '',
794 - 'orderby' => 'meta_value',
795 - 'order' => 'ASC',
796 - 'container_schema' => $this->list_shema['container'],
797 - 'item_schema' => $this->list_shema['item'],
798 - ), 'shortcode_list'), $atts);
799 -
800 - if ($atts['container_schema'] != $this->list_shema['container'])
801 - $atts['container_schema'] = html_entity_decode($atts['container_schema']);
802 - if ($atts['item_schema'] != $this->list_shema['item'])
803 - $atts['item_schema'] = html_entity_decode($atts['item_schema']);
804 - return $this->list_events($atts, 'event_list', 'shortcode');
805 - }
806 -
807 - /**
808 - * @desc Shortcode to display a map of events
809 - * @param array $atts
810 - * @filter eventpost_params
811 - * @return string
812 - */
813 - public function shortcode_map($atts) {
814 - $ep_settings = $this->settings;
815 -
816 - $defaults = array(
817 - // Display
818 - 'width' => '',
819 - 'height' => '',
820 - 'tile' => $ep_settings['tile'],
821 - 'title' => '',
822 - 'before_title' => '<h3>',
823 - 'after_title' => '</h3>',
824 - 'style' => '',
825 - 'thumbnail' => '',
826 - 'thumbnail_size' => '',
827 - 'excerpt' => '',
828 - // Filters
829 - 'nb' => 0,
830 - 'future' => true,
831 - 'past' => false,
832 - 'cat' => '',
833 - 'tag' => '',
834 - 'orderby' => 'meta_value',
835 - 'order' => 'ASC',
836 - );
837 - // UI options
838 - foreach($this->map_interactions as $int_key=>$int_name){
839 - $defaults[$int_key]=true;
840 - }
841 - // - UI options
842 - foreach($this->map_interactions as $int_key=>$int_name){
843 - $defaults['disable_'.strtolower($int_key)]=false;
844 - }
845 -
846 - $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $atts);
847 - // UI options
848 - foreach($this->map_interactions as $int_key=>$int_name){
849 - if($atts['disable_'.strtolower($int_key)]==true){
850 - $atts[$int_key]=false;
851 - }
852 - unset($atts['disable_'.strtolower($int_key)]);
853 - }
854 - $atts['geo'] = 1;
855 - $atts['type'] = 'div';
856 - return $this->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
857 - }
858 -
859 - /**
860 - * @desc Shortcode to display a calendar of events
861 - * @param array $atts
862 - * @filter eventpost_params
863 - * @return string
864 - */
865 - public function shortcode_cal($atts) {
866 - $this->load_scripts();
867 - $ep_settings = $this->settings;
868 - $atts = shortcode_atts(apply_filters('eventpost_params', array(
869 - 'date' => date('Y-n'),
870 - 'cat' => '',
871 - 'mondayfirst' => 0, //1 : weeks starts on monday
872 - 'datepicker' => 1
873 - ), 'shortcode_cal'), $atts);
874 - extract($atts);
875 - return '<div class="eventpost_calendar" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '">' . $this->calendar($atts) . '</div>';
876 - }
877 -
878 - /**
879 - * @desc Return an HTML list of events
880 - * @param array $atts
881 - * @filter eventpost_params
960 + * Return an HTML list of events
961 + *
962 + * @filter eventpost_params($defaults, 'list_events')
882 963 * @filter eventpost_listevents
883 964 * @filter eventpost_item_scheme_entities
884 965 * @filter eventpost_item_scheme_values
966 + *
967 + * @param array $atts
968 + * @param string $id
969 + * @param string $context
885 970 * @return string
886 971 */
887 972 public function list_events($atts, $id = 'event_list', $context='') {
888 973 $ep_settings = $this->settings;
@@ -893,8 +978,9 @@
893 978 'past' => false,
894 979 'geo' => 0,
895 980 'width' => '',
896 981 'height' => '',
982 + 'zoom' => '',
897 983 'tile' => $ep_settings['tile'],
898 984 'title' => '',
899 985 'before_title' => '<h3>',
900 986 'after_title' => '</h3>',
@@ -923,11 +1009,8 @@
923 1009 }
924 1010 $ret = '';
925 1011 $this->list_id++;
926 1012 if (sizeof($events) > 0) {
927 - if($id=='event_geolist'){
928 - $this->load_map_scripts();
929 - }
930 1013 if (!empty($title)) {
931 1014 $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title);
932 1015 }
933 1016
@@ -934,14 +1017,21 @@
934 1017 $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div';
935 1018
936 1019 $list = '';
937 1020
938 - foreach ($events as $post) { //$post=get_post($item_id);
939 - $item_id = $post->ID;
940 - $class_item = ($post->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past';
941 - if ($ep_settings['emptylink'] == 0 && empty($post->post_content)) {
942 - $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;
943 1030 }
1031 + elseif(empty($ob->permalink)){
1032 + $event->permalink=$event->guid;
1033 + }
944 1034 $list.=str_replace(
945 1035 apply_filters('eventpost_item_scheme_entities', array(
946 1036 '%child%',
947 1037 '%class%',
@@ -955,22 +1045,22 @@
955 1045 '%event_excerpt%'
956 1046 )), apply_filters('eventpost_item_scheme_values', array(
957 1047 $child,
958 1048 $class_item,
959 - $post->color,
960 - $post->permalink,
961 - $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>' : '',
962 - $post->post_title,
963 - $this->get_singledate($post),
964 - $this->get_singlecat($post),
965 - $this->get_singleloc($post),
966 - $excerpt == true && $post->post_excerpt!='' ? '<span class="event_exerpt">'.$post->post_excerpt.'</span>' : '',
967 - )), $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
968 1058 );
969 1059 }
970 1060 $attributes = '';
971 1061 if($id == 'event_geolist'){
972 - $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="';
973 1063 foreach($this->map_interactions as $int_key=>$int_name){
974 1064 $attributes.=$atts[$int_key]==false ? $int_key.', ' : '';
975 1065 }
976 1066 $attributes.='"';
@@ -994,15 +1084,19 @@
994 1084 $list
995 1085 ), $container_schema
996 1086 );
997 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 + }
998 1091 return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
999 1092 }
1000 1093
1001 1094 /**
1002 1095 * get_events
1003 - * @param array $attr
1004 - * @filter eventpost_params
1096 + * @param array $atts
1097 + * @filter eventpost_params
1098 + * @filter eventpost_get_items
1005 1099 * @return array of post_ids wich are events
1006 1100 */
1007 1101 public function get_events($atts) {
1008 1102 $requete = (shortcode_atts(apply_filters('eventpost_params', array(
@@ -1013,9 +1107,12 @@
1013 1107 'cat' => '',
1014 1108 'tag' => '',
1015 1109 'date' => '',
1016 1110 'orderby' => 'meta_value',
1111 + 'orderbykey' => $this->META_START,
1017 1112 'order' => 'ASC',
1113 + 'tax_name' => '',
1114 + 'tax_term' => '',
1018 1115 'post_type'=> $this->settings['posttypes']
1019 1116 ), 'get_events'), $atts));
1020 1117 extract($requete);
1021 1118 wp_reset_query();
@@ -1022,13 +1119,26 @@
1022 1119
1023 1120 $arg = array(
1024 1121 'post_type' => $post_type,
1025 1122 'posts_per_page' => $nb,
1026 - 'meta_key' => $this->META_START,
1123 + 'meta_key' => $orderbykey,
1027 1124 'orderby' => $orderby,
1028 1125 'order' => $order
1029 1126 );
1030 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 + }
1031 1141 // CAT
1032 1142 if ($cat != '') {
1033 1143 if (preg_match('/[a-zA-Z]/i', $cat)) {
1034 1144 $arg['category_name'] = $cat;
@@ -1127,12 +1237,11 @@
1127 1237
1128 1238 $query_md5 = 'eventpost_' . md5(var_export($requete, true));
1129 1239 // Check if cache is activated
1130 1240 if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
1131 - return is_array($cached_events) ? $cached_events : array();
1241 + return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg);
1132 1242 }
1133 1243
1134 -
1135 1244 $events = apply_filters('eventpost_get', '', $requete, $arg);
1136 1245 if ('' === $events) {
1137 1246 global $wpdb;
1138 1247 $query = new WP_Query($arg);
@@ -1144,9 +1253,9 @@
1144 1253 }
1145 1254 if ($this->settings['cache'] == 1){
1146 1255 set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
1147 1256 }
1148 - return $events;
1257 + return apply_filters('eventpost_get_items', $events, $requete, $arg);
1149 1258 }
1150 1259
1151 1260 /**
1152 1261 *
@@ -1153,12 +1262,16 @@
1153 1262 * @param object $event
1154 1263 * @return object
1155 1264 */
1156 1265 public function retreive($event = null) {
1157 - if(isset($event->start)){
1158 - return $event;
1159 - }
1160 - $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 + }
1161 1274 $ob->start = get_post_meta($ob->ID, $this->META_START, true);
1162 1275 $ob->end = get_post_meta($ob->ID, $this->META_END, true);
1163 1276 if (!$this->dateisvalid($ob->start)){
1164 1277 $ob->start = '';
@@ -1164,9 +1277,10 @@
1164 1277 $ob->start = '';
1165 1278 }
1166 1279 if (!$this->dateisvalid($ob->end)){
1167 1280 $ob->end = '';
1168 - }
1281 + }
1282 + $ob->root_ID = $ob->ID;
1169 1283 $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
1170 1284 $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
1171 1285 $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
1172 1286 $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true);
@@ -1177,212 +1291,78 @@
1177 1291 $ob->blog_id = get_current_blog_id();
1178 1292 if ($ob->color == ''){
1179 1293 $ob->color = '000000';
1180 1294 }
1181 - return apply_filters('eventpost_retreive', $ob);
1295 +
1296 + $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob);
1297 + return $EventPost_cache[$ob->ID];
1182 1298 }
1183 1299
1184 - /** ADMIN ISSUES * */
1185 -
1186 1300 /**
1187 - * set_shortcode_ui
1188 - * needs Shortcake (shortcode UI) plugin
1189 - * https://wordpress.org/plugins/shortcode-ui/
1301 + *
1302 + * @param mixte $_term
1303 + * @param string $taxonomy
1304 + * @param string $post_type
1190 1305 */
1191 - public function shortcode_ui(){
1192 - if(!function_exists('shortcode_ui_register_for_shortcode')){
1193 - return;
1194 - }
1195 - $shortcodes_list_atts=array(
1196 - 'label' => __('Events list','eventpost'),
1197 - 'listItemImage' => 'dashicons-calendar',
1198 - 'post_type'=>array('page','post'),
1199 - 'attrs' => array(
1200 - 0=>array(
1201 - 'label' => __('Number of posts','eventpost'),
1202 - 'attr' => 'nb',
1203 - 'type' => 'number',
1204 - 'description' => __('-1 is for: no limit','eventpost')
1205 - ),
1206 - 1=>array(
1207 - 'label' => __('Categories','eventpost'),
1208 - 'attr' => 'cat',
1209 - 'type' => 'text',
1210 - ),
1211 - 2=>array(
1212 - 'label' => __('Tags','eventpost'),
1213 - 'attr' => 'tag',
1214 - 'type' => 'text',
1215 - ),
1216 - 3=>array(
1217 - 'label' => __('Future events:','eventpost'),
1218 - 'attr' => 'future',
1219 - 'type' => 'select',
1220 - 'options' => array(
1221 - '1' => __('Yes','eventpost'),
1222 - '0' => __('No','eventpost'),
1223 - ),
1224 - ),
1225 - 4=>array(
1226 - 'label' => __('Past events:','eventpost'),
1227 - 'attr' => 'past',
1228 - 'type' => 'select',
1229 - 'options' => array(
1230 - '1' => __('Yes','eventpost'),
1231 - '0' => __('No','eventpost'),
1232 - ),
1233 - ),
1234 - 5=>array(
1235 - 'label' => __('Only geotagged events:','eventpost'),
1236 - 'attr' => 'geo',
1237 - 'type' => 'select',
1238 - 'options' => array(
1239 - '1' => __('Yes','eventpost'),
1240 - '0' => __('No','eventpost'),
1241 - ),
1242 - ),
1243 - 6=>array(
1244 - 'label' => __('Thumbnail:','eventpost'),
1245 - 'attr' => 'thumbnail',
1246 - 'type' => 'select',
1247 - 'options' => array(
1248 - '1' => __('Yes','eventpost'),
1249 - '0' => __('No','eventpost'),
1250 - ),
1251 - ),
1252 - 7=>array(
1253 - 'label' => __('Thumbnail size:','eventpost'),
1254 - 'attr' => 'thumbnail_size',
1255 - 'type' => 'select',
1256 - 'options' => array(
1257 - 'thumbnail' => __('Thumbnail'),
1258 - 'medium' => __('Medium'),
1259 - 'large' => __('Large'),
1260 - ),
1261 - ),
1262 - 8=>array(
1263 - 'label' => __('Order by:','eventpost'),
1264 - 'attr' => 'orderby',
1265 - 'type' => 'select',
1266 - 'options' => array(
1267 - 'meta_value' => __('Date'),
1268 - 'title' => __('Title'),
1269 - ),
1270 - ),
1271 - 9=>array(
1272 - 'label' => __('Order:','eventpost'),
1273 - 'attr' => 'order',
1274 - 'type' => 'select',
1275 - 'options' => array(
1276 - 'ASC' => __('Asc.'),
1277 - 'DESC' => __('Desc.'),
1278 - ),
1279 - ),
1280 - ),
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'
1281 1323 );
1282 - /*
1283 - * Map
1284 - */
1285 - $shortcodes_map_atts = $shortcodes_list_atts;
1286 - unset($shortcodes_map_atts['attrs'][5]); // Remove geotagged attr
1287 - unset($shortcodes_map_atts['attrs'][8]); // Remove orderby attr
1288 - unset($shortcodes_map_atts['attrs'][9]); // Remove order attr
1289 - array_unshift($shortcodes_map_atts['attrs'],
1290 - array(
1291 - 'label' => __('Width','eventpost'),
1292 - 'attr' => 'width',
1293 - 'type' => 'text',
1294 - ),
1295 - array(
1296 - 'label' => __('Height','eventpost'),
1297 - 'attr' => 'height',
1298 - 'type' => 'text',
1299 - )
1300 - );
1301 - $shortcodes_map_atts['label']=__('Events map','eventpost');
1302 - $shortcodes_map_atts['listItemImage']='dashicons-location-alt';
1303 - foreach($this->map_interactions as $int_key=>$int_name){
1304 - $shortcodes_map_atts['attrs'][]=array(
1305 - 'label' => sprintf(__('Disable %s interaction','eventpost'), $int_name),
1306 - 'attr' => 'disable_'.$int_key,
1307 - 'type' => 'checkbox'
1308 - );
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;
1309 1333 }
1310 - shortcode_ui_register_for_shortcode('events_list', apply_filters('eventpost_shortcodeui_list',$shortcodes_list_atts));
1311 - shortcode_ui_register_for_shortcode('events_map', apply_filters('eventpost_shortcodeui_map',$shortcodes_map_atts));
1312 1334
1313 - /*
1314 - * Calendar
1315 - */
1316 - $shortcodes_cal_atts=array(
1317 - 'label' => __('Events calendar','eventpost'),
1318 - 'listItemImage' => 'dashicons-calendar-alt',
1319 - 'post_type'=>array('page','post'),
1320 - 'attrs' => array(
1321 - array(
1322 - 'label' => __('Default date','eventpost'),
1323 - 'attr' => 'date',
1324 - 'type' => 'text',
1325 - 'description' => date('Y-n')
1326 - ),
1327 - array(
1328 - 'label' => __('Categories','eventpost'),
1329 - 'attr' => 'cat',
1330 - 'type' => 'text',
1331 - ),
1332 - array(
1333 - 'label' => __('Monday first','eventpost'),
1334 - 'attr' => 'mondayfirst',
1335 - 'type' => 'checkbox',
1336 - ),
1337 - array(
1338 - 'label' => __('Date selector','eventpost'),
1339 - 'attr' => 'datepicker',
1340 - 'type' => 'checkbox',
1341 - )
1342 - )
1343 - );
1344 - shortcode_ui_register_for_shortcode('events_cal', apply_filters('eventpost_shortcodeui_cal',$shortcodes_cal_atts));
1345 - /*
1346 - * Details
1347 - */
1348 - $shortcodes_details_atts=array(
1349 - 'label' => __('Event details','eventpost'),
1350 - 'listItemImage' => 'dashicons-clock',
1351 - 'attrs' => array(
1352 - array(
1353 - 'label' => __('Attribute','eventpost'),
1354 - 'attr' => 'attribute',
1355 - 'type' => 'select',
1356 - 'options' => array(
1357 - '' => __('Full details','eventpost'),
1358 - 'date' => __('Full date','eventpost'),
1359 - 'start' => __('Begin date','eventpost'),
1360 - 'end' => __('End date','eventpost'),
1361 - 'address' => __('Address text','eventpost'),
1362 - 'location' => __('Location','eventpost'),
1363 - ),
1364 - ),
1365 - )
1366 - );
1367 - 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 + }
1368 1343
1344 + return $term;
1345 +
1369 1346 }
1370 1347
1348 + /** ADMIN ISSUES * */
1349 +
1371 1350 /**
1372 - * @desc add custom boxes in posts edit page
1351 + * add custom boxes in posts edit page
1373 1352 */
1374 1353 public function add_custom_box() {
1375 1354 foreach($this->settings['posttypes'] as $posttype){
1376 - add_meta_box('event_post_date', __('Event date', 'eventpost'), array(&$this, 'inner_custom_box_date'), $posttype, $this->settings['adminpos'], 'core');
1377 - add_meta_box('event_post_loc', __('Event location', 'eventpost'), 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);
1378 1358 }
1379 1359 if(!function_exists('shortcode_ui_register_for_shortcode')){
1380 - add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'eventpost'), array(&$this, 'inner_custom_box_edit'), 'page');
1360 + add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page');
1381 1361 }
1382 1362 }
1383 1363 /**
1384 - * @desc disokay the date custom box
1364 + * display the date custom box
1385 1365 */
1386 1366 public function inner_custom_box_date() {
1387 1367 wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
1388 1368 $post_id = get_the_ID();
@@ -1395,95 +1375,124 @@
1395 1375 if (strpos($language, '-') > -1) {
1396 1376 $language = strtolower(substr($language, 0, 2));
1397 1377 }
1398 1378 $colors = $this->get_colors();
1399 - if (sizeof($colors) > 0):
1400 - ?>
1401 - <div class="misc-pub-section event-color-section">
1402 - <?php _e('Color:', 'eventpost'); ?>
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; ?>
1403 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">
1404 1429 <?php foreach ($colors as $color => $file): ?>
1405 - <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>">
1406 - <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
1407 - if ($eventcolor == $color) {
1408 - echo 'checked';
1409 - }
1410 - ?>/>
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); ?>/>
1411 1433 </label>
1412 1434 <?php endforeach; ?>
1435 + </span>
1413 1436 </p>
1414 1437 </div>
1415 1438 <?php endif; ?>
1416 - <div class="misc-pub-section">
1417 - <label for="<?php echo $this->META_START; ?>_date">
1418 - <?php _e('Begin:', 'eventpost') ?>
1419 - <span id="<?php echo $this->META_START; ?>_date_human" class="human_date">
1420 - <?php
1421 - if ($event->time_start != '') {
1422 - echo $this->human_date($event->time_start) . date(' H:i', $event->time_start);
1423 - }
1424 - else{
1425 - _e('Pick a date','eventpost');
1426 - }
1427 - ?>
1428 - </span>
1429 - <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"/>
1430 - </label>
1431 - <br>
1432 - <label for="<?php echo $this->META_END; ?>_date">
1433 - <?php _e('End:', 'eventpost') ?>
1434 - <span id="<?php echo $this->META_END; ?>_date_human" class="human_date">
1435 - <?php
1436 - if ($event->time_start != '') {
1437 - echo $this->human_date($event->time_end) . date(' H:i', $event->time_end);
1438 - }
1439 - else{
1440 - _e('Pick a date','eventpost');
1441 - }
1442 - ?>
1443 - </span>
1444 - <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"/>
1445 - </label>
1446 - </div>
1447 1439 <?php
1440 + do_action ('eventpost_custom_box_date', $event);
1448 1441 }
1449 1442 /**
1450 - * @desc displays the location custom box
1443 + * displays the location custom box
1451 1444 */
1452 - public function inner_custom_box_loc() {
1453 - $post_id = get_the_ID();
1454 - $event = $this->retreive($post_id);
1445 + public function inner_custom_box_loc($post) {
1446 + $event = $this->retreive($post);
1455 1447 ?>
1456 - <div class="misc-pub-section">
1457 - <p><a href="#event_address_search" id="event_address_search">
1458 - <span class="dashicons dashicons-search"></span>
1459 - <?php _e('Look for event\'s GPS coordinates:', 'eventpost') ?>
1460 - </a>
1461 - <span id="eventaddress_result"></span>
1462 - </p>
1448 +
1449 + <div class="eventpost-misc-pub-section">
1463 1450 <label for="<?php echo $this->META_ADD; ?>">
1464 - <?php _e('Event address, as it will be displayed:', 'eventpost') ?>
1465 - <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>
1466 1453 </label>
1454 + </div>
1467 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>
1468 1483 </div>
1469 - <div class="misc-pub-section">
1470 - <label for="<?php echo $this->META_LAT; ?>">
1471 - <?php _e('Latitude:', 'eventpost') ?>
1472 - <input type="text" value ="<?php echo $event->lat ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>"/>
1473 - </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>
1474 1487 </div>
1475 - <div class="misc-pub-section">
1476 - <label for="<?php echo $this->META_LONG; ?>">
1477 - <?php _e('Longitude:', 'eventpost') ?>
1478 - <input type="text" value ="<?php echo $event->long ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>"/>
1479 - </label>
1480 - </div>
1481 1488 <?php
1489 + do_action ('eventpost_custom_box_loc', $event);
1490 + $this->load_map_scripts();
1482 1491 }
1483 1492
1484 1493 /**
1485 - * @desc display custombox containing shortcode wizard
1494 + * display custombox containing shortcode wizard
1486 1495 */
1487 1496 public function inner_custom_box_edit() {
1488 1497 $ep_settings = $this->settings;
1489 1498 ?>
@@ -1489,36 +1498,36 @@
1489 1498 ?>
1490 1499 <?php do_action('before_eventpost_generator'); ?>
1491 1500 <div class="all">
1492 1501 <p>
1493 - <label for="ep_sce_type"><?php _e('Type :', 'eventpost'); ?>
1502 + <label for="ep_sce_type"><?php _e('Type :', 'event-post'); ?>
1494 1503 <select id="ep_sce_type">
1495 - <option value='list'><?php _e('List', 'eventpost') ?></option>
1496 - <option value='map'><?php _e('Map', 'eventpost') ?></option>
1504 + <option value='list'><?php _e('List', 'event-post') ?></option>
1505 + <option value='map'><?php _e('Map', 'event-post') ?></option>
1497 1506 </select>
1498 1507 </label>
1499 1508 </p>
1500 1509
1501 1510 <p>
1502 - <label for="ep_sce_nb"><?php _e('Number of posts', 'eventpost'); ?>
1511 + <label for="ep_sce_nb"><?php _e('Number of posts', 'event-post'); ?>
1503 1512 <input id="ep_sce_nb" type="number" value="5" data-att="nb"/>
1504 - <a class="button" id="ep_sce_nball"><?php _e('All', 'eventpost'); ?></a>
1513 + <a class="button" id="ep_sce_nball"><?php _e('All', 'event-post'); ?></a>
1505 1514 </label>
1506 1515 </p>
1507 1516
1508 1517 <p>
1509 - <label for="ep_sce_cat"><?php _e('Only in :', 'eventpost'); ?>
1518 + <label for="ep_sce_cat"><?php _e('Only in :', 'event-post'); ?>
1510 1519 <select id="ep_sce_cat" data-att="cat">
1511 - <option value=''><?php _e('All', 'eventpost') ?></option>
1520 + <option value=''><?php _e('All', 'event-post') ?></option>
1512 1521 <?php
1513 1522 $cats = get_categories();
1514 1523 foreach ($cats as $cat) {
1515 1524 ?>
1516 - <option value="<?= $cat->slug ?>" <?php
1525 + <option value="<?php echo $cat->slug; ?>" <?php
1517 1526 if ($cat->slug == $eventpost_cat) {
1518 1527 echo'selected';
1519 1528 }
1520 - ?>><?= $cat->cat_name ?></option>
1529 + ?>><?php echo $cat->cat_name; ?></option>
1521 1530 <?php } ?>
1522 1531 </select>
1523 1532 </label>
1524 1533 </p>
@@ -1523,18 +1532,18 @@
1523 1532 </label>
1524 1533 </p>
1525 1534
1526 1535 <p>
1527 - <label for="ep_sce_future"><?php _e('Future events:', 'eventpost'); ?>
1536 + <label for="ep_sce_future"><?php _e('Future events:', 'event-post'); ?>
1528 1537 <select id="ep_sce_future" data-att="future">
1529 - <option value='1'><?php _e('Yes', 'eventpost') ?></option>
1530 - <option value='0'><?php _e('No', 'eventpost') ?></option>
1538 + <option value='1'><?php _e('Yes', 'event-post') ?></option>
1539 + <option value='0'><?php _e('No', 'event-post') ?></option>
1531 1540 </select>
1532 1541 </label>
1533 - <label for="ep_sce_past"><?php _e('Past events:', 'eventpost'); ?>
1542 + <label for="ep_sce_past"><?php _e('Past events:', 'event-post'); ?>
1534 1543 <select id="ep_sce_past" data-att="past">
1535 - <option value='0'><?php _e('No', 'eventpost') ?></option>
1536 - <option value='1'><?php _e('Yes', 'eventpost') ?></option>
1544 + <option value='0'><?php _e('No', 'event-post') ?></option>
1545 + <option value='1'><?php _e('Yes', 'event-post') ?></option>
1537 1546 </select>
1538 1547 </label>
1539 1548 </p>
1540 1549
@@ -1539,12 +1548,12 @@
1539 1548 </p>
1540 1549
1541 1550 <div id="ep_sce_listonly" class="list">
1542 1551 <p>
1543 - <label for="ep_sce_geo"><?php _e('Only geotagged events:', 'eventpost'); ?>
1552 + <label for="ep_sce_geo"><?php _e('Only geotagged events:', 'event-post'); ?>
1544 1553 <select id="ep_sce_geo" data-att="geo">
1545 - <option value='0'><?php _e('No', 'eventpost') ?></option>
1546 - <option value='1'><?php _e('Yes', 'eventpost') ?></option>
1554 + <option value='0'><?php _e('No', 'event-post') ?></option>
1555 + <option value='1'><?php _e('Yes', 'event-post') ?></option>
1547 1556 </select>
1548 1557 </label>
1549 1558 </p>
1550 1559 </div>
@@ -1549,39 +1558,33 @@
1549 1558 </p>
1550 1559 </div>
1551 1560 <div id="ep_sce_maponly" class="map">
1552 1561 <p>
1553 - <label for="ep_sce_tile"><?php _e('Map background', 'eventpost'); ?>
1562 + <label for="ep_sce_tile"><?php _e('Map background', 'event-post'); ?>
1554 1563 <select id="ep_sce_tile" data-att="tile">
1555 - <?php
1556 - foreach ($this->maps as $id => $map):
1557 - ?>
1558 - <option value="<?php
1559 - if ($ep_settings['tile'] != $map['id']) {
1560 - echo $map['id'];
1561 - }
1562 - ?>" <?php
1563 - if ($ep_settings['tile'] == $map['id']) {
1564 - echo'selected';
1565 - }
1566 - ?>>
1567 - <?php echo $map['name']; ?><?php
1568 - if ($ep_settings['tile'] == $map['id']) {
1569 - echo' (default)';
1570 - }
1571 - ?>
1572 - </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>
1573 1576 <?php endforeach; ?>
1574 1577 </select>
1575 1578 </label>
1576 1579 </p>
1577 1580 <p>
1578 - <label for="ep_sce_width"><?php _e('Width', 'eventpost'); ?>
1581 + <label for="ep_sce_width"><?php _e('Width', 'event-post'); ?>
1579 1582 <input id="ep_sce_width" type="text" value="500px" data-att="width"/>
1580 1583 </label>
1581 1584 </p>
1582 1585 <p>
1583 - <label for="ep_sce_height"><?php _e('Height', 'eventpost'); ?>
1586 + <label for="ep_sce_height"><?php _e('Height', 'event-post'); ?>
1584 1587 <input id="ep_sce_height" type="text" value="500px" data-att="height"/>
1585 1588 </label>
1586 1589 </p>
1587 1590 </div>
@@ -1586,9 +1589,9 @@
1586 1589 </p>
1587 1590 </div>
1588 1591 <?php do_action('after_eventpost_generator'); ?>
1589 1592 <div id="ep_sce_shortcode">[event_list]</div>
1590 - <a class="button" id="ep_sce_submit"><?php _e('Insert shortcode', 'eventpost'); ?></a>
1593 + <a class="button" id="ep_sce_submit"><?php _e('Insert shortcode', 'event-post'); ?></a>
1591 1594 </div>
1592 1595 <script>
1593 1596 var IEbof = false;
1594 1597 </script>
@@ -1598,9 +1601,96 @@
1598 1601 <?php
1599 1602 }
1600 1603
1601 1604 /**
1602 - * @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
1603 1693 * @param int $post_id
1604 1694 * @return void
1605 1695 */
1606 1696 public function save_postdata($post_id) {
@@ -1642,10 +1732,33 @@
1642 1732 delete_post_meta($post_id, $this->META_ADD);
1643 1733 delete_post_meta($post_id, $this->META_LAT);
1644 1734 delete_post_meta($post_id, $this->META_LONG);
1645 1735 }
1736 +
1737 + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array();
1646 1738 }
1647 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 +
1648 1761 /**
1649 1762 *
1650 1763 * @param string $date
1651 1764 * @param string $cat
@@ -1662,9 +1775,9 @@
1662 1775 if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
1663 1776 $event->guid = '#';
1664 1777 }
1665 1778 $ret.='<li>'
1666 - . '<a href="' . $event->guid . '">'
1779 + . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">'
1667 1780 . '<h4>' . $event->post_title . '</h4>'
1668 1781 .$this->get_single($event)
1669 1782 . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
1670 1783 .'</a>'
@@ -1674,9 +1787,9 @@
1674 1787 return $ret;
1675 1788 }
1676 1789 return'';
1677 1790 } else {
1678 - 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);
1679 1792 }
1680 1793 }
1681 1794
1682 1795
@@ -1699,8 +1812,12 @@
1699 1812 $mois = substr($date, 5);
1700 1813
1701 1814 $time = mktime(0, 0, 0, $mois, 1, $annee);
1702 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);
1703 1820
1704 1821 $JourMax = date("t", $time);
1705 1822 $NoJour = -date("w", $time);
1706 1823 if ($mondayfirst == 0) {
@@ -1711,27 +1828,32 @@
1711 1828 }
1712 1829 if ($NoJour > 0 && $mondayfirst == 1) {
1713 1830 $NoJour -=7;
1714 1831 }
1715 - $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">';
1716 1837 if ($datepicker == 1) {
1717 - $ret.='<thead><tr><td colspan="7">';
1718 - $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> ';
1719 1840 $ret.=$annee;
1720 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Year', $time)) . '" class="eventpost_cal_bt">&gt;&gt;</a> ';
1721 - $ret.='<a data-date="' . date('Y-n', strtotime('-1 Month', $time)) . '" class="eventpost_cal_bt">&lt;</a> ';
1722 - $ret.=$this->NomDuMois[$mois];
1723 - $ret.='<a data-date="' . date('Y-n', strtotime('+1 Month', $time)) . '" class="eventpost_cal_bt">&gt;</a> ';
1724 - $ret.='<a data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'eventpost') . '</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>';
1725 1847 }
1726 - $ret.='<tbody>';
1727 - $ret.='<tr class="event_post_cal_days">';
1848 + $ret.='</th></tr><tr class="event_post_cal_days">';
1728 1849 for ($w = 0; $w < 7; $w++) {
1729 - $ret.='<td>' . strtoupper(substr($this->Week[$w], 0, 1)) . '</td>';
1850 + $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>';
1730 1851 }
1731 1852 $ret.='</tr>';
1853 + $ret.='</thead>';
1732 1854
1733 -
1855 + $ret.='<tbody>';
1734 1856 $sqldate = date('Y-m', $time);
1735 1857 $cejour = date('Y-m-d');
1736 1858 for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois
1737 1859 $ret.='<tr>';
@@ -1737,11 +1859,14 @@
1737 1859 $ret.='<tr>';
1738 1860 for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
1739 1861 if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
1740 1862 $td = '<td class="event_post_day">';
1741 - if ($sqldate . '-' . $NoJour == $cejour) {
1863 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) {
1742 1864 $td = '<td class="event_post_day_now">';
1743 1865 }
1866 + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){
1867 + $td = '<td class="event_post_day_over">'; // Patch ahf
1868 + }
1744 1869 $ret.=$td;
1745 1870
1746 1871 $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail);
1747 1872 $ret.='</td>';
@@ -1756,9 +1881,9 @@
1756 1881 return $ret;
1757 1882 }
1758 1883
1759 1884 /**
1760 - * @desc echoes the content of the calendar in ajax context
1885 + * echoes the content of the calendar in ajax context
1761 1886 */
1762 1887 public function ajaxcal() {
1763 1888 echo $this->calendar(array(
1764 1889 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')),
@@ -1771,9 +1896,9 @@
1771 1896 exit();
1772 1897 }
1773 1898
1774 1899 /**
1775 - * @desc echoes the date of the calendar in ajax context
1900 + * echoes the date of the calendar in ajax context
1776 1901 */
1777 1902 public function ajaxdate() {
1778 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')));
1779 1904 exit();
@@ -1779,21 +1904,96 @@
1779 1904 exit();
1780 1905 }
1781 1906
1782 1907 /**
1783 - * @desc echoes a date in ajax context
1908 + * echoes a date in ajax context
1784 1909 */
1785 1910 public function HumanDate() {
1786 1911 if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
1787 1912 $date = strtotime($_REQUEST['date']);
1788 - echo $this->human_date($date) . date(' H:i', $date);
1913 + echo $this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date));
1789 1914 exit();
1790 1915 }
1791 1916 }
1792 1917
1793 1918 /**
1794 - * @desc AJAX Get lat long from address
1919 + * Displays a search form
1920 + *
1921 + * @param type $atts
1922 + * @return type
1795 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 + */
1796 1996 public function GetLatLong() {
1797 1997 if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
1798 1998 // verifier le cache
1799 1999 $q = $_REQUEST['q'];
@@ -1799,14 +1999,17 @@
1799 1999 $q = $_REQUEST['q'];
1800 2000 header('Content-Type: application/json');
1801 2001 $transient_name = 'eventpost_osquery_' . $q;
1802 2002 $val = get_transient($transient_name);
1803 - if (false === $val || empty($val)) {
2003 + if (false === $val || empty($val) || !is_string($val)) {
1804 2004 $language = get_bloginfo('language');
1805 2005 if (strpos($language, '-') > -1) {
1806 2006 $language = strtolower(substr($language, 0, 2));
1807 2007 }
1808 - $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 + }
1809 2012 set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
1810 2013 }
1811 2014 echo $val;
1812 2015 exit();
@@ -1813,22 +2016,24 @@
1813 2016 }
1814 2017 }
1815 2018
1816 2019 /**
1817 - * @desc alters columns
2020 + * alters columns
1818 2021 * @param array $defaults
1819 2022 * @return array
2023 + * @filter eventpost_columns_head
1820 2024 */
1821 2025 public function columns_head($defaults) {
1822 - $defaults['event'] = __('Event', 'eventpost');
1823 - $defaults['location'] = __('Location', 'eventpost');
1824 - return $defaults;
2026 + $defaults['event'] = __('Event', 'event-post');
2027 + $defaults['location'] = __('Location', 'event-post');
2028 + return apply_filters('eventpost_columns_head', $defaults);
1825 2029 }
1826 2030
1827 2031 /**
1828 - * @desc echoes content of a row in a given column
2032 + * echoes content of a row in a given column
1829 2033 * @param string $column_name
1830 2034 * @param int $post_id
2035 + * @action eventpost_columns_content
1831 2036 */
1832 2037 public function columns_content($column_name, $post_id) {
1833 2038 if ($column_name == 'location') {
1834 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
@@ -1834,315 +2039,413 @@
1834 2039 $lat = get_post_meta($post_id, $this->META_LAT, true);
1835 2040 $lon = get_post_meta($post_id, $this->META_LONG, true);
1836 2041
1837 2042 if (!empty($lat) && !empty($lon)) {
2043 + add_thickbox();
1838 2044 $color = get_post_meta($post_id, $this->META_COLOR, true);
1839 2045 if ($color == ''){
1840 2046 $color = '777777';
1841 2047 }
1842 - 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> ';
1843 2053 }
2054 + $this->column_edit_hidden_fields($post_id, 'location');
1844 2055 }
1845 2056 if ($column_name == 'event') {
1846 2057 echo $this->print_date($post_id, false);
2058 + $this->column_edit_hidden_fields($post_id, 'event');
1847 2059 }
2060 + do_action('eventpost_columns_content', $column_name, $post_id);
1848 2061 }
1849 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 +
1850 2072 /** ADMIN PAGES **/
1851 2073
1852 2074 /**
1853 - * @desc save settings end redirect
1854 - * @return void
2075 + * Settings link on the plugins page
1855 2076 */
1856 - public function save_settings(){
1857 - if (!current_user_can('manage_options')){
1858 - return;
1859 - }
1860 - if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) {
1861 - wp_die(__('Security error', 'eventpost'));
1862 - }
1863 -
1864 - $valid_post = array(
1865 - 'ep_settings'=>array(
1866 - 'filter' => FILTER_SANITIZE_STRING,
1867 - 'flags' => FILTER_REQUIRE_ARRAY
1868 - )
1869 - );
1870 -
1871 - foreach ($this->settings as $item_name=>$item_value){
1872 - $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING;
1873 - }
1874 -
1875 - $post_types=(array) $_POST['ep_settings']['posttypes'];
1876 - $posttypes = get_post_types();
1877 - foreach($post_types as $posttype){
1878 - if(!in_array($posttype, $posttypes)){
1879 - unset($post_types[$posttype]);
1880 - }
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);
1881 2096 }
2097 + return $plugin_meta;
2098 + }
1882 2099
1883 - if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) {
1884 - $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']);
1885 - $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']);
1886 - $settings['ep_settings']['posttypes']= array_values($post_types);
1887 - update_option('ep_settings', $settings['ep_settings']);
1888 - }
1889 - wp_redirect('options-general.php?page=event-settings&confirm=options_saved');
1890 - exit;
1891 - }
1892 2100 /**
1893 - * @desc adds menu items
2101 + * adds menu items
1894 2102 */
1895 2103 public function manage_options() {
1896 - add_submenu_page('options-general.php', __('Event settings', 'eventpost'), __('Event settings', 'eventpost'), 'manage_options', 'event-settings', array(&$this, 'manage_settings'));
2104 + add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings'));
1897 2105 }
1898 2106 /**
1899 - * @desc adds items to the native "right now" dashboard widget
2107 + * adds items to the native "right now" dashboard widget
1900 2108 * @param array $elements
1901 2109 * @return array
1902 2110 */
1903 2111 public function dashboard_right_now($elements){
1904 - array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','eventpost'), count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))))."</i>");
1905 - array_push($elements, '<i class="dashicons dashicons-location"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Geolocalized events','eventpost'), count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1))))."</i>");
1906 - return $elements;
2112 + $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1)));
2113 + $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1)));
2114 + if($nb_date){
2115 + array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','event-post'), $nb_date)."</i>");
2116 + }
2117 + if($nb_geo){
2118 + array_push($elements, '<i class="dashicons dashicons-location"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Geolocalized events','event-post'), $nb_geo)."</i>");
2119 + }
2120 + return $elements;
1907 2121 }
1908 2122
1909 2123 /**
1910 - * @desc output content of the setting page
2124 + * @action eventpost_register_settings
1911 2125 */
1912 - public function manage_settings() {
1913 - if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?>
1914 - <div class="updated"><p><strong><?php _e('Event settings saved !', 'eventpost') ?></strong></p></div>
1915 - <?php
1916 - }
1917 - $ep_settings = $this->settings;
1918 - ?>
1919 - <div class="wrap">
1920 - <div class="icon32" id="icon-options-general"><br></div>
1921 - <h2><?php _e('Event settings', 'eventpost'); ?></h2>
1922 - <form name="form1" method="post" action="admin-post.php">
1923 - <input type="hidden" name="action" value="EventPostSaveSettings">
1924 - <?php wp_nonce_field('ep_nonce_settings','ep_nonce_settings') ?>
1925 - <table class="form-table" id="eventpost-settings-table">
1926 - <tbody>
1927 - <tr><td colspan="2">
1928 - <h3><?php _e('Event settings', 'eventpost'); ?></h3>
1929 - </td>
1930 - </tr>
1931 - <tr>
1932 - <th><label for="ep_dateformat">
1933 - <?php _e('Date format', 'eventpost') ?>
1934 - </label></th>
1935 - <td><input type="text" name="ep_settings[dateformat]" id="ep_dateformat" value="<?php echo $ep_settings['dateformat']; ?>" class="widefat">
1936 - </td>
1937 - </tr>
1938 - <tr>
1939 - <th><label for="ep_timeformatformat">
1940 - <?php _e('Time format', 'eventpost') ?>
1941 - </label></th>
1942 - <td><input type="text" name="ep_settings[timeformat]" id="ep_dateformat" value="<?php echo $ep_settings['timeformat']; ?>" class="widefat">
1943 - </td>
1944 - </tr>
1945 - <tr>
1946 - <th><label for="ep_dateexport">
1947 - <?php _e('Show export buttons on:', 'eventpost') ?>
2126 + public function register_settings(){
2127 + register_setting( 'eventpost-settings', 'ep_settings' );
1948 2128
1949 - </label></th>
1950 - <td><select name="ep_settings[export]" id="ep_dateexport" class="widefat">
1951 - <option value="list" <?php selected($ep_settings['export'], 'list', true);?>>
1952 - <?php _e('List only', 'eventpost') ?>
1953 - </option>
1954 - <option value="single" <?php selected($ep_settings['export'], 'single', true);?>>
1955 - <?php _e('Single only', 'eventpost') ?>
1956 - </option>
1957 - <option value="both" <?php selected($ep_settings['export'], 'both', true);?>>
1958 - <?php _e('Both', 'eventpost') ?>
1959 - </option>
1960 - <option value="none" <?php selected($ep_settings['export'], 'none', true);?>>
1961 - <?php _e('None', 'eventpost') ?>
1962 - </option>
1963 - </select></td>
1964 - </tr>
1965 - <tr><td colspan="2">
1966 - <h3><?php _e('List settings', 'eventpost'); ?></h3>
1967 - </td>
1968 - </tr>
1969 - <tr>
1970 - <th><label for="ep_container_shema">
1971 - <?php _e('Container shema', 'eventpost') ?>
1972 - </label></th>
1973 - <td><textarea class="widefat" name="ep_settings[container_shema]" id="ep_container_shema"><?php echo $ep_settings['container_shema']; ?></textarea>
1974 - <p><?php _e('default:','eventpost') ?></p>
1975 - <code><?php echo htmlentities($this->default_list_shema['container']) ?></code>
1976 - </td>
1977 - </tr>
1978 - <tr>
1979 - <th><label for="ep_item_shema">
1980 - <?php _e('Item shema', 'eventpost') ?>
1981 - </label></th>
1982 - <td><textarea class="widefat" name="ep_settings[item_shema]" id="ep_item_shema"><?php echo $ep_settings['item_shema']; ?></textarea>
1983 - <p><?php _e('default:','eventpost') ?></p>
1984 - <code><?php echo htmlentities($this->default_list_shema['item']) ?></code>
1985 - </td>
1986 - </tr>
1987 - <tr><td colspan="2">
1988 - <h3><?php _e('Map settings', 'eventpost'); ?></h3>
1989 - </td>
1990 - </tr>
1991 - <tr>
1992 - <th><label for="ep_tile">
1993 - <?php _e('Map background', 'eventpost') ?>
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 + );
1994 2184
1995 - </label></th>
1996 - <td><select name="ep_settings[tile]" id="ep_tile" class="widefat">
1997 - <?php
1998 - foreach ($this->maps as $id => $map):
1999 - ?>
2000 - <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
2001 - <?php echo $map['name']; ?>
2002 - </option>
2003 - <?php endforeach; ?>
2004 - </select></td>
2005 - </tr>
2006 - <tr>
2007 - <th>
2008 - <?php _e('Makers custom directory (leave empty for default settings)', 'eventpost') ?>
2009 - </label></th>
2010 - <td>
2011 - <label for="ep_markpath">
2012 - <?php _e('Root path:', 'eventpost') ?><br>
2013 - ABSPATH/<input name="ep_settings[markpath]" id="ep_markpath" value="<?php echo $this->settings['markpath'] ?>" class="widefat">
2014 - </label><br>
2015 - <label for="ep_markurl">
2016 - <?php _e('URL:', 'eventpost') ?><br>
2017 - <input name="ep_settings[markurl]" id="ep_markurl" value="<?php echo $this->settings['markurl'] ?>" class="widefat">
2018 - </label>
2019 - </td>
2020 - </tr>
2021 - <tr><td colspan="2">
2022 - <h3><?php _e('Global settings', 'eventpost'); ?></h3>
2023 - </td>
2024 - </tr>
2025 - <tr>
2026 - <th><label for="ep_emptylink">
2027 - <?php _e('Print link for empty posts', 'eventpost') ?>
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 + );
2028 2235
2029 - </label></th>
2030 - <td><select name="ep_settings[emptylink]" id="ep_emptylink" class="widefat">
2031 - <option value="1" <?php selected($ep_settings['emptylink'], 1, true);?>>
2032 - <?php _e('Link all posts', 'eventpost'); ?>
2033 - </option>
2034 - <option value="0" <?php selected($ep_settings['emptylink'], 0, true);?>>
2035 - <?php _e('Do not link posts with empty content', 'eventpost'); ?>
2036 - </option>
2037 - </select></td>
2038 - </tr>
2039 - <tr>
2040 - <th><label for="ep_singlepos">
2041 - <?php _e('Event bar position for single posts', 'eventpost') ?>
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 + );
2042 2260
2043 - </label></th>
2044 - <td><select name="ep_settings[singlepos]" id="ep_singlepos" class="widefat">
2045 - <option value="before" <?php selected($ep_settings['singlepos'], 'before', true); ?>>
2046 - <?php _e('Before the content', 'eventpost'); ?>
2047 - </option>
2048 - <option value="after" <?php selected($ep_settings['singlepos'], 'after', true); ?>>
2049 - <?php _e('After the content', 'eventpost'); ?>
2050 - </option>
2051 - </select></td>
2052 - </tr>
2053 - <tr>
2054 - <th><label for="ep_loopicons">
2055 - <?php _e('Add icons for events in the loop', 'eventpost') ?>
2056 - </label></th>
2057 - <td><select name="ep_settings[loopicons]" id="ep_loopicons" class="widefat">
2058 - <option value="1" <?php selected($ep_settings['loopicons'],'1', true) ?>>
2059 - <?php _e('Yes', 'eventpost'); ?></option>
2060 - <option value="0" <?php selected($ep_settings['loopicons'],'0', true) ?>>
2061 - <?php _e('No', 'eventpost'); ?></option>
2062 - </select></td>
2063 - </tr>
2064 - <tr>
2065 - <th><label for="ep_adminpos">
2066 - <?php _e('Position of event details boxes', 'eventpost') ?>
2067 - </label></th>
2068 - <td><select name="ep_settings[adminpos]" id="ep_adminpos" class="widefat">
2069 - <option value="side" <?php selected($ep_settings['adminpos'],'side', true) ?>>
2070 - <?php _e('Side', 'eventpost'); ?></option>
2071 - <option value="normal" <?php selected($ep_settings['adminpos'],'normal', true) ?>>
2072 - <?php _e('Under the text', 'eventpost'); ?></option>
2073 - </select></td>
2074 - </tr>
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 + );
2075 2305
2076 - <tr><td colspan="2">
2077 - <h3><?php _e('Admin UI settings', 'eventpost'); ?></h3>
2078 - </td>
2079 - </tr>
2080 - <tr>
2081 - <th><label for="ep_posttypes">
2082 - <?php _e('Wich post types can be events ?', 'eventpost') ?>
2083 - </label></th>
2084 - <td><?php $posttypes = get_post_types(array(), 'objects'); ?>
2085 - <?php foreach($posttypes as $posttype): ?>
2086 - <p><label>
2087 - <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) ?>>
2088 - <?php echo $posttype->labels->name; ?></option>
2089 - </label></p>
2090 - <?php endforeach; ?>
2091 - </td>
2092 - </tr>
2093 - <tr>
2094 - <th>
2095 - <?php _e('Datepicker style', 'eventpost') ?>
2096 - <?php $now = date('Y-m-d H:i:s'); ?>
2097 - <?php $human_date = $this->human_date(current_time('timestamp')) . date(' H:i'); ?>
2098 - </th>
2099 - <td>
2100 - <p>
2101 - <label><input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="dual" <?php checked($ep_settings['datepicker'],'dual', true) ?>>
2102 - <?php _e('Dual', 'eventpost'); ?></option>
2103 - </label>
2104 - <span id="eventpost_dual_date_human" class="human_date">
2105 - <?php echo $human_date; ?>
2106 - </span>
2107 - <input type="text" class="eventpost-datepicker-dual" id="eventpost_dual_date" value="<?php echo $now; ?>">
2108 - </p>
2109 - <p>
2110 - <label><input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="separate" <?php checked($ep_settings['datepicker'],'separate', true) ?>>
2111 - <?php _e('Separate', 'eventpost'); ?></option>
2112 - </label>
2113 - <span id="eventpost_separate_date_human" class="human_date">
2114 - <?php echo $human_date; ?>
2115 - </span>
2116 - <input type="text" class="eventpost-datepicker-separate" id="eventpost_separate_date" value="<?php echo $now; ?>">
2117 - </p>
2118 - <p>
2119 - <label><input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="browser" <?php checked($ep_settings['datepicker'],'browser', true) ?>>
2120 - <?php _e('Browser\'s style', 'eventpost'); ?></option>
2121 - </label>
2122 - <input type="datetime" class="eventpost-datepicker-browser" value="<?php echo $now; ?>">
2123 - </p>
2124 - </td>
2125 - </tr>
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 + );
2126 2354
2127 - <tr><td colspan="2">
2128 - <h3><?php _e('Performances settings', 'eventpost'); ?></h3>
2129 - </td>
2130 - </tr>
2131 - <tr>
2132 - <td colspan="2">
2133 - <label for="ep_cache">
2134 - <input type="checkbox" name="ep_settings[cache]" id="ep_cache" <?php if($ep_settings['cache']=='1'){ echo'checked';} ?> value="1">
2135 - <?php _e('Use cache for results','eventpost')?>
2136 - </label>
2137 - </td>
2138 - </tr>
2139 - <tr>
2140 - <td colspan="2"><p class="submit"><input type="submit" value="<?php _e('Apply settings', 'eventpost'); ?>" class="button button-primary" id="submit" name="submit"> </p></td>
2141 - </tr>
2142 - <?php do_action('eventpost_settings_form'); ?>
2143 - </tbody>
2144 - </table>
2355 + do_action('eventpost_register_settings');
2356 + }
2357 + function settings_section_callback( $arg ) {
2358 + echo '<hr>';
2359 + }
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(); ?>
2145 2448 </form>
2146 2449 </div>
2147 2450 <?php
2148 2451 do_action('eventpost_after_settings_form');
@@ -2158,49 +2461,91 @@
2158 2461 * @param timestamp $timestamp
2159 2462 * @return string
2160 2463 */
2161 2464 public function ics_date($timestamp){
2162 - return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z';
2465 + return date("Ymd",$timestamp).'T'.date("His",$timestamp);
2163 2466 }
2164 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 +
2165 2481 /**
2166 - * @desc outputs an RSS document
2482 + * outputs an ICS document
2167 2483 */
2168 2484 public function feed(){
2169 2485 if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){
2170 - $timezone_string = get_option('timezone_string');
2171 - 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";
2172 2490
2173 - header("content-type:text/calendar");
2491 + header("content-type:text/x-icalendar");
2174 2492 header("Pragma: public");
2175 2493 header("Expires: 0");
2176 2494 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
2177 2495 header("Cache-Control: public");
2178 2496 header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" );
2179 - echo"BEGIN:VCALENDAR\r\n"
2180 - . "PRODID:EventPost\r\n"
2181 - . "VERSION:2.0\r\n";
2182 - /*
2183 - . "BEGIN:VTIMEZONE\r\n"
2184 - . "TZID:$timezone_string\r\n"
2185 - . "X-LIC-LOCATION:$timezone_string\r\n"
2186 - . "END:VTIMEZONE";
2187 - *
2188 - */
2189 - $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));
2190 2529 foreach ($events as $event) {
2191 - echo"BEGIN:VEVENT\r\n"
2192 - . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n"
2193 - . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n"
2194 - . "SUMMARY:".$event->post_title."\r\n"
2195 - . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n"
2196 - . "LOCATION:".str_replace(',','\,',$event->address)."\r\n"
2197 - . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n"
2198 - . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n"
2199 - . "DESCRIPTION:".$event->guid."\r\n"
2200 - . "END:VEVENT\r\n";
2201 - }
2202 - echo"END:VCALENDAR\r\n";
2203 - 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;
2204 2549 }
2205 2550 }
2206 -}
2551 +}