PluginProbe
Event Post / 4.3
Event Post v4.3
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.3, at eventpost.php

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