PluginProbe
Event Post / 3.9
Event Post v3.9
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
event-post / eventpost.php

eventpost.php in Event Post 3.9, at eventpost.php

2,206 lines 87.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Event Post
4 Plugin URI: http://ecolosites.eelv.fr/articles-evenement-eventpost/
5 Description: Add calendar and/or geolocation metadata on posts
6 Version: 3.9.0
7 Author: bastho
8 Contributors: n4thaniel, ecolosites
9 Author URI: http://ecolosites.eelv.fr/
10 License: GPLv2
11 Text Domain: eventpost
12 Domain Path: /languages/
13 Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda
14 */
15
16
17 $EventPost = new EventPost();
18
19 class EventPost {
20 const META_START = 'event_begin';
21 const META_END = 'event_end';
22 const META_COLOR = 'event_color';
23 // http://codex.wordpress.org/Geodata
24 const META_ADD = 'geo_address';
25 const META_LAT = 'geo_latitude';
26 const META_LONG = 'geo_longitude';
27
28 public $list_id;
29 public $NomDuMois;
30 public $Week;
31 public $settings;
32 public $dateformat;
33
34 public $version = '3.8.0';
35
36 public $map_interactions;
37
38 public function __construct() {
39 load_plugin_textdomain('eventpost', false, 'event-post/languages');
40
41 add_action('save_post', array(&$this, 'save_postdata'));
42 add_action('admin_menu', array(&$this, 'manage_options'));
43 add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
44
45 // Scripts
46 add_action('admin_enqueue_scripts', array(&$this, 'admin_head'));
47 add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
48 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
49
50 // Single
51 add_filter('the_content', array(&$this, 'display_single'), 9999);
52 add_filter('the_title', array(&$this, 'the_title'), 9999);
53 add_action('the_event', array(&$this, 'print_single'));
54 add_action('wp_head', array(&$this, 'single_header'));
55
56 // Ajax
57 add_action('wp_ajax_EventPostGetLatLong', array(&$this, 'GetLatLong'));
58 add_action('wp_ajax_EventPostHumanDate', array(&$this, 'HumanDate'));
59 add_action('wp_ajax_EventPostCalendar', array(&$this, 'ajaxcal'));
60 add_action('wp_ajax_nopriv_EventPostCalendar', array(&$this, 'ajaxcal'));
61 add_action('wp_ajax_EventPostCalendarDate', array(&$this, 'ajaxdate'));
62 add_action('wp_ajax_nopriv_EventPostCalendarDate', array(&$this, 'ajaxdate'));
63
64 // Calendar publishing
65 add_action('wp_ajax_EventPostFeed', array(&$this, 'feed'));
66 add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed'));
67
68 //Shortcodes
69 add_action('init', array(&$this,'init'));
70 add_shortcode('events_list', array(&$this, 'shortcode_list'));
71 add_shortcode('events_map', array(&$this, 'shortcode_map'));
72 add_shortcode('events_cal', array(&$this, 'shortcode_cal'));
73 add_shortcode('event_details', array(&$this, 'shortcode_single'));
74 //
75 add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
76
77 // Admin
78 add_action('admin_post_EventPostSaveSettings', array(&$this, 'save_settings'));
79
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');
84
85 $this->META_START = 'event_begin';
86 $this->META_END = 'event_end';
87 $this->META_COLOR = 'event_color';
88 // http://codex.wordpress.org/Geodata
89 $this->META_ADD = 'geo_address';
90 $this->META_LAT = 'geo_latitude';
91 $this->META_LONG = 'geo_longitude';
92 $this->list_id = 0;
93 $this->NomDuMois = array('', __('Jan', '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'));
95
96 $this->maps = $this->get_maps();
97 $this->settings = $this->get_settings();
98
99
100 // Edit
101 add_action('add_meta_boxes', array(&$this, 'add_custom_box'));
102 foreach($this->settings['posttypes'] as $posttype){
103 add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2);
104 add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2);
105 }
106
107
108 if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) {
109 $this->markpath = ABSPATH.'/'.$this->settings['markpath'];
110 $this->markurl = $this->settings['markurl'];
111 } else {
112 $this->markpath = plugin_dir_path(__FILE__) . 'markers/';
113 $this->markurl = plugins_url('/markers/', __FILE__);
114 }
115
116 $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'eventpost'));
117
118 $this->default_list_shema = array(
119 'container' => '
120 <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>
121 %list%
122 </%type%>',
123 'item' => '
124 <%child% class="event_item %class%" data-color="%color%">
125 <a href="%event_link%">
126 %event_thumbnail%
127 <h5>%event_title%</h5>
128 </a>
129 %event_date%
130 %event_cat%
131 %event_location%
132 %event_excerpt%
133 </%child%>'
134 );
135 $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema);
136
137 $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'),
147 );
148
149 }
150
151 /**
152 * PHP4 constructor
153 */
154 public function EventPost(){
155 $this->__construct();
156 }
157
158 /**
159 * Call functions when WP is ready
160 */
161 public function init(){
162 $this->shortcode_ui();
163 }
164
165 /**
166 * @desc Usefull hexadecimal to decimal converter
167 * @param string $color
168 * @return array $color($R, $G, $B)
169 */
170 public function hex2dec($color = '000000') {
171 $tbl_color = array();
172 if (!strstr('#', $color)){
173 $color = '#' . $color;
174 }
175 $tbl_color['R'] = hexdec(substr($color, 1, 2));
176 $tbl_color['G'] = hexdec(substr($color, 3, 2));
177 $tbl_color['B'] = hexdec(substr($color, 5, 2));
178 return $tbl_color;
179 }
180 /**
181 *
182 * @global array $_wp_additional_image_sizes
183 * @return array
184 */
185 function get_thumbnail_sizes(){
186 global $_wp_additional_image_sizes;
187 $sizes = array('thumbnail', 'medium', 'large', 'full');
188 foreach($_wp_additional_image_sizes as $size=>$attrs){
189 $sizes[]=$size;
190 }
191 return $sizes;
192 }
193
194 /**
195 * Just for localisation
196 */
197 private function no_use() {
198 __('Add calendar and/or geolocation metadata on posts', 'eventpost');
199 __('Event Post', 'eventpost');
200 }
201
202 /**
203 * @desc get blog settings, load and saves default settings id needed
204 * @action eventpost_getsettings
205 * @filter eventpost_getsettings
206 * @return array
207 */
208 public function get_settings() {
209 $ep_settings = get_option('ep_settings');
210 $reg_settings=false;
211 if(!is_array($ep_settings)){
212 $ep_settings = array();
213 }
214 if (!isset($ep_settings['dateformat']) || empty($ep_settings['dateformat'])) {
215 $ep_settings['dateformat'] = get_option('date_format');
216 $reg_settings=true;
217 }
218 if (!isset($ep_settings['timeformat']) || empty($ep_settings['timeformat'])) {
219 $ep_settings['timeformat'] = get_option('time_format');
220 $reg_settings=true;
221 }
222 if (!isset($ep_settings['tile']) || empty($ep_settings['tile']) || !isset($this->maps[$ep_settings['tile']])) {
223 $maps = array_keys($this->maps);
224 $ep_settings['tile'] = $this->maps[$maps[0]]['id'];
225 $reg_settings=true;
226 }
227 if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) {
228 $ep_settings['cache'] = 0;
229 $reg_settings=true;
230 }
231 if (!isset($ep_settings['export']) || empty($ep_settings['export'])) {
232 $ep_settings['export'] = 'both';
233 $reg_settings=true;
234 }
235 if (!isset($ep_settings['emptylink'])) {
236 $ep_settings['emptylink'] = 1;
237 $reg_settings=true;
238 }
239 if (!isset($ep_settings['markpath'])) {
240 $ep_settings['markpath'] = '';
241 $reg_settings=true;
242 }
243 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
244 $ep_settings['singlepos'] = 'after';
245 $reg_settings=true;
246 }
247 if (!isset($ep_settings['loopicons'])) {
248 $ep_settings['loopicons'] = 1;
249 $reg_settings=true;
250 }
251 if (!isset($ep_settings['adminpos']) || empty($ep_settings['adminpos'])) {
252 $ep_settings['adminpos'] = 'side';
253 $reg_settings=true;
254 }
255 if (!isset($ep_settings['container_shema']) ) {
256 $ep_settings['container_shema'] = '';
257 $reg_settings=true;
258 }
259
260 if (!isset($ep_settings['item_shema']) ) {
261 $ep_settings['item_shema'] = '';
262 $reg_settings=true;
263 }
264
265 if(!isset($ep_settings['datepicker'])){
266 $ep_settings['datepicker']='dual';
267 $reg_settings=true;
268 }
269
270 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
271 $ep_settings['posttypes']=array('post');
272 $reg_settings=true;
273 }
274
275 do_action('eventpost_getsettings');
276
277 //Save settings not changed
278 if($reg_settings===true){
279 update_option('ep_settings', $ep_settings);
280 }
281 return apply_filters('eventpost_getsettings', $ep_settings);
282 }
283
284 /**
285 *
286 * @param array $shema
287 * @return array
288 */
289 public function custom_shema($shema){
290 if(!empty($this->settings['container_shema'])){
291 $shema['container']=$this->settings['container_shema'];
292 }
293 if(!empty($this->settings['item_shema'])){
294 $shema['item']=$this->settings['item_shema'];
295 }
296 return $shema;
297 }
298
299 /**
300 *
301 * @return array
302 */
303 public function get_maps() {
304 $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 }
317 }
318 }
319 return $maps;
320 }
321
322 /**
323 *
324 * @return array
325 */
326 public function get_colors() {
327 $colors = array();
328 if (is_dir($this->markpath)) {
329 $files = scandir($this->markpath);
330 foreach ($files as $file) {
331 if (substr($file, -4) == '.png') {
332 $colors[substr($file, 0, -4)] = $this->markurl . $file;
333 }
334 }
335 }
336 return $colors;
337 }
338
339 /**
340 *
341 * @param string $color
342 * @return sring
343 */
344 public function get_marker($color) {
345 if (is_file($this->markpath . $color . '.png')) {
346 return $this->markurl . $color . '.png';
347 }
348 return plugins_url('/markers/ffffff.png', __FILE__);
349 }
350
351 /**
352 * Enqueue CSS files
353 */
354 public function load_styles() {
355 //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);
358 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'));
360 }
361
362 /**
363 * Enqueue JS files
364 */
365 public function load_scripts() {
366 // JS
367 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(
370 'imgpath' => plugins_url('/img/', __FILE__),
371 'maptiles' => $this->maps,
372 'defaulttile' => $this->settings['tile'],
373 'ajaxurl' => admin_url() . 'admin-ajax.php',
374 'map_interactions'=>$this->map_interactions,
375 ));
376 }
377 /**
378 * Enqueue JS files for maps
379 */
380 public function load_map_scripts() {
381 // JS
382 $this->load_scripts();
383 wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true);
384 }
385
386 /**
387 * Enqueue CSS files in admin
388 */
389 public function admin_head() {
390 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 }
395 }
396
397 /**
398 * Enqueue JS files in admin
399 */
400 public function admin_scripts() {
401 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);
405 }
406 if($this->settings['datepicker']=='separate' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
407 wp_enqueue_script('jquery-ui-datepicker');
408 }
409 $language = get_bloginfo('language');
410 if (strpos($language, '-') > -1) {
411 $language = strtolower(substr($language, 0, 2));
412 }
413 wp_localize_script('eventpost-admin', 'eventpost', array(
414 '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'),
419 'META_START' => $this->META_START,
420 'META_END' => $this->META_END,
421 'META_ADD' => $this->META_ADD,
422 'META_LAT' => $this->META_LAT,
423 'META_LONG' => $this->META_LONG,
424 'lang'=>$language,
425 ));
426 }
427
428 /**
429 * @desc Add custom header meta for single events
430 */
431 public function single_header() {
432 if (is_single()) {
433 $event = $this->retreive();
434 if ($event->address != '' || ($event->lat != '' && $event->long != '')) {
435 ?>
436 <meta name="geo.placename" content="<?php echo $event->address ?>" />
437 <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
438 <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
439 <?php
440 }
441 if ($event->start != '' && $event->end != '') {
442 ?>
443 <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" />
444 <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" />
445 <?php
446 }
447 }
448 }
449
450 /**
451 *
452 * @param string $str
453 * @return boolean
454 */
455 public function dateisvalid($str) {
456 return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != '';
457 }
458
459 /**
460 *
461 * @param string $date
462 * @param string $sep
463 * @return string
464 */
465 public function parsedate($date, $sep = '') {
466 if (!empty($date)) {
467 return substr($date, 0, 10) . $sep . substr($date, 11, 8);
468 } else {
469 return '';
470 }
471 }
472
473 /**
474 *
475 * @param mixed $date
476 * @param string $format
477 * @return type
478 */
479 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');
486 }
487 return date_i18n($format, $date);
488 }
489
490 /**
491 *
492 * @param WP_Post object $post
493 * @param mixed $links
494 * @return string
495 */
496 public function print_date($post = null, $links = 'deprecated') {
497 $dates = '';
498 $event = $this->retreive($post);
499 $start_date = $event->start;
500 $end_date = $post->end;
501 if ($event->start != '' && $event->end != '') {
502 $gmt_offset = get_option('gmt_offset ');
503 $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 }
532
533 if (!is_admin() && $event->time_end > current_time('timestamp') && (
534 $this->settings['export'] == 'both' ||
535 ($this->settings['export'] == 'single' && is_single() ) ||
536 ($this->settings['export'] == 'list' && !is_single() )
537 )) {
538 // Export event
539 $title = urlencode($post->post_title);
540 $address = urlencode($post->address);
541 $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);
547 $uid = $post->ID . '-' . $post->blog_id;
548
549 // 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);
551
552 // 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';
554
555 // 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
558 $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>';
565 }
566 $dates.='</div>';
567 }
568 return apply_filters('eventpost_printdate', $dates);
569 }
570
571 /**
572 *
573 * @param WP_Post object $post
574 * @return string
575 */
576 public function print_location($post = null) {
577 $location = '';
578 if ($post == null)
579 $post = get_post();
580 elseif (is_numeric($post)) {
581 $post = get_post($post);
582 }
583 if (!isset($post->start)) {
584 $post = $this->retreive($post);
585 }
586 $address = $post->address;
587 $lat = $post->lat;
588 $long = $post->long;
589 $color = $post->color;
590
591 if ($address != '' || ($lat != '' && $long != '')) {
592 $location.='<address';
593 if ($lat != '' && $long != '') {
594 $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" ';
595 }
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>';
599 }
600 $location.='</address>';
601 }
602
603 return apply_filters('eventpost_printlocation', $location);
604 }
605
606 /**
607 *
608 * @param WP_Post object $post
609 * @return string
610 */
611 public function print_categories($post = null) {
612 if ($post == null)
613 $post = get_post();
614 elseif (is_numeric($post)) {
615 $post = get_post($post);
616 }
617 if (!isset($post->start)) {
618 $post = $this->retreive($post);
619 }
620 $cats = '';
621 $categories = $post->categories;
622 if ($categories) {
623 $cats.='<span class="event_category"';
624 $color = $post->color;
625 if ($color != '') {
626 $cats.=' style="color:#' . $color . '"';
627 }
628 $cats.='>';
629 foreach ($categories as $category) {
630 $cats .= $category->name . ' ';
631 }
632 $cats.='</span>';
633 }
634 return $cats;
635 }
636
637 /**
638 * @desc Generate, return or output date event datas
639 * @param WP_Post object $post
640 * @param string $class
641 * @return string
642 */
643 public function get_single($post = null, $class = '') {
644 if ($post == null) {
645 $post = $this->retreive();
646 }
647 $datas_date = $this->print_date($post);
648 $datas_cat = $this->print_categories($post);
649 $datas_loc = $this->print_location($post);
650 if ($datas_date != '' || $datas_loc != '') {
651 $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>';
653 }
654 return '';
655 }
656
657 /**
658 *
659 * @param WP_Post object $post
660 * @param string $class
661 * @return string
662 */
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>';
665 }
666
667 /**
668 *
669 * @param WP_Post object $post
670 * @param string $class
671 * @return string
672 */
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>';
675 }
676
677 /**
678 *
679 * @param WP_Post object $post
680 * @param string $class
681 * @return string
682 */
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>';
685 }
686
687 /**
688 *
689 * @param string $content
690 * @return string
691 */
692 public function display_single($content) {
693 if (is_page() || !is_single() || is_home())
694 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 }
709 add_filter('the_content', array(&$this, 'display_single'), 9999);
710 return $content;
711 }
712
713 /**
714 *
715 * @param WP_Post object $post
716 * @echoes string
717 * @return void
718 */
719 public function print_single($post = null) {
720 echo $this->get_single($post);
721 }
722
723 /**
724 * the_title
725 * @desc alter the post title in order to add icons if needed
726 * @param string $title
727 * @return string
728 */
729 public function the_title($title){
730 if(!in_the_loop() || !$this->settings['loopicons']){
731 return $title;
732 }
733 $event = $this->retreive();
734 if(!empty($event->start)){
735 $title .= ' <span class="dashicons dashicons-calendar"></span>';
736 }
737 if(!empty($event->lat) && !empty($event->long)){
738 $title .= ' <span class="dashicons dashicons-location"></span>';
739 }
740 return $title;
741 }
742
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
770 /**
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
882 * @filter eventpost_listevents
883 * @filter eventpost_item_scheme_entities
884 * @filter eventpost_item_scheme_values
885 * @return string
886 */
887 public function list_events($atts, $id = 'event_list', $context='') {
888 $ep_settings = $this->settings;
889 $defaults = array(
890 'nb' => 0,
891 'type' => 'div',
892 'future' => true,
893 'past' => false,
894 'geo' => 0,
895 'width' => '',
896 'height' => '',
897 'tile' => $ep_settings['tile'],
898 'title' => '',
899 'before_title' => '<h3>',
900 'after_title' => '</h3>',
901 'cat' => '',
902 'tag' => '',
903 'events' => '',
904 'style' => '',
905 'thumbnail' => '',
906 'thumbnail_size' => '',
907 'excerpt' => '',
908 'orderby' => 'meta_value',
909 'order' => 'ASC',
910 'class' => '',
911 'container_schema' => $this->list_shema['container'],
912 'item_schema' => $this->list_shema['item'],
913 );
914 // Map UI options
915 foreach($this->map_interactions as $int_key=>$int_name){
916 $defaults[$int_key]=true;
917 }
918 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events'), $atts);
919
920 extract($atts);
921 if (!is_array($events)) {
922 $events = $this->get_events($atts);
923 }
924 $ret = '';
925 $this->list_id++;
926 if (sizeof($events) > 0) {
927 if($id=='event_geolist'){
928 $this->load_map_scripts();
929 }
930 if (!empty($title)) {
931 $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title);
932 }
933
934 $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div';
935
936 $list = '';
937
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;
943 }
944 $list.=str_replace(
945 apply_filters('eventpost_item_scheme_entities', array(
946 '%child%',
947 '%class%',
948 '%color%',
949 '%event_link%',
950 '%event_thumbnail%',
951 '%event_title%',
952 '%event_date%',
953 '%event_cat%',
954 '%event_location%',
955 '%event_excerpt%'
956 )), apply_filters('eventpost_item_scheme_values', array(
957 $child,
958 $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
968 );
969 }
970 $attributes = '';
971 if($id == 'event_geolist'){
972 $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-disabled-interactions="';
973 foreach($this->map_interactions as $int_key=>$int_name){
974 $attributes.=$atts[$int_key]==false ? $int_key.', ' : '';
975 }
976 $attributes.='"';
977 }
978 $ret.=str_replace(
979 array(
980 '%type%',
981 '%id%',
982 '%class%',
983 '%listid%',
984 '%style%',
985 '%attributes%',
986 '%list%'
987 ), array(
988 $type,
989 $id,
990 $class,
991 $id . $this->list_id,
992 (!empty($width) ? 'width:' . $width . ';' : '') . (!empty($height) ? 'height:' . $height . ';' : '') . $style,
993 $attributes,
994 $list
995 ), $container_schema
996 );
997 }
998 return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
999 }
1000
1001 /**
1002 * get_events
1003 * @param array $attr
1004 * @filter eventpost_params
1005 * @return array of post_ids wich are events
1006 */
1007 public function get_events($atts) {
1008 $requete = (shortcode_atts(apply_filters('eventpost_params', array(
1009 'nb' => 5,
1010 'future' => true,
1011 'past' => false,
1012 'geo' => 0,
1013 'cat' => '',
1014 'tag' => '',
1015 'date' => '',
1016 'orderby' => 'meta_value',
1017 'order' => 'ASC',
1018 'post_type'=> $this->settings['posttypes']
1019 ), 'get_events'), $atts));
1020 extract($requete);
1021 wp_reset_query();
1022
1023 $arg = array(
1024 'post_type' => $post_type,
1025 'posts_per_page' => $nb,
1026 'meta_key' => $this->META_START,
1027 'orderby' => $orderby,
1028 'order' => $order
1029 );
1030
1031 // CAT
1032 if ($cat != '') {
1033 if (preg_match('/[a-zA-Z]/i', $cat)) {
1034 $arg['category_name'] = $cat;
1035 } else {
1036 $arg['cat'] = $cat;
1037 }
1038 }
1039 // TAG
1040 if ($tag != '') {
1041 $arg['tag'] = $tag;
1042 }
1043 // DATES
1044 $meta_query = array(
1045 array(
1046 'key' => $this->META_END,
1047 'value' => '',
1048 'compare' => '!='
1049 ),
1050 array(
1051 'key' => $this->META_END,
1052 'value' => '0:0:00 0:',
1053 'compare' => '!='
1054 ),
1055 array(
1056 'key' => $this->META_END,
1057 'value' => ':00',
1058 'compare' => '!='
1059 ),
1060 array(
1061 'key' => $this->META_START,
1062 'value' => '',
1063 'compare' => '!='
1064 ),
1065 array(
1066 'key' => $this->META_START,
1067 'value' => '0:0:00 0:',
1068 'compare' => '!='
1069 )
1070 );
1071 if ($future == 0 && $past == 0) {
1072 $meta_query = array();
1073 $arg['meta_key'] = null;
1074 $arg['orderby'] = null;
1075 $arg['order'] = null;
1076 } elseif ($future == 1 && $past == 0) {
1077 $meta_query[] = array(
1078 'key' => $this->META_END,
1079 'value' => current_time('mysql'),
1080 'compare' => '>=',
1081 //'type'=>'DATETIME'
1082 );
1083 } elseif ($future == 0 && $past == 1) {
1084 $meta_query[] = array(
1085 'key' => $this->META_END,
1086 'value' => current_time('mysql'),
1087 'compare' => '<=',
1088 //'type'=>'DATETIME'
1089 );
1090 }
1091 if ($date != '') {
1092 $date = date('Y-m-d', $date);
1093
1094 $meta_query = array(
1095 array(
1096 'key' => $this->META_END,
1097 'value' => $date . ' 00:00:00',
1098 'compare' => '>=',
1099 'type' => 'DATETIME'
1100 ),
1101 array(
1102 'key' => $this->META_START,
1103 'value' => $date . ' 23:59:59',
1104 'compare' => '<=',
1105 'type' => 'DATETIME'
1106 )
1107 );
1108 }
1109 // GEO
1110 if ($geo == 1) {
1111 $meta_query[] = array(
1112 'key' => $this->META_LAT,
1113 'value' => '',
1114 'compare' => '!='
1115 );
1116 $meta_query[] = array(
1117 'key' => $this->META_LONG,
1118 'value' => '',
1119 'compare' => '!='
1120 );
1121 $arg['meta_key'] = $this->META_LAT;
1122 $arg['orderby'] = 'meta_value';
1123 $arg['order'] = 'DESC';
1124 }
1125
1126 $arg['meta_query'] = $meta_query;
1127
1128 $query_md5 = 'eventpost_' . md5(var_export($requete, true));
1129 // Check if cache is activated
1130 if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
1131 return is_array($cached_events) ? $cached_events : array();
1132 }
1133
1134
1135 $events = apply_filters('eventpost_get', '', $requete, $arg);
1136 if ('' === $events) {
1137 global $wpdb;
1138 $query = new WP_Query($arg);
1139 $events = $wpdb->get_col($query->request);
1140 foreach ($events as $k => $post) {
1141 $event = $this->retreive($post);
1142 $events[$k] = $event;
1143 }
1144 }
1145 if ($this->settings['cache'] == 1){
1146 set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
1147 }
1148 return $events;
1149 }
1150
1151 /**
1152 *
1153 * @param object $event
1154 * @return object
1155 */
1156 public function retreive($event = null) {
1157 if(isset($event->start)){
1158 return $event;
1159 }
1160 $ob = get_post($event);
1161 $ob->start = get_post_meta($ob->ID, $this->META_START, true);
1162 $ob->end = get_post_meta($ob->ID, $this->META_END, true);
1163 if (!$this->dateisvalid($ob->start)){
1164 $ob->start = '';
1165 }
1166 if (!$this->dateisvalid($ob->end)){
1167 $ob->end = '';
1168 }
1169 $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
1170 $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
1171 $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
1172 $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true);
1173 $ob->long = get_post_meta($ob->ID, $this->META_LONG, true);
1174 $ob->color = get_post_meta($ob->ID, $this->META_COLOR, true);
1175 $ob->categories = get_the_category($ob->ID);
1176 $ob->permalink = get_permalink($ob->ID);
1177 $ob->blog_id = get_current_blog_id();
1178 if ($ob->color == ''){
1179 $ob->color = '000000';
1180 }
1181 return apply_filters('eventpost_retreive', $ob);
1182 }
1183
1184 /** ADMIN ISSUES * */
1185
1186 /**
1187 * set_shortcode_ui
1188 * needs Shortcake (shortcode UI) plugin
1189 * https://wordpress.org/plugins/shortcode-ui/
1190 */
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 ),
1281 );
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 );
1309 }
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
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));
1368
1369 }
1370
1371 /**
1372 * @desc add custom boxes in posts edit page
1373 */
1374 public function add_custom_box() {
1375 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');
1378 }
1379 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');
1381 }
1382 }
1383 /**
1384 * @desc disokay the date custom box
1385 */
1386 public function inner_custom_box_date() {
1387 wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
1388 $post_id = get_the_ID();
1389 $event = $this->retreive($post_id);
1390 $start_date = $event->start;
1391 $end_date = $event->end;
1392 $eventcolor = $event->color;
1393
1394 $language = get_bloginfo('language');
1395 if (strpos($language, '-') > -1) {
1396 $language = strtolower(substr($language, 0, 2));
1397 }
1398 $colors = $this->get_colors();
1399 if (sizeof($colors) > 0):
1400 ?>
1401 <div class="misc-pub-section event-color-section">
1402 <?php _e('Color:', 'eventpost'); ?>
1403 <p>
1404 <?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 ?>/>
1411 </label>
1412 <?php endforeach; ?>
1413 </p>
1414 </div>
1415 <?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 <?php
1448 }
1449 /**
1450 * @desc displays the location custom box
1451 */
1452 public function inner_custom_box_loc() {
1453 $post_id = get_the_ID();
1454 $event = $this->retreive($post_id);
1455 ?>
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>
1463 <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>
1466 </label>
1467
1468 </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>
1474 </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 <?php
1482 }
1483
1484 /**
1485 * @desc display custombox containing shortcode wizard
1486 */
1487 public function inner_custom_box_edit() {
1488 $ep_settings = $this->settings;
1489 ?>
1490 <?php do_action('before_eventpost_generator'); ?>
1491 <div class="all">
1492 <p>
1493 <label for="ep_sce_type"><?php _e('Type :', 'eventpost'); ?>
1494 <select id="ep_sce_type">
1495 <option value='list'><?php _e('List', 'eventpost') ?></option>
1496 <option value='map'><?php _e('Map', 'eventpost') ?></option>
1497 </select>
1498 </label>
1499 </p>
1500
1501 <p>
1502 <label for="ep_sce_nb"><?php _e('Number of posts', 'eventpost'); ?>
1503 <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>
1505 </label>
1506 </p>
1507
1508 <p>
1509 <label for="ep_sce_cat"><?php _e('Only in :', 'eventpost'); ?>
1510 <select id="ep_sce_cat" data-att="cat">
1511 <option value=''><?php _e('All', 'eventpost') ?></option>
1512 <?php
1513 $cats = get_categories();
1514 foreach ($cats as $cat) {
1515 ?>
1516 <option value="<?= $cat->slug ?>" <?php
1517 if ($cat->slug == $eventpost_cat) {
1518 echo'selected';
1519 }
1520 ?>><?= $cat->cat_name ?></option>
1521 <?php } ?>
1522 </select>
1523 </label>
1524 </p>
1525
1526 <p>
1527 <label for="ep_sce_future"><?php _e('Future events:', 'eventpost'); ?>
1528 <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>
1531 </select>
1532 </label>
1533 <label for="ep_sce_past"><?php _e('Past events:', 'eventpost'); ?>
1534 <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>
1537 </select>
1538 </label>
1539 </p>
1540
1541 <div id="ep_sce_listonly" class="list">
1542 <p>
1543 <label for="ep_sce_geo"><?php _e('Only geotagged events:', 'eventpost'); ?>
1544 <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>
1547 </select>
1548 </label>
1549 </p>
1550 </div>
1551 <div id="ep_sce_maponly" class="map">
1552 <p>
1553 <label for="ep_sce_tile"><?php _e('Map background', 'eventpost'); ?>
1554 <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>
1573 <?php endforeach; ?>
1574 </select>
1575 </label>
1576 </p>
1577 <p>
1578 <label for="ep_sce_width"><?php _e('Width', 'eventpost'); ?>
1579 <input id="ep_sce_width" type="text" value="500px" data-att="width"/>
1580 </label>
1581 </p>
1582 <p>
1583 <label for="ep_sce_height"><?php _e('Height', 'eventpost'); ?>
1584 <input id="ep_sce_height" type="text" value="500px" data-att="height"/>
1585 </label>
1586 </p>
1587 </div>
1588 <?php do_action('after_eventpost_generator'); ?>
1589 <div id="ep_sce_shortcode">[event_list]</div>
1590 <a class="button" id="ep_sce_submit"><?php _e('Insert shortcode', 'eventpost'); ?></a>
1591 </div>
1592 <script>
1593 var IEbof = false;
1594 </script>
1595 <!--[if lt IE 9]>
1596 <script>IEbof=true;</script>
1597 <![endif]-->
1598 <?php
1599 }
1600
1601 /**
1602 * @desc When the post is saved, saves our custom data
1603 * @param int $post_id
1604 * @return void
1605 */
1606 public function save_postdata($post_id) {
1607 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
1608 return;
1609 }
1610
1611 if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce', FILTER_SANITIZE_STRING), plugin_basename(__FILE__))){
1612 return;
1613 }
1614
1615 // Clean color or no color
1616 if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR, FILTER_SANITIZE_STRING)) {
1617 update_post_meta($post_id, $this->META_COLOR, $color);
1618 }
1619 // Clean date or no date
1620 if ((false !== $start = filter_input(INPUT_POST, $this->META_START, FILTER_SANITIZE_STRING)) &&
1621 (false !== $end = filter_input(INPUT_POST, $this->META_END, FILTER_SANITIZE_STRING)) &&
1622 '' != $start &&
1623 '' != $end) {
1624 update_post_meta($post_id, $this->META_START, substr($start,0,16).':00');
1625 update_post_meta($post_id, $this->META_END, substr($end,0,16).':00');
1626 }
1627 else {
1628 delete_post_meta($post_id, $this->META_START);
1629 delete_post_meta($post_id, $this->META_END);
1630 }
1631
1632 // Clean location or no location
1633 if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT, FILTER_SANITIZE_STRING)) &&
1634 (false !== $long = filter_input(INPUT_POST, $this->META_LONG, FILTER_SANITIZE_STRING)) &&
1635 '' != $lat &&
1636 '' != $long) {
1637 update_post_meta($post_id, $this->META_ADD, filter_input(INPUT_POST, $this->META_ADD, FILTER_SANITIZE_STRING));
1638 update_post_meta($post_id, $this->META_LAT, $lat);
1639 update_post_meta($post_id, $this->META_LONG, $long);
1640 }
1641 else {
1642 delete_post_meta($post_id, $this->META_ADD);
1643 delete_post_meta($post_id, $this->META_LAT);
1644 delete_post_meta($post_id, $this->META_LONG);
1645 }
1646 }
1647
1648 /**
1649 *
1650 * @param string $date
1651 * @param string $cat
1652 * @param boolean $display
1653 * @return boolean
1654 */
1655 public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='') {
1656 $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true));
1657 $nb = count($events);
1658 if ($display) {
1659 if ($nb > 0) {
1660 $ret.='<ul>';
1661 foreach ($events as $event) {
1662 if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
1663 $event->guid = '#';
1664 }
1665 $ret.='<li>'
1666 . '<a href="' . $event->guid . '">'
1667 . '<h4>' . $event->post_title . '</h4>'
1668 .$this->get_single($event)
1669 . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
1670 .'</a>'
1671 . '</li>';
1672 }
1673 $ret.='</ul>';
1674 return $ret;
1675 }
1676 return'';
1677 } 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);
1679 }
1680 }
1681
1682
1683 /**
1684 * @param array $atts
1685 * @filter eventpost_params
1686 * @return string
1687 */
1688 public function calendar($atts) {
1689 extract(shortcode_atts(apply_filters('eventpost_params', array(
1690 'date' => date('Y-n'),
1691 'cat' => '',
1692 'mondayfirst' => 0, //1 : weeks starts on monday
1693 'datepicker' => 1,
1694 'colored' => 1,
1695 'thumbnail'=>'',
1696 ), 'calendar'), $atts));
1697
1698 $annee = substr($date, 0, 4);
1699 $mois = substr($date, 5);
1700
1701 $time = mktime(0, 0, 0, $mois, 1, $annee);
1702
1703
1704 $JourMax = date("t", $time);
1705 $NoJour = -date("w", $time);
1706 if ($mondayfirst == 0) {
1707 $NoJour +=1;
1708 } else {
1709 $NoJour +=2;
1710 $this->Week[] = array_shift($this->Week);
1711 }
1712 if ($NoJour > 0 && $mondayfirst == 1) {
1713 $NoJour -=7;
1714 }
1715 $ret = '<table>';
1716 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> ';
1719 $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>';
1725 }
1726 $ret.='<tbody>';
1727 $ret.='<tr class="event_post_cal_days">';
1728 for ($w = 0; $w < 7; $w++) {
1729 $ret.='<td>' . strtoupper(substr($this->Week[$w], 0, 1)) . '</td>';
1730 }
1731 $ret.='</tr>';
1732
1733
1734 $sqldate = date('Y-m', $time);
1735 $cejour = date('Y-m-d');
1736 for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois
1737 $ret.='<tr>';
1738 for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
1739 if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
1740 $td = '<td class="event_post_day">';
1741 if ($sqldate . '-' . $NoJour == $cejour) {
1742 $td = '<td class="event_post_day_now">';
1743 }
1744 $ret.=$td;
1745
1746 $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail);
1747 $ret.='</td>';
1748 } else {
1749 $ret.='<td></td>';
1750 }
1751 $NoJour ++;
1752 }
1753 $ret.='</tr>';
1754 }
1755 $ret.='</tbody></table>';
1756 return $ret;
1757 }
1758
1759 /**
1760 * @desc echoes the content of the calendar in ajax context
1761 */
1762 public function ajaxcal() {
1763 echo $this->calendar(array(
1764 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')),
1765 'cat' => esc_attr(FILTER_INPUT(INPUT_GET, 'cat')),
1766 'mondayfirst' => esc_attr(FILTER_INPUT(INPUT_GET, 'mf')),
1767 'datepicker' => esc_attr(FILTER_INPUT(INPUT_GET, 'dp')),
1768 'colored' => esc_attr(FILTER_INPUT(INPUT_GET, 'color')),
1769 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')),
1770 ));
1771 exit();
1772 }
1773
1774 /**
1775 * @desc echoes the date of the calendar in ajax context
1776 */
1777 public function ajaxdate() {
1778 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 exit();
1780 }
1781
1782 /**
1783 * @desc echoes a date in ajax context
1784 */
1785 public function HumanDate() {
1786 if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
1787 $date = strtotime($_REQUEST['date']);
1788 echo $this->human_date($date) . date(' H:i', $date);
1789 exit();
1790 }
1791 }
1792
1793 /**
1794 * @desc AJAX Get lat long from address
1795 */
1796 public function GetLatLong() {
1797 if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
1798 // verifier le cache
1799 $q = $_REQUEST['q'];
1800 header('Content-Type: application/json');
1801 $transient_name = 'eventpost_osquery_' . $q;
1802 $val = get_transient($transient_name);
1803 if (false === $val || empty($val)) {
1804 $language = get_bloginfo('language');
1805 if (strpos($language, '-') > -1) {
1806 $language = strtolower(substr($language, 0, 2));
1807 }
1808 $val = file_get_contents('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language);
1809 set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
1810 }
1811 echo $val;
1812 exit();
1813 }
1814 }
1815
1816 /**
1817 * @desc alters columns
1818 * @param array $defaults
1819 * @return array
1820 */
1821 public function columns_head($defaults) {
1822 $defaults['event'] = __('Event', 'eventpost');
1823 $defaults['location'] = __('Location', 'eventpost');
1824 return $defaults;
1825 }
1826
1827 /**
1828 * @desc echoes content of a row in a given column
1829 * @param string $column_name
1830 * @param int $post_id
1831 */
1832 public function columns_content($column_name, $post_id) {
1833 if ($column_name == 'location') {
1834 $lat = get_post_meta($post_id, $this->META_LAT, true);
1835 $lon = get_post_meta($post_id, $this->META_LONG, true);
1836
1837 if (!empty($lat) && !empty($lon)) {
1838 $color = get_post_meta($post_id, $this->META_COLOR, true);
1839 if ($color == ''){
1840 $color = '777777';
1841 }
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>';
1843 }
1844 }
1845 if ($column_name == 'event') {
1846 echo $this->print_date($post_id, false);
1847 }
1848 }
1849
1850 /** ADMIN PAGES **/
1851
1852 /**
1853 * @desc save settings end redirect
1854 * @return void
1855 */
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 }
1881 }
1882
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 /**
1893 * @desc adds menu items
1894 */
1895 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'));
1897 }
1898 /**
1899 * @desc adds items to the native "right now" dashboard widget
1900 * @param array $elements
1901 * @return array
1902 */
1903 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;
1907 }
1908
1909 /**
1910 * @desc output content of the setting page
1911 */
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') ?>
1948
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') ?>
1994
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') ?>
2028
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') ?>
2042
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>
2075
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>
2126
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>
2145 </form>
2146 </div>
2147 <?php
2148 do_action('eventpost_after_settings_form');
2149 }
2150
2151 /*
2152 * feed
2153 * generate ICS or VCS files from a category
2154 */
2155
2156 /**
2157 *
2158 * @param timestamp $timestamp
2159 * @return string
2160 */
2161 public function ics_date($timestamp){
2162 return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z';
2163 }
2164
2165 /**
2166 * @desc outputs an RSS document
2167 */
2168 public function feed(){
2169 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);
2172
2173 header("content-type:text/calendar");
2174 header("Pragma: public");
2175 header("Expires: 0");
2176 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
2177 header("Cache-Control: public");
2178 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));
2190 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;
2204 }
2205 }
2206 }