PluginProbe
Event Post / 4.2
Event Post v4.2
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
event-post / eventpost.php

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

2,066 lines 83.5 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: 4.2.4
7 Author: bastho
8 Contributors: n4thaniel, ecolosites
9 Author URI: http://ecolosites.eelv.fr/
10 License: GPLv2
11 Text Domain: event-post
12 Domain Path: /languages/
13 Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda
14 */
15
16
17 $EventPost = new EventPost();
18
19 /**
20 * The main class where everything begins.
21 *
22 * Add calendar and/or geolocation metadata on posts
23 */
24 class EventPost {
25 const META_START = 'event_begin';
26 const META_END = 'event_end';
27 const META_COLOR = 'event_color';
28 // http://codex.wordpress.org/Geodata
29 const META_ADD = 'geo_address';
30 const META_LAT = 'geo_latitude';
31 const META_LONG = 'geo_longitude';
32
33 public $list_id;
34 public $NomDuMois;
35 public $Week;
36 public $settings;
37 public $dateformat;
38
39 public $version = '4.2.4';
40
41 public $map_interactions;
42
43 public $Shortcodes;
44
45 public function __construct() {
46 load_plugin_textdomain('event-post', false, 'event-post/languages');
47
48 add_action('widgets_init', array(&$this,'init'), 1);
49 add_action('save_post', array(&$this, 'save_postdata'));
50 add_action('admin_menu', array(&$this, 'manage_options'));
51 add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now'));
52
53 // Scripts
54 add_action('admin_enqueue_scripts', array(&$this, 'admin_head'));
55 add_action('admin_print_scripts', array(&$this, 'admin_scripts'));
56 add_action('wp_enqueue_scripts', array(&$this, 'load_styles'));
57
58 // Single
59 add_filter('the_content', array(&$this, 'display_single'), 9999);
60 add_filter('the_title', array(&$this, 'the_title'), 9999);
61 add_action('the_event', array(&$this, 'print_single'));
62 add_action('wp_head', array(&$this, 'single_header'));
63
64 // Ajax
65 add_action('wp_ajax_EventPostGetLatLong', array(&$this, 'GetLatLong'));
66 add_action('wp_ajax_EventPostHumanDate', array(&$this, 'HumanDate'));
67 add_action('wp_ajax_EventPostCalendar', array(&$this, 'ajaxcal'));
68 add_action('wp_ajax_nopriv_EventPostCalendar', array(&$this, 'ajaxcal'));
69 add_action('wp_ajax_EventPostCalendarDate', array(&$this, 'ajaxdate'));
70 add_action('wp_ajax_nopriv_EventPostCalendarDate', array(&$this, 'ajaxdate'));
71
72 // Calendar publishing
73 add_action('wp_ajax_EventPostFeed', array(&$this, 'feed'));
74 add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed'));
75
76 //
77 add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1);
78
79 // Admin
80 add_action('admin_post_EventPostSaveSettings', array(&$this, 'save_settings'));
81
82 add_action('widgets_init', array(&$this, 'register_widgets'),1,1);
83
84 include_once (plugin_dir_path(__FILE__) . 'widget.php');
85 include_once (plugin_dir_path(__FILE__) . 'widget.cal.php');
86 include_once (plugin_dir_path(__FILE__) . 'widget.map.php');
87 include_once (plugin_dir_path(__FILE__) . 'multisite.php');
88 include_once (plugin_dir_path(__FILE__) . 'shortcodes.php');
89
90 }
91
92 /**
93 * PHP4 constructor
94 */
95 public function EventPost(){
96 $this->__construct();
97 }
98
99 /**
100 * Init all variables when WP is ready
101 */
102 public function init(){
103 $this->META_START = 'event_begin';
104 $this->META_END = 'event_end';
105 $this->META_COLOR = 'event_color';
106 // http://codex.wordpress.org/Geodata
107 $this->META_ADD = 'geo_address';
108 $this->META_LAT = 'geo_latitude';
109 $this->META_LONG = 'geo_longitude';
110 $this->list_id = 0;
111 $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'));
112 $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post'));
113
114 $this->maps = $this->get_maps();
115 $this->settings = $this->get_settings();
116
117 $this->Shortcodes = new EventPost_Shortcodes();
118
119 // Edit
120 add_action('add_meta_boxes', array(&$this, 'add_custom_box'));
121 foreach($this->settings['posttypes'] as $posttype){
122 add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2);
123 add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2);
124 }
125
126
127 if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) {
128 $this->markpath = ABSPATH.'/'.$this->settings['markpath'];
129 $this->markurl = $this->settings['markurl'];
130 } else {
131 $this->markpath = plugin_dir_path(__FILE__) . 'markers/';
132 $this->markurl = plugins_url('/markers/', __FILE__);
133 }
134
135 $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post'));
136
137 $this->default_list_shema = array(
138 'container' => '
139 <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>
140 %list%
141 </%type%>',
142 'item' => '
143 <%child% class="event_item %class%" data-color="%color%">
144 <a href="%event_link%">
145 %event_thumbnail%
146 <h5>%event_title%</h5>
147 </a>
148 %event_date%
149 %event_cat%
150 %event_location%
151 %event_excerpt%
152 </%child%>'
153 );
154 $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema);
155
156 $this->map_interactions=array(
157 'DragRotate'=>__('Drag Rotate', 'event-post'),
158 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'),
159 'DragPan'=>__('Drag Pan', 'event-post'),
160 'PinchRotate'=>__('Pinch Rotate', 'event-post'),
161 'PinchZoom'=>__('Pinch Zoom', 'event-post'),
162 'KeyboardPan'=>__('Keyboard Pan', 'event-post'),
163 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'),
164 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'),
165 'DragZoom'=>__('Drag Zoom', 'event-post'),
166 );
167 }
168
169 public function register_widgets(){
170 register_widget('EventPost_List');
171 register_widget('EventPost_Map');
172 register_widget('EventPost_Cal');
173 }
174
175 /**
176 * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color.
177 * @param string $color
178 * @return array $color($R, $G, $B)
179 */
180 public function hex2dec($color = '000000') {
181 $tbl_color = array();
182 if (!strstr('#', $color)){
183 $color = '#' . $color;
184 }
185 $tbl_color['R'] = hexdec(substr($color, 1, 2));
186 $tbl_color['G'] = hexdec(substr($color, 3, 2));
187 $tbl_color['B'] = hexdec(substr($color, 5, 2));
188 return $tbl_color;
189 }
190 /**
191 * Fetch all registered image sizes
192 * @global array $_wp_additional_image_sizes
193 * @return array
194 */
195 function get_thumbnail_sizes(){
196 global $_wp_additional_image_sizes;
197 $sizes = array('thumbnail', 'medium', 'large', 'full');
198 foreach(array_keys($_wp_additional_image_sizes) as $size){
199 $sizes[]=$size;
200 }
201 return $sizes;
202 }
203
204 /**
205 * Just for localization
206 */
207 private function no_use() {
208 __('Add calendar and/or geolocation metadata on posts', 'event-post');
209 __('Event Post', 'event-post');
210 }
211
212 /**
213 * Get blog settings, load and saves default settings if needed. Can be filterred using
214 *
215 * `<?php add_filter('eventpost_getsettings', 'some_function'); ?>`
216 *
217 * @action eventpost_getsettings
218 * @filter eventpost_getsettings
219 * @return array
220 */
221 public function get_settings() {
222 $ep_settings = get_option('ep_settings');
223 $reg_settings=false;
224 if(!is_array($ep_settings)){
225 $ep_settings = array();
226 }
227 if (!isset($ep_settings['dateformat']) || empty($ep_settings['dateformat'])) {
228 $ep_settings['dateformat'] = get_option('date_format');
229 $reg_settings=true;
230 }
231 if (!isset($ep_settings['timeformat']) || empty($ep_settings['timeformat'])) {
232 $ep_settings['timeformat'] = get_option('time_format');
233 $reg_settings=true;
234 }
235 if (!isset($ep_settings['tile']) || empty($ep_settings['tile']) || !isset($this->maps[$ep_settings['tile']])) {
236 $maps = array_keys($this->maps);
237 $ep_settings['tile'] = $this->maps[$maps[0]]['id'];
238 $reg_settings=true;
239 }
240 if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) {
241 $ep_settings['cache'] = 0;
242 $reg_settings=true;
243 }
244 if (!isset($ep_settings['export']) || empty($ep_settings['export'])) {
245 $ep_settings['export'] = 'both';
246 $reg_settings=true;
247 }
248 if (!isset($ep_settings['dateforhumans'])) {
249 $ep_settings['dateforhumans'] = 1;
250 $reg_settings=true;
251 }
252 if (!isset($ep_settings['emptylink'])) {
253 $ep_settings['emptylink'] = 1;
254 $reg_settings=true;
255 }
256 if (!isset($ep_settings['markpath'])) {
257 $ep_settings['markpath'] = '';
258 $reg_settings=true;
259 }
260 if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) {
261 $ep_settings['singlepos'] = 'after';
262 $reg_settings=true;
263 }
264 if (!isset($ep_settings['loopicons'])) {
265 $ep_settings['loopicons'] = 1;
266 $reg_settings=true;
267 }
268 if (!isset($ep_settings['adminpos']) || empty($ep_settings['adminpos'])) {
269 $ep_settings['adminpos'] = 'side';
270 $reg_settings=true;
271 }
272 if (!isset($ep_settings['container_shema']) ) {
273 $ep_settings['container_shema'] = '';
274 $reg_settings=true;
275 }
276
277 if (!isset($ep_settings['item_shema']) ) {
278 $ep_settings['item_shema'] = '';
279 $reg_settings=true;
280 }
281
282 if(!isset($ep_settings['datepicker'])){
283 $ep_settings['datepicker']='dual';
284 $reg_settings=true;
285 }
286
287 if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){
288 $ep_settings['posttypes']=array('post');
289 $reg_settings=true;
290 }
291
292 do_action('eventpost_getsettings');
293
294 //Save settings not changed
295 if($reg_settings===true){
296 update_option('ep_settings', $ep_settings);
297 }
298 return apply_filters('eventpost_getsettings', $ep_settings);
299 }
300
301 /**
302 * Checks if HTML schemas are not empty
303 * @param array $shema
304 * @return array
305 */
306 public function custom_shema($shema){
307 if(!empty($this->settings['container_shema'])){
308 $shema['container']=$this->settings['container_shema'];
309 }
310 if(!empty($this->settings['item_shema'])){
311 $shema['item']=$this->settings['item_shema'];
312 }
313 return $shema;
314 }
315
316 /**
317 * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example:
318 *
319 * ```
320 * <?php
321 * add_filter('eventpost_getsettings', 'map_function');
322 * function map_function($maps){
323 * array_push($maps, array(
324 * 'name'=>'Myt custom map',
325 * 'id'=>'custom_map',
326 * 'urls'=>array(
327 * 'http://a.customurl.org/{z}/{x}/{y}.png',
328 * 'http://b.customurl.org/{z}/{x}/{y}.png',
329 * 'http://c.customurl.org/{z}/{x}/{y}.png',
330 * )
331 * ));
332 * return $maps;
333 * }
334 * ?>
335 * ```
336 *
337 * @filter eventpost_maps
338 * @return array of map arrays ['name', 'id', 'urls']
339 */
340 public function get_maps() {
341 $maps = array();
342 $filename = plugin_dir_path(__FILE__) . 'maps.json';
343 if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) {
344 // Convert objects to array to ensure retrocompatibility
345 $arrays = array();
346 foreach($json as $map){
347 $arrays[$map->id] = (array) $map;
348 }
349 $maps = apply_filters('eventpost_maps', $arrays);
350 }
351 return $maps;
352 }
353
354 /**
355 *
356 * @return array
357 */
358 public function get_colors() {
359 $colors = array();
360 if (is_dir($this->markpath)) {
361 $files = scandir($this->markpath);
362 foreach ($files as $file) {
363 if (substr($file, -4) == '.png') {
364 $colors[substr($file, 0, -4)] = $this->markurl . $file;
365 }
366 }
367 }
368 return $colors;
369 }
370
371 /**
372 *
373 * @param string $color
374 * @return sring
375 */
376 public function get_marker($color) {
377 if (is_file($this->markpath . $color . '.png')) {
378 return $this->markurl . $color . '.png';
379 }
380 return plugins_url('/markers/ffffff.png', __FILE__);
381 }
382
383 /**
384 * Enqueue CSS files
385 */
386 public function load_styles() {
387 //CSS
388 wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
389 wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version);
390 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
391 wp_enqueue_style('dashicons-css', includes_url('/css/dashicons.min.css'));
392 }
393
394 /**
395 * Enqueue JS files
396 */
397 public function load_scripts() {
398 // JS
399 wp_enqueue_script('jquery', false, false, false, true);
400 wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), false, $this->version, true);
401 wp_localize_script('event-post', 'eventpost_params', array(
402 'imgpath' => plugins_url('/img/', __FILE__),
403 'maptiles' => $this->maps,
404 'defaulttile' => $this->settings['tile'],
405 'ajaxurl' => admin_url() . 'admin-ajax.php',
406 'map_interactions'=>$this->map_interactions,
407 ));
408 }
409 /**
410 * Enqueue JS files for maps
411 */
412 public function load_map_scripts() {
413 // JS
414 wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true);
415 $this->load_scripts();
416 }
417
418 /**
419 * Enqueue CSS files in admin
420 */
421 public function admin_head() {
422 $page = basename($_SERVER['SCRIPT_NAME']);
423 if( $page!='post-new.php' && !($page=='post.php' && isset($_GET['action']) & $_GET['action']=='edit') ){
424 return;
425 }
426 wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version);
427 wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version);
428 wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version);
429 if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
430 wp_enqueue_style('event-post-datetimepicker', plugins_url('/css/jquery.datetimepicker.css', __FILE__), false, $this->version);
431 }
432 }
433
434 /**
435 * Enqueue JS files in admin
436 */
437 public function admin_scripts() {
438 $page = basename($_SERVER['SCRIPT_NAME']);
439 if( $page!='post-new.php' && !($page=='post.php' && isset($_GET['action']) & $_GET['action']=='edit') ){
440 return;
441 }
442 wp_enqueue_script('jquery');
443 wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), array('jquery'), $this->version, true);
444 if($this->settings['datepicker']=='dual' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
445 wp_enqueue_script('event-post-datetimepicker', plugins_url('/js/jquery.datetimepicker.js', __FILE__), array('jquery'), $this->version, true);
446 }
447 if($this->settings['datepicker']=='separate' || (isset($_GET['page']) && $_GET['page']=='event-settings')){
448 wp_enqueue_script('jquery-ui-datepicker');
449 }
450 $language = get_bloginfo('language');
451 if (strpos($language, '-') > -1) {
452 $language = strtolower(substr($language, 0, 2));
453 }
454 wp_localize_script('event-post-admin', 'eventpost', array(
455 'imgpath' => plugins_url('/img/', __FILE__),
456 'date_choose' => __('Choose', 'event-post'),
457 'date_format' => __('yy-mm-dd', 'event-post'),
458 'more_icons' => __('More icons', 'event-post'),
459 'pick_a_date'=>__('Pick a date','event-post'),
460 'META_START' => $this->META_START,
461 'META_END' => $this->META_END,
462 'META_ADD' => $this->META_ADD,
463 'META_LAT' => $this->META_LAT,
464 'META_LONG' => $this->META_LONG,
465 'lang'=>$language,
466 'maptiles' => $this->maps,
467 'defaulttile' => $this->settings['tile']
468 ));
469 }
470
471 /**
472 * Add custom header meta for single events
473 */
474 public function single_header() {
475 if (is_single()) {
476 $event = $this->retreive();
477 if ($event->address != '' || ($event->lat != '' && $event->long != '')) {
478 ?>
479 <meta name="geo.placename" content="<?php echo $event->address ?>" />
480 <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
481 <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" />
482 <?php
483 }
484 if ($event->start != '' && $event->end != '') {
485 ?>
486 <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" />
487 <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" />
488 <?php
489 }
490 }
491 }
492
493 /**
494 *
495 * @param string $str
496 * @return boolean
497 */
498 public function dateisvalid($str) {
499 return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != '';
500 }
501
502 /**
503 *
504 * @param string $date
505 * @param string $sep
506 * @return string
507 */
508 public function parsedate($date, $sep = '') {
509 if (!empty($date)) {
510 return substr($date, 0, 10) . $sep . substr($date, 11, 8);
511 } else {
512 return '';
513 }
514 }
515
516 /**
517 *
518 * @param mixed $date
519 * @param string $format
520 * @return type
521 */
522 public function human_date($date, $format = 'l j F Y') {
523 if($this->settings['dateforhumans']){
524 if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) {
525 return __('today', 'event-post');
526 } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) {
527 return __('tomorrow', 'event-post');
528 } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) {
529 return __('yesterday', 'event-post');
530 }
531 }
532 return date_i18n($format, $date);
533 }
534
535 /**
536 *
537 * @param timestamp $time_start
538 * @param timestamp $time_end
539 * @return string
540 */
541 public function delta_date($time_start, $time_end){
542 if(!$time_start || !$time_end){
543 return;
544 }
545
546 //Display dates
547 $dates='<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">';
548 if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) {
549 $dates.= '<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">'
550 . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>";
551 if (date('H:i', $time_start) != date('H:i', $time_end) && date('H:i', $time_start) != '00:00' && date('H:i', $time_end) != '00:00') {
552 $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
553 <span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>
554 <span class="linking_word linking_word-t">' . __('to', 'event-post') . '</span>
555 <span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>';
556 }
557 elseif (date('H:i', $time_start) != '00:00') {
558 $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span>
559 <time class="time time-single" itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' . date_i18n($this->settings['timeformat'], $time_start) . '</time>';
560 }
561 $dates.='</time>';
562 } else {
563 $dates.= '
564 <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span>
565 <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']) . '</time>
566 <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span>
567 <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']) . '</time>
568 ';
569 }
570 return $dates;
571 }
572
573 /**
574 *
575 * @param WP_Post object $post
576 * @param mixed $links
577 * @return string
578 */
579 public function print_date($post = null, $links = 'deprecated', $context='') {
580 $dates = '';
581 $event = $this->retreive($post);
582 if ($event->start != '' && $event->end != '') {
583
584 $dates.=$this->delta_date($event->time_start, $event->time_end);
585
586 $timezone_string = get_option('timezone_string');
587 $gmt_offset = get_option('gmt_offset ');
588 $codegmt = 0;
589 if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') {
590 $codegmt = $gmt_offset * -1;
591 $gmt_offset = '+' . $gmt_offset;
592 }
593
594 if (!is_admin() && $event->time_end > current_time('timestamp') && (
595 $this->settings['export'] == 'both' ||
596 ($this->settings['export'] == 'single' && is_single() ) ||
597 ($this->settings['export'] == 'list' && !is_single() )
598 )) {
599 // Export event
600 $title = urlencode($post->post_title);
601 $address = urlencode($post->address);
602 $url = urlencode($post->guid);
603
604 $mt = strtotime($codegmt . ' Hours', $event->time_start);
605 $d_s = date("Ymd", $mt) . 'T' . date("His", $mt);
606 $mte = strtotime($codegmt . ' Hours', $event->time_end);
607 $d_e = date("Ymd", $mte) . 'T' . date("His", $mte);
608 $uid = $post->ID . '-' . $post->blog_id;
609
610 // format de date ICS
611 $ics_url = plugins_url('export/ics.php', __FILE__) . '?t=' . $title . '&amp;u=' . $uid . '&amp;sd=' . $d_s . '&amp;ed=' . $d_e . '&amp;a=' . $address . '&amp;d=' . $url . '&amp;tz=%3BTZID%3D' . urlencode($timezone_string);
612
613 // format de date Google cal
614 $google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&amp;text=' . $title . '&amp;dates=' . $d_s . 'Z/' . $d_e . 'Z&amp;details=' . $url . '&amp;ctz='.$timezone_string.'&amp;location=' . $address . '&amp;trp=false&amp;sprop=&amp;sprop=name';
615
616 // format de date VCS
617 $vcs_url = plugins_url('export/vcs.php', __FILE__) . '?t=' . $title . '&amp;u=' . $uid . '&amp;sd=' . $d_s . '&amp;ed=' . $d_e . '&amp;a=' . $address . '&amp;d=' . $url . '&amp;tz=%3BTZID%3D' . urlencode($timezone_string);
618
619 $dates.='
620 <span class="eventpost-date-export">
621 <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a>
622 <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a>
623 <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a>
624 <i class=" dashicons-before dashicons-calendar"></i>
625 </span>';
626 }
627 $dates.='</div>';
628 }
629 return apply_filters('eventpost_printdate', $dates);
630 }
631
632 /**
633 *
634 * @param WP_Post object $post
635 * @return string
636 */
637 public function print_location($post=null, $context='') {
638 $location = '';
639 if ($post == null)
640 $post = get_post();
641 elseif (is_numeric($post)) {
642 $post = get_post($post);
643 }
644 if (!isset($post->start)) {
645 $post = $this->retreive($post);
646 }
647 $address = $post->address;
648 $lat = $post->lat;
649 $long = $post->long;
650 $color = $post->color;
651
652 if ($address != '' || ($lat != '' && $long != '')) {
653 $location.='<address';
654 if ($lat != '' && $long != '') {
655 $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" ';
656 }
657 $location.=' itemprop="adr"><span>' . $address . '</span>';
658 if ($context=='single' && $lat != '' && $long != '') {
659 $location.='<a class="event_link gps dashicons-before dashicons-location-alt" href="https://www.openstreetmap.org/?lat=' . $lat.='&amp;lon=' . $long.='&amp;zoom=13" target="_blank" itemprop="geo">' . __('Map', 'event-post') . '</a>';
660 }
661 $location.='</address>';
662 }
663
664 return apply_filters('eventpost_printlocation', $location);
665 }
666
667 /**
668 *
669 * @param WP_Post object $post
670 * @return string
671 */
672 public function print_categories($post=null, $context='') {
673 if ($post == null)
674 $post = get_post();
675 elseif (is_numeric($post)) {
676 $post = get_post($post);
677 }
678 if (!isset($post->start)) {
679 $post = $this->retreive($post);
680 }
681 $cats = '';
682 $categories = $post->categories;
683 if ($categories) {
684 $cats.='<span class="event_category"';
685 $color = $post->color;
686 if ($color != '') {
687 $cats.=' style="color:#' . $color . '"';
688 }
689 $cats.='>';
690 foreach ($categories as $category) {
691 $cats .= $category->name . ' ';
692 }
693 $cats.='</span>';
694 }
695 return $cats;
696 }
697
698 /**
699 * Generate, return or output date event datas
700 * @param WP_Post object $post
701 * @param string $class
702 * @return string
703 */
704 public function get_single($post = null, $class = '', $context='') {
705 if ($post == null) {
706 $post = $this->retreive();
707 }
708 $datas_date = $this->print_date($post, null, $context);
709 $datas_cat = $this->print_categories($post, $context);
710 $datas_loc = $this->print_location($post, $context);
711 if ($datas_date != '' || $datas_loc != '') {
712 $rgb = $this->hex2dec($post->color);
713 return '<div class="event_data ' . $class . '" style="border-left-color:#' . $post->color . ';background:rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ',0.1)" itemscope itemtype="http://microformats.org/profile/hcard">' . $datas_date . $datas_cat . $datas_loc . '</div>';
714 }
715 return '';
716 }
717
718 /**
719 * Displays dates of a gieven post
720 * @param WP_Post object $post
721 * @param string $class
722 * @return string
723 */
724 public function get_singledate($post = null, $class = '', $context='') {
725 return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_date($post, null, $context) . '</div>';
726 }
727
728 /**
729 * Displays coloured terms of a given post
730 * @param WP_Post object $post
731 * @param string $class
732 * @return string
733 */
734 public function get_singlecat($post = null, $class = '', $context='') {
735 return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_categories($post, $context) . '</div>';
736 }
737
738 /**
739 * Displays location of a given post
740 * @param WP_Post object $post
741 * @param string $class
742 * @return string
743 */
744 public function get_singleloc($post = null, $class = '', $context='') {
745 return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . $this->print_location($post, $context) . '</div>';
746 }
747
748 /**
749 * Uses `the_content` filter to add event details before or after the content of the current post
750 * @param string $content
751 * @return string
752 */
753 public function display_single($content) {
754 if (is_page() || !is_single() || is_home())
755 return $content;
756 $post = get_queried_object();
757 //Prevent from filters applying "the_content" on another thing than the current post content
758 remove_filter('the_content', array(&$this, 'display_single'), 9999);
759 $current_content = apply_filters('the_content', $post->post_content);
760 if ($current_content == $content) {
761 $post = $this->retreive();
762 if($this->settings['singlepos']=='before'){
763 $content=$this->get_single($post, 'event_single', 'single').$content;
764 }
765 else{
766 $content.=$this->get_single($post, 'event_single', 'single');
767 }
768 $this->load_map_scripts();
769 }
770 add_filter('the_content', array(&$this, 'display_single'), 9999);
771 return $content;
772 }
773
774 /**
775 * Outputs events details (dates, geoloc, terms) of given post
776 * @param WP_Post object $post
777 * @echoes string
778 * @return void
779 */
780 public function print_single($post = null) {
781 echo $this->get_single($post);
782 }
783
784 /**
785 * Alter the post title in order to add icons if needed
786 * @param string $title
787 * @return string
788 */
789 public function the_title($title){
790 if(!in_the_loop() || !$this->settings['loopicons']){
791 return $title;
792 }
793 $event = $this->retreive();
794 if(!empty($event->start)){
795 $title .= ' <span class="dashicons dashicons-calendar"></span>';
796 }
797 if(!empty($event->lat) && !empty($event->long)){
798 $title .= ' <span class="dashicons dashicons-location"></span>';
799 }
800 return $title;
801 }
802
803
804 /**
805 * Return an HTML list of events
806 * @param array $atts
807 * @filter eventpost_params
808 * @filter eventpost_listevents
809 * @filter eventpost_item_scheme_entities
810 * @filter eventpost_item_scheme_values
811 * @return string
812 */
813 public function list_events($atts, $id = 'event_list', $context='') {
814 $ep_settings = $this->settings;
815 $defaults = array(
816 'nb' => 0,
817 'type' => 'div',
818 'future' => true,
819 'past' => false,
820 'geo' => 0,
821 'width' => '',
822 'height' => '',
823 'tile' => $ep_settings['tile'],
824 'title' => '',
825 'before_title' => '<h3>',
826 'after_title' => '</h3>',
827 'cat' => '',
828 'tag' => '',
829 'events' => '',
830 'style' => '',
831 'thumbnail' => '',
832 'thumbnail_size' => '',
833 'excerpt' => '',
834 'orderby' => 'meta_value',
835 'order' => 'ASC',
836 'class' => '',
837 'container_schema' => $this->list_shema['container'],
838 'item_schema' => $this->list_shema['item'],
839 );
840 // Map UI options
841 foreach($this->map_interactions as $int_key=>$int_name){
842 $defaults[$int_key]=true;
843 }
844 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events'), $atts);
845
846 extract($atts);
847 if (!is_array($events)) {
848 $events = $this->get_events($atts);
849 }
850 $ret = '';
851 $this->list_id++;
852 if (sizeof($events) > 0) {
853 if($id=='event_geolist'){
854 $this->load_map_scripts();
855 }
856 if (!empty($title)) {
857 $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title);
858 }
859
860 $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div';
861
862 $list = '';
863
864 foreach ($events as $post) { //$post=get_post($item_id);
865 $class_item = ($post->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past';
866 if ($ep_settings['emptylink'] == 0 && empty($post->post_content)) {
867 $post->permalink = '#' . $id . $this->list_id;
868 }
869 $list.=str_replace(
870 apply_filters('eventpost_item_scheme_entities', array(
871 '%child%',
872 '%class%',
873 '%color%',
874 '%event_link%',
875 '%event_thumbnail%',
876 '%event_title%',
877 '%event_date%',
878 '%event_cat%',
879 '%event_location%',
880 '%event_excerpt%'
881 )), apply_filters('eventpost_item_scheme_values', array(
882 $child,
883 $class_item,
884 $post->color,
885 $post->permalink,
886 $thumbnail == true ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($post->ID, !empty($thumbnail_size) ? $thumbnail_size : 'thumbnail', array('class' => 'attachment-thumbnail wp-post-image event_thumbnail')) . '</span>' : '',
887 $post->post_title,
888 $this->get_singledate($post, '', $context),
889 $this->get_singlecat($post, '', $context),
890 $this->get_singleloc($post, '', $context),
891 $excerpt == true && $post->post_excerpt!='' ? '<span class="event_exerpt">'.$post->post_excerpt.'</span>' : '',
892 )), $item_schema
893 );
894 }
895 $attributes = '';
896 if($id == 'event_geolist'){
897 $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-disabled-interactions="';
898 foreach($this->map_interactions as $int_key=>$int_name){
899 $attributes.=$atts[$int_key]==false ? $int_key.', ' : '';
900 }
901 $attributes.='"';
902 }
903 $ret.=str_replace(
904 array(
905 '%type%',
906 '%id%',
907 '%class%',
908 '%listid%',
909 '%style%',
910 '%attributes%',
911 '%list%'
912 ), array(
913 $type,
914 $id,
915 $class,
916 $id . $this->list_id,
917 (!empty($width) ? 'width:' . $width . ';' : '') . (!empty($height) ? 'height:' . $height . ';' : '') . $style,
918 $attributes,
919 $list
920 ), $container_schema
921 );
922 }
923 return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context);
924 }
925
926 /**
927 * get_events
928 * @param array $attr
929 * @filter eventpost_params
930 * @return array of post_ids wich are events
931 */
932 public function get_events($atts) {
933 $requete = (shortcode_atts(apply_filters('eventpost_params', array(
934 'nb' => 5,
935 'future' => true,
936 'past' => false,
937 'geo' => 0,
938 'cat' => '',
939 'tag' => '',
940 'date' => '',
941 'orderby' => 'meta_value',
942 'order' => 'ASC',
943 'tax_name' => '',
944 'tax_term' => '',
945 'post_type'=> $this->settings['posttypes']
946 ), 'get_events'), $atts));
947 extract($requete);
948 wp_reset_query();
949
950 $arg = array(
951 'post_type' => $post_type,
952 'posts_per_page' => $nb,
953 'meta_key' => $this->META_START,
954 'orderby' => $orderby,
955 'order' => $order
956 );
957
958 if($tax_name=='category'){
959 $tax_name='';
960 $cat=$tax_term;
961 }
962 elseif($tax_name=='post-tag'){
963 $tax_name='';
964 $tag=$tax_term;
965 }
966
967 // CUSTOM TAXONOMY
968 if ($tax_name != '' && $tax_term != '') {
969 $arg[$tax_name] = $tax_term;
970 }
971 // CAT
972 if ($cat != '') {
973 if (preg_match('/[a-zA-Z]/i', $cat)) {
974 $arg['category_name'] = $cat;
975 } else {
976 $arg['cat'] = $cat;
977 }
978 }
979 // TAG
980 if ($tag != '') {
981 $arg['tag'] = $tag;
982 }
983 // DATES
984 $meta_query = array(
985 array(
986 'key' => $this->META_END,
987 'value' => '',
988 'compare' => '!='
989 ),
990 array(
991 'key' => $this->META_END,
992 'value' => '0:0:00 0:',
993 'compare' => '!='
994 ),
995 array(
996 'key' => $this->META_END,
997 'value' => ':00',
998 'compare' => '!='
999 ),
1000 array(
1001 'key' => $this->META_START,
1002 'value' => '',
1003 'compare' => '!='
1004 ),
1005 array(
1006 'key' => $this->META_START,
1007 'value' => '0:0:00 0:',
1008 'compare' => '!='
1009 )
1010 );
1011 if ($future == 0 && $past == 0) {
1012 $meta_query = array();
1013 $arg['meta_key'] = null;
1014 $arg['orderby'] = null;
1015 $arg['order'] = null;
1016 } elseif ($future == 1 && $past == 0) {
1017 $meta_query[] = array(
1018 'key' => $this->META_END,
1019 'value' => current_time('mysql'),
1020 'compare' => '>=',
1021 //'type'=>'DATETIME'
1022 );
1023 } elseif ($future == 0 && $past == 1) {
1024 $meta_query[] = array(
1025 'key' => $this->META_END,
1026 'value' => current_time('mysql'),
1027 'compare' => '<=',
1028 //'type'=>'DATETIME'
1029 );
1030 }
1031 if ($date != '') {
1032 $date = date('Y-m-d', $date);
1033
1034 $meta_query = array(
1035 array(
1036 'key' => $this->META_END,
1037 'value' => $date . ' 00:00:00',
1038 'compare' => '>=',
1039 'type' => 'DATETIME'
1040 ),
1041 array(
1042 'key' => $this->META_START,
1043 'value' => $date . ' 23:59:59',
1044 'compare' => '<=',
1045 'type' => 'DATETIME'
1046 )
1047 );
1048 }
1049 // GEO
1050 if ($geo == 1) {
1051 $meta_query[] = array(
1052 'key' => $this->META_LAT,
1053 'value' => '',
1054 'compare' => '!='
1055 );
1056 $meta_query[] = array(
1057 'key' => $this->META_LONG,
1058 'value' => '',
1059 'compare' => '!='
1060 );
1061 $arg['meta_key'] = $this->META_LAT;
1062 $arg['orderby'] = 'meta_value';
1063 $arg['order'] = 'DESC';
1064 }
1065
1066 $arg['meta_query'] = $meta_query;
1067
1068 $query_md5 = 'eventpost_' . md5(var_export($requete, true));
1069 // Check if cache is activated
1070 if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) {
1071 return is_array($cached_events) ? $cached_events : array();
1072 }
1073
1074
1075 $events = apply_filters('eventpost_get', '', $requete, $arg);
1076 if ('' === $events) {
1077 global $wpdb;
1078 $query = new WP_Query($arg);
1079 $events = $wpdb->get_col($query->request);
1080 foreach ($events as $k => $post) {
1081 $event = $this->retreive($post);
1082 $events[$k] = $event;
1083 }
1084 }
1085 if ($this->settings['cache'] == 1){
1086 set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS);
1087 }
1088 return $events;
1089 }
1090
1091 /**
1092 *
1093 * @param object $event
1094 * @return object
1095 */
1096 public function retreive($event = null) {
1097 if(isset($event->start)){
1098 return $event;
1099 }
1100 $ob = get_post($event);
1101 $ob->start = get_post_meta($ob->ID, $this->META_START, true);
1102 $ob->end = get_post_meta($ob->ID, $this->META_END, true);
1103 if (!$this->dateisvalid($ob->start)){
1104 $ob->start = '';
1105 }
1106 if (!$this->dateisvalid($ob->end)){
1107 $ob->end = '';
1108 }
1109 $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : '';
1110 $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : '';
1111 $ob->address = get_post_meta($ob->ID, $this->META_ADD, true);
1112 $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true);
1113 $ob->long = get_post_meta($ob->ID, $this->META_LONG, true);
1114 $ob->color = get_post_meta($ob->ID, $this->META_COLOR, true);
1115 $ob->categories = get_the_category($ob->ID);
1116 $ob->permalink = get_permalink($ob->ID);
1117 $ob->blog_id = get_current_blog_id();
1118 if ($ob->color == ''){
1119 $ob->color = '000000';
1120 }
1121 return apply_filters('eventpost_retreive', $ob);
1122 }
1123
1124 /**
1125 *
1126 * @param mixte $_term
1127 * @param string $taxonomy
1128 * @param string $post_type
1129 */
1130 public function retreive_term($_term=null, $taxonomy='category', $post_type='post') {
1131 $term = get_term($_term, $taxonomy);
1132
1133 if(!$term){
1134 return $term;
1135 }
1136
1137 $term->start = $term->end = $term->time_start = $term->time_end = Null;
1138
1139 $request = array(
1140 'post_type'=>$post_type,
1141 'tax_name'=>$term->taxonomy,
1142 'tax_term'=>$term->slug,
1143 'future'=>true,
1144 'past'=>true
1145 );
1146
1147 $events = $this->get_events($request);
1148
1149 $term->events_count = count($events);
1150 if($term->events_count){
1151 $term->start = $events[0]->start;
1152 $term->time_start = $events[0]->time_start;
1153 $term->end = $events[$term->events_count-1]->end;
1154 $term->time_end = $events[$term->events_count-1]->time_end;
1155 }
1156
1157 return $term;
1158
1159 }
1160
1161 /** ADMIN ISSUES * */
1162
1163 /**
1164 * add custom boxes in posts edit page
1165 */
1166 public function add_custom_box() {
1167 foreach($this->settings['posttypes'] as $posttype){
1168 add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, $this->settings['adminpos'], 'core');
1169 add_meta_box('event_post_loc', __('Event location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, $this->settings['adminpos'], 'core');
1170 }
1171 if(!function_exists('shortcode_ui_register_for_shortcode')){
1172 add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page');
1173 }
1174 }
1175 /**
1176 * display the date custom box
1177 */
1178 public function inner_custom_box_date() {
1179 wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce');
1180 $post_id = get_the_ID();
1181 $event = $this->retreive($post_id);
1182 $start_date = $event->start;
1183 $end_date = $event->end;
1184 $eventcolor = $event->color;
1185
1186 $language = get_bloginfo('language');
1187 if (strpos($language, '-') > -1) {
1188 $language = strtolower(substr($language, 0, 2));
1189 }
1190 $colors = $this->get_colors();
1191 if (sizeof($colors) > 0):
1192 ?>
1193 <div class="misc-pub-section event-color-section">
1194 <?php _e('Color:', 'event-post'); ?>
1195 <p>
1196 <?php foreach ($colors as $color => $file): ?>
1197 <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>" title="<?php echo $file; ?>">
1198 <img src="<?=$this->markurl.$color.'.png' ?>"><input type="radio" value ="<?php echo $color ?>" name="<?php echo $this->META_COLOR; ?>" id="<?php echo $this->META_COLOR; ?><?php echo $color ?>" <?php
1199 if ($eventcolor == $color) {
1200 echo 'checked';
1201 }
1202 ?>/>
1203 </label>
1204 <?php endforeach; ?>
1205 </p>
1206 </div>
1207 <?php endif; ?>
1208 <div class="misc-pub-section">
1209 <label for="<?php echo $this->META_START; ?>_date">
1210 <?php _e('Begin:', 'event-post') ?>
1211 <span id="<?php echo $this->META_START; ?>_date_human" class="human_date">
1212 <?php
1213 if ($event->time_start != '') {
1214 echo $this->human_date($event->time_start) . date(' H:i', $event->time_start);
1215 }
1216 else{
1217 _e('Pick a date','event-post');
1218 }
1219 ?>
1220 </span>
1221 <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value="<?php echo substr($start_date,0,16) ?>" name="<?php echo $this->META_START; ?>" id="<?php echo $this->META_START; ?>_date"/>
1222 </label>
1223 <br>
1224 <label for="<?php echo $this->META_END; ?>_date">
1225 <?php _e('End:', 'event-post') ?>
1226 <span id="<?php echo $this->META_END; ?>_date_human" class="human_date">
1227 <?php
1228 if ($event->time_start != '') {
1229 echo $this->human_date($event->time_end) . date(' H:i', $event->time_end);
1230 }
1231 else{
1232 _e('Pick a date','event-post');
1233 }
1234 ?>
1235 </span>
1236 <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value ="<?php echo substr($end_date,0,16) ?>" name="<?php echo $this->META_END; ?>" id="<?php echo $this->META_END; ?>_date"/>
1237 </label>
1238 </div>
1239 <?php
1240 }
1241 /**
1242 * displays the location custom box
1243 */
1244 public function inner_custom_box_loc() {
1245 $post_id = get_the_ID();
1246 $event = $this->retreive($post_id);
1247 ?>
1248 <div class="misc-pub-section">
1249 <p><a href="#event_address_search" id="event_address_search">
1250 <span class="dashicons dashicons-search"></span>
1251 <?php _e('Look for event\'s GPS coordinates:', 'event-post') ?>
1252 </a>
1253 <span id="eventaddress_result"></span>
1254 </p>
1255 <label for="<?php echo $this->META_ADD; ?>">
1256 <?php _e('Event address, as it will be displayed:', 'event-post') ?>
1257 <textarea name="<?php echo $this->META_ADD; ?>" id="<?php echo $this->META_ADD; ?>"><?php echo $event->address ?></textarea>
1258 </label>
1259
1260 </div>
1261 <div class="misc-pub-section">
1262 <label for="<?php echo $this->META_LAT; ?>">
1263 <?php _e('Latitude:', 'event-post') ?>
1264 <input type="text" value ="<?php echo $event->lat ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>"/>
1265 </label>
1266 </div>
1267 <div class="misc-pub-section">
1268 <label for="<?php echo $this->META_LONG; ?>">
1269 <?php _e('Longitude:', 'event-post') ?>
1270 <input type="text" value ="<?php echo $event->long ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>"/>
1271 </label>
1272 </div>
1273 <div class="misc-pub-section">
1274 <div id="event-post-map-preview" data-marker="<?php echo $this->get_marker($event->color); ?>"></div>
1275 </div>
1276 <?php
1277 $this->load_map_scripts();
1278 }
1279
1280 /**
1281 * display custombox containing shortcode wizard
1282 */
1283 public function inner_custom_box_edit() {
1284 $ep_settings = $this->settings;
1285 ?>
1286 <?php do_action('before_eventpost_generator'); ?>
1287 <div class="all">
1288 <p>
1289 <label for="ep_sce_type"><?php _e('Type :', 'event-post'); ?>
1290 <select id="ep_sce_type">
1291 <option value='list'><?php _e('List', 'event-post') ?></option>
1292 <option value='map'><?php _e('Map', 'event-post') ?></option>
1293 </select>
1294 </label>
1295 </p>
1296
1297 <p>
1298 <label for="ep_sce_nb"><?php _e('Number of posts', 'event-post'); ?>
1299 <input id="ep_sce_nb" type="number" value="5" data-att="nb"/>
1300 <a class="button" id="ep_sce_nball"><?php _e('All', 'event-post'); ?></a>
1301 </label>
1302 </p>
1303
1304 <p>
1305 <label for="ep_sce_cat"><?php _e('Only in :', 'event-post'); ?>
1306 <select id="ep_sce_cat" data-att="cat">
1307 <option value=''><?php _e('All', 'event-post') ?></option>
1308 <?php
1309 $cats = get_categories();
1310 foreach ($cats as $cat) {
1311 ?>
1312 <option value="<?= $cat->slug ?>" <?php
1313 if ($cat->slug == $eventpost_cat) {
1314 echo'selected';
1315 }
1316 ?>><?= $cat->cat_name ?></option>
1317 <?php } ?>
1318 </select>
1319 </label>
1320 </p>
1321
1322 <p>
1323 <label for="ep_sce_future"><?php _e('Future events:', 'event-post'); ?>
1324 <select id="ep_sce_future" data-att="future">
1325 <option value='1'><?php _e('Yes', 'event-post') ?></option>
1326 <option value='0'><?php _e('No', 'event-post') ?></option>
1327 </select>
1328 </label>
1329 <label for="ep_sce_past"><?php _e('Past events:', 'event-post'); ?>
1330 <select id="ep_sce_past" data-att="past">
1331 <option value='0'><?php _e('No', 'event-post') ?></option>
1332 <option value='1'><?php _e('Yes', 'event-post') ?></option>
1333 </select>
1334 </label>
1335 </p>
1336
1337 <div id="ep_sce_listonly" class="list">
1338 <p>
1339 <label for="ep_sce_geo"><?php _e('Only geotagged events:', 'event-post'); ?>
1340 <select id="ep_sce_geo" data-att="geo">
1341 <option value='0'><?php _e('No', 'event-post') ?></option>
1342 <option value='1'><?php _e('Yes', 'event-post') ?></option>
1343 </select>
1344 </label>
1345 </p>
1346 </div>
1347 <div id="ep_sce_maponly" class="map">
1348 <p>
1349 <label for="ep_sce_tile"><?php _e('Map background', 'event-post'); ?>
1350 <select id="ep_sce_tile" data-att="tile">
1351 <?php foreach ($this->maps as $map): ?>
1352 <option value="<?php
1353 if ($ep_settings['tile'] != $map['id']) {
1354 echo $map['id'];
1355 }
1356 ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
1357 <?php echo $map['name']; ?><?php
1358 if ($ep_settings['tile'] == $map['id']) {
1359 echo' (default)';
1360 }
1361 ?>
1362 </option>
1363 <?php endforeach; ?>
1364 </select>
1365 </label>
1366 </p>
1367 <p>
1368 <label for="ep_sce_width"><?php _e('Width', 'event-post'); ?>
1369 <input id="ep_sce_width" type="text" value="500px" data-att="width"/>
1370 </label>
1371 </p>
1372 <p>
1373 <label for="ep_sce_height"><?php _e('Height', 'event-post'); ?>
1374 <input id="ep_sce_height" type="text" value="500px" data-att="height"/>
1375 </label>
1376 </p>
1377 </div>
1378 <?php do_action('after_eventpost_generator'); ?>
1379 <div id="ep_sce_shortcode">[event_list]</div>
1380 <a class="button" id="ep_sce_submit"><?php _e('Insert shortcode', 'event-post'); ?></a>
1381 </div>
1382 <script>
1383 var IEbof = false;
1384 </script>
1385 <!--[if lt IE 9]>
1386 <script>IEbof=true;</script>
1387 <![endif]-->
1388 <?php
1389 }
1390
1391 /**
1392 * When the post is saved, saves our custom data
1393 * @param int $post_id
1394 * @return void
1395 */
1396 public function save_postdata($post_id) {
1397 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
1398 return;
1399 }
1400
1401 if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce', FILTER_SANITIZE_STRING), plugin_basename(__FILE__))){
1402 return;
1403 }
1404
1405 // Clean color or no color
1406 if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR, FILTER_SANITIZE_STRING)) {
1407 update_post_meta($post_id, $this->META_COLOR, $color);
1408 }
1409 // Clean date or no date
1410 if ((false !== $start = filter_input(INPUT_POST, $this->META_START, FILTER_SANITIZE_STRING)) &&
1411 (false !== $end = filter_input(INPUT_POST, $this->META_END, FILTER_SANITIZE_STRING)) &&
1412 '' != $start &&
1413 '' != $end) {
1414 update_post_meta($post_id, $this->META_START, substr($start,0,16).':00');
1415 update_post_meta($post_id, $this->META_END, substr($end,0,16).':00');
1416 }
1417 else {
1418 delete_post_meta($post_id, $this->META_START);
1419 delete_post_meta($post_id, $this->META_END);
1420 }
1421
1422 // Clean location or no location
1423 if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT, FILTER_SANITIZE_STRING)) &&
1424 (false !== $long = filter_input(INPUT_POST, $this->META_LONG, FILTER_SANITIZE_STRING)) &&
1425 '' != $lat &&
1426 '' != $long) {
1427 update_post_meta($post_id, $this->META_ADD, filter_input(INPUT_POST, $this->META_ADD, FILTER_SANITIZE_STRING));
1428 update_post_meta($post_id, $this->META_LAT, $lat);
1429 update_post_meta($post_id, $this->META_LONG, $long);
1430 }
1431 else {
1432 delete_post_meta($post_id, $this->META_ADD);
1433 delete_post_meta($post_id, $this->META_LAT);
1434 delete_post_meta($post_id, $this->META_LONG);
1435 }
1436 }
1437
1438 /**
1439 *
1440 * @param string $date
1441 * @param string $cat
1442 * @param boolean $display
1443 * @return boolean
1444 */
1445 public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='') {
1446 $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true));
1447 $nb = count($events);
1448 if ($display) {
1449 if ($nb > 0) {
1450 $ret.='<ul>';
1451 foreach ($events as $event) {
1452 if ($this->settings['emptylink'] == 0 && empty($event->post_content)) {
1453 $event->guid = '#';
1454 }
1455 $ret.='<li>'
1456 . '<a href="' . $event->permalink . '">'
1457 . '<h4>' . $event->post_title . '</h4>'
1458 .$this->get_single($event)
1459 . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '')
1460 .'</a>'
1461 . '</li>';
1462 }
1463 $ret.='</ul>';
1464 return $ret;
1465 }
1466 return'';
1467 } else {
1468 return $nb > 0 ? '<a data-date="' . date('Y-m-d', $date) . '" class="eventpost_cal_link"'.($colored?' style="background-color:#'.$events[0]->color.'"':'').'>' . date('j', $date) . '</a>' : date('j', $date);
1469 }
1470 }
1471
1472
1473 /**
1474 * @param array $atts
1475 * @filter eventpost_params
1476 * @return string
1477 */
1478 public function calendar($atts) {
1479 extract(shortcode_atts(apply_filters('eventpost_params', array(
1480 'date' => date('Y-n'),
1481 'cat' => '',
1482 'mondayfirst' => 0, //1 : weeks starts on monday
1483 'datepicker' => 1,
1484 'colored' => 1,
1485 'thumbnail'=>'',
1486 ), 'calendar'), $atts));
1487
1488 $annee = substr($date, 0, 4);
1489 $mois = substr($date, 5);
1490
1491 $time = mktime(0, 0, 0, $mois, 1, $annee);
1492
1493
1494 $JourMax = date("t", $time);
1495 $NoJour = -date("w", $time);
1496 if ($mondayfirst == 0) {
1497 $NoJour +=1;
1498 } else {
1499 $NoJour +=2;
1500 $this->Week[] = array_shift($this->Week);
1501 }
1502 if ($NoJour > 0 && $mondayfirst == 1) {
1503 $NoJour -=7;
1504 }
1505 $ret = '<table class="event-post-calendar-table">';
1506 if ($datepicker == 1) {
1507 $ret.='<caption>';
1508 $ret.='<a data-date="' . date('Y-n', strtotime('-1 Year', $time)) . '" class="eventpost_cal_bt">&lt;&lt;</a> ';
1509 $ret.=$annee;
1510 $ret.='<a data-date="' . date('Y-n', strtotime('+1 Year', $time)) . '" class="eventpost_cal_bt">&gt;&gt;</a> ';
1511 $ret.='<a data-date="' . date('Y-n', strtotime('-1 Month', $time)) . '" class="eventpost_cal_bt">&lt;</a> ';
1512 $ret.=$this->NomDuMois[$mois];
1513 $ret.='<a data-date="' . date('Y-n', strtotime('+1 Month', $time)) . '" class="eventpost_cal_bt">&gt;</a> ';
1514 $ret.='<a data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</a>';
1515 $ret.='</caption>';
1516 }
1517 $ret.='<thead>';
1518 $ret.='<tr class="event_post_cal_days">';
1519 for ($w = 0; $w < 7; $w++) {
1520 $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>';
1521 }
1522 $ret.='</tr>';
1523 $ret.='</thead>';
1524
1525 $ret.='<tbody>';
1526 $sqldate = date('Y-m', $time);
1527 $cejour = date('Y-m-d');
1528 for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois
1529 $ret.='<tr>';
1530 for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine
1531 if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher
1532 $td = '<td class="event_post_day">';
1533 if ($sqldate . '-' . $NoJour == $cejour) {
1534 $td = '<td class="event_post_day_now">';
1535 }
1536 $ret.=$td;
1537
1538 $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail);
1539 $ret.='</td>';
1540 } else {
1541 $ret.='<td></td>';
1542 }
1543 $NoJour ++;
1544 }
1545 $ret.='</tr>';
1546 }
1547 $ret.='</tbody></table>';
1548 return $ret;
1549 }
1550
1551 /**
1552 * echoes the content of the calendar in ajax context
1553 */
1554 public function ajaxcal() {
1555 echo $this->calendar(array(
1556 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')),
1557 'cat' => esc_attr(FILTER_INPUT(INPUT_GET, 'cat')),
1558 'mondayfirst' => esc_attr(FILTER_INPUT(INPUT_GET, 'mf')),
1559 'datepicker' => esc_attr(FILTER_INPUT(INPUT_GET, 'dp')),
1560 'colored' => esc_attr(FILTER_INPUT(INPUT_GET, 'color')),
1561 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')),
1562 ));
1563 exit();
1564 }
1565
1566 /**
1567 * echoes the date of the calendar in ajax context
1568 */
1569 public function ajaxdate() {
1570 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')));
1571 exit();
1572 }
1573
1574 /**
1575 * echoes a date in ajax context
1576 */
1577 public function HumanDate() {
1578 if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) {
1579 $date = strtotime($_REQUEST['date']);
1580 echo $this->human_date($date, $this->settings['dateformat']) .' '. date($this->settings['timeformat'], $date);
1581 exit();
1582 }
1583 }
1584
1585 /**
1586 * AJAX Get lat long from address
1587 */
1588 public function GetLatLong() {
1589 if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) {
1590 // verifier le cache
1591 $q = $_REQUEST['q'];
1592 header('Content-Type: application/json');
1593 $transient_name = 'eventpost_osquery_' . $q;
1594 $val = get_transient($transient_name);
1595 if (false === $val || empty($val)) {
1596 $language = get_bloginfo('language');
1597 if (strpos($language, '-') > -1) {
1598 $language = strtolower(substr($language, 0, 2));
1599 }
1600 $val = file_get_contents('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language);
1601 set_transient($transient_name, $val, 30 * DAY_IN_SECONDS);
1602 }
1603 echo $val;
1604 exit();
1605 }
1606 }
1607
1608 /**
1609 * alters columns
1610 * @param array $defaults
1611 * @return array
1612 */
1613 public function columns_head($defaults) {
1614 $defaults['event'] = __('Event', 'event-post');
1615 $defaults['location'] = __('Location', 'event-post');
1616 return $defaults;
1617 }
1618
1619 /**
1620 * echoes content of a row in a given column
1621 * @param string $column_name
1622 * @param int $post_id
1623 */
1624 public function columns_content($column_name, $post_id) {
1625 if ($column_name == 'location') {
1626 $lat = get_post_meta($post_id, $this->META_LAT, true);
1627 $lon = get_post_meta($post_id, $this->META_LONG, true);
1628
1629 if (!empty($lat) && !empty($lon)) {
1630 $color = get_post_meta($post_id, $this->META_COLOR, true);
1631 if ($color == ''){
1632 $color = '777777';
1633 }
1634 echo'<a href="https://www.openstreetmap.org/?lat=' . $lat.='&amp;lon=' . $lon.='&amp;zoom=13" target="_blank"><img src="' . plugins_url('/markers/', __FILE__) . $color . '.png" alt="' . get_post_meta($post_id, $this->META_ADD, true) . '"/></a>';
1635 }
1636 }
1637 if ($column_name == 'event') {
1638 echo $this->print_date($post_id, false);
1639 }
1640 }
1641
1642 /** ADMIN PAGES **/
1643
1644 /**
1645 * save settings end redirect
1646 * @return void
1647 */
1648 public function save_settings(){
1649 if (!current_user_can('manage_options')){
1650 return;
1651 }
1652 if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) {
1653 wp_die(__('Security error', 'event-post'));
1654 }
1655
1656 $valid_post = array(
1657 'ep_settings'=>array(
1658 'filter' => FILTER_SANITIZE_STRING,
1659 'flags' => FILTER_REQUIRE_ARRAY
1660 )
1661 );
1662
1663 foreach ($this->settings as $item_name=>$item_value){
1664 $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING;
1665 }
1666
1667 $post_types=(array) $_POST['ep_settings']['posttypes'];
1668 $posttypes = get_post_types();
1669 foreach($post_types as $posttype){
1670 if(!in_array($posttype, $posttypes)){
1671 unset($post_types[$posttype]);
1672 }
1673 }
1674
1675 if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) {
1676 $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']);
1677 $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']);
1678 $settings['ep_settings']['posttypes']= array_values($post_types);
1679 update_option('ep_settings', $settings['ep_settings']);
1680 }
1681 wp_redirect('options-general.php?page=event-settings&confirm=options_saved');
1682 exit;
1683 }
1684 /**
1685 * adds menu items
1686 */
1687 public function manage_options() {
1688 add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings'));
1689 }
1690 /**
1691 * adds items to the native "right now" dashboard widget
1692 * @param array $elements
1693 * @return array
1694 */
1695 public function dashboard_right_now($elements){
1696 $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1)));
1697 $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1)));
1698 if($nb_date){
1699 array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','event-post'), $nb_date)."</i>");
1700 }
1701 if($nb_geo){
1702 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>");
1703 }
1704 return $elements;
1705 }
1706
1707 /**
1708 * output content of the setting page
1709 */
1710 public function manage_settings() {
1711 if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?>
1712 <div class="updated"><p><strong><?php _e('Event settings saved !', 'event-post') ?></strong></p></div>
1713 <?php
1714 }
1715 $ep_settings = $this->settings;
1716 ?>
1717 <div class="wrap">
1718 <div class="icon32" id="icon-options-general"><br></div>
1719 <h1><?php _e('Event settings', 'event-post'); ?></h1>
1720 <form name="form1" method="post" action="admin-post.php">
1721 <input type="hidden" name="action" value="EventPostSaveSettings">
1722 <?php wp_nonce_field('ep_nonce_settings','ep_nonce_settings') ?>
1723 <h2><?php _e('Global settings', 'event-post'); ?></h2>
1724 <table class="form-table" id="eventpost-settings-table-global">
1725 <tbody>
1726 <tr>
1727 <th>
1728 <label for="ep_emptylink">
1729 <?php _e('Print link for empty posts', 'event-post') ?>
1730 </label>
1731 </th>
1732 <td>
1733 <select name="ep_settings[emptylink]" id="ep_emptylink">
1734 <option value="1" <?php selected($ep_settings['emptylink'], 1, true);?>>
1735 <?php _e('Link all posts', 'event-post'); ?>
1736 </option>
1737 <option value="0" <?php selected($ep_settings['emptylink'], 0, true);?>>
1738 <?php _e('Do not link posts with empty content', 'event-post'); ?>
1739 </option>
1740 </select>
1741 </td>
1742 </tr>
1743 <tr>
1744 <th>
1745 <label for="ep_singlepos">
1746 <?php _e('Event bar position for single posts', 'event-post') ?>
1747 </label>
1748 </th>
1749 <td>
1750 <select name="ep_settings[singlepos]" id="ep_singlepos">
1751 <option value="before" <?php selected($ep_settings['singlepos'], 'before', true); ?>>
1752 <?php _e('Before the content', 'event-post'); ?>
1753 </option>
1754 <option value="after" <?php selected($ep_settings['singlepos'], 'after', true); ?>>
1755 <?php _e('After the content', 'event-post'); ?>
1756 </option>
1757 </select>
1758 </td>
1759 </tr>
1760 <tr>
1761 <th>
1762 <label for="ep_loopicons">
1763 <?php _e('Add icons for events in the loop', 'event-post') ?>
1764 </label>
1765 </th>
1766 <td>
1767 <select name="ep_settings[loopicons]" id="ep_loopicons">
1768 <option value="1" <?php selected($ep_settings['loopicons'],'1', true) ?>>
1769 <?php _e('Yes', 'event-post'); ?></option>
1770 <option value="0" <?php selected($ep_settings['loopicons'],'0', true) ?>>
1771 <?php _e('No', 'event-post'); ?></option>
1772 </select>
1773 </td>
1774 </tr>
1775 <tr>
1776 <th>
1777 <label for="ep_adminpos">
1778 <?php _e('Position of event details boxes', 'event-post') ?>
1779 </label>
1780 </th>
1781 <td>
1782 <select name="ep_settings[adminpos]" id="ep_adminpos">
1783 <option value="side" <?php selected($ep_settings['adminpos'],'side', true) ?>>
1784 <?php _e('Side', 'event-post'); ?></option>
1785 <option value="normal" <?php selected($ep_settings['adminpos'],'normal', true) ?>>
1786 <?php _e('Under the text', 'event-post'); ?></option>
1787 </select>
1788 </td>
1789 </tr>
1790 </tbody>
1791 </table><!-- #eventpost-settings-table-global -->
1792
1793 <h2><?php _e('Date settings', 'event-post'); ?></h2>
1794 <table class="form-table" id="eventpost-settings-table-event">
1795 <tbody>
1796 <tr>
1797 <th>
1798 <label for="ep_dateformat">
1799 <?php _e('Date format', 'event-post') ?>
1800 </label>
1801 </th>
1802 <td>
1803 <input type="text" name="ep_settings[dateformat]" id="ep_dateformat" value="<?php echo $ep_settings['dateformat']; ?>" size="10">
1804 </td>
1805 </tr>
1806 <tr>
1807 <th>
1808 <label for="ep_timeformatformat">
1809 <?php _e('Time format', 'event-post') ?>
1810 </label>
1811 </th>
1812 <td>
1813 <input type="text" name="ep_settings[timeformat]" id="ep_dateformat" value="<?php echo $ep_settings['timeformat']; ?>" size="10">
1814 </td>
1815 </tr>
1816 <tr>
1817 <th>
1818 <label for="ep_dateexport">
1819 <?php _e('Show export buttons on:', 'event-post') ?>
1820 </label>
1821 </th>
1822 <td>
1823 <select name="ep_settings[export]" id="ep_dateexport">
1824 <option value="list" <?php selected($ep_settings['export'], 'list', true);?>>
1825 <?php _e('List only', 'event-post') ?>
1826 </option>
1827 <option value="single" <?php selected($ep_settings['export'], 'single', true);?>>
1828 <?php _e('Single only', 'event-post') ?>
1829 </option>
1830 <option value="both" <?php selected($ep_settings['export'], 'both', true);?>>
1831 <?php _e('Both', 'event-post') ?>
1832 </option>
1833 <option value="none" <?php selected($ep_settings['export'], 'none', true);?>>
1834 <?php _e('None', 'event-post') ?>
1835 </option>
1836 </select>
1837 </td>
1838 </tr>
1839 <tr>
1840 <th>
1841 <label for="ep_dateforhumans">
1842 <?php _e('Relative human dates:', 'event-post') ?>
1843 </label>
1844 </th>
1845 <td>
1846 <select name="ep_settings[dateforhumans]" id="ep_dateforhumans">
1847 <option value="1" <?php selected($ep_settings['dateforhumans'], '1', true);?>>
1848 <?php _e('Yes', 'event-post') ?>
1849 </option>
1850 <option value="0" <?php selected($ep_settings['dateforhumans'], '0', true);?>>
1851 <?php _e('No', 'event-post') ?>
1852 </option>
1853 </select>
1854 <p class="description"><?php _e('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post') ?></p>
1855 </td>
1856 </tr>
1857 </tbody>
1858 </table><!-- #eventpost-settings-table-event -->
1859
1860 <h2><?php _e('List settings', 'event-post'); ?></h2>
1861 <table class="form-table" id="eventpost-settings-table-list">
1862 <tbody>
1863 <tr>
1864 <th>
1865 <label for="ep_container_shema">
1866 <?php _e('Container shema', 'event-post') ?>
1867 </label>
1868 </th>
1869 <td>
1870 <textarea class="widefat" name="ep_settings[container_shema]" id="ep_container_shema"><?php echo $ep_settings['container_shema']; ?></textarea>
1871 <p><?php _e('default:','event-post') ?></p>
1872 <code><?php echo htmlentities($this->default_list_shema['container']) ?></code>
1873 </td>
1874 </tr>
1875 <tr>
1876 <th>
1877 <label for="ep_item_shema">
1878 <?php _e('Item shema', 'event-post') ?>
1879 </label>
1880 </th>
1881 <td>
1882 <textarea class="widefat" name="ep_settings[item_shema]" id="ep_item_shema"><?php echo $ep_settings['item_shema']; ?></textarea>
1883 <p><?php _e('default:','event-post') ?></p>
1884 <code><?php echo htmlentities($this->default_list_shema['item']) ?></code>
1885 </td>
1886 </tr>
1887 </tbody>
1888 </table><!-- #eventpost-settings-table-list -->
1889
1890 <h2><?php _e('Map settings', 'event-post'); ?></h2>
1891 <table class="form-table" id="eventpost-settings-table-map">
1892 <tbody>
1893 <tr>
1894 <th>
1895 <label for="ep_tile">
1896 <?php _e('Map background', 'event-post') ?>
1897 </label>
1898 </th>
1899 <td>
1900 <select name="ep_settings[tile]" id="ep_tile">
1901 <?php foreach ($this->maps as $map): ?>
1902 <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>>
1903 <?php echo $map['name']; ?>
1904 </option>
1905 <?php endforeach; ?>
1906 </select></td>
1907 </tr>
1908 <tr>
1909 <th>
1910 <?php _e('Makers custom directory (leave empty for default settings)', 'event-post') ?>
1911 </th>
1912 <td>
1913 <label for="ep_markpath">
1914 <?php _e('Root path:', 'event-post') ?><br>
1915 ABSPATH/<input name="ep_settings[markpath]" id="ep_markpath" value="<?php echo $this->settings['markpath'] ?>" class="widefat">
1916 </label><br>
1917 <label for="ep_markurl">
1918 <?php _e('URL:', 'event-post') ?><br>
1919 <input name="ep_settings[markurl]" id="ep_markurl" value="<?php echo $this->settings['markurl'] ?>" class="widefat">
1920 </label>
1921 </td>
1922 </tr>
1923 </tbody>
1924 </table><!-- #eventpost-settings-table-map -->
1925
1926 <h2><?php _e('Admin UI settings', 'event-post'); ?></h2>
1927 <table class="form-table" id="eventpost-settings-table-admin">
1928 <tbody>
1929 <tr>
1930 <th>
1931 <label for="ep_posttypes">
1932 <?php _e('Wich post types can be events ?', 'event-post') ?>
1933 </label>
1934 </th>
1935 <td><?php $posttypes = get_post_types(array(), 'objects'); ?>
1936 <?php foreach($posttypes as $posttype): ?>
1937 <p>
1938 <label>
1939 <input type="checkbox" name="ep_settings[posttypes][<?php echo $posttype->name; ?>]" value="<?php echo $posttype->name; ?>" <?php checked(in_array($posttype->name, $ep_settings['posttypes']),true, true) ?>>
1940 <?php echo $posttype->labels->name; ?>
1941 </label>
1942 </p>
1943 <?php endforeach; ?>
1944 </td>
1945 </tr>
1946 <tr>
1947 <th>
1948 <?php _e('Datepicker style', 'event-post') ?>
1949 <?php $now = current_time('mysql'); ?>
1950 <?php $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); ?>
1951 </th>
1952 <td>
1953 <p>
1954 <label>
1955 <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="dual" <?php checked($ep_settings['datepicker'],'dual', true) ?>>
1956 <?php _e('Dual', 'event-post'); ?>
1957 </label>
1958 <span id="eventpost_dual_date_human" class="human_date">
1959 <?php echo $human_date; ?>
1960 </span>
1961 <input type="text" class="eventpost-datepicker-dual" id="eventpost_dual_date" value="<?php echo $now; ?>">
1962 </p>
1963 <p>
1964 <label>
1965 <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="separate" <?php checked($ep_settings['datepicker'],'separate', true) ?>>
1966 <?php _e('Separate', 'event-post'); ?>
1967 </label>
1968 <span id="eventpost_separate_date_human" class="human_date">
1969 <?php echo $human_date; ?>
1970 </span>
1971 <input type="text" class="eventpost-datepicker-separate" id="eventpost_separate_date" value="<?php echo $now; ?>">
1972 </p>
1973 <p>
1974 <label>
1975 <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_dual" value="browser" <?php checked($ep_settings['datepicker'],'browser', true) ?>>
1976 <?php _e('Browser\'s style', 'event-post'); ?>
1977 </label>
1978 <input type="datetime" class="eventpost-datepicker-browser" value="<?php echo $now; ?>">
1979 </p>
1980 </td>
1981 </tr>
1982 </tbody>
1983 </table><!-- #eventpost-settings-table-admin -->
1984
1985 <h2><?php _e('Performances settings', 'event-post'); ?></h2>
1986 <table class="form-table" id="eventpost-settings-table-perfs">
1987 <tbody>
1988 <tr>
1989 <th>
1990 <?php _e('Use cache', 'event-post') ?>
1991 </th>
1992 <td>
1993 <label for="ep_cache">
1994 <input type="checkbox" name="ep_settings[cache]" id="ep_cache" <?php if($ep_settings['cache']=='1'){ echo'checked';} ?> value="1">
1995 <?php _e('Use cache for results','event-post')?>
1996 </label>
1997 </td>
1998 </tr>
1999 </tbody>
2000 </table><!-- #eventpost-settings-table-perfs -->
2001
2002 <p class="submit">
2003 <input type="submit" value="<?php _e('Apply settings', 'event-post'); ?>" class="button button-primary" id="submit" name="submit">
2004 </p>
2005 <?php do_action('eventpost_settings_form'); ?>
2006
2007 </form>
2008 </div>
2009 <?php
2010 do_action('eventpost_after_settings_form');
2011 }
2012
2013 /*
2014 * feed
2015 * generate ICS or VCS files from a category
2016 */
2017
2018 /**
2019 *
2020 * @param timestamp $timestamp
2021 * @return string
2022 */
2023 public function ics_date($timestamp){
2024 return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z';
2025 }
2026
2027 /**
2028 * outputs an RSS document
2029 */
2030 public function feed(){
2031 if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){
2032 $timezone_string = get_option('timezone_string');
2033 date_default_timezone_set($timezone_string);
2034
2035 header("content-type:text/calendar");
2036 header("Pragma: public");
2037 header("Expires: 0");
2038 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
2039 header("Cache-Control: public");
2040 header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" );
2041 echo"BEGIN:VCALENDAR\r\n"
2042 . "PRODID:EventPost\r\n"
2043 . "VERSION:2.0\r\n"
2044 . "BEGIN:VTIMEZONE\r\n"
2045 . "TZID:$timezone_string\r\n"
2046 . "X-LIC-LOCATION:$timezone_string\r\n"
2047 . "END:VTIMEZONE";
2048
2049 $events=$this->get_events(array('cat'=>$cat,'nb'=>-1));
2050 foreach ($events as $event) {
2051 echo"BEGIN:VEVENT\r\n"
2052 . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n"
2053 . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n"
2054 . "SUMMARY:".$event->post_title."\r\n"
2055 . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n"
2056 . "LOCATION:".str_replace(',','\,',$event->address)."\r\n"
2057 . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n"
2058 . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n"
2059 . "DESCRIPTION:".$event->guid."\r\n"
2060 . "END:VEVENT\r\n";
2061 }
2062 echo"END:VCALENDAR\r\n";
2063 exit;
2064 }
2065 }
2066 }