| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 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.4 | |
| 7 | - Author: bastho | |
| 8 | - Contributors: ecolosites | |
| 4 | + Plugin URI: http://event-post.com | |
| 5 | + Description: Add calendar and/or geolocation metadata on posts. For a better experience, we recommand to use it with <a href="https://wordpress.org/plugins/shortcode-ui/" target="_blank">Shortcake (shortcode UI)</a> installed. | |
| 6 | + Version: 5.0.2 | |
| 7 | + Author: N.O.U.S. Open Useful and Simple | |
| 8 | + Contributors: bastho, ecolosites | |
| 9 | 9 | Author URI: http://avecnous.eu |
| 10 | 10 | License: GPLv2 |
| 11 | 11 | Text Domain: event-post |
| 12 | 12 | Domain Path: /languages/ |
| @@ -12,9 +12,9 @@ | ||
| 12 | 12 | Domain Path: /languages/ |
| 13 | 13 | Tags: Post,posts,event,date,geolocalization,gps,widget,map,openstreetmap,EELV,calendar,agenda |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | - | |
| 16 | +global $EventPost; | |
| 17 | 17 | $EventPost = new EventPost(); |
| 18 | 18 | |
| 19 | 19 | $EventPost_cache=array(); |
| 20 | 20 | |
| @@ -37,11 +37,12 @@ | ||
| 37 | 37 | public $Week; |
| 38 | 38 | public $settings; |
| 39 | 39 | public $dateformat; |
| 40 | 40 | |
| 41 | - public $version = '4.4'; | |
| 41 | + public $version = '4.5'; | |
| 42 | 42 | |
| 43 | 43 | public $map_interactions; |
| 44 | + public $quick_edit_fields; | |
| 44 | 45 | |
| 45 | 46 | public $Shortcodes; |
| 46 | 47 | |
| 47 | 48 | public function __construct() { |
| @@ -46,15 +47,16 @@ | ||
| 46 | 47 | |
| 47 | 48 | public function __construct() { |
| 48 | 49 | load_plugin_textdomain('event-post', false, 'event-post/languages'); |
| 49 | 50 | |
| 50 | - add_action('widgets_init', array(&$this,'init'), 1); | |
| 51 | + add_action('widgets_init', array(&$this,'init'), 1); | |
| 51 | 52 | add_action('save_post', array(&$this, 'save_postdata')); |
| 52 | 53 | add_action('admin_menu', array(&$this, 'manage_options')); |
| 53 | - add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now')); | |
| 54 | + add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now')); | |
| 54 | 55 | |
| 55 | 56 | // Scripts |
| 56 | 57 | add_action( 'admin_init', array(&$this, 'editor_styles')); |
| 58 | + add_action( 'admin_init', array(&$this, 'register_settings')); | |
| 57 | 59 | add_action('admin_enqueue_scripts', array(&$this, 'admin_head')); |
| 58 | 60 | add_action('admin_print_scripts', array(&$this, 'admin_scripts')); |
| 59 | 61 | add_action('wp_enqueue_scripts', array(&$this, 'load_styles')); |
| 60 | 62 | |
| @@ -59,9 +61,9 @@ | ||
| 59 | 61 | add_action('wp_enqueue_scripts', array(&$this, 'load_styles')); |
| 60 | 62 | |
| 61 | 63 | // Single |
| 62 | 64 | add_filter('the_content', array(&$this, 'display_single'), 9999); |
| 63 | - add_filter('the_title', array(&$this, 'the_title'), 9999); | |
| 65 | + add_filter('the_title', array(&$this, 'the_title'), 9999, 2); | |
| 64 | 66 | add_action('the_event', array(&$this, 'print_single')); |
| 65 | 67 | add_action('wp_head', array(&$this, 'single_header')); |
| 66 | 68 | |
| 67 | 69 | // Ajax |
| @@ -76,16 +78,26 @@ | ||
| 76 | 78 | add_action('wp_ajax_EventPostFeed', array(&$this, 'feed')); |
| 77 | 79 | add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed')); |
| 78 | 80 | |
| 79 | 81 | // |
| 80 | - add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1); | |
| 82 | + add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1); | |
| 81 | 83 | |
| 82 | 84 | // Admin |
| 83 | - add_action('admin_post_EventPostSaveSettings', array(&$this, 'save_settings')); | |
| 85 | + add_filter('plugin_action_links_event-post/eventpost.php', array( &$this, 'settings_link' ) ); | |
| 86 | + add_filter('plugin_row_meta', array( &$this, 'row_meta' ), 1, 4); | |
| 84 | 87 | |
| 85 | 88 | add_action('widgets_init', array(&$this, 'register_widgets'),1,1); |
| 86 | 89 | |
| 90 | + // Quick edit | |
| 91 | + add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit' ), 10, 2 ); | |
| 92 | + add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit' ), 10, 2 ); | |
| 93 | + add_action( 'admin_print_scripts-edit.php', array(&$this, 'scripts_edit') ); | |
| 94 | + add_action( 'wp_ajax_inline-save', array(&$this, 'inline_save'), 1 ); | |
| 95 | + add_action( 'wp_ajax_eventpost_save_bulk', array(&$this, 'save_bulkdatas') ); | |
| 96 | + add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_color'), 10, 3); | |
| 97 | + | |
| 87 | 98 | $inc_path = plugin_dir_path(__FILE__).'inc/'; |
| 99 | + include_once ($inc_path . 'wrappers.php'); | |
| 88 | 100 | include_once ($inc_path . 'widget.php'); |
| 89 | 101 | include_once ($inc_path . 'widget.cal.php'); |
| 90 | 102 | include_once ($inc_path . 'widget.map.php'); |
| 91 | 103 | include_once ($inc_path . 'multisite.php'); |
| @@ -175,8 +187,28 @@ | ||
| 175 | 187 | 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'), |
| 176 | 188 | 'DragZoom'=>__('Drag Zoom', 'event-post'), |
| 177 | 189 | ); |
| 178 | 190 | |
| 191 | + $this->quick_edit_fields = apply_filters('eventpost_quick_edit_fields', array( | |
| 192 | + 'event'=>array( | |
| 193 | + $this->META_START=>__('Begin:', 'event-post'), | |
| 194 | + $this->META_END=>__('End:', 'event-post'), | |
| 195 | + $this->META_COLOR=>__('Color:', 'event-post'), | |
| 196 | + ), | |
| 197 | + 'location'=>array( | |
| 198 | + $this->META_ADD=>__('Address:', 'event-post'), | |
| 199 | + $this->META_LAT=>__('Latitude:', 'event-post'), | |
| 200 | + $this->META_LONG=>__('Longitude:', 'event-post'), | |
| 201 | + ), | |
| 202 | + ) | |
| 203 | + ); | |
| 204 | + $this->bulk_edit_fields = apply_filters('eventpost_bulk_edit_fields', array( | |
| 205 | + 'event'=>array( | |
| 206 | + $this->META_COLOR=>__('Color:', 'event-post'), | |
| 207 | + ), | |
| 208 | + ) | |
| 209 | + ); | |
| 210 | + | |
| 179 | 211 | } |
| 180 | 212 | |
| 181 | 213 | public function register_widgets(){ |
| 182 | 214 | register_widget('EventPost_List'); |
| @@ -248,8 +280,12 @@ | ||
| 248 | 280 | $maps = array_keys($this->maps); |
| 249 | 281 | $ep_settings['tile'] = $this->maps[$maps[0]]['id']; |
| 250 | 282 | $reg_settings=true; |
| 251 | 283 | } |
| 284 | + if(!isset($ep_settings['zoom']) || !is_numeric($ep_settings['zoom'])){ | |
| 285 | + $ep_settings['zoom']=12; | |
| 286 | + $reg_settings=true; | |
| 287 | + } | |
| 252 | 288 | if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) { |
| 253 | 289 | $ep_settings['cache'] = 0; |
| 254 | 290 | $reg_settings=true; |
| 255 | 291 | } |
| @@ -268,8 +304,16 @@ | ||
| 268 | 304 | if (!isset($ep_settings['markpath'])) { |
| 269 | 305 | $ep_settings['markpath'] = ''; |
| 270 | 306 | $reg_settings=true; |
| 271 | 307 | } |
| 308 | + if (!isset($ep_settings['markurl'])) { | |
| 309 | + $ep_settings['markurl'] = ''; | |
| 310 | + $reg_settings=true; | |
| 311 | + } | |
| 312 | + if (!isset($ep_settings['customcss'])) { | |
| 313 | + $ep_settings['customcss'] = ''; | |
| 314 | + $reg_settings=true; | |
| 315 | + } | |
| 272 | 316 | if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) { |
| 273 | 317 | $ep_settings['singlepos'] = 'after'; |
| 274 | 318 | $reg_settings=true; |
| 275 | 319 | } |
| @@ -396,10 +440,20 @@ | ||
| 396 | 440 | * Enqueue CSS files |
| 397 | 441 | */ |
| 398 | 442 | public function load_styles() { |
| 399 | 443 | //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); | |
| 444 | + if(!empty($this->settings['customcss'])){ | |
| 445 | + wp_enqueue_style('event-post-custom', $this->settings['customcss']); | |
| 446 | + } | |
| 447 | + elseif(is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')){ | |
| 448 | + wp_enqueue_style('event-post-custom', get_theme_file_uri('event-post.css')); | |
| 449 | + } | |
| 450 | + else{ | |
| 451 | + wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version); | |
| 452 | + wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version); | |
| 453 | + } | |
| 454 | + | |
| 455 | + // Lib scripts | |
| 402 | 456 | wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version); |
| 403 | 457 | wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css')); |
| 404 | 458 | } |
| 405 | 459 | /** |
| @@ -419,8 +473,9 @@ | ||
| 419 | 473 | wp_localize_script('event-post', 'eventpost_params', array( |
| 420 | 474 | 'imgpath' => plugins_url('/img/', __FILE__), |
| 421 | 475 | 'maptiles' => $this->maps, |
| 422 | 476 | 'defaulttile' => $this->settings['tile'], |
| 477 | + 'zoom' => $this->settings['zoom'], | |
| 423 | 478 | 'ajaxurl' => admin_url() . 'admin-ajax.php', |
| 424 | 479 | 'map_interactions'=>$this->map_interactions, |
| 425 | 480 | )); |
| 426 | 481 | } |
| @@ -451,17 +506,20 @@ | ||
| 451 | 506 | |
| 452 | 507 | /** |
| 453 | 508 | * Enqueue JS files in admin |
| 454 | 509 | */ |
| 455 | - public function admin_scripts($deps = array('jquery')) { | |
| 510 | + public function admin_scripts($deps = array('jquery'), $force=false) { | |
| 456 | 511 | $page = basename($_SERVER['SCRIPT_NAME']); |
| 457 | - if( $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){ | |
| 512 | + if(!$force && $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings')){ | |
| 458 | 513 | return; |
| 459 | 514 | } |
| 460 | 515 | wp_enqueue_script('jquery'); |
| 461 | 516 | wp_enqueue_script('jquery-effects-core'); |
| 462 | 517 | wp_enqueue_script('jquery-effects-shake'); |
| 463 | - if($this->settings['datepicker']=='simple' || (isset($_GET['page']) && $_GET['page']=='event-settings')){ | |
| 518 | + if(!is_array($deps)){ | |
| 519 | + $deps = array('jquery'); | |
| 520 | + } | |
| 521 | + if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){ | |
| 464 | 522 | wp_enqueue_script('jquery-ui-datepicker'); |
| 465 | 523 | $deps[] = 'jquery-ui-datepicker'; |
| 466 | 524 | } |
| 467 | 525 | wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true); |
| @@ -469,8 +527,9 @@ | ||
| 469 | 527 | if (strpos($language, '-') > -1) { |
| 470 | 528 | $language = strtolower(substr($language, 0, 2)); |
| 471 | 529 | } |
| 472 | 530 | wp_localize_script('event-post-admin', 'eventpost', array( |
| 531 | + 'ajaxurl' => admin_url('admin-ajax.php'), | |
| 473 | 532 | 'imgpath' => plugins_url('/img/', __FILE__), |
| 474 | 533 | 'date_choose' => '<span class="screen-reader-text">'.__('Choose', 'event-post').'</span><i class="dashicons dashicons-calendar-alt"></i>', |
| 475 | 534 | 'date_format' => __('yy-mm-dd', 'event-post'), |
| 476 | 535 | 'more_icons' => __('More icons', 'event-post'), |
| @@ -501,8 +560,19 @@ | ||
| 501 | 560 | 'maptiles' => $this->maps, |
| 502 | 561 | 'defaulttile' => $this->settings['tile'] |
| 503 | 562 | )); |
| 504 | 563 | } |
| 564 | + function scripts_edit() { | |
| 565 | + // load only when editing a supported post type | |
| 566 | + $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; | |
| 567 | + if ( in_array( $current_post_type, $this->settings['posttypes'] ) ) { | |
| 568 | + wp_enqueue_script( 'eventpost-inline-edit', plugins_url( 'js/inline-edit.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), '', true ); | |
| 569 | + wp_localize_script('eventpost-inline-edit', 'eventpost_inline_edit', array( | |
| 570 | + 'quick'=>$this->quick_edit_fields, | |
| 571 | + 'bulk'=>$this->bulk_edit_fields | |
| 572 | + )); | |
| 573 | + } | |
| 574 | + } | |
| 505 | 575 | |
| 506 | 576 | /** |
| 507 | 577 | * Add custom header meta for single events |
| 508 | 578 | */ |
| @@ -513,15 +583,17 @@ | ||
| 513 | 583 | ?> |
| 514 | 584 | <meta name="geo.placename" content="<?php echo $event->address ?>" /> |
| 515 | 585 | <meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" /> |
| 516 | 586 | <meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" /> |
| 517 | - <?php | |
| 587 | +<meta property="place:location:latitude" content="<?php echo $event->lat ?>" /> | |
| 588 | +<meta property="place:location:longitude" content="<?php echo $event->long ?>" /> | |
| 589 | +<?php | |
| 518 | 590 | } |
| 519 | 591 | if ($event->start != '' && $event->end != '') { |
| 520 | 592 | ?> |
| 521 | 593 | <meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" /> |
| 522 | 594 | <meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" /> |
| 523 | - <?php | |
| 595 | +<?php | |
| 524 | 596 | } |
| 525 | 597 | } |
| 526 | 598 | } |
| 527 | 599 | |
| @@ -526,13 +598,23 @@ | ||
| 526 | 598 | } |
| 527 | 599 | |
| 528 | 600 | /** |
| 529 | 601 | * |
| 602 | + * @param type $str | |
| 603 | + * @return string | |
| 604 | + * @since 5.0.1 | |
| 605 | + */ | |
| 606 | + public function date_cleanup($str){ | |
| 607 | + return trim(str_replace(array('0', ' ', ':', '-'), '', $str)); | |
| 608 | + } | |
| 609 | + | |
| 610 | + /** | |
| 611 | + * | |
| 530 | 612 | * @param string $str |
| 531 | 613 | * @return boolean |
| 532 | 614 | */ |
| 533 | 615 | public function dateisvalid($str) { |
| 534 | - return is_string($str) && trim(str_replace(array(':', '0'), '', $str)) != ''; | |
| 616 | + return is_string($str) && $this->date_cleanup($str) != ''; | |
| 535 | 617 | } |
| 536 | 618 | |
| 537 | 619 | /** |
| 538 | 620 | * |
| @@ -579,9 +661,9 @@ | ||
| 579 | 661 | } |
| 580 | 662 | |
| 581 | 663 | //Display dates |
| 582 | 664 | $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">'; |
| 583 | - if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) { | |
| 665 | + if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) { // same day | |
| 584 | 666 | $dates.= "\n\t\t\t\t\t\t\t".'<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' |
| 585 | 667 | . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>"; |
| 586 | 668 | if (date('H:i', $time_start) != date('H:i', $time_end) && date('H:i', $time_start) != '00:00' && date('H:i', $time_end) != '00:00') { |
| 587 | 669 | $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span> |
| @@ -593,15 +675,22 @@ | ||
| 593 | 675 | $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span> |
| 594 | 676 | <time class="time time-single" itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' . date_i18n($this->settings['timeformat'], $time_start) . '</time>'; |
| 595 | 677 | } |
| 596 | 678 | $dates.="\n\t\t\t\t\t\t\t".'</time>'; |
| 597 | - } else { | |
| 679 | + } else { // not same day | |
| 598 | 680 | $dates.= ' |
| 599 | 681 | <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span> |
| 600 | - <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']) . '</time> | |
| 682 | + <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']); | |
| 683 | + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00'){ | |
| 684 | + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_start); | |
| 685 | + } | |
| 686 | + $dates.='</time> | |
| 601 | 687 | <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span> |
| 602 | - <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']) . '</time> | |
| 603 | - '; | |
| 688 | + <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']); | |
| 689 | + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00') { | |
| 690 | + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_end); | |
| 691 | + } | |
| 692 | + $dates.='</time>'; | |
| 604 | 693 | } |
| 605 | 694 | $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->'; |
| 606 | 695 | return $dates; |
| 607 | 696 | } |
| @@ -619,14 +708,9 @@ | ||
| 619 | 708 | |
| 620 | 709 | $dates.=$this->delta_date($event->time_start, $event->time_end); |
| 621 | 710 | |
| 622 | 711 | $timezone_string = get_option('timezone_string'); |
| 623 | - $gmt_offset = get_option('gmt_offset '); | |
| 624 | - $codegmt = 0; | |
| 625 | - if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') { | |
| 626 | - $codegmt = $gmt_offset * -1; | |
| 627 | - $gmt_offset = '+' . $gmt_offset; | |
| 628 | - } | |
| 712 | + $gmt_offset = $gmt = $this->get_gmt_offset(); | |
| 629 | 713 | |
| 630 | 714 | if (!is_admin() && $event->time_end > current_time('timestamp') && ( |
| 631 | 715 | $this->settings['export'] == 'both' || |
| 632 | 716 | ($this->settings['export'] == 'single' && is_single() ) || |
| @@ -631,28 +715,55 @@ | ||
| 631 | 715 | $this->settings['export'] == 'both' || |
| 632 | 716 | ($this->settings['export'] == 'single' && is_single() ) || |
| 633 | 717 | ($this->settings['export'] == 'list' && !is_single() ) |
| 634 | 718 | )) { |
| 719 | + | |
| 635 | 720 | // Export event |
| 636 | 721 | $title = urlencode($post->post_title); |
| 637 | 722 | $address = urlencode($post->address); |
| 638 | 723 | $url = urlencode($post->guid); |
| 639 | - | |
| 640 | - $mt = strtotime($codegmt . ' Hours', $event->time_start); | |
| 641 | - $d_s = date("Ymd", $mt) . 'T' . date("His", $mt); | |
| 642 | - $mte = strtotime($codegmt . ' Hours', $event->time_end); | |
| 643 | - $d_e = date("Ymd", $mte) . 'T' . date("His", $mte); | |
| 724 | + $allday = ($post->time_start && $post->time_end && date('H:i:s', $post->time_start) == '00:00:00' && date('H:i:s', $post->time_end) == '00:00:00'); | |
| 725 | + $d_s = date("Ymd", $event->time_start) . ($allday ? '' : 'T' . date("His", $event->time_start)); | |
| 726 | + $d_e = date("Ymd", $event->time_end) . ($allday ? '' : 'T' . date("His", $event->time_end)); | |
| 644 | 727 | $uid = $post->ID . '-' . $post->blog_id; |
| 645 | 728 | |
| 646 | 729 | // format de date ICS |
| 647 | - $ics_url = plugins_url('export/ics.php', __FILE__) . '?t=' . $title . '&u=' . $uid . '&sd=' . $d_s . '&ed=' . $d_e . '&a=' . $address . '&d=' . $url . '&tz=%3BTZID%3D' . urlencode($timezone_string); | |
| 730 | + $ics_url = add_query_arg(array( | |
| 731 | + 't'=>$title, | |
| 732 | + 'u'=>$uid, | |
| 733 | + 'sd'=>$d_s, | |
| 734 | + 'ed'=>$d_e, | |
| 735 | + 'a'=>$address, | |
| 736 | + 'd'=>$url, | |
| 737 | + 'tz'=>$timezone_string, | |
| 738 | + 'gmt'=>urlencode($gmt_offset) | |
| 739 | + ), plugins_url('export/ics.php', __FILE__)); | |
| 648 | 740 | |
| 649 | 741 | // format de date Google cal |
| 650 | - $google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&text=' . $title . '&dates=' . $d_s . 'Z/' . $d_e . 'Z&details=' . $url . '&ctz='.$timezone_string.'&location=' . $address . '&trp=false&sprop=&sprop=name'; | |
| 742 | + //$google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&text=' . $title . '&dates=' . $d_s . 'Z/' . $d_e . 'Z&details=' . $url . '&ctz='.$timezone_string.'&location=' . $address . '&trp=false&sprop=&sprop=name'; | |
| 743 | + $google_url = add_query_arg(array( | |
| 744 | + 'action'=>'TEMPLATE', | |
| 745 | + 'trp'=>'false', | |
| 746 | + 'sprop'=>'name', | |
| 747 | + 'text'=>$title, | |
| 748 | + 'dates'=>$d_s.'Z/'.$d_e.'Z', | |
| 749 | + 'location'=>$address, | |
| 750 | + 'details'=>$url, | |
| 751 | + 'ctz'=>$timezone_string, | |
| 752 | + 'gmt'=> urlencode($gmt_offset) | |
| 753 | + ), 'https://www.google.com/calendar/event'); | |
| 651 | 754 | |
| 652 | 755 | // format de date VCS |
| 653 | - $vcs_url = plugins_url('export/vcs.php', __FILE__) . '?t=' . $title . '&u=' . $uid . '&sd=' . $d_s . '&ed=' . $d_e . '&a=' . $address . '&d=' . $url . '&tz=%3BTZID%3D' . urlencode($timezone_string); | |
| 654 | - | |
| 756 | + $vcs_url = add_query_arg(array( | |
| 757 | + 't'=>$title, | |
| 758 | + 'u'=>$uid, | |
| 759 | + 'sd'=>$d_s, | |
| 760 | + 'ed'=>$d_e, | |
| 761 | + 'a'=>$address, | |
| 762 | + 'd'=>$url, | |
| 763 | + 'tz'=>$timezone_string, | |
| 764 | + 'gmt'=>$gmt_offset | |
| 765 | + ), plugins_url('export/vcs.php', __FILE__)); | |
| 655 | 766 | $dates.=' |
| 656 | 767 | <span class="eventpost-date-export"> |
| 657 | 768 | <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a> |
| 658 | 769 | <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a> |
| @@ -791,26 +902,21 @@ | ||
| 791 | 902 | * @param string $content |
| 792 | 903 | * @return string |
| 793 | 904 | */ |
| 794 | 905 | public function display_single($content) { |
| 795 | - if (is_page() || !is_single() || is_home()) | |
| 906 | + if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){ | |
| 796 | 907 | return $content; |
| 797 | - $post = get_queried_object(); | |
| 798 | - //Prevent from filters applying "the_content" on another thing than the current post content | |
| 799 | - remove_filter('the_content', array(&$this, 'display_single'), 9999); | |
| 800 | - $current_content = apply_filters('the_content', $post->post_content); | |
| 801 | - if ($current_content == $content) { | |
| 802 | - $post = $this->retreive(); | |
| 803 | - $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post); | |
| 804 | - if($this->settings['singlepos']=='before'){ | |
| 805 | - $content=$eventbar.$content; | |
| 806 | - } | |
| 807 | - else{ | |
| 808 | - $content.=$eventbar; | |
| 809 | - } | |
| 810 | - $this->load_map_scripts(); | |
| 811 | 908 | } |
| 812 | - add_filter('the_content', array(&$this, 'display_single'), 9999); | |
| 909 | + | |
| 910 | + $post = $this->retreive(); | |
| 911 | + $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post); | |
| 912 | + if($this->settings['singlepos']=='before'){ | |
| 913 | + $content=$eventbar.$content; | |
| 914 | + } | |
| 915 | + elseif($this->settings['singlepos']=='after'){ | |
| 916 | + $content.=$eventbar; | |
| 917 | + } | |
| 918 | + $this->load_map_scripts(); | |
| 813 | 919 | return $content; |
| 814 | 920 | } |
| 815 | 921 | |
| 816 | 922 | /** |
| @@ -827,18 +933,25 @@ | ||
| 827 | 933 | * Alter the post title in order to add icons if needed |
| 828 | 934 | * @param string $title |
| 829 | 935 | * @return string |
| 830 | 936 | */ |
| 831 | - public function the_title($title){ | |
| 832 | - if(!in_the_loop() || !$this->settings['loopicons']){ | |
| 937 | + public function the_title($title, $post_id = null){ | |
| 938 | + if(!$post_id || !in_the_loop() || !$this->settings['loopicons']){ | |
| 833 | 939 | return $title; |
| 834 | 940 | } |
| 835 | - $event = $this->retreive(); | |
| 941 | + $icons_ = array( | |
| 942 | + // Emojis | |
| 943 | + 1=>array('🗓', '🗺'), | |
| 944 | + // Dashicons | |
| 945 | + 2=>array('<span class="dashicons dashicons-calendar"></span>', '<span class="dashicons dashicons-location"></span>'), | |
| 946 | + ); | |
| 947 | + | |
| 948 | + $event = $this->retreive($post_id); | |
| 836 | 949 | if(!empty($event->start)){ |
| 837 | - $title .= ' <span class="dashicons dashicons-calendar"></span>'; | |
| 950 | + $title .= ' '.$icons_[$this->settings['loopicons']][0]; | |
| 838 | 951 | } |
| 839 | 952 | if(!empty($event->lat) && !empty($event->long)){ |
| 840 | - $title .= ' <span class="dashicons dashicons-location"></span>'; | |
| 953 | + $title .= ' '.$icons_[$this->settings['loopicons']][1]; | |
| 841 | 954 | } |
| 842 | 955 | return $title; |
| 843 | 956 | } |
| 844 | 957 | |
| @@ -865,8 +978,9 @@ | ||
| 865 | 978 | 'past' => false, |
| 866 | 979 | 'geo' => 0, |
| 867 | 980 | 'width' => '', |
| 868 | 981 | 'height' => '', |
| 982 | + 'zoom' => '', | |
| 869 | 983 | 'tile' => $ep_settings['tile'], |
| 870 | 984 | 'title' => '', |
| 871 | 985 | 'before_title' => '<h3>', |
| 872 | 986 | 'after_title' => '</h3>', |
| @@ -944,9 +1058,9 @@ | ||
| 944 | 1058 | ); |
| 945 | 1059 | } |
| 946 | 1060 | $attributes = ''; |
| 947 | 1061 | if($id == 'event_geolist'){ |
| 948 | - $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-disabled-interactions="'; | |
| 1062 | + $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-zoom="'.$zoom.'" data-disabled-interactions="'; | |
| 949 | 1063 | foreach($this->map_interactions as $int_key=>$int_name){ |
| 950 | 1064 | $attributes.=$atts[$int_key]==false ? $int_key.', ' : ''; |
| 951 | 1065 | } |
| 952 | 1066 | $attributes.='"'; |
| @@ -970,8 +1084,11 @@ | ||
| 970 | 1084 | $list |
| 971 | 1085 | ), $container_schema |
| 972 | 1086 | ); |
| 973 | 1087 | } |
| 1088 | + elseif(filter_input(INPUT_POST, 'action')=='bulk_do_shortcode'){ | |
| 1089 | + return '<div class="event_geolist_icon_loader"><p><span class="dashicons dashicons-calendar"></span></p><p class="screen-reader-text">'.__('An empty list of events', 'event-post').'</p></div>'; | |
| 1090 | + } | |
| 974 | 1091 | return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context); |
| 975 | 1092 | } |
| 976 | 1093 | |
| 977 | 1094 | /** |
| @@ -1484,8 +1601,95 @@ | ||
| 1484 | 1601 | <?php |
| 1485 | 1602 | } |
| 1486 | 1603 | |
| 1487 | 1604 | /** |
| 1605 | + * | |
| 1606 | + * @param string $column_name | |
| 1607 | + * @param boolean $bulk | |
| 1608 | + */ | |
| 1609 | + function quick_edit( $column_name, $post_type, $bulk=false) { | |
| 1610 | + | |
| 1611 | + if ($bulk) { | |
| 1612 | + static $eventpostprintNonceBulk = TRUE; | |
| 1613 | + if ($eventpostprintNonceBulk) { | |
| 1614 | + $eventpostprintNonceBulk = FALSE; | |
| 1615 | + } | |
| 1616 | + $fields = $this->bulk_edit_fields; | |
| 1617 | + echo '<input type="hidden" name="eventpost-bulk-editor" id="eventpost-bulk-editor" value="eventpost-bulk-editor">'; | |
| 1618 | + } | |
| 1619 | + else { | |
| 1620 | + static $eventpostprintNonce = TRUE; | |
| 1621 | + if ($eventpostprintNonce) { | |
| 1622 | + $eventpostprintNonce = FALSE; | |
| 1623 | + } | |
| 1624 | + $fields = $this->quick_edit_fields; | |
| 1625 | + } | |
| 1626 | + wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); | |
| 1627 | + if(isset($fields[$column_name])): ?> | |
| 1628 | + <fieldset class="inline-edit-col-left inline-edit-<?php echo $column_name; ?>"> | |
| 1629 | + <div class="inline-edit-group"> | |
| 1630 | + <?php foreach ($fields[$column_name] as $fieldname=>$fieldlabel): ?> | |
| 1631 | + <fieldset class="inline-edit-col inline-edit-<?php echo $fieldname; ?>"> | |
| 1632 | + <div class="inline-edit-col column-<?php echo $fieldname; ?>"> | |
| 1633 | + <label class="inline-edit-group"> | |
| 1634 | + <span class="title"><?php echo $fieldlabel; ?></span> | |
| 1635 | + <span class="input-text-wrap"> | |
| 1636 | + <?php echo $this->inline_field($fieldname, $bulk); ?> | |
| 1637 | + </span> | |
| 1638 | + </label> | |
| 1639 | + </div> | |
| 1640 | + </fieldset> | |
| 1641 | + <?php endforeach; ?> | |
| 1642 | + </div> | |
| 1643 | + </fieldset> | |
| 1644 | + <?php endif; | |
| 1645 | + } | |
| 1646 | + | |
| 1647 | + /** | |
| 1648 | + * | |
| 1649 | + * @param type $fieldname | |
| 1650 | + * @return type | |
| 1651 | + */ | |
| 1652 | + function inline_field($fieldname, $bulk){ | |
| 1653 | + return apply_filters('eventpost_inline_field', '<input name="'.$fieldname.'" class="eventpost-inline-'.$fieldname.'" value="" type="text">', $fieldname, $bulk); | |
| 1654 | + } | |
| 1655 | + | |
| 1656 | + function inline_field_color($html, $fieldname, $bulk){ | |
| 1657 | + if($fieldname==$this->META_COLOR){ | |
| 1658 | + $colors = $this->get_colors(); | |
| 1659 | + $html=''; | |
| 1660 | + if($bulk){ | |
| 1661 | + $html.= '<span class="eventpost-bulk-colorpicker-button link">'.__('No Change', 'event-post').'</span>'; | |
| 1662 | + } | |
| 1663 | + $html .= '<select name="'.$fieldname.'" class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'" >'; | |
| 1664 | + if($bulk){ | |
| 1665 | + $html.='<option value="false">— '.__('No Change', 'event-post').' —</option>'; | |
| 1666 | + } | |
| 1667 | + foreach ($colors as $color=>$image_path){ | |
| 1668 | + $html.='<option value="'.$color.'" data-path="'.$image_path.'">'.$color.'</option>'; | |
| 1669 | + } | |
| 1670 | + $html.= '</select>'; | |
| 1671 | + } | |
| 1672 | + return $html; | |
| 1673 | + } | |
| 1674 | + | |
| 1675 | + /** | |
| 1676 | + * | |
| 1677 | + * @param type $column_name | |
| 1678 | + * @param type $post_type | |
| 1679 | + */ | |
| 1680 | + function bulk_edit($column_name, $post_type){ | |
| 1681 | + $this->quick_edit($column_name, $post_type, true); | |
| 1682 | + } | |
| 1683 | + | |
| 1684 | + /** | |
| 1685 | + * | |
| 1686 | + */ | |
| 1687 | + function inline_save(){ | |
| 1688 | + $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); | |
| 1689 | + $this->save_postdata($post_id); | |
| 1690 | + } | |
| 1691 | + /** | |
| 1488 | 1692 | * When the post is saved, saves our custom data |
| 1489 | 1693 | * @param int $post_id |
| 1490 | 1694 | * @return void |
| 1491 | 1695 | */ |
| @@ -1528,10 +1732,33 @@ | ||
| 1528 | 1732 | delete_post_meta($post_id, $this->META_ADD); |
| 1529 | 1733 | delete_post_meta($post_id, $this->META_LAT); |
| 1530 | 1734 | delete_post_meta($post_id, $this->META_LONG); |
| 1531 | 1735 | } |
| 1736 | + | |
| 1737 | + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array(); | |
| 1532 | 1738 | } |
| 1533 | 1739 | |
| 1740 | + function save_bulkdatas() { | |
| 1741 | + $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; | |
| 1742 | + if (in_array($current_post_type, $this->settings['posttypes'])) { | |
| 1743 | + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array(); | |
| 1744 | + if (!empty($post_ids) && is_array($post_ids)) { | |
| 1745 | + foreach ($this->bulk_edit_fields as $sets) { | |
| 1746 | + foreach ($sets as $fieldname => $fieldlabel) { | |
| 1747 | + if ((false != $value = filter_input(INPUT_POST, $fieldname))) { | |
| 1748 | + foreach ($post_ids as $post_id) { | |
| 1749 | + update_post_meta($post_id, $fieldname, $value); | |
| 1750 | + } | |
| 1751 | + } | |
| 1752 | + } | |
| 1753 | + } | |
| 1754 | + } | |
| 1755 | + wp_send_json(true); | |
| 1756 | + exit; | |
| 1757 | + } | |
| 1758 | + wp_send_json(false); | |
| 1759 | + } | |
| 1760 | + | |
| 1534 | 1761 | /** |
| 1535 | 1762 | * |
| 1536 | 1763 | * @param string $date |
| 1537 | 1764 | * @param string $cat |
| @@ -1612,9 +1839,9 @@ | ||
| 1612 | 1839 | $ret.='<button data-date="' . date('Y-n', $prev_year) . '" tabindex="0" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $prev_year)).'" class="eventpost_cal_bt"><<</button> '; |
| 1613 | 1840 | $ret.=$annee; |
| 1614 | 1841 | $ret.='<button data-date="' . date('Y-n', $next_year) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $next_year)).'" class="eventpost_cal_bt">>></button> '; |
| 1615 | 1842 | $ret.='<button data-date="' . date('Y-n', $prev_month) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date_i18n('F Y', $prev_month)).'" class="eventpost_cal_bt"><</button> '; |
| 1616 | - $ret.=$this->NomDuMois[$mois]; | |
| 1843 | + $ret.=$this->NomDuMois[abs($mois)]; | |
| 1617 | 1844 | $ret.='<button data-date="' . date('Y-n', $next_month) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date_i18n('F Y', $next_month)).'" class="eventpost_cal_bt">></button> '; |
| 1618 | 1845 | $ret.='<button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button>'; |
| 1619 | 1846 | $ret.='</div>'; |
| 1620 | 1847 | } |
| @@ -1635,8 +1862,11 @@ | ||
| 1635 | 1862 | $td = '<td class="event_post_day">'; |
| 1636 | 1863 | if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) { |
| 1637 | 1864 | $td = '<td class="event_post_day_now">'; |
| 1638 | 1865 | } |
| 1866 | + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){ | |
| 1867 | + $td = '<td class="event_post_day_over">'; // Patch ahf | |
| 1868 | + } | |
| 1639 | 1869 | $ret.=$td; |
| 1640 | 1870 | |
| 1641 | 1871 | $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail); |
| 1642 | 1872 | $ret.='</td>'; |
| @@ -1685,8 +1915,83 @@ | ||
| 1685 | 1915 | } |
| 1686 | 1916 | } |
| 1687 | 1917 | |
| 1688 | 1918 | /** |
| 1919 | + * Displays a search form | |
| 1920 | + * | |
| 1921 | + * @param type $atts | |
| 1922 | + * @return type | |
| 1923 | + */ | |
| 1924 | + public function search($atts) { | |
| 1925 | + $params = shortcode_atts(apply_filters('eventpost_params', array( | |
| 1926 | + 'dates' => true, | |
| 1927 | + 'q' => true, | |
| 1928 | + 'tax' => false, | |
| 1929 | + ), 'search'), $atts); | |
| 1930 | + $this->list_id++; | |
| 1931 | + | |
| 1932 | + $list_id = $this->list_id; | |
| 1933 | + $q = (false !== $q = filter_input(INPUT_GET, 'q')) ? $q : ''; | |
| 1934 | + $from = (false !== $from = filter_input(INPUT_GET, 'from')) ? $from : ''; | |
| 1935 | + $to = (false !== $to = filter_input(INPUT_GET, 'to')) ? $to : ''; | |
| 1936 | + $tax = (false !== $tax = filter_input(INPUT_GET, 'tax')) ? $tax : ''; | |
| 1937 | + | |
| 1938 | + $cleaned_from = $this->date_cleanup($from); | |
| 1939 | + $cleaned_to = $this->date_cleanup($to); | |
| 1940 | + if(empty($cleaned_from)){ | |
| 1941 | + $from=false; | |
| 1942 | + } | |
| 1943 | + if(empty($cleaned_to)){ | |
| 1944 | + $to=false; | |
| 1945 | + } | |
| 1946 | + | |
| 1947 | + // Search form | |
| 1948 | + $this->admin_scripts(null, true); | |
| 1949 | + wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version); | |
| 1950 | + include (plugin_dir_path(__FILE__) . 'views/search-form.php'); | |
| 1951 | + | |
| 1952 | + // Results | |
| 1953 | + if ($list_id == filter_input(INPUT_GET, 'evenpost_search')) { | |
| 1954 | + $arg = array( | |
| 1955 | + 'post_type' => $this->settings['posttypes'], | |
| 1956 | + 'meta_key' => $this->META_START, | |
| 1957 | + 'orderby' => 'meta_value', | |
| 1958 | + 'order' => 'ASC', | |
| 1959 | + 's' => $q | |
| 1960 | + ); | |
| 1961 | + if ($tax) { | |
| 1962 | + $arg['cat'] = $tax; | |
| 1963 | + } | |
| 1964 | + | |
| 1965 | + if ($from || $to) { | |
| 1966 | + | |
| 1967 | + $arg['meta_query'] = array(); | |
| 1968 | + if ($from) { | |
| 1969 | + $arg['meta_query'][] = array( | |
| 1970 | + 'key' => $this->META_START, | |
| 1971 | + 'value' => $from, | |
| 1972 | + 'compare' => '>=', | |
| 1973 | + 'type' => 'DATETIME' | |
| 1974 | + ); | |
| 1975 | + } | |
| 1976 | + if ($to) { | |
| 1977 | + $arg['meta_query'][] = $meta_query = array( | |
| 1978 | + array( | |
| 1979 | + 'key' => $this->META_END, | |
| 1980 | + 'value' => $to, | |
| 1981 | + 'compare' => '<=', | |
| 1982 | + 'type' => 'DATETIME' | |
| 1983 | + ), | |
| 1984 | + ); | |
| 1985 | + } | |
| 1986 | + } | |
| 1987 | + $events = new WP_Query($arg); | |
| 1988 | + include (plugin_dir_path(__FILE__) . 'views/search-results.php'); | |
| 1989 | + wp_reset_query(); | |
| 1990 | + } | |
| 1991 | + } | |
| 1992 | + | |
| 1993 | + /** | |
| 1689 | 1994 | * AJAX Get lat long from address |
| 1690 | 1995 | */ |
| 1691 | 1996 | public function GetLatLong() { |
| 1692 | 1997 | if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { |
| @@ -1694,14 +1999,17 @@ | ||
| 1694 | 1999 | $q = $_REQUEST['q']; |
| 1695 | 2000 | header('Content-Type: application/json'); |
| 1696 | 2001 | $transient_name = 'eventpost_osquery_' . $q; |
| 1697 | 2002 | $val = get_transient($transient_name); |
| 1698 | - if (false === $val || empty($val)) { | |
| 2003 | + if (false === $val || empty($val) || !is_string($val)) { | |
| 1699 | 2004 | $language = get_bloginfo('language'); |
| 1700 | 2005 | if (strpos($language, '-') > -1) { |
| 1701 | 2006 | $language = strtolower(substr($language, 0, 2)); |
| 1702 | 2007 | } |
| 1703 | - $val = file_get_contents('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language); | |
| 2008 | + $remote_val = wp_safe_remote_request('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language); | |
| 2009 | + if(json_decode($remote_val['body'])){ | |
| 2010 | + $val = $remote_val['body']; | |
| 2011 | + } | |
| 1704 | 2012 | set_transient($transient_name, $val, 30 * DAY_IN_SECONDS); |
| 1705 | 2013 | } |
| 1706 | 2014 | echo $val; |
| 1707 | 2015 | exit(); |
| @@ -1742,57 +2050,54 @@ | ||
| 1742 | 2050 | . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>' |
| 1743 | 2051 | . get_post_meta($post_id, $this->META_ADD, true) |
| 1744 | 2052 | . '</a> '; |
| 1745 | 2053 | } |
| 2054 | + $this->column_edit_hidden_fields($post_id, 'location'); | |
| 1746 | 2055 | } |
| 1747 | 2056 | if ($column_name == 'event') { |
| 1748 | 2057 | echo $this->print_date($post_id, false); |
| 2058 | + $this->column_edit_hidden_fields($post_id, 'event'); | |
| 1749 | 2059 | } |
| 1750 | 2060 | do_action('eventpost_columns_content', $column_name, $post_id); |
| 1751 | 2061 | } |
| 1752 | 2062 | |
| 2063 | + function column_edit_hidden_fields($post_id, $set){ | |
| 2064 | + $event = $this->retreive($post_id); | |
| 2065 | + echo '<div class="hidden">'; | |
| 2066 | + foreach($this->quick_edit_fields[$set] as $fieldname=>$fieldlabel){ | |
| 2067 | + echo'<span class="inline-edit-value '.$fieldname.'">'.esc_attr($event->$fieldname).'</span>'; | |
| 2068 | + } | |
| 2069 | + echo '</div>'; | |
| 2070 | + } | |
| 2071 | + | |
| 1753 | 2072 | /** ADMIN PAGES **/ |
| 1754 | 2073 | |
| 1755 | 2074 | /** |
| 1756 | - * save settings end redirect | |
| 1757 | - * @return void | |
| 2075 | + * Settings link on the plugins page | |
| 1758 | 2076 | */ |
| 1759 | - public function save_settings(){ | |
| 1760 | - if (!current_user_can('manage_options')){ | |
| 1761 | - return; | |
| 1762 | - } | |
| 1763 | - if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) { | |
| 1764 | - wp_die(__('Security error', 'event-post')); | |
| 1765 | - } | |
| 1766 | - | |
| 1767 | - $valid_post = array( | |
| 1768 | - 'ep_settings'=>array( | |
| 1769 | - 'filter' => FILTER_SANITIZE_STRING, | |
| 1770 | - 'flags' => FILTER_REQUIRE_ARRAY | |
| 1771 | - ) | |
| 1772 | - ); | |
| 1773 | - | |
| 1774 | - foreach ($this->settings as $item_name=>$item_value){ | |
| 1775 | - $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING; | |
| 1776 | - } | |
| 1777 | - | |
| 1778 | - $post_types=(array) $_POST['ep_settings']['posttypes']; | |
| 1779 | - $posttypes = get_post_types(); | |
| 1780 | - foreach($post_types as $posttype){ | |
| 1781 | - if(!in_array($posttype, $posttypes)){ | |
| 1782 | - unset($post_types[$posttype]); | |
| 1783 | - } | |
| 2077 | + public function settings_link( $links ) { | |
| 2078 | + $settings_link = '<a href="options-general.php?page=event-settings">' . __( 'Settings', 'event-post' ) . '</a>'; | |
| 2079 | + // place it before other links | |
| 2080 | + array_unshift( $links, $settings_link ); | |
| 2081 | + return $links; | |
| 2082 | + } | |
| 2083 | + /** | |
| 2084 | + * | |
| 2085 | + * @param type $plugin_meta | |
| 2086 | + * @param type $plugin_file | |
| 2087 | + * @param type $plugin_data | |
| 2088 | + * @param type $status | |
| 2089 | + * @return type | |
| 2090 | + */ | |
| 2091 | + public function row_meta($plugin_meta, $plugin_file, $plugin_data, $status){ | |
| 2092 | + if($plugin_file=='event-post/eventpost.php'){ | |
| 2093 | + $plugin_link = '<a href="http://event-post.com" target="_blank">' . __( 'Plugin site', 'event-post' ) . '</a>'; | |
| 2094 | + $review_link = '<a href="https://wordpress.org/support/plugin/event-post/reviews/#new-post" target="_blank">' . __( 'Give a note', 'event-post' ) . '</a>'; | |
| 2095 | + array_push($plugin_meta, $plugin_link, $review_link); | |
| 1784 | 2096 | } |
| 2097 | + return $plugin_meta; | |
| 2098 | + } | |
| 1785 | 2099 | |
| 1786 | - if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) { | |
| 1787 | - $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']); | |
| 1788 | - $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']); | |
| 1789 | - $settings['ep_settings']['posttypes']= array_values($post_types); | |
| 1790 | - update_option('ep_settings', $settings['ep_settings']); | |
| 1791 | - } | |
| 1792 | - wp_redirect('options-general.php?page=event-settings&confirm=options_saved'); | |
| 1793 | - exit; | |
| 1794 | - } | |
| 1795 | 2100 | /** |
| 1796 | 2101 | * adds menu items |
| 1797 | 2102 | */ |
| 1798 | 2103 | public function manage_options() { |
| @@ -1815,305 +2120,332 @@ | ||
| 1815 | 2120 | return $elements; |
| 1816 | 2121 | } |
| 1817 | 2122 | |
| 1818 | 2123 | /** |
| 1819 | - * output content of the setting page | |
| 2124 | + * @action eventpost_register_settings | |
| 1820 | 2125 | */ |
| 1821 | - public function manage_settings() { | |
| 1822 | - if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?> | |
| 1823 | - <div class="updated"><p><strong><?php _e('Event settings saved !', 'event-post') ?></strong></p></div> | |
| 1824 | - <?php | |
| 1825 | - } | |
| 1826 | - $ep_settings = $this->settings; | |
| 1827 | - ?> | |
| 1828 | - <div class="wrap"> | |
| 1829 | - <div class="icon32" id="icon-options-general"><br></div> | |
| 1830 | - <h1><?php _e('Event settings', 'event-post'); ?></h1> | |
| 1831 | - <form name="form1" method="post" action="admin-post.php"> | |
| 1832 | - <input type="hidden" name="action" value="EventPostSaveSettings"> | |
| 1833 | - <?php wp_nonce_field('ep_nonce_settings','ep_nonce_settings') ?> | |
| 1834 | - <h2><?php _e('Global settings', 'event-post'); ?></h2> | |
| 1835 | - <table class="form-table" id="eventpost-settings-table-global"> | |
| 1836 | - <tbody> | |
| 1837 | - <tr> | |
| 1838 | - <th> | |
| 1839 | - <label for="ep_emptylink"> | |
| 1840 | - <?php _e('Print link for empty posts', 'event-post') ?> | |
| 1841 | - </label> | |
| 1842 | - </th> | |
| 1843 | - <td> | |
| 1844 | - <select name="ep_settings[emptylink]" id="ep_emptylink"> | |
| 1845 | - <option value="1" <?php selected($ep_settings['emptylink'], 1, true);?>> | |
| 1846 | - <?php _e('Link all posts', 'event-post'); ?> | |
| 1847 | - </option> | |
| 1848 | - <option value="0" <?php selected($ep_settings['emptylink'], 0, true);?>> | |
| 1849 | - <?php _e('Do not link posts with empty content', 'event-post'); ?> | |
| 1850 | - </option> | |
| 1851 | - </select> | |
| 1852 | - </td> | |
| 1853 | - </tr> | |
| 1854 | - <tr> | |
| 1855 | - <th> | |
| 1856 | - <label for="ep_singlepos"> | |
| 1857 | - <?php _e('Event bar position for single posts', 'event-post') ?> | |
| 1858 | - </label> | |
| 1859 | - </th> | |
| 1860 | - <td> | |
| 1861 | - <select name="ep_settings[singlepos]" id="ep_singlepos"> | |
| 1862 | - <option value="before" <?php selected($ep_settings['singlepos'], 'before', true); ?>> | |
| 1863 | - <?php _e('Before the content', 'event-post'); ?> | |
| 1864 | - </option> | |
| 1865 | - <option value="after" <?php selected($ep_settings['singlepos'], 'after', true); ?>> | |
| 1866 | - <?php _e('After the content', 'event-post'); ?> | |
| 1867 | - </option> | |
| 1868 | - </select> | |
| 1869 | - </td> | |
| 1870 | - </tr> | |
| 1871 | - <tr> | |
| 1872 | - <th> | |
| 1873 | - <label for="ep_loopicons"> | |
| 1874 | - <?php _e('Add icons for events in the loop', 'event-post') ?> | |
| 1875 | - </label> | |
| 1876 | - </th> | |
| 1877 | - <td> | |
| 1878 | - <select name="ep_settings[loopicons]" id="ep_loopicons"> | |
| 1879 | - <option value="1" <?php selected($ep_settings['loopicons'],'1', true) ?>> | |
| 1880 | - <?php _e('Yes', 'event-post'); ?></option> | |
| 1881 | - <option value="0" <?php selected($ep_settings['loopicons'],'0', true) ?>> | |
| 1882 | - <?php _e('No', 'event-post'); ?></option> | |
| 1883 | - </select> | |
| 1884 | - </td> | |
| 1885 | - </tr> | |
| 1886 | - <tr> | |
| 1887 | - <th> | |
| 1888 | - <label for="ep_adminpos"> | |
| 1889 | - <?php _e('Position of event details boxes', 'event-post') ?> | |
| 1890 | - </label> | |
| 1891 | - </th> | |
| 1892 | - <td> | |
| 1893 | - <select name="ep_settings[adminpos]" id="ep_adminpos"> | |
| 1894 | - <option value="side" <?php selected($ep_settings['adminpos'],'side', true) ?>> | |
| 1895 | - <?php _e('Side', 'event-post'); ?></option> | |
| 1896 | - <option value="normal" <?php selected($ep_settings['adminpos'],'normal', true) ?>> | |
| 1897 | - <?php _e('Under the text', 'event-post'); ?></option> | |
| 1898 | - </select> | |
| 1899 | - </td> | |
| 1900 | - </tr> | |
| 1901 | - </tbody> | |
| 1902 | - </table><!-- #eventpost-settings-table-global --> | |
| 2126 | + public function register_settings(){ | |
| 2127 | + register_setting( 'eventpost-settings', 'ep_settings' ); | |
| 1903 | 2128 | |
| 1904 | - <h2><?php _e('Date settings', 'event-post'); ?></h2> | |
| 1905 | - <table class="form-table" id="eventpost-settings-table-event"> | |
| 1906 | - <tbody> | |
| 1907 | - <tr> | |
| 1908 | - <th> | |
| 1909 | - <label for="ep_dateformat"> | |
| 1910 | - <?php _e('Date format', 'event-post') ?> | |
| 1911 | - </label> | |
| 1912 | - </th> | |
| 1913 | - <td> | |
| 1914 | - <input type="text" name="ep_settings[dateformat]" id="ep_dateformat" value="<?php echo $ep_settings['dateformat']; ?>" size="10"> | |
| 1915 | - </td> | |
| 1916 | - </tr> | |
| 1917 | - <tr> | |
| 1918 | - <th> | |
| 1919 | - <label for="ep_timeformatformat"> | |
| 1920 | - <?php _e('Time format', 'event-post') ?> | |
| 1921 | - </label> | |
| 1922 | - </th> | |
| 1923 | - <td> | |
| 1924 | - <input type="text" name="ep_settings[timeformat]" id="ep_dateformat" value="<?php echo $ep_settings['timeformat']; ?>" size="10"> | |
| 1925 | - </td> | |
| 1926 | - </tr> | |
| 1927 | - <tr> | |
| 1928 | - <th> | |
| 1929 | - <label for="ep_dateexport"> | |
| 1930 | - <?php _e('Show export buttons on:', 'event-post') ?> | |
| 1931 | - </label> | |
| 1932 | - </th> | |
| 1933 | - <td> | |
| 1934 | - <select name="ep_settings[export]" id="ep_dateexport"> | |
| 1935 | - <option value="list" <?php selected($ep_settings['export'], 'list', true);?>> | |
| 1936 | - <?php _e('List only', 'event-post') ?> | |
| 1937 | - </option> | |
| 1938 | - <option value="single" <?php selected($ep_settings['export'], 'single', true);?>> | |
| 1939 | - <?php _e('Single only', 'event-post') ?> | |
| 1940 | - </option> | |
| 1941 | - <option value="both" <?php selected($ep_settings['export'], 'both', true);?>> | |
| 1942 | - <?php _e('Both', 'event-post') ?> | |
| 1943 | - </option> | |
| 1944 | - <option value="none" <?php selected($ep_settings['export'], 'none', true);?>> | |
| 1945 | - <?php _e('None', 'event-post') ?> | |
| 1946 | - </option> | |
| 1947 | - </select> | |
| 1948 | - </td> | |
| 1949 | - </tr> | |
| 1950 | - <tr> | |
| 1951 | - <th> | |
| 1952 | - <label for="ep_dateforhumans"> | |
| 1953 | - <?php _e('Relative human dates:', 'event-post') ?> | |
| 1954 | - </label> | |
| 1955 | - </th> | |
| 1956 | - <td> | |
| 1957 | - <select name="ep_settings[dateforhumans]" id="ep_dateforhumans"> | |
| 1958 | - <option value="1" <?php selected($ep_settings['dateforhumans'], '1', true);?>> | |
| 1959 | - <?php _e('Yes', 'event-post') ?> | |
| 1960 | - </option> | |
| 1961 | - <option value="0" <?php selected($ep_settings['dateforhumans'], '0', true);?>> | |
| 1962 | - <?php _e('No', 'event-post') ?> | |
| 1963 | - </option> | |
| 1964 | - </select> | |
| 1965 | - <p class="description"><?php _e('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post') ?></p> | |
| 1966 | - </td> | |
| 1967 | - </tr> | |
| 1968 | - </tbody> | |
| 1969 | - </table><!-- #eventpost-settings-table-event --> | |
| 2129 | + // Global | |
| 2130 | + add_settings_section( | |
| 2131 | + 'eventpost-settings-general', | |
| 2132 | + '<span class="dashicons dashicons-admin-appearance"></span> '.__('Global settings', 'event-post'), | |
| 2133 | + array(&$this, 'settings_section_callback'), | |
| 2134 | + 'eventpost-settings' | |
| 2135 | + ); | |
| 2136 | + //-- | |
| 2137 | + add_settings_field( | |
| 2138 | + 'emptylink', | |
| 2139 | + __('Print link for empty posts', 'event-post'), | |
| 2140 | + array(&$this, 'settings_field_select_callback'), | |
| 2141 | + 'eventpost-settings', | |
| 2142 | + 'eventpost-settings-general', | |
| 2143 | + array( 'name' => 'emptylink', 'options'=>array( | |
| 2144 | + 1=>__('Link all posts', 'event-post'), | |
| 2145 | + 0=>__('Do not link posts with empty content', 'event-post') | |
| 2146 | + ) | |
| 2147 | + ) | |
| 2148 | + ); | |
| 2149 | + add_settings_field( | |
| 2150 | + 'singlepos', | |
| 2151 | + __('Event bar position for single posts', 'event-post'), | |
| 2152 | + array(&$this, 'settings_field_select_callback'), | |
| 2153 | + 'eventpost-settings', | |
| 2154 | + 'eventpost-settings-general', | |
| 2155 | + array( 'name' => 'singlepos', 'options'=>array( | |
| 2156 | + 'before'=>__('Before the content', 'event-post'), | |
| 2157 | + 'after'=>__('After the content', 'event-post'), | |
| 2158 | + 'none'=>__('Not displayed', 'event-post') | |
| 2159 | + ) ) | |
| 2160 | + ); | |
| 2161 | + add_settings_field( | |
| 2162 | + 'loopicons', | |
| 2163 | + __('Add icons for events in the loop', 'event-post'), | |
| 2164 | + array(&$this, 'settings_field_select_callback'), | |
| 2165 | + 'eventpost-settings', | |
| 2166 | + 'eventpost-settings-general', | |
| 2167 | + array( 'name' => 'loopicons', 'options'=>array( | |
| 2168 | + 1=>__('Emojis', 'event-post'), | |
| 2169 | + 0=>__('Hide', 'event-post'), | |
| 2170 | + 2=>__('Icons', 'event-post') | |
| 2171 | + ) ) | |
| 2172 | + ); | |
| 2173 | + add_settings_field( | |
| 2174 | + 'customcss', | |
| 2175 | + __('Use this custom CSS file', 'event-post'), | |
| 2176 | + array(&$this, 'settings_field_default_callback'), | |
| 2177 | + 'eventpost-settings', | |
| 2178 | + 'eventpost-settings-general', | |
| 2179 | + array( 'name' => 'customcss', 'description'=>sprintf(__('Leave empty to use the <a href="%s" target="_blank">default CSS file</a>.', 'event-post'), plugins_url('/css/eventpost.min.css', __FILE__)).'<br>' | |
| 2180 | + . (is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css') | |
| 2181 | + ? __('Your theme contains an <code>event-post.css</code> file. It will be used as default stylesheet.', 'event-post') | |
| 2182 | + : __('You can also add a <code>event-post.css</code> in your theme directory. It will be used as default stylesheet.', 'event-post'))) | |
| 2183 | + ); | |
| 1970 | 2184 | |
| 1971 | - <h2><?php _e('List settings', 'event-post'); ?></h2> | |
| 1972 | - <table class="form-table" id="eventpost-settings-table-list"> | |
| 1973 | - <tbody> | |
| 1974 | - <tr> | |
| 1975 | - <th> | |
| 1976 | - <label for="ep_container_shema"> | |
| 1977 | - <?php _e('Container shema', 'event-post') ?> | |
| 1978 | - </label> | |
| 1979 | - </th> | |
| 1980 | - <td> | |
| 1981 | - <textarea class="widefat" name="ep_settings[container_shema]" id="ep_container_shema"><?php echo $ep_settings['container_shema']; ?></textarea> | |
| 1982 | - <p><?php _e('default:','event-post') ?></p> | |
| 1983 | - <code><?php echo htmlentities($this->default_list_shema['container']) ?></code> | |
| 1984 | - </td> | |
| 1985 | - </tr> | |
| 1986 | - <tr> | |
| 1987 | - <th> | |
| 1988 | - <label for="ep_item_shema"> | |
| 1989 | - <?php _e('Item shema', 'event-post') ?> | |
| 1990 | - </label> | |
| 1991 | - </th> | |
| 1992 | - <td> | |
| 1993 | - <textarea class="widefat" name="ep_settings[item_shema]" id="ep_item_shema"><?php echo $ep_settings['item_shema']; ?></textarea> | |
| 1994 | - <p><?php _e('default:','event-post') ?></p> | |
| 1995 | - <code><?php echo htmlentities($this->default_list_shema['item']) ?></code> | |
| 1996 | - </td> | |
| 1997 | - </tr> | |
| 1998 | - </tbody> | |
| 1999 | - </table><!-- #eventpost-settings-table-list --> | |
| 2185 | + // Date | |
| 2186 | + add_settings_section( | |
| 2187 | + 'eventpost-settings-date', | |
| 2188 | + '<span class="dashicons dashicons-clock"></span> '.__('Date settings', 'event-post'), | |
| 2189 | + array(&$this, 'settings_section_callback'), | |
| 2190 | + 'eventpost-settings' | |
| 2191 | + ); | |
| 2192 | + //-- | |
| 2193 | + add_settings_field( | |
| 2194 | + 'dateformat', | |
| 2195 | + __('Date format', 'event-post'), | |
| 2196 | + array(&$this, 'settings_field_default_callback'), | |
| 2197 | + 'eventpost-settings', | |
| 2198 | + 'eventpost-settings-date', | |
| 2199 | + array( 'name' => 'dateformat') | |
| 2200 | + ); | |
| 2201 | + add_settings_field( | |
| 2202 | + 'timeformat', | |
| 2203 | + __('Time format', 'event-post'), | |
| 2204 | + array(&$this, 'settings_field_default_callback'), | |
| 2205 | + 'eventpost-settings', | |
| 2206 | + 'eventpost-settings-date', | |
| 2207 | + array( 'name' => 'timeformat') | |
| 2208 | + ); | |
| 2209 | + add_settings_field( | |
| 2210 | + 'export', | |
| 2211 | + __('Show export buttons on:', 'event-post'), | |
| 2212 | + array(&$this, 'settings_field_select_callback'), | |
| 2213 | + 'eventpost-settings', | |
| 2214 | + 'eventpost-settings-date', | |
| 2215 | + array( 'name' => 'export', 'options'=>array( | |
| 2216 | + 'list'=>__('List only', 'event-post'), | |
| 2217 | + 'single'=>__('Single only', 'event-post'), | |
| 2218 | + 'both'=>__('Both', 'event-post'), | |
| 2219 | + 'none'=>__('None', 'event-post'), | |
| 2220 | + ) ) | |
| 2221 | + ); | |
| 2222 | + add_settings_field( | |
| 2223 | + 'dateforhumans', | |
| 2224 | + __('Relative human dates:', 'event-post'), | |
| 2225 | + array(&$this, 'settings_field_select_callback'), | |
| 2226 | + 'eventpost-settings', | |
| 2227 | + 'eventpost-settings-date', | |
| 2228 | + array( 'name' => 'dateforhumans', | |
| 2229 | + 'description'=>__('Replace absolute dates by "today", "yesterday", and "tomorrow".', 'event-post'), | |
| 2230 | + 'options'=>array( | |
| 2231 | + 1=>__('Yes', 'event-post'), | |
| 2232 | + 0=>__('No', 'event-post'), | |
| 2233 | + ) ) | |
| 2234 | + ); | |
| 2000 | 2235 | |
| 2001 | - <h2><?php _e('Map settings', 'event-post'); ?></h2> | |
| 2002 | - <table class="form-table" id="eventpost-settings-table-map"> | |
| 2003 | - <tbody> | |
| 2004 | - <tr> | |
| 2005 | - <th> | |
| 2006 | - <label for="ep_tile"> | |
| 2007 | - <?php _e('Map background', 'event-post') ?> | |
| 2008 | - </label> | |
| 2009 | - </th> | |
| 2010 | - <td> | |
| 2011 | - <select name="ep_settings[tile]" id="ep_tile"> | |
| 2012 | - <?php foreach ($this->maps as $map): ?> | |
| 2013 | - <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>> | |
| 2014 | - <?php echo $map['name']; ?> | |
| 2015 | - </option> | |
| 2016 | - <?php endforeach; ?> | |
| 2017 | - </select></td> | |
| 2018 | - </tr> | |
| 2019 | - <tr> | |
| 2020 | - <th> | |
| 2021 | - <?php _e('Makers custom directory (leave empty for default settings)', 'event-post') ?> | |
| 2022 | - </th> | |
| 2023 | - <td> | |
| 2024 | - <label for="ep_markpath"> | |
| 2025 | - <?php _e('Root path:', 'event-post') ?><br> | |
| 2026 | - ABSPATH/<input name="ep_settings[markpath]" id="ep_markpath" value="<?php echo $this->settings['markpath'] ?>" class="widefat"> | |
| 2027 | - </label><br> | |
| 2028 | - <label for="ep_markurl"> | |
| 2029 | - <?php _e('URL:', 'event-post') ?><br> | |
| 2030 | - <input name="ep_settings[markurl]" id="ep_markurl" value="<?php echo $this->settings['markurl'] ?>" class="widefat"> | |
| 2031 | - </label> | |
| 2032 | - </td> | |
| 2033 | - </tr> | |
| 2034 | - </tbody> | |
| 2035 | - </table><!-- #eventpost-settings-table-map --> | |
| 2236 | + // List | |
| 2237 | + add_settings_section( | |
| 2238 | + 'eventpost-settings-list', | |
| 2239 | + '<span class="dashicons dashicons-editor-ul"></span> '.__('List settings', 'event-post'), | |
| 2240 | + array(&$this, 'settings_section_callback'), | |
| 2241 | + 'eventpost-settings' | |
| 2242 | + ); | |
| 2243 | + //-- | |
| 2244 | + add_settings_field( | |
| 2245 | + 'container_shema', | |
| 2246 | + __('Container shema', 'event-post'), | |
| 2247 | + array(&$this, 'settings_field_textarea_callback'), | |
| 2248 | + 'eventpost-settings', | |
| 2249 | + 'eventpost-settings-list', | |
| 2250 | + array( 'name' => 'container_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities($this->default_list_shema['container']).'</code>') | |
| 2251 | + ); | |
| 2252 | + add_settings_field( | |
| 2253 | + 'item_shema', | |
| 2254 | + __('Container shema', 'event-post'), | |
| 2255 | + array(&$this, 'settings_field_textarea_callback'), | |
| 2256 | + 'eventpost-settings', | |
| 2257 | + 'eventpost-settings-list', | |
| 2258 | + array( 'name' => 'item_shema', 'description'=>__('default:','event-post').' <code>'.htmlentities($this->default_list_shema['item']).'</code>') | |
| 2259 | + ); | |
| 2036 | 2260 | |
| 2037 | - <h2><?php _e('Admin UI settings', 'event-post'); ?></h2> | |
| 2038 | - <table class="form-table" id="eventpost-settings-table-admin"> | |
| 2039 | - <tbody> | |
| 2040 | - <tr> | |
| 2041 | - <th> | |
| 2042 | - <label for="ep_posttypes"> | |
| 2043 | - <?php _e('Wich post types can be events ?', 'event-post') ?> | |
| 2044 | - </label> | |
| 2045 | - </th> | |
| 2046 | - <td><?php $posttypes = apply_filters('eventpost_get_post_types', get_post_types(array(), 'objects')); ?> | |
| 2047 | - <?php foreach($posttypes as $type=>$posttype): ?> | |
| 2048 | - <p> | |
| 2049 | - <label> | |
| 2050 | - <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) ?>> | |
| 2051 | - <?php echo $posttype->labels->name; ?> | |
| 2052 | - </label> | |
| 2053 | - </p> | |
| 2054 | - <?php endforeach; ?> | |
| 2055 | - </td> | |
| 2056 | - </tr> | |
| 2057 | - <tr> | |
| 2058 | - <th> | |
| 2059 | - <?php _e('Datepicker style', 'event-post') ?> | |
| 2060 | - <?php $now = current_time('mysql'); ?> | |
| 2061 | - <?php $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); ?> | |
| 2062 | - </th> | |
| 2063 | - <td> | |
| 2064 | - <div> | |
| 2065 | - <label> | |
| 2066 | - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_simple" value="simple" <?php checked($ep_settings['datepicker'],'simple', true) ?>> | |
| 2067 | - <?php _e('Simple', 'event-post'); ?> | |
| 2068 | - </label> | |
| 2069 | - <p> | |
| 2070 | - <span id="eventpost_simple_date_human" class="human_date"> | |
| 2071 | - <?php echo $human_date; ?> | |
| 2072 | - </span> | |
| 2073 | - <input type="text" class="eventpost-datepicker-simple" id="eventpost_simple_date" value="<?php echo $now; ?>"> | |
| 2074 | - </p> | |
| 2075 | - </div> | |
| 2076 | - <div> | |
| 2077 | - <label> | |
| 2078 | - <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_native" value="native" <?php checked($ep_settings['datepicker'],'native', true) ?>> | |
| 2079 | - <?php _e('Native WordPress style', 'event-post'); ?> | |
| 2080 | - </label> | |
| 2081 | - <p> | |
| 2082 | - <span id="eventpost_native_date_human" class="human_date"> | |
| 2083 | - <?php echo $human_date; ?> | |
| 2084 | - </span> | |
| 2085 | - <input type="text" class="eventpost-datepicker-native" id="eventpost_native_date" value="<?php echo $now; ?>"> | |
| 2086 | - </p> | |
| 2087 | - </div> | |
| 2088 | - </td> | |
| 2089 | - </tr> | |
| 2090 | - </tbody> | |
| 2091 | - </table><!-- #eventpost-settings-table-admin --> | |
| 2261 | + // Map | |
| 2262 | + add_settings_section( | |
| 2263 | + 'eventpost-settings-map', | |
| 2264 | + '<span class="dashicons dashicons-location-alt"></span> '.__('Map settings', 'event-post'), | |
| 2265 | + array(&$this, 'settings_section_callback'), | |
| 2266 | + 'eventpost-settings' | |
| 2267 | + ); | |
| 2268 | + //-- | |
| 2269 | + $maps = array(); | |
| 2270 | + foreach ($this->maps as $map){ | |
| 2271 | + $maps[$map['id']]=$map['name'].(isset($map['urls_retina']) ? ' '.__('(Retina support)', 'event-post') : ''); | |
| 2272 | + } | |
| 2273 | + add_settings_field( | |
| 2274 | + 'tile', | |
| 2275 | + __('Map background', 'event-post'), | |
| 2276 | + array(&$this, 'settings_field_select_callback'), | |
| 2277 | + 'eventpost-settings', | |
| 2278 | + 'eventpost-settings-map', | |
| 2279 | + array( 'name' => 'tile', 'options'=>$maps) | |
| 2280 | + ); | |
| 2281 | + add_settings_field( | |
| 2282 | + 'zoom', | |
| 2283 | + __('Default zoom', 'event-post'), | |
| 2284 | + array(&$this, 'settings_field_default_callback'), | |
| 2285 | + 'eventpost-settings', | |
| 2286 | + 'eventpost-settings-map', | |
| 2287 | + array( 'name' => 'zoom') | |
| 2288 | + ); | |
| 2289 | + add_settings_field( | |
| 2290 | + 'markpath', | |
| 2291 | + __('Makers custom directory after <code>ABSPATH/</code>', 'event-post'), | |
| 2292 | + array(&$this, 'settings_field_default_callback'), | |
| 2293 | + 'eventpost-settings', | |
| 2294 | + 'eventpost-settings-map', | |
| 2295 | + array( 'name' => 'markpath', 'description'=>__('(leave empty for default settings)','event-post')) | |
| 2296 | + ); | |
| 2297 | + add_settings_field( | |
| 2298 | + 'markurl', | |
| 2299 | + __('Makers custom directory URL', 'event-post'), | |
| 2300 | + array(&$this, 'settings_field_default_callback'), | |
| 2301 | + 'eventpost-settings', | |
| 2302 | + 'eventpost-settings-map', | |
| 2303 | + array( 'name' => 'markurl', 'description'=>__('(leave empty for default settings)','event-post')) | |
| 2304 | + ); | |
| 2092 | 2305 | |
| 2093 | - <h2><?php _e('Performances settings', 'event-post'); ?></h2> | |
| 2094 | - <table class="form-table" id="eventpost-settings-table-perfs"> | |
| 2095 | - <tbody> | |
| 2096 | - <tr> | |
| 2097 | - <th> | |
| 2098 | - <?php _e('Use cache', 'event-post') ?> | |
| 2099 | - </th> | |
| 2100 | - <td> | |
| 2101 | - <label for="ep_cache"> | |
| 2102 | - <input type="checkbox" name="ep_settings[cache]" id="ep_cache" <?php if($ep_settings['cache']=='1'){ echo'checked';} ?> value="1"> | |
| 2103 | - <?php _e('Use cache for results','event-post')?> | |
| 2104 | - </label> | |
| 2105 | - </td> | |
| 2106 | - </tr> | |
| 2107 | - </tbody> | |
| 2108 | - </table><!-- #eventpost-settings-table-perfs --> | |
| 2306 | + // Admin | |
| 2307 | + add_settings_section( | |
| 2308 | + 'eventpost-settings-admin', | |
| 2309 | + '<span class="dashicons dashicons-admin-generic"></span> '.__('Admin settings', 'event-post'), | |
| 2310 | + array(&$this, 'settings_section_callback'), | |
| 2311 | + 'eventpost-settings' | |
| 2312 | + ); | |
| 2313 | + //-- | |
| 2314 | + add_settings_field( | |
| 2315 | + 'adminpos', | |
| 2316 | + __('Position of event details boxes', 'event-post'), | |
| 2317 | + array(&$this, 'settings_field_select_callback'), | |
| 2318 | + 'eventpost-settings', | |
| 2319 | + 'eventpost-settings-admin', | |
| 2320 | + array( 'name' => 'adminpos', 'options'=>array( | |
| 2321 | + 'side'=>__('Side', 'event-post'), | |
| 2322 | + 'normal'=>__('Under the text', 'event-post'), | |
| 2323 | + ) ) | |
| 2324 | + ); | |
| 2325 | + $post_types = array(); | |
| 2326 | + $posttypes = apply_filters('eventpost_get_post_types', get_post_types(array(), 'objects')); | |
| 2327 | + foreach($posttypes as $type=>$posttype){ | |
| 2328 | + $post_types[$posttype->name]=$posttype->labels->name; | |
| 2329 | + } | |
| 2330 | + add_settings_field( | |
| 2331 | + 'posttypes', | |
| 2332 | + __('Wich post types can be events?', 'event-post'), | |
| 2333 | + array(&$this, 'settings_field_checkbox_callback'), | |
| 2334 | + 'eventpost-settings', | |
| 2335 | + 'eventpost-settings-admin', | |
| 2336 | + array( 'name' => 'posttypes', 'options'=>$post_types) | |
| 2337 | + ); | |
| 2338 | + add_settings_field( | |
| 2339 | + 'datepicker', | |
| 2340 | + __('Datepicker style', 'event-post'), | |
| 2341 | + array(&$this, 'settings_field_datepicker_callback'), | |
| 2342 | + 'eventpost-settings', | |
| 2343 | + 'eventpost-settings-admin', | |
| 2344 | + array( 'name' => 'datepicker') | |
| 2345 | + ); | |
| 2346 | + add_settings_field( | |
| 2347 | + 'cache', | |
| 2348 | + __('Use cache', 'event-post'), | |
| 2349 | + array(&$this, 'settings_field_default_callback'), | |
| 2350 | + 'eventpost-settings', | |
| 2351 | + 'eventpost-settings-admin', | |
| 2352 | + array( 'name' => 'cache', 'description'=>__('Use cache for results','event-post')) | |
| 2353 | + ); | |
| 2109 | 2354 | |
| 2110 | - <?php do_action('eventpost_settings_form', $ep_settings); ?> | |
| 2355 | + do_action('eventpost_register_settings'); | |
| 2356 | + } | |
| 2357 | + function settings_section_callback( $arg ) { | |
| 2358 | + echo '<hr>'; | |
| 2359 | + } | |
| 2111 | 2360 | |
| 2112 | - <p class="submit"> | |
| 2113 | - <input type="submit" value="<?php _e('Apply settings', 'event-post'); ?>" class="button button-primary" id="submit" name="submit"> | |
| 2114 | - </p> | |
| 2115 | - | |
| 2361 | + function settings_field_default_callback($args){ | |
| 2362 | + ?> | |
| 2363 | + <input name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" value="<?php echo $this->settings[$args['name']]; ?>" class="regular-text"/> | |
| 2364 | + <?php if(isset($args['description']) && $args['description']): ?> | |
| 2365 | + <p class="description"><?php echo $args['description']; ?></p> | |
| 2366 | + <?php endif; ?> | |
| 2367 | + <?php | |
| 2368 | + } | |
| 2369 | + function settings_field_textarea_callback($args){ | |
| 2370 | + ?> | |
| 2371 | + <textarea name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" class="regular-text"><?php echo $this->settings[$args['name']]; ?></textarea> | |
| 2372 | + <?php if(isset($args['description']) && $args['description']): ?> | |
| 2373 | + <p class="description"><?php echo $args['description']; ?></p> | |
| 2374 | + <?php endif; ?> | |
| 2375 | + <?php | |
| 2376 | + } | |
| 2377 | + function settings_field_select_callback($args){ | |
| 2378 | + ?> | |
| 2379 | + <select name="ep_settings[<?php echo $args['name']; ?>]" id="<?php echo $args['name']; ?>" class=""> | |
| 2380 | + <?php foreach($args['options'] as $value=>$label) : ?> | |
| 2381 | + <option value="<?php echo $value; ?>" <?php selected($value, $this->settings[$args['name']], true);?>><?php echo $label; ?></option> | |
| 2382 | + <?php endforeach; ?> | |
| 2383 | + </select> | |
| 2384 | + <?php if(isset($args['description']) && $args['description']): ?> | |
| 2385 | + <p class="description"><?php echo $args['description']; ?></p> | |
| 2386 | + <?php endif; ?> | |
| 2387 | + <?php | |
| 2388 | + } | |
| 2389 | + function settings_field_checkbox_callback($args){ | |
| 2390 | + ?> | |
| 2391 | + <?php foreach($args['options'] as $value=>$label) : ?> | |
| 2392 | + <p> | |
| 2393 | + <label> | |
| 2394 | + <input type="checkbox" name="ep_settings[<?php echo $args['name']; ?>][<?php echo $value; ?>]" value="<?php echo $value; ?>" <?php checked(in_array($value, $this->settings[$args['name']]),true, true) ?>> | |
| 2395 | + <?php echo $label; ?> | |
| 2396 | + </label> | |
| 2397 | + </p> | |
| 2398 | + <?php endforeach; ?> | |
| 2399 | + <?php if(isset($args['description']) && $args['description']): ?> | |
| 2400 | + <p class="description"><?php echo $args['description']; ?></p> | |
| 2401 | + <?php endif; ?> | |
| 2402 | + <?php | |
| 2403 | + } | |
| 2404 | + function settings_field_datepicker_callback($args){ | |
| 2405 | + $now = current_time('mysql'); | |
| 2406 | + $human_date = $this->human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); | |
| 2407 | + ?> | |
| 2408 | + <div> | |
| 2409 | + <label> | |
| 2410 | + <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_simple" value="simple" <?php checked($this->settings['datepicker'],'simple', true) ?>> | |
| 2411 | + <?php _e('Simple', 'event-post'); ?> | |
| 2412 | + </label> | |
| 2413 | + <p> | |
| 2414 | + <span id="eventpost_simple_date_human" class="human_date"> | |
| 2415 | + <?php echo $human_date; ?> | |
| 2416 | + </span> | |
| 2417 | + <input type="text" class="eventpost-datepicker-simple" id="eventpost_simple_date" value="<?php echo $now; ?>"> | |
| 2418 | + </p> | |
| 2419 | + </div> | |
| 2420 | + <div> | |
| 2421 | + <label> | |
| 2422 | + <input type="radio" name="ep_settings[datepicker]" id="ep_datepicker_native" value="native" <?php checked($this->settings['datepicker'],'native', true) ?>> | |
| 2423 | + <?php _e('Native WordPress style', 'event-post'); ?> | |
| 2424 | + </label> | |
| 2425 | + <p> | |
| 2426 | + <span id="eventpost_native_date_human" class="human_date"> | |
| 2427 | + <?php echo $human_date; ?> | |
| 2428 | + </span> | |
| 2429 | + <input type="text" class="eventpost-datepicker-native" id="eventpost_native_date" value="<?php echo $now; ?>"> | |
| 2430 | + </p> | |
| 2431 | + </div> | |
| 2432 | + <?php | |
| 2433 | + } | |
| 2434 | + /** | |
| 2435 | + * output content of the setting page | |
| 2436 | + */ | |
| 2437 | + public function manage_settings() { | |
| 2438 | + $ep_settings = $this->settings; | |
| 2439 | + ?> | |
| 2440 | + <div class="wrap"> | |
| 2441 | + <?php screen_icon(); ?> | |
| 2442 | + <h2><?php _e('Event settings', 'event-post'); ?></h2> | |
| 2443 | + <form action="options.php" method="post"> | |
| 2444 | + <?php settings_fields( 'eventpost-settings' ); ?> | |
| 2445 | + <?php do_settings_sections('eventpost-settings'); ?> | |
| 2446 | + <?php do_action('eventpost_settings_form', $ep_settings); ?> | |
| 2447 | + <?php submit_button(); ?> | |
| 2116 | 2448 | </form> |
| 2117 | 2449 | </div> |
| 2118 | 2450 | <?php |
| 2119 | 2451 | do_action('eventpost_after_settings_form'); |
| @@ -2129,47 +2461,91 @@ | ||
| 2129 | 2461 | * @param timestamp $timestamp |
| 2130 | 2462 | * @return string |
| 2131 | 2463 | */ |
| 2132 | 2464 | public function ics_date($timestamp){ |
| 2133 | - return date("Ymd",$timestamp).'T'.date("His",$timestamp).'Z'; | |
| 2465 | + return date("Ymd",$timestamp).'T'.date("His",$timestamp); | |
| 2134 | 2466 | } |
| 2135 | 2467 | |
| 2468 | + public function get_gmt_offset(){ | |
| 2469 | + $gmt_offset = get_option('gmt_offset '); | |
| 2470 | + $codegmt = 0; | |
| 2471 | + if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') { | |
| 2472 | + $codegmt = $gmt_offset * -1; | |
| 2473 | + $gmt_offset = '+' . $gmt_offset; | |
| 2474 | + } | |
| 2475 | + if(abs($gmt_offset < 10)){ | |
| 2476 | + $gmt_offset = substr($gmt_offset, 0, 1).'0'.substr($gmt_offset, 1); | |
| 2477 | + } | |
| 2478 | + return $gmt_offset; | |
| 2479 | + } | |
| 2480 | + | |
| 2136 | 2481 | /** |
| 2137 | 2482 | * outputs an ICS document |
| 2138 | 2483 | */ |
| 2139 | 2484 | public function feed(){ |
| 2140 | 2485 | if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){ |
| 2141 | - $timezone_string = get_option('timezone_string'); | |
| 2142 | - date_default_timezone_set($timezone_string); | |
| 2486 | + $vtz = get_option('timezone_string'); | |
| 2487 | + $gmt = $this->get_gmt_offset(); | |
| 2488 | + date_default_timezone_set($vtz); | |
| 2489 | + $separator = "\n"; | |
| 2143 | 2490 | |
| 2144 | - header("content-type:text/calendar"); | |
| 2491 | + header("content-type:text/x-icalendar"); | |
| 2145 | 2492 | header("Pragma: public"); |
| 2146 | 2493 | header("Expires: 0"); |
| 2147 | 2494 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
| 2148 | 2495 | header("Cache-Control: public"); |
| 2149 | 2496 | header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" ); |
| 2150 | - echo"BEGIN:VCALENDAR\r\n" | |
| 2151 | - . "PRODID:EventPost\r\n" | |
| 2152 | - . "VERSION:2.0\r\n" | |
| 2153 | - . "BEGIN:VTIMEZONE\r\n" | |
| 2154 | - . "TZID:$timezone_string\r\n" | |
| 2155 | - . "X-LIC-LOCATION:$timezone_string\r\n" | |
| 2156 | - . "END:VTIMEZONE"; | |
| 2157 | 2497 | |
| 2158 | - $events=$this->get_events(array('cat'=>$cat,'nb'=>-1)); | |
| 2498 | + $props = array(); | |
| 2499 | + | |
| 2500 | + // General | |
| 2501 | + $props[] = 'BEGIN:VCALENDAR'; | |
| 2502 | + $props[] = 'PRODID://WordPress//Event-Post V'. file_get_contents(('VERSION')).'//EN'; | |
| 2503 | + $props[] = 'VERSION:2.0'; | |
| 2504 | + | |
| 2505 | + // Timezone | |
| 2506 | + if(!empty($vtz)){ | |
| 2507 | + array_push($props, | |
| 2508 | + 'BEGIN:VTIMEZONE', | |
| 2509 | + 'TZID:'.$vtz, | |
| 2510 | + 'BEGIN:DAYLIGHT', | |
| 2511 | + 'TZOFFSETFROM:+0100', | |
| 2512 | + 'TZOFFSETTO:'.($gmt).'00', | |
| 2513 | + 'DTSTART:19700329T020000', | |
| 2514 | + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3', | |
| 2515 | + 'END:DAYLIGHT', | |
| 2516 | + 'BEGIN:STANDARD', | |
| 2517 | + 'TZOFFSETFROM:'.($gmt).'00', | |
| 2518 | + 'TZOFFSETTO:+0100', | |
| 2519 | + 'TZNAME:CET', | |
| 2520 | + 'DTSTART:19701025T030000', | |
| 2521 | + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10', | |
| 2522 | + 'END:STANDARD', | |
| 2523 | + 'END:VTIMEZONE' | |
| 2524 | + ); | |
| 2525 | + } | |
| 2526 | + | |
| 2527 | + // Events | |
| 2528 | + $events=$this->get_events(array('cat'=>$cat,'nb'=>-1)); | |
| 2159 | 2529 | foreach ($events as $event) { |
| 2160 | - echo"BEGIN:VEVENT\r\n" | |
| 2161 | - . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n" | |
| 2162 | - . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n" | |
| 2163 | - . "SUMMARY:".$event->post_title."\r\n" | |
| 2164 | - . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n" | |
| 2165 | - . "LOCATION:".str_replace(',','\,',$event->address)."\r\n" | |
| 2166 | - . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n" | |
| 2167 | - . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n" | |
| 2168 | - . "DESCRIPTION:".$event->guid."\r\n" | |
| 2169 | - . "END:VEVENT\r\n"; | |
| 2170 | - } | |
| 2171 | - echo"END:VCALENDAR\r\n"; | |
| 2172 | - exit; | |
| 2530 | + array_push($props, | |
| 2531 | + 'BEGIN:VEVENT', | |
| 2532 | + 'CREATED:'.$this->ics_date(strtotime($event->post_date)).'Z', | |
| 2533 | + 'LAST-MODIFIED:'.$this->ics_date(strtotime($event->post_modified)).'Z', | |
| 2534 | + 'SUMMARY:'.$event->post_title, | |
| 2535 | + 'UID:'.md5(site_url()."_eventpost_".$event->ID), | |
| 2536 | + 'LOCATION:'.str_replace(',','\,',$event->address), | |
| 2537 | + 'DTSTART'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'), | |
| 2538 | + 'DTEND'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_end).(!empty($vtz)?'':'Z'), | |
| 2539 | + 'DESCRIPTION:'.$event->guid, | |
| 2540 | + 'END:VEVENT' | |
| 2541 | + ); | |
| 2542 | + } | |
| 2543 | + | |
| 2544 | + // End | |
| 2545 | + $props[] = 'END:VCALENDAR'; | |
| 2546 | + | |
| 2547 | + echo implode($separator, $props); | |
| 2548 | + exit; | |
| 2173 | 2549 | } |
| 2174 | 2550 | } |
| 2175 | -} | |
| 2551 | +} | |