| @@ -1,42 +1,24 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Plugin Name: Event Post | |
| 4 | - * Plugin URI: https://event-post.com?mtm_campaign=wp-plugin&mtm_kwd=event-post&mtm_medium=dashboard&mtm_source=plugin-uri | |
| 5 | - * Description: Add calendar and/or geolocation metadata on any posts. | |
| 6 | - * Version: 6.1.1 | |
| 7 | - * Author: N.O.U.S. Open Useful and Simple | |
| 8 | - * Contributors: bastho, sabrinaleroy, unecologeek, agencenous | |
| 9 | - * Author URI: https://apps.avecnous.eu/?mtm_campaign=wp-plugin&mtm_kwd=event-post&mtm_medium=dashboard&mtm_source=author | |
| 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,blocks | |
| 14 | - * | |
| 15 | - * @package event-post | |
| 2 | +/* | |
| 3 | + Plugin Name: Event Post | |
| 4 | + Plugin URI: http://event-post.com | |
| 5 | + Description: Add calendar and/or geolocation metadata on posts. For a better experience, we recommand to use it with <a href="https://wordpress.org/plugins/shortcode-ui/" target="_blank">Shortcake (shortcode UI)</a> installed. | |
| 6 | + Version: 5.0.2 | |
| 7 | + Author: N.O.U.S. Open Useful and Simple | |
| 8 | + Contributors: bastho, ecolosites | |
| 9 | + Author URI: http://avecnous.eu | |
| 10 | + 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 | |
| 16 | 14 | */ |
| 17 | 15 | |
| 18 | -if ( ! defined( 'ABSPATH' ) ) exit; | |
| 19 | - | |
| 20 | 16 | global $EventPost; |
| 21 | 17 | $EventPost = new EventPost(); |
| 22 | 18 | |
| 23 | 19 | $EventPost_cache=array(); |
| 24 | 20 | |
| 25 | -function EventPost(){ | |
| 26 | - global $EventPost; | |
| 27 | - return $EventPost; | |
| 28 | -} | |
| 29 | -function event_post_format_color($color){ | |
| 30 | - return str_replace('#', '', $color); | |
| 31 | -} | |
| 32 | -function event_post_get_all_terms($post_id){ | |
| 33 | - $taxonomies= get_taxonomies('','names'); | |
| 34 | - | |
| 35 | - return wp_get_post_terms($post_id, $taxonomies); | |
| 36 | -} | |
| 37 | - | |
| 38 | - | |
| 39 | 21 | /** |
| 40 | 22 | * The main class where everything begins. |
| 41 | 23 | * |
| 42 | 24 | * Add calendar and/or geolocation metadata on posts |
| @@ -41,3315 +23,2529 @@ | ||
| 41 | 23 | * |
| 42 | 24 | * Add calendar and/or geolocation metadata on posts |
| 43 | 25 | */ |
| 44 | 26 | class EventPost { |
| 45 | - /** | |
| 46 | - * The current version | |
| 47 | - * | |
| 48 | - * @var array | |
| 49 | - */ | |
| 50 | - public $version = '5.9.2'; | |
| 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'; | |
| 51 | 34 | |
| 52 | - // -------------------------------------------------------------------------------- | |
| 53 | - // Post metas | |
| 35 | + public $list_id; | |
| 36 | + public $NomDuMois; | |
| 37 | + public $Week; | |
| 38 | + public $settings; | |
| 39 | + public $dateformat; | |
| 54 | 40 | |
| 55 | - /** | |
| 56 | - * The meta name for event start date | |
| 57 | - * | |
| 58 | - * @var string | |
| 59 | - */ | |
| 60 | - public $META_START = 'event_begin'; | |
| 41 | + public $version = '4.5'; | |
| 61 | 42 | |
| 62 | - /** | |
| 63 | - * The meta name for event end date | |
| 64 | - * | |
| 65 | - * @var string | |
| 66 | - */ | |
| 67 | - public $META_END = 'event_end'; | |
| 43 | + public $map_interactions; | |
| 44 | + public $quick_edit_fields; | |
| 68 | 45 | |
| 69 | - /** | |
| 70 | - * The meta name for event color | |
| 71 | - * | |
| 72 | - * @var string | |
| 73 | - */ | |
| 74 | - public $META_COLOR = 'event_color'; | |
| 46 | + public $Shortcodes; | |
| 75 | 47 | |
| 76 | - /** | |
| 77 | - * The meta name for event icon | |
| 78 | - * | |
| 79 | - * @var string | |
| 80 | - */ | |
| 81 | - public $META_ICON = 'event_icon'; | |
| 48 | + public function __construct() { | |
| 49 | + load_plugin_textdomain('event-post', false, 'event-post/languages'); | |
| 82 | 50 | |
| 83 | - // -------------------------------------------------------------------------------- | |
| 84 | - // Post metas related to location | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * The meta name for event address | |
| 88 | - * | |
| 89 | - * @var string | |
| 90 | - */ | |
| 91 | - public $META_ADD = 'geo_address'; | |
| 51 | + add_action('widgets_init', array(&$this,'init'), 1); | |
| 52 | + add_action('save_post', array(&$this, 'save_postdata')); | |
| 53 | + add_action('admin_menu', array(&$this, 'manage_options')); | |
| 54 | + add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now')); | |
| 92 | 55 | |
| 93 | - /** | |
| 94 | - * The meta name for event latitude | |
| 95 | - * | |
| 96 | - * @var string | |
| 97 | - * | |
| 98 | - * @see http://codex.wordpress.org/Geodata | |
| 99 | - */ | |
| 100 | - public $META_LAT = 'geo_latitude'; | |
| 56 | + // Scripts | |
| 57 | + add_action( 'admin_init', array(&$this, 'editor_styles')); | |
| 58 | + add_action( 'admin_init', array(&$this, 'register_settings')); | |
| 59 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_head')); | |
| 60 | + add_action('admin_print_scripts', array(&$this, 'admin_scripts')); | |
| 61 | + add_action('wp_enqueue_scripts', array(&$this, 'load_styles')); | |
| 101 | 62 | |
| 102 | - /** | |
| 103 | - * The meta name for event longitude | |
| 104 | - * | |
| 105 | - * @var string | |
| 106 | - * | |
| 107 | - * @see http://codex.wordpress.org/Geodata | |
| 108 | - */ | |
| 109 | - public $META_LONG = 'geo_longitude'; | |
| 63 | + // Single | |
| 64 | + add_filter('the_content', array(&$this, 'display_single'), 9999); | |
| 65 | + add_filter('the_title', array(&$this, 'the_title'), 9999, 2); | |
| 66 | + add_action('the_event', array(&$this, 'print_single')); | |
| 67 | + add_action('wp_head', array(&$this, 'single_header')); | |
| 110 | 68 | |
| 111 | - /** | |
| 112 | - * The meta name for event location | |
| 113 | - * | |
| 114 | - * @var string | |
| 115 | - * | |
| 116 | - * @see https://schema.org/location | |
| 117 | - */ | |
| 118 | - public $META_VIRTUAL_LOCATION = 'event_virtual_location'; | |
| 119 | - | |
| 120 | - // -------------------------------------------------------------------------------- | |
| 121 | - // Post metas related to status | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * The meta name for event status | |
| 125 | - * | |
| 126 | - * @var string | |
| 127 | - * | |
| 128 | - * @see https://schema.org/eventStatus | |
| 129 | - */ | |
| 130 | - public $META_STATUS = 'event_status'; | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * The meta name for event attendance mode | |
| 134 | - * | |
| 135 | - * @var string | |
| 136 | - * | |
| 137 | - * @see https://schema.org/eventAttendanceMode | |
| 138 | - */ | |
| 139 | - public $META_ATTENDANCE_MODE = 'event_attendance_mode'; | |
| 69 | + // Ajax | |
| 70 | + add_action('wp_ajax_EventPostGetLatLong', array(&$this, 'GetLatLong')); | |
| 71 | + add_action('wp_ajax_EventPostHumanDate', array(&$this, 'HumanDate')); | |
| 72 | + add_action('wp_ajax_EventPostCalendar', array(&$this, 'ajaxcal')); | |
| 73 | + add_action('wp_ajax_nopriv_EventPostCalendar', array(&$this, 'ajaxcal')); | |
| 74 | + add_action('wp_ajax_EventPostCalendarDate', array(&$this, 'ajaxdate')); | |
| 75 | + add_action('wp_ajax_nopriv_EventPostCalendarDate', array(&$this, 'ajaxdate')); | |
| 140 | 76 | |
| 141 | - /** | |
| 142 | - * The meta name for event organizer | |
| 143 | - * | |
| 144 | - * @var string | |
| 145 | - * | |
| 146 | - * @see https://schema.org/Organization | |
| 147 | - */ | |
| 148 | - public $META_ORGANIZATION = 'event_organization'; | |
| 77 | + // Calendar publishing | |
| 78 | + add_action('wp_ajax_EventPostFeed', array(&$this, 'feed')); | |
| 79 | + add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed')); | |
| 149 | 80 | |
| 150 | - /** | |
| 151 | - * The meta name for event organizer | |
| 152 | - * | |
| 153 | - * @var string | |
| 154 | - * @see https://schema.org/Offer | |
| 155 | - */ | |
| 156 | - public $META_OFFER = 'event_offer'; | |
| 157 | - | |
| 158 | - // -------------------------------------------------------------------------------- | |
| 159 | - // Usefull variables | |
| 81 | + // | |
| 82 | + add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1); | |
| 160 | 83 | |
| 161 | - /** | |
| 162 | - * ID of the current list | |
| 163 | - * | |
| 164 | - * @var int | |
| 165 | - */ | |
| 166 | - public $list_id; | |
| 84 | + // Admin | |
| 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); | |
| 167 | 87 | |
| 168 | - /** | |
| 169 | - * ID of the current map | |
| 170 | - * | |
| 171 | - * @var int | |
| 172 | - */ | |
| 173 | - public $map_id=0; | |
| 88 | + add_action('widgets_init', array(&$this, 'register_widgets'),1,1); | |
| 174 | 89 | |
| 175 | - /** | |
| 176 | - * Schema as been outputed or not | |
| 177 | - * | |
| 178 | - * @var bool | |
| 179 | - */ | |
| 180 | - private $is_schema_output=false; | |
| 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); | |
| 181 | 97 | |
| 182 | - /** | |
| 183 | - * Month names | |
| 184 | - * | |
| 185 | - * @var array | |
| 186 | - */ | |
| 187 | - public $NomDuMois; | |
| 98 | + $inc_path = plugin_dir_path(__FILE__).'inc/'; | |
| 99 | + include_once ($inc_path . 'wrappers.php'); | |
| 100 | + include_once ($inc_path . 'widget.php'); | |
| 101 | + include_once ($inc_path . 'widget.cal.php'); | |
| 102 | + include_once ($inc_path . 'widget.map.php'); | |
| 103 | + include_once ($inc_path . 'multisite.php'); | |
| 104 | + include_once ($inc_path . 'shortcodes.php'); | |
| 105 | + include_once ($inc_path . 'openweathermap.php'); | |
| 106 | + include_once ($inc_path . 'children.php'); | |
| 188 | 107 | |
| 189 | - /** | |
| 190 | - * Week days | |
| 191 | - * | |
| 192 | - * @var array | |
| 193 | - */ | |
| 194 | - public $Week; | |
| 108 | + } | |
| 195 | 109 | |
| 196 | - /** | |
| 197 | - * Currencies | |
| 198 | - * | |
| 199 | - * @var array | |
| 200 | - */ | |
| 201 | - public $currencies = array(); | |
| 110 | + /** | |
| 111 | + * PHP4 constructor | |
| 112 | + */ | |
| 113 | + public function EventPost(){ | |
| 114 | + $this->__construct(); | |
| 115 | + } | |
| 202 | 116 | |
| 203 | - /** | |
| 204 | - * Date format | |
| 205 | - * | |
| 206 | - * @var string | |
| 207 | - */ | |
| 208 | - public $dateformat; | |
| 117 | + /** | |
| 118 | + * Init all variables when WP is ready | |
| 119 | + * | |
| 120 | + * @action evenpost_init | |
| 121 | + * @filter eventpost_default_list_shema | |
| 122 | + * @filter eventpost_list_shema | |
| 123 | + */ | |
| 124 | + public function init(){ | |
| 125 | + $this->META_START = 'event_begin'; | |
| 126 | + $this->META_END = 'event_end'; | |
| 127 | + $this->META_COLOR = 'event_color'; | |
| 128 | + // http://codex.wordpress.org/Geodata | |
| 129 | + $this->META_ADD = 'geo_address'; | |
| 130 | + $this->META_LAT = 'geo_latitude'; | |
| 131 | + $this->META_LONG = 'geo_longitude'; | |
| 132 | + $this->list_id = 0; | |
| 133 | + $this->NomDuMois = array('', __('Jan', 'event-post'), __('Feb', 'event-post'), __('Mar', 'event-post'), __('Apr', 'event-post'), __('May', 'event-post'), __('Jun', 'event-post'), __('Jul', 'event-post'), __('Aug', 'event-post'), __('Sept', 'event-post'), __('Oct', 'event-post'), __('Nov', 'event-post'), __('Dec', 'event-post')); | |
| 134 | + $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post')); | |
| 209 | 135 | |
| 210 | - /** | |
| 211 | - * Pagination | |
| 212 | - * | |
| 213 | - * @var array | |
| 214 | - */ | |
| 215 | - private $pagination; | |
| 136 | + $this->maps = $this->get_maps(); | |
| 137 | + $this->settings = $this->get_settings(); | |
| 216 | 138 | |
| 217 | - /** | |
| 218 | - * Plugin path | |
| 219 | - * | |
| 220 | - * @var string | |
| 221 | - */ | |
| 222 | - public $plugin_path; | |
| 139 | + do_action('evenpost_init', $this); | |
| 223 | 140 | |
| 224 | - /** | |
| 225 | - * Script suffix | |
| 226 | - * | |
| 227 | - * @var string | |
| 228 | - */ | |
| 229 | - private $script_sufix; | |
| 141 | + $this->Shortcodes = new EventPost_Shortcodes(); | |
| 230 | 142 | |
| 231 | - /** | |
| 232 | - * Settings values | |
| 233 | - * | |
| 234 | - * @var array | |
| 235 | - */ | |
| 236 | - public $settings; | |
| 143 | + // Edit | |
| 144 | + add_action('add_meta_boxes', array(&$this, 'add_custom_box')); | |
| 145 | + foreach($this->settings['posttypes'] as $posttype){ | |
| 146 | + add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2); | |
| 147 | + add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2); | |
| 148 | + } | |
| 237 | 149 | |
| 238 | - // -------------------------------------------------------------------------------- | |
| 239 | - // Option values | |
| 240 | 150 | |
| 241 | - /** | |
| 242 | - * Map interractions (from openlayers) | |
| 243 | - * | |
| 244 | - * @var array | |
| 245 | - */ | |
| 246 | - public $map_interactions; | |
| 151 | + if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) { | |
| 152 | + $this->markpath = ABSPATH.'/'.$this->settings['markpath']; | |
| 153 | + $this->markurl = $this->settings['markurl']; | |
| 154 | + } else { | |
| 155 | + $this->markpath = plugin_dir_path(__FILE__) . 'markers/'; | |
| 156 | + $this->markurl = plugins_url('/markers/', __FILE__); | |
| 157 | + } | |
| 247 | 158 | |
| 248 | - /** | |
| 249 | - * Fields supported by quick-edit | |
| 250 | - * | |
| 251 | - * @var array | |
| 252 | - */ | |
| 253 | - public $quick_edit_fields; | |
| 159 | + $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post')); | |
| 254 | 160 | |
| 255 | - /** | |
| 256 | - * Fields supported by bulk-edit | |
| 257 | - * | |
| 258 | - * @var array | |
| 259 | - */ | |
| 260 | - public $bulk_edit_fields; | |
| 161 | + $this->default_list_shema = apply_filters('eventpost_default_list_shema', array( | |
| 162 | + 'container' => ' | |
| 163 | + <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>%list% | |
| 164 | + </%type%><!-- .event_loop -->', | |
| 165 | + 'item' => ' | |
| 166 | + <%child% class="event_item %class%" data-color="%color%"> | |
| 167 | + <a href="%event_link%"> | |
| 168 | + %event_thumbnail% | |
| 169 | + <h5>%event_title%</h5> | |
| 170 | + </a> | |
| 171 | + %event_date% | |
| 172 | + %event_cat% | |
| 173 | + %event_location% | |
| 174 | + %event_excerpt% | |
| 175 | + </%child%><!-- .event_item -->' | |
| 176 | + )); | |
| 177 | + $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema); | |
| 261 | 178 | |
| 262 | - /** | |
| 263 | - * Supported attendance modes | |
| 264 | - * | |
| 265 | - * @var array | |
| 266 | - */ | |
| 267 | - public $attendance_modes; | |
| 179 | + $this->map_interactions=array( | |
| 180 | + 'DragRotate'=>__('Drag Rotate', 'event-post'), | |
| 181 | + 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'), | |
| 182 | + 'DragPan'=>__('Drag Pan', 'event-post'), | |
| 183 | + 'PinchRotate'=>__('Pinch Rotate', 'event-post'), | |
| 184 | + 'PinchZoom'=>__('Pinch Zoom', 'event-post'), | |
| 185 | + 'KeyboardPan'=>__('Keyboard Pan', 'event-post'), | |
| 186 | + 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'), | |
| 187 | + 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'), | |
| 188 | + 'DragZoom'=>__('Drag Zoom', 'event-post'), | |
| 189 | + ); | |
| 268 | 190 | |
| 269 | - /** | |
| 270 | - * Supported statuses | |
| 271 | - * | |
| 272 | - * @var array | |
| 273 | - */ | |
| 274 | - public $statuses; | |
| 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 | + ); | |
| 275 | 210 | |
| 276 | - /** | |
| 277 | - * Default list schema (HTML template) | |
| 278 | - * | |
| 279 | - * @var string | |
| 280 | - */ | |
| 281 | - public $default_list_shema; | |
| 211 | + } | |
| 282 | 212 | |
| 283 | - /** | |
| 284 | - * Default timeline schema (HTML template) | |
| 285 | - * | |
| 286 | - * @var string | |
| 287 | - */ | |
| 288 | - public $default_timeline_shema; | |
| 213 | + public function register_widgets(){ | |
| 214 | + register_widget('EventPost_List'); | |
| 215 | + register_widget('EventPost_Map'); | |
| 216 | + register_widget('EventPost_Cal'); | |
| 217 | + } | |
| 289 | 218 | |
| 290 | - /** | |
| 291 | - * Current list schema (HTML template) | |
| 292 | - * | |
| 293 | - * @var string | |
| 294 | - */ | |
| 295 | - public $list_shema; | |
| 296 | - | |
| 297 | - /** | |
| 298 | - * Current timeline schema (HTML template) | |
| 299 | - * | |
| 300 | - * @var string | |
| 301 | - */ | |
| 302 | - public $timeline_shema; | |
| 303 | - | |
| 304 | - // Map variables | |
| 305 | - /** | |
| 306 | - * Map tiles | |
| 307 | - * | |
| 308 | - * @var array | |
| 309 | - */ | |
| 310 | - public $maps; | |
| 311 | - | |
| 312 | - /** | |
| 313 | - * Dirpath for map tiles | |
| 314 | - * | |
| 315 | - * @var string | |
| 316 | - */ | |
| 317 | - public $markpath; | |
| 318 | - | |
| 319 | - /** | |
| 320 | - * Base URL for map tiles | |
| 321 | - * | |
| 322 | - * @var string | |
| 323 | - */ | |
| 324 | - public $markurl; | |
| 325 | - | |
| 326 | - // -------------------------------------------------------------------------------- | |
| 327 | - // Classes | |
| 328 | - | |
| 329 | - /** | |
| 330 | - * Taxonomies object | |
| 331 | - * | |
| 332 | - * @var \EventPost\Taxonomies | |
| 333 | - */ | |
| 334 | - public $Taxonomies; | |
| 335 | - | |
| 336 | - /** | |
| 337 | - * Icons object | |
| 338 | - * | |
| 339 | - * @var \EventPost\Icons | |
| 340 | - */ | |
| 341 | - public $DashIcons; | |
| 342 | - | |
| 343 | - /** | |
| 344 | - * Settings object | |
| 345 | - * | |
| 346 | - * @var \EventPost\Settings | |
| 347 | - */ | |
| 348 | - public $Settings; | |
| 349 | - | |
| 350 | - /** | |
| 351 | - * Shortcodes object | |
| 352 | - * | |
| 353 | - * @var \EventPost\Shortcodes | |
| 354 | - */ | |
| 355 | - public $Shortcodes; | |
| 356 | - | |
| 357 | - /** | |
| 358 | - * Allowed tags in main outputs | |
| 359 | - * | |
| 360 | - * @var array | |
| 361 | - */ | |
| 362 | - public $kses_tags; | |
| 363 | - | |
| 364 | - | |
| 365 | - public function __construct() { | |
| 366 | - add_action('init', array(&$this,'init'), 1); | |
| 367 | - add_action('init', array(&$this,'widgets_init'), 10); | |
| 368 | - add_action('init', array(&$this, 'register_widgets'), 30, 1); | |
| 369 | - | |
| 370 | - add_action('save_post', array(&$this, 'save_postdata')); | |
| 371 | - add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now')); | |
| 372 | - | |
| 373 | - // Scripts | |
| 374 | - add_action( 'admin_init', array(&$this, 'editor_styles')); | |
| 375 | - add_action('admin_enqueue_scripts', array(&$this, 'admin_head')); | |
| 376 | - add_action('admin_print_scripts', array(&$this, 'admin_scripts')); | |
| 377 | - add_action('admin_print_scripts', array(&$this, 'load_scripts'), 1); | |
| 378 | - add_action('wp_enqueue_scripts', array(&$this, 'load_scripts'), 1); | |
| 379 | - add_action('wp_enqueue_scripts', array(&$this, 'load_styles')); | |
| 380 | - | |
| 381 | - // Single | |
| 382 | - add_filter('the_content', array(&$this, 'display_single'), 9999); | |
| 383 | - add_filter('the_title', array(&$this, 'the_title'), 9999, 2); | |
| 384 | - add_action('the_event', array(&$this, 'print_single')); | |
| 385 | - add_action('wp_head', array(&$this, 'single_header')); | |
| 386 | - add_action('wpseo_schema_webpage', array(&$this, 'wpseo_schema_webpage')); | |
| 387 | - | |
| 388 | - // Ajax | |
| 389 | - add_action('wp_ajax_EventPostGetLatLong', array(&$this, 'GetLatLong')); | |
| 390 | - add_action('wp_ajax_EventPostHumanDate', array(&$this, 'HumanDate')); | |
| 391 | - add_action('wp_ajax_EventPostList', array(&$this, 'ajaxlist')); | |
| 392 | - add_action('wp_ajax_EventPostTimeline', array(&$this, 'ajaxTimeline')); | |
| 393 | - add_action('wp_ajax_EventPostNextPage', array(&$this, 'ajaxGetNextPage')); | |
| 394 | - add_action('wp_ajax_nopriv_EventPostNextPage', array(&$this, 'ajaxGetNextPage')); | |
| 395 | - add_action('wp_ajax_EventPostMap', array(&$this, 'ajaxmap')); | |
| 396 | - add_action('wp_ajax_EventPostCalendar', array(&$this, 'ajaxcal')); | |
| 397 | - add_action('wp_ajax_nopriv_EventPostCalendar', array(&$this, 'ajaxcal')); | |
| 398 | - add_action('wp_ajax_EventPostCalendarDate', array(&$this, 'ajaxdate')); | |
| 399 | - add_action('wp_ajax_nopriv_EventPostCalendarDate', array(&$this, 'ajaxdate')); | |
| 400 | - | |
| 401 | - // Calendar publishing | |
| 402 | - add_action('parse_request', array(&$this, 'parse_request'), 100); | |
| 403 | - add_action('wp_ajax_EventPostExport', array(&$this, 'export')); | |
| 404 | - add_action('wp_ajax_nopriv_EventPostExport', array(&$this, 'export')); | |
| 405 | - add_action('wp_ajax_EventPostFeed', array(&$this, 'feed')); | |
| 406 | - add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed')); | |
| 407 | - | |
| 408 | - // Internal filters | |
| 409 | - add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1); | |
| 410 | - | |
| 411 | - // Quick edit | |
| 412 | - add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit' ), 10, 2 ); | |
| 413 | - add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit' ), 10, 2 ); | |
| 414 | - add_action( 'admin_print_scripts-edit.php', array(&$this, 'scripts_edit') ); | |
| 415 | - add_action( 'wp_ajax_inline-save', array(&$this, 'inline_save'), 1 ); | |
| 416 | - add_action( 'bulk_edit_posts', array(&$this, 'save_bulkdatas'), 10, 2 ); | |
| 417 | - add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_color'), 10, 3); | |
| 418 | - add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_icon'), 10, 3); | |
| 419 | - | |
| 420 | - $inc_path = plugin_dir_path(__FILE__).'inc/'; | |
| 421 | - $this->plugin_path = plugin_dir_path(__FILE__); | |
| 422 | - include_once ($inc_path . 'class-settings.php'); | |
| 423 | - include_once ($inc_path . 'wrappers.php'); | |
| 424 | - include_once ($inc_path . 'deprecated/widget.php'); | |
| 425 | - include_once ($inc_path . 'deprecated/widget.cal.php'); | |
| 426 | - include_once ($inc_path . 'deprecated/widget.map.php'); | |
| 427 | - include_once ($inc_path . 'class-multisite.php'); | |
| 428 | - include_once ($inc_path . 'class-shortcodes.php'); | |
| 429 | - include_once ($inc_path . 'openweathermap.php'); | |
| 430 | - include_once ($inc_path . 'class-children.php'); | |
| 431 | - include_once ($inc_path . 'class-icons.php'); | |
| 432 | - include_once ($inc_path . 'class-taxonomies.php'); | |
| 433 | - | |
| 434 | - $this->DashIcons = new EventPost\Icons(); | |
| 435 | - $this->Settings = new EventPost\Settings($this->DashIcons); | |
| 436 | - $this->Taxonomies = new EventPost\Taxonomies($this->DashIcons); | |
| 219 | + /** | |
| 220 | + * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color. | |
| 221 | + * @param string $color | |
| 222 | + * @return array $color($R, $G, $B) | |
| 223 | + */ | |
| 224 | + public function hex2dec($color = '000000') { | |
| 225 | + $tbl_color = array(); | |
| 226 | + if (!strstr('#', $color)){ | |
| 227 | + $color = '#' . $color; | |
| 437 | 228 | } |
| 229 | + $tbl_color['R'] = hexdec(substr($color, 1, 2)); | |
| 230 | + $tbl_color['G'] = hexdec(substr($color, 3, 2)); | |
| 231 | + $tbl_color['B'] = hexdec(substr($color, 5, 2)); | |
| 232 | + return $tbl_color; | |
| 233 | + } | |
| 234 | + /** | |
| 235 | + * Fetch all registered image sizes | |
| 236 | + * @global array $_wp_additional_image_sizes | |
| 237 | + * @return array | |
| 238 | + */ | |
| 239 | + function get_thumbnail_sizes(){ | |
| 240 | + global $_wp_additional_image_sizes; | |
| 241 | + $sizes = array('thumbnail', 'medium', 'large', 'full'); | |
| 242 | + foreach(array_keys($_wp_additional_image_sizes) as $size){ | |
| 243 | + $sizes[]=$size; | |
| 244 | + } | |
| 245 | + return $sizes; | |
| 246 | + } | |
| 438 | 247 | |
| 439 | - /** | |
| 440 | - * PHP4 constructor | |
| 441 | - */ | |
| 442 | - public function EventPost(){ | |
| 443 | - $this->__construct(); | |
| 444 | - } | |
| 248 | + /** | |
| 249 | + * Just for localization | |
| 250 | + */ | |
| 251 | + private function no_use() { | |
| 252 | + __('Add calendar and/or geolocation metadata on posts', 'event-post'); | |
| 253 | + __('Event Post', 'event-post'); | |
| 254 | + } | |
| 445 | 255 | |
| 446 | - public function init(){ | |
| 447 | - $admin_url = admin_url('admin-ajax.php?action=EventPostFeed'); | |
| 448 | - $admin_url = str_replace(site_url(), '', $admin_url); | |
| 449 | - $plugins_url = plugins_url('export/ics.php', __FILE__); | |
| 450 | - $plugins_url = str_replace(site_url(), '', $plugins_url); | |
| 451 | - add_rewrite_rule('event-feed/?', $admin_url , 'top'); | |
| 452 | - add_rewrite_rule('eventpost/([0-9]*)\.(ics|vcs)?',$plugins_url, 'top'); | |
| 453 | - | |
| 454 | - $this->list_id = 0; | |
| 455 | - $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')); | |
| 456 | - $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post')); | |
| 457 | - $this->attendance_modes = array( | |
| 458 | - 'OfflineEventAttendanceMode' => _x('Physical', 'Attendance Mode', 'event-post'), | |
| 459 | - 'MixedEventAttendanceMode' => _x('Mixed', 'Attendance Mode', 'event-post'), | |
| 460 | - 'OnlineEventAttendanceMode' => _x('Online', 'Attendance Mode', 'event-post'), | |
| 461 | - ); | |
| 462 | - $this->statuses = array( | |
| 463 | - 'EventScheduled' => _x('Scheduled', 'Event Status', 'event-post'), | |
| 464 | - 'EventCancelled' => _x('Cancelled', 'Event Status', 'event-post'), | |
| 465 | - 'EventMovedOnline' => _x('Moved Online', 'Event Status', 'event-post'), | |
| 466 | - 'EventPostponed' => _x('Postoned', 'Event Status', 'event-post'), | |
| 467 | - 'EventRescheduled' => _x('Rescheduled', 'Event Status', 'event-post'), | |
| 468 | - 'EventCompleted' => _x('Completed', 'Event Status', 'event-post'), | |
| 469 | - ); | |
| 470 | - | |
| 471 | - $this->maps = $this->get_maps(); | |
| 472 | - $this->settings = $this->get_settings(); | |
| 473 | - | |
| 474 | - do_action('evenpost_init', $this); | |
| 475 | - | |
| 476 | - // Edit | |
| 477 | - add_action('add_meta_boxes', array(&$this, 'add_custom_box')); | |
| 478 | - foreach($this->settings['posttypes'] as $posttype){ | |
| 479 | - add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2); | |
| 480 | - add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2); | |
| 481 | - } | |
| 482 | - $this->Taxonomies->add_fields_to_taxonomies($this->settings['posttypes']); | |
| 483 | - | |
| 484 | - $this->markpath = ''; | |
| 485 | - $this->markurl = ''; | |
| 486 | - if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) { | |
| 487 | - $this->markpath = ABSPATH.'/'.$this->settings['markpath']; | |
| 488 | - $this->markurl = $this->settings['markurl']; | |
| 489 | - } else { | |
| 490 | - // $this->markpath = plugin_dir_path(__FILE__) . 'markers/'; | |
| 491 | - // $this->markurl = plugins_url('/markers/', __FILE__); | |
| 492 | - } | |
| 493 | - | |
| 494 | - $this->currencies = include (plugin_dir_path(__FILE__) . 'inc/data/currencies.php'); | |
| 495 | - | |
| 496 | - $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post')); | |
| 497 | - | |
| 498 | - $this->default_list_shema = apply_filters('eventpost_default_list_shema', array( | |
| 499 | - 'container' => '<%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>'. | |
| 500 | - '%list%'. | |
| 501 | - '%pagination%'. | |
| 502 | - '</%type%><!-- .event_loop -->', | |
| 503 | - 'item' => '<%child% class="event_item %class%" data-color="%color%" style="%style%">'. | |
| 504 | - '<a href="%event_link%">'. | |
| 505 | - '%event_thumbnail%'. | |
| 506 | - '<h5>%event_title% </h5>'. | |
| 507 | - '</a>'. | |
| 508 | - '%event_price%'. | |
| 509 | - '%event_date%'. | |
| 510 | - '%event_cat%'. | |
| 511 | - '%event_location%'. | |
| 512 | - '%event_excerpt%'. | |
| 513 | - '</%child%><!-- .event_item -->' | |
| 514 | - )); | |
| 515 | - $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema); | |
| 516 | - | |
| 517 | - $this->default_timeline_shema = apply_filters('eventpost_default_timeline_shema', array( | |
| 518 | - 'container' => ' | |
| 519 | - <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%> | |
| 520 | - %prev_arrow% | |
| 521 | - <div class="track"> | |
| 522 | - %list% | |
| 523 | - </div> | |
| 524 | - %next_arrow% | |
| 525 | - </%type%><!-- .event_loop -->', | |
| 526 | - 'item' => '<%child% class="event_item %class%" data-color="%color%" style="%style%"> | |
| 527 | - <div class="anchor" style="background-color:#%color%"></div> | |
| 528 | - %event_date% | |
| 529 | - %event_location% | |
| 530 | - %event_cat% | |
| 531 | - %event_excerpt% | |
| 532 | - <a href="%event_link%"> | |
| 533 | - %event_thumbnail% | |
| 534 | - <h5>%event_title%</h5> | |
| 535 | - </a> | |
| 536 | - %event_price% | |
| 537 | - </%child%><!-- .event_item -->' | |
| 538 | - )); | |
| 539 | - $this->timeline_shema = apply_filters('eventpost_timeline_shema',$this->default_timeline_shema); | |
| 540 | - | |
| 541 | - $this->map_interactions=array( | |
| 542 | - 'DragRotate'=>__('Drag Rotate', 'event-post'), | |
| 543 | - 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'), | |
| 544 | - 'DragPan'=>__('Drag Pan', 'event-post'), | |
| 545 | - 'PinchRotate'=>__('Pinch Rotate', 'event-post'), | |
| 546 | - 'PinchZoom'=>__('Pinch Zoom', 'event-post'), | |
| 547 | - 'KeyboardPan'=>__('Keyboard Pan', 'event-post'), | |
| 548 | - 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'), | |
| 549 | - 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'), | |
| 550 | - 'DragZoom'=>__('Drag Zoom', 'event-post'), | |
| 551 | - ); | |
| 552 | - | |
| 553 | - $this->quick_edit_fields = apply_filters('eventpost_quick_edit_fields', array( | |
| 554 | - 'event'=>array( | |
| 555 | - $this->META_START=>__('Begin:', 'event-post'), | |
| 556 | - $this->META_END=>__('End:', 'event-post'), | |
| 557 | - $this->META_COLOR=>__('Color:', 'event-post'), | |
| 558 | - $this->META_ICON=>__('Icon:', 'event-post'), | |
| 559 | - ), | |
| 560 | - 'location'=>array( | |
| 561 | - $this->META_ADD=>__('Address:', 'event-post'), | |
| 562 | - $this->META_LAT=>__('Latitude:', 'event-post'), | |
| 563 | - $this->META_LONG=>__('Longitude:', 'event-post'), | |
| 564 | - ), | |
| 565 | - ) | |
| 566 | - ); | |
| 567 | - $this->bulk_edit_fields = apply_filters('eventpost_bulk_edit_fields', array( | |
| 568 | - 'event'=>array( | |
| 569 | - $this->META_COLOR=>__('Color:', 'event-post'), | |
| 570 | - $this->META_ICON=>__('Icon:', 'event-post'), | |
| 571 | - ), | |
| 572 | - ) | |
| 573 | - ); | |
| 574 | - | |
| 575 | - $this->kses_tags = apply_filters('eventpost_kses_tags', json_decode( | |
| 576 | - file_get_contents(plugin_dir_path(__FILE__).'inc/data/kses-tags.json'), | |
| 577 | - true | |
| 578 | - )); | |
| 579 | - | |
| 580 | - | |
| 256 | + /** | |
| 257 | + * Get blog settings, load and saves default settings if needed. Can be filterred using | |
| 258 | + * | |
| 259 | + * `<?php add_filter('eventpost_getsettings', 'some_function'); ?>` | |
| 260 | + * | |
| 261 | + * @action eventpost_getsettings_action | |
| 262 | + * @filter eventpost_getsettings | |
| 263 | + * @return array | |
| 264 | + */ | |
| 265 | + public function get_settings() { | |
| 266 | + $ep_settings = get_option('ep_settings'); | |
| 267 | + $reg_settings=false; | |
| 268 | + if(!is_array($ep_settings)){ | |
| 269 | + $ep_settings = array(); | |
| 581 | 270 | } |
| 271 | + if (!isset($ep_settings['dateformat']) || empty($ep_settings['dateformat'])) { | |
| 272 | + $ep_settings['dateformat'] = get_option('date_format'); | |
| 273 | + $reg_settings=true; | |
| 274 | + } | |
| 275 | + if (!isset($ep_settings['timeformat']) || empty($ep_settings['timeformat'])) { | |
| 276 | + $ep_settings['timeformat'] = get_option('time_format'); | |
| 277 | + $reg_settings=true; | |
| 278 | + } | |
| 279 | + if (!isset($ep_settings['tile']) || empty($ep_settings['tile']) || !isset($this->maps[$ep_settings['tile']])) { | |
| 280 | + $maps = array_keys($this->maps); | |
| 281 | + $ep_settings['tile'] = $this->maps[$maps[0]]['id']; | |
| 282 | + $reg_settings=true; | |
| 283 | + } | |
| 284 | + if(!isset($ep_settings['zoom']) || !is_numeric($ep_settings['zoom'])){ | |
| 285 | + $ep_settings['zoom']=12; | |
| 286 | + $reg_settings=true; | |
| 287 | + } | |
| 288 | + if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) { | |
| 289 | + $ep_settings['cache'] = 0; | |
| 290 | + $reg_settings=true; | |
| 291 | + } | |
| 292 | + if (!isset($ep_settings['export']) || empty($ep_settings['export'])) { | |
| 293 | + $ep_settings['export'] = 'both'; | |
| 294 | + $reg_settings=true; | |
| 295 | + } | |
| 296 | + if (!isset($ep_settings['dateforhumans'])) { | |
| 297 | + $ep_settings['dateforhumans'] = 1; | |
| 298 | + $reg_settings=true; | |
| 299 | + } | |
| 300 | + if (!isset($ep_settings['emptylink'])) { | |
| 301 | + $ep_settings['emptylink'] = 1; | |
| 302 | + $reg_settings=true; | |
| 303 | + } | |
| 304 | + if (!isset($ep_settings['markpath'])) { | |
| 305 | + $ep_settings['markpath'] = ''; | |
| 306 | + $reg_settings=true; | |
| 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 | + } | |
| 316 | + if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) { | |
| 317 | + $ep_settings['singlepos'] = 'after'; | |
| 318 | + $reg_settings=true; | |
| 319 | + } | |
| 320 | + if (!isset($ep_settings['loopicons'])) { | |
| 321 | + $ep_settings['loopicons'] = 1; | |
| 322 | + $reg_settings=true; | |
| 323 | + } | |
| 324 | + if (!isset($ep_settings['adminpos']) || empty($ep_settings['adminpos'])) { | |
| 325 | + $ep_settings['adminpos'] = 'side'; | |
| 326 | + $reg_settings=true; | |
| 327 | + } | |
| 328 | + if (!isset($ep_settings['container_shema']) ) { | |
| 329 | + $ep_settings['container_shema'] = ''; | |
| 330 | + $reg_settings=true; | |
| 331 | + } | |
| 582 | 332 | |
| 583 | - /** | |
| 584 | - * Init all variables when WP is ready | |
| 585 | - * | |
| 586 | - * @action evenpost_init | |
| 587 | - * @filter eventpost_default_list_shema | |
| 588 | - * @filter eventpost_list_shema | |
| 589 | - */ | |
| 590 | - public function widgets_init(){ | |
| 591 | - $this->Shortcodes = new EventPost\Shortcodes(); | |
| 333 | + if (!isset($ep_settings['item_shema']) ) { | |
| 334 | + $ep_settings['item_shema'] = ''; | |
| 335 | + $reg_settings=true; | |
| 336 | + } | |
| 592 | 337 | |
| 593 | - if(function_exists('register_block_type')){ | |
| 594 | - $block_path = plugin_dir_path(__FILE__).'inc/blocks/'; | |
| 595 | - include_once ($block_path . 'eventslist.php'); | |
| 596 | - include_once ($block_path . 'eventstimeline.php'); | |
| 597 | - include_once ($block_path . 'eventsmap.php'); | |
| 598 | - include_once ($block_path . 'eventscalendar.php'); | |
| 599 | - include_once ($block_path . 'eventdetails.php'); | |
| 600 | - } | |
| 338 | + if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){ | |
| 339 | + $ep_settings['datepicker']='simple'; | |
| 340 | + $reg_settings=true; | |
| 341 | + } | |
| 601 | 342 | |
| 343 | + if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){ | |
| 344 | + $ep_settings['posttypes']=array('post'); | |
| 345 | + $reg_settings=true; | |
| 346 | + } | |
| 602 | 347 | |
| 603 | - // WooCommerce | |
| 604 | - if (class_exists('WooCommerce') && in_array('product', $this->settings['posttypes'])) { | |
| 605 | - include_once (plugin_dir_path(__FILE__).'inc/woocommerce.php'); | |
| 606 | - } | |
| 607 | - } | |
| 348 | + do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings)); | |
| 608 | 349 | |
| 609 | - public function register_widgets(){ | |
| 610 | - register_widget('EventPost_List'); | |
| 611 | - register_widget('EventPost_Map'); | |
| 612 | - register_widget('EventPost_Cal'); | |
| 613 | - } | |
| 350 | + //Save settings not changed | |
| 351 | + if($reg_settings===true){ | |
| 352 | + update_option('ep_settings', $ep_settings); | |
| 353 | + } | |
| 354 | + return apply_filters('eventpost_getsettings', $ep_settings); | |
| 355 | + } | |
| 614 | 356 | |
| 615 | - /** | |
| 616 | - * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color. | |
| 617 | - * | |
| 618 | - * @param string $color | |
| 619 | - * | |
| 620 | - * @return array $color($R, $G, $B) | |
| 621 | - */ | |
| 622 | - public function hex2dec($color = '000000') { | |
| 623 | - $tbl_color = array(); | |
| 624 | - if(!is_string($color) || empty($color)){ | |
| 625 | - $color = '000000'; | |
| 626 | - } | |
| 627 | - if (substr($color, 0, 1)!='#'){ | |
| 628 | - $color = '#' . $color; | |
| 629 | - } | |
| 630 | - $tbl_color['R'] = hexdec(substr($color, 1, 2)); | |
| 631 | - $tbl_color['G'] = hexdec(substr($color, 3, 2)); | |
| 632 | - $tbl_color['B'] = hexdec(substr($color, 5, 2)); | |
| 633 | - return $tbl_color; | |
| 634 | - } | |
| 635 | - | |
| 636 | - /** | |
| 637 | - * Fetch all registered image sizes | |
| 638 | - * | |
| 639 | - * @global array $_wp_additional_image_sizes | |
| 640 | - * | |
| 641 | - * @return array | |
| 642 | - */ | |
| 643 | - function get_thumbnail_sizes(){ | |
| 644 | - global $_wp_additional_image_sizes; | |
| 645 | - $sizes = array('thumbnail', 'medium', 'large', 'full'); | |
| 646 | - foreach(array_keys($_wp_additional_image_sizes) as $size){ | |
| 647 | - $sizes[]=$size; | |
| 648 | - } | |
| 649 | - return $sizes; | |
| 650 | - } | |
| 651 | - | |
| 652 | - /** | |
| 653 | - * Get blog settings, load and saves default settings if needed. Can be filterred using | |
| 654 | - * | |
| 655 | - * @example `<?php add_filter('eventpost_getsettings', 'some_function'); ?>` | |
| 656 | - * | |
| 657 | - * @action eventpost_getsettings_action | |
| 658 | - * @filter eventpost_getsettings | |
| 659 | - * | |
| 660 | - * @return array | |
| 661 | - */ | |
| 662 | - public function get_settings() { | |
| 663 | - $ep_settings = $this->Settings->get_settings(); | |
| 664 | - return apply_filters('eventpost_getsettings', $ep_settings); | |
| 665 | - } | |
| 666 | - | |
| 667 | - /** | |
| 668 | - * Checks if HTML schemas are not empty | |
| 669 | - * | |
| 670 | - * @param array $shema | |
| 671 | - * | |
| 672 | - * @return array | |
| 673 | - */ | |
| 674 | - public function custom_shema($shema){ | |
| 357 | + /** | |
| 358 | + * Checks if HTML schemas are not empty | |
| 359 | + * @param array $shema | |
| 360 | + * @return array | |
| 361 | + */ | |
| 362 | + public function custom_shema($shema){ | |
| 675 | 363 | if(!empty($this->settings['container_shema'])){ |
| 676 | - $shema['container']=$this->settings['container_shema']; | |
| 364 | + $shema['container']=$this->settings['container_shema']; | |
| 677 | 365 | } |
| 678 | 366 | if(!empty($this->settings['item_shema'])){ |
| 679 | - $shema['item']=$this->settings['item_shema']; | |
| 367 | + $shema['item']=$this->settings['item_shema']; | |
| 680 | 368 | } |
| 681 | 369 | return $shema; |
| 682 | - } | |
| 370 | + } | |
| 683 | 371 | |
| 684 | - /** | |
| 685 | - * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example: | |
| 686 | - * | |
| 687 | - * ``` | |
| 688 | - * <?php | |
| 689 | - * add_filter('eventpost_getsettings', 'map_function'); | |
| 690 | - * function map_function($maps){ | |
| 691 | - * array_push($maps, array( | |
| 692 | - * 'name'=>'Myt custom map', | |
| 693 | - * 'id'=>'custom_map', | |
| 694 | - * 'urls'=>array( | |
| 695 | - * 'http://a.customurl.org/{z}/{x}/{y}.png', | |
| 696 | - * 'http://b.customurl.org/{z}/{x}/{y}.png', | |
| 697 | - * 'http://c.customurl.org/{z}/{x}/{y}.png', | |
| 698 | - * ) | |
| 699 | - * )); | |
| 700 | - * return $maps; | |
| 701 | - * } | |
| 702 | - * ?> | |
| 703 | - * ``` | |
| 704 | - * | |
| 705 | - * @filter eventpost_maps | |
| 706 | - * | |
| 707 | - * @return array of map arrays ['name', 'id', 'urls'] | |
| 708 | - */ | |
| 709 | - public function get_maps() { | |
| 710 | - $maps = array(); | |
| 711 | - $filename = plugin_dir_path(__FILE__) . 'maps.json'; | |
| 712 | - if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) { | |
| 713 | - // Convert objects to array to ensure retrocompatibility | |
| 714 | - $arrays = array(); | |
| 715 | - foreach($json as $map){ | |
| 716 | - $arrays[$map->id] = (array) $map; | |
| 717 | - } | |
| 718 | - $maps = apply_filters('eventpost_maps', $arrays); | |
| 719 | - } | |
| 720 | - return $maps; | |
| 721 | - } | |
| 372 | + /** | |
| 373 | + * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example: | |
| 374 | + * | |
| 375 | + * ``` | |
| 376 | + * <?php | |
| 377 | + * add_filter('eventpost_getsettings', 'map_function'); | |
| 378 | + * function map_function($maps){ | |
| 379 | + * array_push($maps, array( | |
| 380 | + * 'name'=>'Myt custom map', | |
| 381 | + * 'id'=>'custom_map', | |
| 382 | + * 'urls'=>array( | |
| 383 | + * 'http://a.customurl.org/{z}/{x}/{y}.png', | |
| 384 | + * 'http://b.customurl.org/{z}/{x}/{y}.png', | |
| 385 | + * 'http://c.customurl.org/{z}/{x}/{y}.png', | |
| 386 | + * ) | |
| 387 | + * )); | |
| 388 | + * return $maps; | |
| 389 | + * } | |
| 390 | + * ?> | |
| 391 | + * ``` | |
| 392 | + * | |
| 393 | + * @filter eventpost_maps | |
| 394 | + * @return array of map arrays ['name', 'id', 'urls'] | |
| 395 | + */ | |
| 396 | + public function get_maps() { | |
| 397 | + $maps = array(); | |
| 398 | + $filename = plugin_dir_path(__FILE__) . 'maps.json'; | |
| 399 | + if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) { | |
| 400 | + // Convert objects to array to ensure retrocompatibility | |
| 401 | + $arrays = array(); | |
| 402 | + foreach($json as $map){ | |
| 403 | + $arrays[$map->id] = (array) $map; | |
| 404 | + } | |
| 405 | + $maps = apply_filters('eventpost_maps', $arrays); | |
| 406 | + } | |
| 407 | + return $maps; | |
| 408 | + } | |
| 722 | 409 | |
| 723 | - /** | |
| 724 | - * Get colors | |
| 725 | - * | |
| 726 | - * @return array | |
| 727 | - */ | |
| 728 | - public function get_colors() { | |
| 729 | - $colors = array(); | |
| 730 | - if (is_dir($this->markpath)) { | |
| 731 | - $files = scandir($this->markpath); | |
| 732 | - foreach ($files as $file) { | |
| 733 | - if (substr($file, -4) == '.png') { | |
| 734 | - $colors[substr($file, 0, -4)] = $this->markurl . $file; | |
| 735 | - } | |
| 736 | - } | |
| 737 | - } | |
| 738 | - return $colors; | |
| 739 | - } | |
| 410 | + /** | |
| 411 | + * | |
| 412 | + * @return array | |
| 413 | + */ | |
| 414 | + public function get_colors() { | |
| 415 | + $colors = array(); | |
| 416 | + if (is_dir($this->markpath)) { | |
| 417 | + $files = scandir($this->markpath); | |
| 418 | + foreach ($files as $file) { | |
| 419 | + if (substr($file, -4) == '.png') { | |
| 420 | + $colors[substr($file, 0, -4)] = $this->markurl . $file; | |
| 421 | + } | |
| 422 | + } | |
| 423 | + } | |
| 424 | + return $colors; | |
| 425 | + } | |
| 740 | 426 | |
| 741 | - /** | |
| 742 | - * Get color of a post | |
| 743 | - * | |
| 744 | - * @param int $post_id | |
| 745 | - * @param bool $default | |
| 746 | - * @param bool $check_taxo | |
| 747 | - * | |
| 748 | - * @return string color | |
| 749 | - */ | |
| 750 | - public function get_post_color($post_id, $default = false, $check_taxo = false) { | |
| 751 | - $color = get_post_meta($post_id, $this->META_COLOR,true); | |
| 752 | - if($color && !empty($color)){ | |
| 753 | - return event_post_format_color($color); | |
| 754 | - }else{ | |
| 755 | - if($check_taxo){ | |
| 756 | - foreach(event_post_get_all_terms($post_id) as $term){ | |
| 757 | - $taxo_color = $this->Taxonomies->get_taxonomy_color($term->term_id); | |
| 758 | - if($taxo_color){ | |
| 759 | - return event_post_format_color($taxo_color); | |
| 760 | - } | |
| 761 | - } | |
| 762 | - } | |
| 763 | - } | |
| 764 | - return event_post_format_color($default); | |
| 765 | - } | |
| 427 | + /** | |
| 428 | + * | |
| 429 | + * @param string $color | |
| 430 | + * @return sring | |
| 431 | + */ | |
| 432 | + public function get_marker($color) { | |
| 433 | + if (is_file($this->markpath . $color . '.png')) { | |
| 434 | + return $this->markurl . $color . '.png'; | |
| 435 | + } | |
| 436 | + return plugins_url('/markers/ffffff.png', __FILE__); | |
| 437 | + } | |
| 766 | 438 | |
| 767 | - /** | |
| 768 | - * Get icon of a post | |
| 769 | - * | |
| 770 | - * @param int $post_id | |
| 771 | - * @param bool $default | |
| 772 | - * @param bool $check_taxo | |
| 773 | - * | |
| 774 | - * @return string|false icon | |
| 775 | - */ | |
| 776 | - public function get_post_icon($post_id, $default = false, $check_taxo = false) { | |
| 777 | - $icon = get_post_meta($post_id, $this->META_ICON,true); | |
| 778 | - if($icon && !empty($icon)){ | |
| 779 | - return $icon; | |
| 780 | - }else{ | |
| 781 | - if($check_taxo){ | |
| 782 | - foreach(event_post_get_all_terms($post_id) as $term){ | |
| 783 | - $taxo_icon = $this->Taxonomies->get_taxonomy_icon($term->term_id); | |
| 784 | - if($taxo_icon){ | |
| 785 | - return event_post_format_color($taxo_icon); | |
| 786 | - } | |
| 787 | - } | |
| 788 | - } | |
| 789 | - } | |
| 790 | - return $default; | |
| 791 | - } | |
| 439 | + /** | |
| 440 | + * Enqueue CSS files | |
| 441 | + */ | |
| 442 | + public function load_styles() { | |
| 443 | + //CSS | |
| 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 | + } | |
| 792 | 454 | |
| 793 | - /** | |
| 794 | - * Get the URL of a marker | |
| 795 | - * | |
| 796 | - * @param string $color | |
| 797 | - * | |
| 798 | - * @return sring | |
| 799 | - */ | |
| 800 | - public function get_marker($color) { | |
| 801 | - if (is_file($this->markpath . $color . '.png')) { | |
| 802 | - return $this->markurl . $color . '.png'; | |
| 803 | - } | |
| 804 | - return ""; | |
| 805 | - } | |
| 455 | + // Lib scripts | |
| 456 | + wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version); | |
| 457 | + wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css')); | |
| 458 | + } | |
| 459 | + /** | |
| 460 | + * Enqueue Editor style | |
| 461 | + */ | |
| 462 | + public function editor_styles() { | |
| 463 | + add_editor_style( plugins_url('/css/eventpost.min.css', __FILE__) ); | |
| 464 | + } | |
| 806 | 465 | |
| 807 | - /** | |
| 808 | - * Enqueue CSS files | |
| 809 | - */ | |
| 810 | - public function load_styles($deps = null) { | |
| 811 | - //CSS | |
| 812 | - if(!empty($this->settings['customcss'])){ | |
| 813 | - wp_enqueue_style('event-post-custom', $this->settings['customcss']); | |
| 814 | - } | |
| 815 | - elseif(is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')){ | |
| 816 | - wp_enqueue_style('event-post-custom', get_theme_file_uri('event-post.css')); | |
| 817 | - } | |
| 818 | - else{ | |
| 819 | - wp_register_style('event-post', plugins_url('/build/front/front.css', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/front/front.css" )); | |
| 820 | - wp_enqueue_style('event-post'); | |
| 821 | - } | |
| 466 | + /** | |
| 467 | + * Enqueue JS files | |
| 468 | + */ | |
| 469 | + public function load_scripts($deps = array('jquery')) { | |
| 470 | + // JS | |
| 471 | + wp_enqueue_script('jquery', false, false, false, true); | |
| 472 | + wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), $deps, $this->version, true); | |
| 473 | + wp_localize_script('event-post', 'eventpost_params', array( | |
| 474 | + 'imgpath' => plugins_url('/img/', __FILE__), | |
| 475 | + 'maptiles' => $this->maps, | |
| 476 | + 'defaulttile' => $this->settings['tile'], | |
| 477 | + 'zoom' => $this->settings['zoom'], | |
| 478 | + 'ajaxurl' => admin_url() . 'admin-ajax.php', | |
| 479 | + 'map_interactions'=>$this->map_interactions, | |
| 480 | + )); | |
| 481 | + } | |
| 482 | + /** | |
| 483 | + * Enqueue JS files for maps | |
| 484 | + */ | |
| 485 | + public function load_map_scripts() { | |
| 486 | + // JS | |
| 487 | + wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true); | |
| 488 | + $this->load_scripts(array('jquery', 'openlayers')); | |
| 489 | + if(is_admin()){ | |
| 490 | + $this->admin_scripts(array('jquery', 'openlayers')); | |
| 491 | + } | |
| 492 | + } | |
| 822 | 493 | |
| 823 | - // Lib scripts | |
| 824 | - wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css')); | |
| 825 | - } | |
| 494 | + /** | |
| 495 | + * Enqueue CSS files in admin | |
| 496 | + */ | |
| 497 | + public function admin_head() { | |
| 498 | + $page = basename($_SERVER['SCRIPT_NAME']); | |
| 499 | + if( $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){ | |
| 500 | + return; | |
| 501 | + } | |
| 502 | + wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version); | |
| 503 | + wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version); | |
| 504 | + wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version); | |
| 505 | + } | |
| 826 | 506 | |
| 827 | - /** | |
| 828 | - * Enqueue Editor style | |
| 829 | - */ | |
| 830 | - public function editor_styles() { | |
| 831 | - add_editor_style( plugins_url('/build/front/front.css', __FILE__) ); | |
| 832 | - } | |
| 507 | + /** | |
| 508 | + * Enqueue JS files in admin | |
| 509 | + */ | |
| 510 | + public function admin_scripts($deps = array('jquery'), $force=false) { | |
| 511 | + $page = basename($_SERVER['SCRIPT_NAME']); | |
| 512 | + if(!$force && $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings')){ | |
| 513 | + return; | |
| 514 | + } | |
| 515 | + wp_enqueue_script('jquery'); | |
| 516 | + wp_enqueue_script('jquery-effects-core'); | |
| 517 | + wp_enqueue_script('jquery-effects-shake'); | |
| 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')){ | |
| 522 | + wp_enqueue_script('jquery-ui-datepicker'); | |
| 523 | + $deps[] = 'jquery-ui-datepicker'; | |
| 524 | + } | |
| 525 | + wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true); | |
| 526 | + $language = get_bloginfo('language'); | |
| 527 | + if (strpos($language, '-') > -1) { | |
| 528 | + $language = strtolower(substr($language, 0, 2)); | |
| 529 | + } | |
| 530 | + wp_localize_script('event-post-admin', 'eventpost', array( | |
| 531 | + 'ajaxurl' => admin_url('admin-ajax.php'), | |
| 532 | + 'imgpath' => plugins_url('/img/', __FILE__), | |
| 533 | + 'date_choose' => '<span class="screen-reader-text">'.__('Choose', 'event-post').'</span><i class="dashicons dashicons-calendar-alt"></i>', | |
| 534 | + 'date_format' => __('yy-mm-dd', 'event-post'), | |
| 535 | + 'more_icons' => __('More icons', 'event-post'), | |
| 536 | + 'pick_a_date'=>__('Pick a date','event-post'), | |
| 537 | + 'use_current_location'=>__('Use my current location','event-post'), | |
| 538 | + 'start_drag'=>__('Click to<br>drag the map<br>and change location','event-post'), | |
| 539 | + 'empty_address'=>__('Be kind to fill a non empty address :)', 'event-post'), | |
| 540 | + 'search'=>__('Type an address', 'event-post'), | |
| 541 | + 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'), | |
| 542 | + 'datepickeri18n'=>array( | |
| 543 | + 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'), | |
| 544 | + 'day'=>__('Day', 'event-post'), | |
| 545 | + 'month'=>__('Month', 'event-post'), | |
| 546 | + 'year'=>__('Day', 'event-post'), | |
| 547 | + 'hour'=>__('Hour', 'event-post'), | |
| 548 | + 'minute'=>__('Minute', 'event-post'), | |
| 549 | + 'ok'=>__('OK', 'event-post'), | |
| 550 | + 'cancel'=>__('Cancel', 'event-post'), | |
| 551 | + 'edit'=>__('Edit', 'event-post'), | |
| 552 | + 'months'=>$this->NomDuMois, | |
| 553 | + ), | |
| 554 | + 'META_START' => $this->META_START, | |
| 555 | + 'META_END' => $this->META_END, | |
| 556 | + 'META_ADD' => $this->META_ADD, | |
| 557 | + 'META_LAT' => $this->META_LAT, | |
| 558 | + 'META_LONG' => $this->META_LONG, | |
| 559 | + 'lang'=>$language, | |
| 560 | + 'maptiles' => $this->maps, | |
| 561 | + 'defaulttile' => $this->settings['tile'] | |
| 562 | + )); | |
| 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 | + } | |
| 833 | 575 | |
| 834 | - /** | |
| 835 | - * Enqueue JS files | |
| 836 | - */ | |
| 837 | - public function load_scripts() { | |
| 838 | - wp_enqueue_script('event-post', plugins_url('/build/front/front.js', __FILE__), array(), filemtime( "{$this->plugin_path}/build/front/front.js" ), true); | |
| 839 | - $maps = $this->maps; | |
| 840 | - foreach($maps as $m=>$map){ | |
| 841 | - if(isset($map['api_param']) && $this->settings['tile_api_key']){ | |
| 842 | - foreach($map['urls'] as $i=>$url){ | |
| 843 | - $maps[$m]['urls'][$i] = add_query_arg($map['api_param'], $this->settings['tile_api_key'], $url); | |
| 844 | - } | |
| 845 | - } | |
| 846 | - } | |
| 847 | - wp_add_inline_script('event-post', 'var EventPost = EventPost || {}; EventPost.front='.wp_json_encode(array( | |
| 848 | - 'scripts' => array( | |
| 849 | - 'map' => plugins_url('/build/map/event-map.js', __FILE__) | |
| 850 | - ), | |
| 851 | - 'imgpath' => plugins_url('/img/', __FILE__), | |
| 852 | - 'maptiles' => $maps, | |
| 853 | - 'defaulttile' => $this->settings['tile'], | |
| 854 | - 'zoom' => $this->settings['zoom'], | |
| 855 | - 'ajaxurl' => admin_url() . 'admin-ajax.php', | |
| 856 | - 'map_interactions'=>$this->map_interactions, | |
| 857 | - )), 'before'); | |
| 858 | - } | |
| 859 | - /** | |
| 860 | - * Enqueue JS files for maps | |
| 861 | - */ | |
| 862 | - public function load_map_scripts() { | |
| 863 | - $this->load_styles(array('event-post-map')); | |
| 864 | - // JS | |
| 865 | - if(is_admin()){ | |
| 866 | - $this->admin_scripts(array('jquery', 'event-post-map')); | |
| 867 | - } | |
| 868 | - } | |
| 869 | - | |
| 870 | - /** | |
| 871 | - * Enqueue CSS files in admin | |
| 872 | - */ | |
| 873 | - public function admin_head() { | |
| 874 | - $page = basename($_SERVER['SCRIPT_NAME']); | |
| 875 | - if( $page!='post-new.php' && $page!='edit-tags.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){ | |
| 876 | - return; | |
| 877 | - } | |
| 878 | - wp_enqueue_style('event-post-admin', plugins_url('/build/admin/admin.css', __FILE__), false, filemtime( "{$this->plugin_path}/build/admin/admin.css" )); | |
| 879 | - } | |
| 880 | - | |
| 881 | - /** | |
| 882 | - * Enqueue JS files in admin | |
| 883 | - */ | |
| 884 | - public function admin_scripts($deps = array('jquery'), $force=false) { | |
| 885 | - $page = basename($_SERVER['SCRIPT_NAME']); | |
| 886 | - if(!$force && | |
| 887 | - $page!='post-new.php' && | |
| 888 | - $page!='edit-tags.php' && | |
| 889 | - $page!='term.php' && | |
| 890 | - !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && | |
| 891 | - !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') | |
| 892 | - ){ | |
| 893 | - return; | |
| 894 | - } | |
| 895 | - wp_enqueue_script('jquery'); | |
| 896 | - wp_enqueue_script('jquery-effects-core'); | |
| 897 | - wp_enqueue_script('jquery-effects-shake'); | |
| 898 | - wp_enqueue_style( 'wp-color-picker'); | |
| 899 | - wp_enqueue_script( 'wp-color-picker'); | |
| 900 | - if(!is_array($deps)){ | |
| 901 | - $deps = array('jquery','wp-color-picker'); | |
| 902 | - } | |
| 903 | - if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){ | |
| 904 | - wp_enqueue_script('jquery-ui-datepicker'); | |
| 905 | - $deps[] = 'jquery-ui-datepicker'; | |
| 906 | - } | |
| 907 | - wp_enqueue_script('event-post-admin', plugins_url('/build/admin/admin.js', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/admin/admin.js" ), true); | |
| 908 | - $language = get_bloginfo('language'); | |
| 909 | - if (strpos($language, '-') > -1) { | |
| 910 | - $language = strtolower(substr($language, 0, 2)); | |
| 911 | - } | |
| 912 | - wp_add_inline_script('event-post-admin', 'var EventPost = EventPost || {}; EventPost.admin='.wp_json_encode(array( | |
| 913 | - 'ajaxurl' => admin_url('admin-ajax.php'), | |
| 914 | - 'imgpath' => plugins_url('/img/', __FILE__), | |
| 915 | - 'date_choose' => __('Choose', 'event-post'), | |
| 916 | - 'date_format' => __('yy-mm-dd', 'event-post'), | |
| 917 | - 'more_icons' => __('More icons', 'event-post'), | |
| 918 | - 'pick_a_date'=>__('Pick a date','event-post'), | |
| 919 | - 'use_current_location'=>__('Use my current location','event-post'), | |
| 920 | - 'start_drag'=>__('Click to<br>drag the map<br>and change location','event-post'), | |
| 921 | - 'empty_address'=>__('Be kind to fill a non empty address:)', 'event-post'), | |
| 922 | - 'search'=>__('Type an address', 'event-post'), | |
| 923 | - 'search_button'=>__('Search', 'event-post'), | |
| 924 | - 'geocoding_attribution'=>__('Geocoding by <a href="https://nominatim.openstreetmap.org/" target="_blank">OpenStreetmap Nominatim</a>', 'event-post'), | |
| 925 | - 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'), | |
| 926 | - 'datepickeri18n'=>array( | |
| 927 | - // Translators: %1$s is the month name, %2$s is the day number, %3$s is the year, %4$s is the hour, %5$s is the minute | |
| 928 | - 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'), | |
| 929 | - 'day'=>__('Day', 'event-post'), | |
| 930 | - 'month'=>__('Month', 'event-post'), | |
| 931 | - 'year'=>__('Day', 'event-post'), | |
| 932 | - 'hour'=>__('Hour', 'event-post'), | |
| 933 | - 'minute'=>__('Minute', 'event-post'), | |
| 934 | - 'ok'=>__('OK', 'event-post'), | |
| 935 | - 'cancel'=>__('Cancel', 'event-post'), | |
| 936 | - 'remove'=>__('Remove', 'event-post'), | |
| 937 | - 'edit'=>__('Edit', 'event-post'), | |
| 938 | - 'months'=>$this->NomDuMois, | |
| 939 | - ), | |
| 940 | - 'META_START' => $this->META_START, | |
| 941 | - 'META_END' => $this->META_END, | |
| 942 | - 'META_ADD' => $this->META_ADD, | |
| 943 | - 'META_LAT' => $this->META_LAT, | |
| 944 | - 'META_LONG' => $this->META_LONG, | |
| 945 | - 'META_STATUS' => $this->META_STATUS, | |
| 946 | - 'META_ATTENDANCE_MODE' => $this->META_ATTENDANCE_MODE, | |
| 947 | - 'lang'=>$language, | |
| 948 | - 'maptiles' => $this->maps, | |
| 949 | - 'defaulttile' => $this->settings['tile'], | |
| 950 | - 'palette' => $this->get_theme_palette("hex"), | |
| 951 | - 'available_images' => $this->get_colors(), | |
| 952 | - ))); | |
| 953 | - } | |
| 954 | - function scripts_edit() { | |
| 955 | - // load only when editing a supported post type | |
| 956 | - $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; | |
| 957 | - if ( in_array( $current_post_type, $this->settings['posttypes'] ) ) { | |
| 958 | - wp_enqueue_script( 'eventpost-inline-edit', plugins_url( 'build/admin/inline-edit.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), '', true ); | |
| 959 | - wp_add_inline_script('eventpost-inline-edit', 'var EventPost = EventPost || {}; EventPost.inlineEdit='.wp_json_encode(array( | |
| 960 | - 'quick'=>$this->quick_edit_fields, | |
| 961 | - 'bulk'=>$this->bulk_edit_fields, | |
| 962 | - ))); | |
| 963 | - } | |
| 964 | - } | |
| 965 | - | |
| 966 | - function get_rich_result($event){ | |
| 967 | - /* | |
| 968 | - * https://search.google.com/test/rich-results | |
| 969 | - { | |
| 970 | - "@context": "https://schema.org", | |
| 971 | - "@type": "Event", | |
| 972 | - "name": "The Adventures of Kira and Morrison", | |
| 973 | - "startDate": "2025-07-21T19:00", | |
| 974 | - "endDate": "2025-07-21T23:00", | |
| 975 | - "eventStatus": "https://schema.org/EventScheduled", | |
| 976 | - "eventAttendanceMode": "https://schema.org/OnlineEventAttendanceMode", | |
| 977 | - "location": { | |
| 978 | - "@type": "VirtualLocation", | |
| 979 | - "url": "https://operaonline.stream5.com/" | |
| 980 | - }, | |
| 981 | - "image": [ | |
| 982 | - "https://example.com/photos/1x1/photo.jpg", | |
| 983 | - "https://example.com/photos/4x3/photo.jpg", | |
| 984 | - "https://example.com/photos/16x9/photo.jpg" | |
| 985 | - ], | |
| 986 | - "description": "The Adventures of Kira and Morrison is coming to Snickertown in a can’t miss performance.", | |
| 987 | - "offers": { | |
| 988 | - "@type": "Offer", | |
| 989 | - "url": "https://www.example.com/event_offer/12345_201803180430", | |
| 990 | - "price": "30", | |
| 991 | - "priceCurrency": "USD", | |
| 992 | - "availability": "https://schema.org/InStock", | |
| 993 | - "validFrom": "2024-05-21T12:00" | |
| 994 | - }, | |
| 995 | - "performer": { | |
| 996 | - "@type": "PerformingGroup", | |
| 997 | - "name": "Kira and Morrison" | |
| 998 | - } | |
| 999 | - } | |
| 1000 | - */ | |
| 1001 | - $location_virtual = array( | |
| 1002 | - '@type'=>'VirtualLocation', | |
| 1003 | - 'url'=>$event->virtual_location, | |
| 1004 | - ); | |
| 1005 | - $physical_location = array( | |
| 1006 | - '@type'=>'place', | |
| 1007 | - 'name'=>$event->address, | |
| 1008 | - 'address'=>$event->address, | |
| 1009 | - 'geo'=>array( | |
| 1010 | - '@type'=>'GeoCoordinates', | |
| 1011 | - 'latitude'=>$event->lat, | |
| 1012 | - 'longitude'=>$event->long, | |
| 1013 | - ), | |
| 1014 | - ); | |
| 1015 | - $min = 60 * get_option('gmt_offset'); | |
| 1016 | - $sign = $min < 0 ? "-" : "+"; | |
| 1017 | - $absmin = abs($min); | |
| 1018 | - $gmt_offset = sprintf("%s%02d:%02d", $sign, $absmin/60, $absmin%60); | |
| 1019 | - $time_format = (is_numeric($event->time_start) && is_numeric($event->time_end) && date('H:i', $event->time_start) != date('H:i', $event->time_end) && date('H:i', $event->time_start) != '00:00' && date('H:i', $event->time_end) != '00:00') ? 'Y-m-d\Th:i:00'.$gmt_offset : 'Y-m-d'; | |
| 1020 | - | |
| 1021 | - $rich_data = array( | |
| 1022 | - '@context'=>'https://schema.org', | |
| 1023 | - '@type'=>'event', | |
| 1024 | - 'name'=>$event->post_title, | |
| 1025 | - 'datePublished'=>str_replace(' ', 'T', $event->post_date_gmt).$gmt_offset, | |
| 1026 | - 'dateModified'=>str_replace(' ', 'T', $event->post_modified_gmt).$gmt_offset, | |
| 1027 | - 'startDate'=>$event->time_start ? date($time_format, $event->time_start) : null, | |
| 1028 | - 'endDate'=>$event->time_end ? date($time_format, $event->time_end) : null, | |
| 1029 | - 'eventStatus'=>$event->status, | |
| 1030 | - 'eventAttendanceMode'=>$event->attendance_mode, | |
| 1031 | - 'location'=> ($event->attendance_mode == 'MixedEventAttendanceMode') ? array($location_virtual,$physical_location) : ($event->attendance_mode == 'OnlineEventAttendanceMode' ? $location_virtual : $physical_location), | |
| 1032 | - 'image'=> has_post_thumbnail($event->ID) ? array( | |
| 1033 | - get_the_post_thumbnail_url($event->ID, 'post-thumbnail'), | |
| 1034 | - get_the_post_thumbnail_url($event->ID, 'medium'), | |
| 1035 | - get_the_post_thumbnail_url($event->ID, 'large'), | |
| 1036 | - get_the_post_thumbnail_url($event->ID, 'full'), | |
| 1037 | - ) : null, | |
| 1038 | - 'description'=>$event->description, | |
| 1039 | - ); | |
| 1040 | - if(!empty($event->organization)){ | |
| 1041 | - $rich_data['organizer'] = array( | |
| 1042 | - '@type'=>'Organization', | |
| 1043 | - 'name'=>$event->organization, | |
| 1044 | - ); | |
| 1045 | - } | |
| 1046 | - if(!empty($event->offer)){ | |
| 1047 | - $rich_data['offers'] = array( | |
| 1048 | - '@type'=>'Offer', | |
| 1049 | - // 'availability'=>$event->availability, | |
| 1050 | - // 'validFrom'=>date($time_format, $event->time_start), | |
| 1051 | - ); | |
| 1052 | - if(!empty($event->offer['url'])){ | |
| 1053 | - $rich_data['offers']['url'] = $event->offer['url']; | |
| 1054 | - } | |
| 1055 | - if(!empty($event->offer['price'])){ | |
| 1056 | - $rich_data['offers']['price'] = $event->offer['price']; | |
| 1057 | - } | |
| 1058 | - if(!empty($event->offer['currency'])){ | |
| 1059 | - $rich_data['offers']['priceCurrency'] = $event->offer['currency']; | |
| 1060 | - } | |
| 1061 | - } | |
| 1062 | - | |
| 1063 | - return apply_filters('event-post-rich-result', $rich_data, $event); | |
| 1064 | - } | |
| 1065 | - | |
| 1066 | - function wpseo_schema_webpage($rich_result){ | |
| 1067 | - $event = $this->retreive(); | |
| 1068 | - if ($event != false){ | |
| 1069 | - if ($event->time_start != '' && $event->time_end != '') { | |
| 1070 | - $rich_result = array_merge($rich_result, $this->get_rich_result($event)); | |
| 1071 | - } | |
| 1072 | - $this->is_schema_output = true; | |
| 1073 | - } | |
| 1074 | - return $rich_result; | |
| 1075 | - } | |
| 1076 | - | |
| 1077 | - function get_theme_palette($return = "hex"){ | |
| 1078 | - $theme_options = wp_get_global_settings(); | |
| 1079 | - $colors = []; | |
| 1080 | - if(isset($theme_options['color']['palette']['theme'])){ | |
| 1081 | - $colors = $theme_options['color']['palette']['theme']; | |
| 1082 | - }elseif(isset($theme_options['color']['palette']['default'])){ | |
| 1083 | - $colors = $theme_options['color']['palette']['default']; | |
| 1084 | - } | |
| 1085 | - if($return == "hex"){ | |
| 1086 | - $color_hexs = []; | |
| 1087 | - foreach($colors as $color){ | |
| 1088 | - $color_hexs[] = $color["color"]; | |
| 1089 | - } | |
| 1090 | - return $color_hexs; | |
| 1091 | - } | |
| 1092 | - return $colors; | |
| 1093 | - } | |
| 1094 | - | |
| 1095 | - /** | |
| 1096 | - * Add custom header meta for single events | |
| 1097 | - */ | |
| 1098 | - public function single_header() { | |
| 1099 | - if (is_single()) { | |
| 1100 | - $twitter_label_id=0; | |
| 1101 | - $event = $this->retreive(); | |
| 1102 | - $has_location = $has_time = false; | |
| 1103 | - if ($event != false) { | |
| 1104 | - if ($event->address != '' || ($event->lat != '' && $event->long != '')) { | |
| 1105 | - $twitter_label_id++; | |
| 1106 | - $has_location = true; | |
| 1107 | - ?> | |
| 1108 | -<meta name="geo.placename" content="<?php echo esc_attr($event->address) ?>" /> | |
| 1109 | -<meta name="geo.position" content="<?php echo esc_attr($event->lat) ?>;<?php echo esc_attr($event->long) ?>" /> | |
| 1110 | -<meta name="ICBM" content="<?php echo esc_attr($event->lat) ?>;<?php echo esc_attr($event->long) ?>" /> | |
| 1111 | -<meta property="place:location:latitude" content="<?php echo esc_attr($event->lat) ?>" /> | |
| 1112 | -<meta property="place:location:longitude" content="<?php echo esc_attr($event->long) ?>" /> | |
| 1113 | -<meta name="twitter:label<?php echo esc_attr($twitter_label_id); ?>" content="<?php esc_attr_e('Location', 'event-post'); ?>"/> | |
| 1114 | -<meta name="twitter:data<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr($event->address) ?>"/> | |
| 576 | + /** | |
| 577 | + * Add custom header meta for single events | |
| 578 | + */ | |
| 579 | + public function single_header() { | |
| 580 | + if (is_single()) { | |
| 581 | + $event = $this->retreive(); | |
| 582 | + if ($event->address != '' || ($event->lat != '' && $event->long != '')) { | |
| 583 | + ?> | |
| 584 | +<meta name="geo.placename" content="<?php echo $event->address ?>" /> | |
| 585 | +<meta name="geo.position" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" /> | |
| 586 | +<meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo $event->long ?>" /> | |
| 587 | +<meta property="place:location:latitude" content="<?php echo $event->lat ?>" /> | |
| 588 | +<meta property="place:location:longitude" content="<?php echo $event->long ?>" /> | |
| 1115 | 589 | <?php |
| 1116 | - } | |
| 1117 | - if ($event->start != '' && $event->end != '') { | |
| 1118 | - $has_time = true; | |
| 1119 | - $twitter_label_id++; | |
| 1120 | - ?> | |
| 1121 | -<meta name="datetime-coverage-start" content="<?php echo esc_attr(date('c', $event->time_start)) ?>" /> | |
| 1122 | -<meta name="datetime-coverage-end" content="<?php echo esc_attr(date('c', $event->time_end)) ?>" /> | |
| 1123 | -<meta name="twitter:label<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr('Date', 'event-post'); ?>"/> | |
| 1124 | -<meta name="twitter:data<?php echo esc_attr($twitter_label_id); ?>" content="<?php echo esc_attr($this->human_date($event->time_start)) ?>"/> | |
| 590 | + } | |
| 591 | + if ($event->start != '' && $event->end != '') { | |
| 592 | + ?> | |
| 593 | +<meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" /> | |
| 594 | +<meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" /> | |
| 1125 | 595 | <?php |
| 1126 | - } | |
| 1127 | - if(($has_location || $has_time) && !$this->is_schema_output){ | |
| 1128 | - $rich_result = $this->get_rich_result($event); | |
| 1129 | - $this->is_schema_output = true; | |
| 1130 | - ?> | |
| 1131 | - <script type="application/ld+json"><?php echo \wp_json_encode($rich_result); ?></script> | |
| 1132 | - <?php | |
| 1133 | - } | |
| 1134 | - } | |
| 1135 | - } | |
| 1136 | - } | |
| 596 | + } | |
| 597 | + } | |
| 598 | + } | |
| 1137 | 599 | |
| 1138 | - /** | |
| 1139 | - * Cleanups a date | |
| 1140 | - * | |
| 1141 | - * @param type $str | |
| 1142 | - * | |
| 1143 | - * @since 5.0.1 | |
| 1144 | - * | |
| 1145 | - * @return string | |
| 1146 | - */ | |
| 1147 | - public function date_cleanup($str){ | |
| 1148 | - return trim(str_replace(array('0', ' ', ':', '-'), '', $str)); | |
| 1149 | - } | |
| 600 | + /** | |
| 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 | + } | |
| 1150 | 609 | |
| 1151 | - /** | |
| 1152 | - * Checks if a date is valid or not | |
| 1153 | - * | |
| 1154 | - * @param string $str | |
| 1155 | - * | |
| 1156 | - * @return boolean | |
| 1157 | - */ | |
| 1158 | - public function dateisvalid($str) { | |
| 1159 | - return is_string($str) && $this->date_cleanup($str) != ''; | |
| 1160 | - } | |
| 610 | + /** | |
| 611 | + * | |
| 612 | + * @param string $str | |
| 613 | + * @return boolean | |
| 614 | + */ | |
| 615 | + public function dateisvalid($str) { | |
| 616 | + return is_string($str) && $this->date_cleanup($str) != ''; | |
| 617 | + } | |
| 1161 | 618 | |
| 1162 | - /** | |
| 1163 | - * Parse a date from a string | |
| 1164 | - * | |
| 1165 | - * @param string $date | |
| 1166 | - * @param string $sep | |
| 1167 | - * | |
| 1168 | - * @return string | |
| 1169 | - */ | |
| 1170 | - public function parsedate($date, $sep = '') { | |
| 1171 | - if (!empty($date)) { | |
| 1172 | - return substr($date, 0, 10) . $sep . substr($date, 11, 8); | |
| 1173 | - } else { | |
| 1174 | - return ''; | |
| 1175 | - } | |
| 1176 | - } | |
| 619 | + /** | |
| 620 | + * | |
| 621 | + * @param string $date | |
| 622 | + * @param string $sep | |
| 623 | + * @return string | |
| 624 | + */ | |
| 625 | + public function parsedate($date, $sep = '') { | |
| 626 | + if (!empty($date)) { | |
| 627 | + return substr($date, 0, 10) . $sep . substr($date, 11, 8); | |
| 628 | + } else { | |
| 629 | + return ''; | |
| 630 | + } | |
| 631 | + } | |
| 1177 | 632 | |
| 1178 | - /** | |
| 1179 | - * Sanitize a coordinate string | |
| 1180 | - * Only keeps, numbers, dots and commas | |
| 1181 | - * | |
| 1182 | - * @param string $str | |
| 1183 | - * | |
| 1184 | - * @since 5.9.9 | |
| 1185 | - * | |
| 1186 | - * @return string | |
| 1187 | - */ | |
| 1188 | - public function sanitize_coordinate($str){ | |
| 1189 | - return preg_replace('/[^0-9\.,-]/', '', $str); | |
| 1190 | - } | |
| 633 | + /** | |
| 634 | + * | |
| 635 | + * @param mixed $date | |
| 636 | + * @param string $format | |
| 637 | + * @return type | |
| 638 | + */ | |
| 639 | + public function human_date($date, $format = 'l j F Y') { | |
| 640 | + if($this->settings['dateforhumans']){ | |
| 641 | + if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) { | |
| 642 | + return __('today', 'event-post'); | |
| 643 | + } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) { | |
| 644 | + return __('tomorrow', 'event-post'); | |
| 645 | + } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) { | |
| 646 | + return __('yesterday', 'event-post'); | |
| 647 | + } | |
| 648 | + } | |
| 649 | + return date_i18n($format, $date); | |
| 650 | + } | |
| 1191 | 651 | |
| 1192 | - /** | |
| 1193 | - * Format a date for humans | |
| 1194 | - * | |
| 1195 | - * @param mixed $date | |
| 1196 | - * @param string $format | |
| 1197 | - * | |
| 1198 | - * @return type | |
| 1199 | - */ | |
| 1200 | - public function human_date($date, $format = 'l j F Y') { | |
| 1201 | - if($this->settings['dateforhumans']){ | |
| 1202 | - if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) { | |
| 1203 | - return __('today', 'event-post'); | |
| 1204 | - } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) { | |
| 1205 | - return __('tomorrow', 'event-post'); | |
| 1206 | - } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) { | |
| 1207 | - return __('yesterday', 'event-post'); | |
| 1208 | - } | |
| 1209 | - } | |
| 1210 | - return date_i18n($format, $date); | |
| 1211 | - } | |
| 652 | + /** | |
| 653 | + * | |
| 654 | + * @param timestamp $time_start | |
| 655 | + * @param timestamp $time_end | |
| 656 | + * @return string | |
| 657 | + */ | |
| 658 | + public function delta_date($time_start, $time_end){ | |
| 659 | + if(!$time_start || !$time_end){ | |
| 660 | + return; | |
| 661 | + } | |
| 1212 | 662 | |
| 1213 | - /** | |
| 1214 | - * Returns a range of dates | |
| 1215 | - * | |
| 1216 | - * @param timestamp $time_start | |
| 1217 | - * @param timestamp $time_end | |
| 1218 | - * | |
| 1219 | - * @return string | |
| 1220 | - */ | |
| 1221 | - public function delta_date($time_start, $time_end){ | |
| 1222 | - if(!$time_start || !$time_end){ | |
| 1223 | - return; | |
| 1224 | - } | |
| 663 | + //Display dates | |
| 664 | + $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">'; | |
| 665 | + if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) { // same day | |
| 666 | + $dates.= "\n\t\t\t\t\t\t\t".'<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' | |
| 667 | + . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>"; | |
| 668 | + if (date('H:i', $time_start) != date('H:i', $time_end) && date('H:i', $time_start) != '00:00' && date('H:i', $time_end) != '00:00') { | |
| 669 | + $dates.=' <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span> | |
| 670 | + <span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span> | |
| 671 | + <span class="linking_word linking_word-t">' . __('to', 'event-post') . '</span> | |
| 672 | + <span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>'; | |
| 673 | + } | |
| 674 | + elseif (date('H:i', $time_start) != '00:00') { | |
| 675 | + $dates.=' <span class="linking_word">' . __('at', 'event-post') . '</span> | |
| 676 | + <time class="time time-single" itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' . date_i18n($this->settings['timeformat'], $time_start) . '</time>'; | |
| 677 | + } | |
| 678 | + $dates.="\n\t\t\t\t\t\t\t".'</time>'; | |
| 679 | + } else { // not same day | |
| 680 | + $dates.= ' | |
| 681 | + <span class="linking_word linking_word-from">' . __('from', 'event-post') . '</span> | |
| 682 | + <time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' . $this->human_date($time_start, $this->settings['dateformat']); | |
| 683 | + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00'){ | |
| 684 | + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_start); | |
| 685 | + } | |
| 686 | + $dates.='</time> | |
| 687 | + <span class="linking_word linking_word-to">' . __('to', 'event-post') . '</span> | |
| 688 | + <time class="date date-end" itemprop="dtend" datetime="' . date('c', $time_end) . '">' . $this->human_date($time_end, $this->settings['dateformat']); | |
| 689 | + if (date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00') { | |
| 690 | + $dates.= ', ' . date_i18n($this->settings['timeformat'], $time_end); | |
| 691 | + } | |
| 692 | + $dates.='</time>'; | |
| 693 | + } | |
| 694 | + $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->'; | |
| 695 | + return $dates; | |
| 696 | + } | |
| 1225 | 697 | |
| 1226 | - // Translators: %1$s, %4$s are opening tags, %2$s and %5$s are closing tag, %3$s is the first date, %6$s is the second date | |
| 1227 | - $from_to_days = _x('%1$sfrom%2$s %3$s %4$sto%5$s %6$s', 'Days', 'event-post'); | |
| 1228 | - // Translators: %1$s is the first date, %4$s is the second date, %2$s is an opening tag, %3$s is a closing tag | |
| 1229 | - $single_day_at = _x('%1$s%2$s,%3$s %4$s', 'From/To single day at time', 'event-post'); | |
| 1230 | - // Translators: %1$s, %4$s are opening tags, %2$s and %5$s are closing tag, %3$s is the first hour, %6$s is the second hour | |
| 1231 | - $from_to_hours = _x('%1$sfrom%2$s %3$s %4$sto%5$s %6$s', 'Hours', 'event-post'); | |
| 1232 | - // Translators: %1$s is an opening tag, %2$s is a closing tag, %3$s is the time | |
| 1233 | - $at_time = _x('%1$sat%2$s %3$s', 'Time', 'event-post'); | |
| 698 | + /** | |
| 699 | + * | |
| 700 | + * @param WP_Post object $post | |
| 701 | + * @param mixed $links | |
| 702 | + * @return string | |
| 703 | + */ | |
| 704 | + public function print_date($post = null, $links = 'deprecated', $context='') { | |
| 705 | + $dates = ''; | |
| 706 | + $event = $this->retreive($post); | |
| 707 | + if ($event->start != '' && $event->end != '') { | |
| 1234 | 708 | |
| 1235 | - //Display dates | |
| 1236 | - $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">'; | |
| 1237 | - // Same day | |
| 1238 | - if (date('Ymd', $time_start) == date('Ymd', $time_end)) { | |
| 1239 | - $dates.= "\n\t\t\t\t\t\t\t".'<time itemprop="dtstart" datetime="' . date_i18n('c', $time_start) . '">' | |
| 1240 | - . '<span class="date date-single">' . $this->human_date($time_end, $this->settings['dateformat']) . "</span>"; | |
| 1241 | - 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') { | |
| 1242 | - $dates.= ' '.sprintf( | |
| 1243 | - $from_to_hours, | |
| 1244 | - '<span class="linking_word linking_word-from">', | |
| 1245 | - '</span>', | |
| 1246 | - '<span class="time time-start">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>', | |
| 1247 | - '<span class="linking_word linking_word-to">', | |
| 1248 | - '</span>', | |
| 1249 | - '<span class="time time-end">' . date_i18n($this->settings['timeformat'], $time_end) . '</span>' | |
| 1250 | - ); | |
| 1251 | - } | |
| 1252 | - elseif (date('H:i', $time_start) != '00:00') { | |
| 1253 | - $dates.= ' '.sprintf( | |
| 1254 | - $at_time, | |
| 1255 | - '<span class="linking_word">', | |
| 1256 | - '</span>', | |
| 1257 | - '<span class="time time-single">' . date_i18n($this->settings['timeformat'], $time_start) . '</span>' | |
| 1258 | - ); | |
| 1259 | - } | |
| 1260 | - $dates.="\n\t\t\t\t\t\t\t".'</time>'; | |
| 1261 | - } | |
| 1262 | - // Not same day | |
| 1263 | - else { | |
| 1264 | - $dates.= ' '.sprintf( | |
| 1265 | - $from_to_days, | |
| 1266 | - '<span class="linking_word linking_word-from">', | |
| 1267 | - '</span>', | |
| 1268 | - '<time class="date date-start" itemprop="dtstart" datetime="' . date('c', $time_start) . '">' | |
| 1269 | - . ((date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00') | |
| 1270 | - ? sprintf($single_day_at, '<span class="date">'.$this->human_date($time_start, $this->settings['dateformat']).'</span>', '<span class="linking_word">', '</span>', '<span class="time">'.date_i18n($this->settings['timeformat'], $time_start).'</span>') | |
| 1271 | - : $this->human_date($time_start, $this->settings['dateformat']) | |
| 1272 | - ) | |
| 1273 | - . '</time>', | |
| 1274 | - '<span class="linking_word linking_word-to">', | |
| 1275 | - '</span>', | |
| 1276 | - '<time class="date date-to" itemprop="dtend" datetime="' . date('c', $time_end) . '">' | |
| 1277 | - . ((date('H:i:s', $time_start) != '00:00:00' || date('H:i:s', $time_end) != '00:00:00') | |
| 1278 | - ? sprintf($single_day_at, '<span class="date">'.$this->human_date($time_end, $this->settings['dateformat']).'</span>', '<span class="linking_word">', '</span>', '<span class="time">'.date_i18n($this->settings['timeformat'], $time_end).'</span>') | |
| 1279 | - : $this->human_date($time_end, $this->settings['dateformat']) | |
| 1280 | - ) | |
| 1281 | - . '</time>' | |
| 1282 | - ); | |
| 1283 | - } | |
| 1284 | - $dates.="\n\t\t\t\t\t\t".'</div><!-- .event_date -->'; | |
| 1285 | - return $dates; | |
| 1286 | - } | |
| 709 | + $dates.=$this->delta_date($event->time_start, $event->time_end); | |
| 1287 | 710 | |
| 1288 | - /** | |
| 1289 | - * Displays a date | |
| 1290 | - * | |
| 1291 | - * @param WP_Post object $post | |
| 1292 | - * @param mixed $links | |
| 1293 | - * | |
| 1294 | - * @return string | |
| 1295 | - */ | |
| 1296 | - public function print_date($post = null, $links = 'deprecated', $context='') { | |
| 1297 | - $dates = ''; | |
| 1298 | - $event = $this->retreive($post); | |
| 1299 | - if ($event != false){ | |
| 1300 | - if ($event->start != '' && $event->end != '') { | |
| 711 | + $timezone_string = get_option('timezone_string'); | |
| 712 | + $gmt_offset = $gmt = $this->get_gmt_offset(); | |
| 1301 | 713 | |
| 1302 | - $dates.=$this->delta_date($event->time_start, $event->time_end); | |
| 1303 | - if( // Status setting | |
| 1304 | - $this->settings['displaystatus'] == 'both' || | |
| 1305 | - ($this->settings['displaystatus'] == 'single' && is_single() ) || | |
| 1306 | - ($this->settings['displaystatus'] == 'list' && !is_single() ) | |
| 1307 | - ){ | |
| 1308 | - $dates.='<span class="eventpost-status">'.$this->statuses[$event->status].'</span>'; | |
| 1309 | - } | |
| 1310 | - $timezone_string = get_option('timezone_string'); | |
| 1311 | - $gmt_offset = $gmt = $this->get_gmt_offset(); | |
| 714 | + if (!is_admin() && $event->time_end > current_time('timestamp') && ( | |
| 715 | + $this->settings['export'] == 'both' || | |
| 716 | + ($this->settings['export'] == 'single' && is_single() ) || | |
| 717 | + ($this->settings['export'] == 'list' && !is_single() ) | |
| 718 | + )) { | |
| 1312 | 719 | |
| 1313 | - if ( | |
| 1314 | - !is_admin() | |
| 1315 | - && ( // Export when setting | |
| 1316 | - $this->settings['export_when'] == 'both' || | |
| 1317 | - ( $this->settings['export_when'] == 'future' && $this->is_future($event) ) || | |
| 1318 | - ( $this->settings['export_when'] == 'past' && $this->is_past($event) ) | |
| 1319 | - ) | |
| 1320 | - && ( // Export setting | |
| 1321 | - $this->settings['export'] == 'both' || | |
| 1322 | - ($this->settings['export'] == 'single' && is_single() ) || | |
| 1323 | - ($this->settings['export'] == 'list' && !is_single() ) | |
| 1324 | - ) | |
| 1325 | - ) { | |
| 1326 | - // Export event | |
| 1327 | - $title = urlencode($post->post_title); | |
| 1328 | - $address = urlencode($post->address); | |
| 1329 | - $desc = urlencode($event->description."\n\n".$post->permalink); | |
| 1330 | - $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'); | |
| 1331 | - $d_s = date("Ymd", $event->time_start) . ($allday ? '' : 'T' . date("His", $event->time_start)); | |
| 1332 | - $d_e = date("Ymd", $event->time_end) . ($allday ? '' : 'T' . date("His", $event->time_end)); | |
| 1333 | - $uid = $post->ID . '-' . $post->blog_id; | |
| 1334 | - $url = $event->permalink; | |
| 720 | + // Export event | |
| 721 | + $title = urlencode($post->post_title); | |
| 722 | + $address = urlencode($post->address); | |
| 723 | + $url = urlencode($post->guid); | |
| 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)); | |
| 727 | + $uid = $post->ID . '-' . $post->blog_id; | |
| 1335 | 728 | |
| 1336 | - // format de date ICS | |
| 1337 | - $permalink_structure = get_option( 'permalink_structure' ); | |
| 1338 | - if($permalink_structure != ""){ | |
| 1339 | - $ics_url = site_url('eventpost/'.$event->ID.'.ics'); | |
| 1340 | - $vcs_url = site_url('eventpost/'.$event->ID.'.vcs'); | |
| 1341 | - } | |
| 1342 | - else{ | |
| 1343 | - $ics_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'ics'), admin_url('admin-ajax.php')); | |
| 1344 | - $vcs_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'vcs'), admin_url('admin-ajax.php')); | |
| 729 | + // format de date ICS | |
| 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__)); | |
| 1345 | 740 | |
| 1346 | - } | |
| 741 | + // format de date Google cal | |
| 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'); | |
| 1347 | 754 | |
| 1348 | - // format de date Google cal | |
| 1349 | - //$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'; | |
| 1350 | - $google_url = add_query_arg(array( | |
| 1351 | - 'action'=>'TEMPLATE', | |
| 1352 | - 'trp'=>'false', | |
| 1353 | - 'sprop'=>'name', | |
| 1354 | - 'text'=>$title, | |
| 1355 | - 'dates'=>$d_s.'/'.$d_e.'', // Removed Z to fix TZ issue | |
| 1356 | - 'location'=>$address, | |
| 1357 | - 'details'=>$desc, | |
| 1358 | - 'gmt'=> urlencode($gmt_offset) | |
| 1359 | - ), 'https://www.google.com/calendar/event'); | |
| 1360 | - if(!empty($timezone_string)){ | |
| 1361 | - $google_url = add_query_arg(array( | |
| 1362 | - 'ctz'=>$timezone_string, | |
| 1363 | - ), $google_url); | |
| 1364 | - } | |
| 755 | + // format de date VCS | |
| 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__)); | |
| 766 | + $dates.=' | |
| 767 | + <span class="eventpost-date-export"> | |
| 768 | + <a href="' . $ics_url . '" class="event_link ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a> | |
| 769 | + <a href="' . $google_url . '" class="event_link gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a> | |
| 770 | + <a href="' . $vcs_url . '" class="event_link vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a> | |
| 771 | + <i class="dashicons-before dashicons-calendar"></i> | |
| 772 | + </span>'; | |
| 773 | + } | |
| 774 | + } | |
| 775 | + return apply_filters('eventpost_printdate', $dates); | |
| 776 | + } | |
| 1365 | 777 | |
| 1366 | - $dates.=' | |
| 1367 | - <span class="eventpost-date-export"> | |
| 1368 | - <a href="' . $ics_url . '" class="event_link event-export ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a> | |
| 1369 | - <a href="' . $google_url . '" class="event_link event-export gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a> | |
| 1370 | - <a href="' . $vcs_url . '" class="event_link event-export vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a> | |
| 1371 | - <i class="dashicons-before dashicons-calendar"></i> | |
| 1372 | - </span>'; | |
| 1373 | - } | |
| 1374 | - } | |
| 1375 | - } | |
| 1376 | - return apply_filters('eventpost_printdate', $dates); | |
| 1377 | - } | |
| 778 | + /** | |
| 779 | + * | |
| 780 | + * @param WP_Post object $post | |
| 781 | + * @return string | |
| 782 | + */ | |
| 783 | + public function print_location($post=null, $context='') { | |
| 784 | + $location = ''; | |
| 785 | + if ($post == null) | |
| 786 | + $post = get_post(); | |
| 787 | + elseif (is_numeric($post)) { | |
| 788 | + $post = get_post($post); | |
| 789 | + } | |
| 790 | + if (!isset($post->start)) { | |
| 791 | + $post = $this->retreive($post); | |
| 792 | + } | |
| 793 | + $address = $post->address; | |
| 794 | + $lat = $post->lat; | |
| 795 | + $long = $post->long; | |
| 796 | + $color = $post->color; | |
| 1378 | 797 | |
| 1379 | - /** | |
| 1380 | - * Outputs location of an event | |
| 1381 | - * | |
| 1382 | - * @param WP_Post object $post | |
| 1383 | - * | |
| 1384 | - * @return string | |
| 1385 | - */ | |
| 1386 | - public function print_location($post=null, $context='') { | |
| 1387 | - $location = ''; | |
| 1388 | - if ($post == null) | |
| 1389 | - $post = get_post(); | |
| 1390 | - elseif (is_numeric($post)) { | |
| 1391 | - $post = get_post($post); | |
| 1392 | - } | |
| 1393 | - if (!isset($post->start)) { | |
| 1394 | - $post = $this->retreive($post); | |
| 1395 | - } | |
| 1396 | - if ($post != false){ | |
| 1397 | - $this->map_id++; | |
| 1398 | - $address = $post->address; | |
| 1399 | - $lat = $post->lat; | |
| 1400 | - $long = $post->long; | |
| 1401 | - $color = $this->get_post_color($post->ID, $this->settings['default_color'], true); | |
| 1402 | - $icon = $this->DashIcons->icons[$this->get_post_icon($post->ID, $this->settings['default_icon'], true)]; | |
| 1403 | - $virtual_location = $post->virtual_location; | |
| 1404 | - $attendance_mode = $post->attendance_mode; | |
| 798 | + if ($address != '' || ($lat != '' && $long != '')) { | |
| 799 | + $location.="\t\t\t\t".'<address'; | |
| 800 | + if ($lat != '' && $long != '') { | |
| 801 | + $location.=' data-id="' . $post->ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" '; | |
| 802 | + } | |
| 803 | + $location.=' itemprop="adr">' | |
| 804 | + . "\n\t\t\t\t\t\t\t".'<span>' | |
| 805 | + . "\n".$address | |
| 806 | + . "\n\t\t\t\t\t\t\t". '</span>'; | |
| 807 | + if ($context=='single' && $lat != '' && $long != '') { | |
| 808 | + $location.="\n\t\t\t\t\t\t\t".'<a class="event_link gps dashicons-before dashicons-location-alt" href="https://www.openstreetmap.org/?lat=' . $lat.='&lon=' . $long.='&zoom=13" target="_blank" itemprop="geo">' . __('Map', 'event-post') . '</a>'; | |
| 809 | + } | |
| 810 | + $location.="\n\t\t\t\t\t\t".'</address>'; | |
| 811 | + } | |
| 1405 | 812 | |
| 1406 | - if ($this->is_online($post) && $virtual_location) { | |
| 1407 | - $location.="\t\t\t\t".'<div><a href="'.esc_url($virtual_location).'" class="eventpost-virtual-location-link" target="_blank" rel="noopener">' | |
| 1408 | - .__('Join link', 'event-post') | |
| 1409 | - .'</a></div>' | |
| 1410 | - ."\n"; | |
| 1411 | - } | |
| 1412 | - if ($this->is_offline($post) && ($address != '' || ($lat != '' && $long != ''))) { | |
| 1413 | - $location.="\t\t\t\t".'<address'; | |
| 1414 | - if ($lat != '' && $long != '') { | |
| 1415 | - $geo_attributes = ' data-latitude="' . esc_attr($lat) . '" | |
| 1416 | - data-longitude="' . esc_attr($long) . '" | |
| 1417 | - data-marker="' . esc_attr($this->get_marker($color)) . '" | |
| 1418 | - data-iconcode="' .esc_attr($icon). '" | |
| 1419 | - data-icon="' . esc_attr(mb_convert_encoding('&#x'.$icon.';', 'UTF-8', 'HTML-ENTITIES')). '" | |
| 1420 | - data-color="#' . esc_attr($color). '" | |
| 1421 | - data-id="' . $post->ID . '-'.$this->map_id.'"'; | |
| 1422 | - $location.=' '.$geo_attributes; | |
| 1423 | - } | |
| 1424 | - $location.=' itemprop="adr" class="eventpost-address">' | |
| 1425 | - . "\n\t\t\t\t\t\t\t".'<span>' | |
| 1426 | - . "\n".$address | |
| 1427 | - . "\n\t\t\t\t\t\t\t". '</span>'; | |
| 1428 | - if ($context=='single' && $lat != '' && $long != '') { | |
| 1429 | - $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=' . esc_attr($lat) .'&lon=' . esc_attr($long) . '&zoom=13" target="_blank" itemprop="geo" ' . $geo_attributes . '>' . __('Map', 'event-post') . '</a>'; | |
| 1430 | - } | |
| 1431 | - $location.="\n\t\t\t\t\t\t".'</address>'; | |
| 1432 | - if (wp_is_mobile() && $lat != '' && $long != '') { | |
| 1433 | - $location.="\n\t\t\t\t\t\t".'<a class="event_link gps-geo-link" href="geo:' . esc_attr($lat) . ',' . esc_attr($long) . '" target="_blank" itemprop="geo" ' . $geo_attributes . '><i class="dashicons-before dashicons-location"></i> ' . __('Open in app', 'event-post') . '</a>'; | |
| 1434 | - } | |
| 1435 | - } | |
| 1436 | - } | |
| 1437 | - return apply_filters('eventpost_printlocation', $location); | |
| 1438 | - } | |
| 813 | + return apply_filters('eventpost_printlocation', $location); | |
| 814 | + } | |
| 1439 | 815 | |
| 1440 | - /** | |
| 1441 | - * Compute darkness of the color | |
| 1442 | - * | |
| 1443 | - * @param string $color | |
| 1444 | - * | |
| 1445 | - * @return float | |
| 1446 | - */ | |
| 1447 | - public function color_darkness($color){ | |
| 1448 | - $color = str_replace('#', '', $color); | |
| 1449 | - $rgb = array(); | |
| 1450 | - for ($x=0;$x<3;$x++) { | |
| 1451 | - $rgb[$x] = hexdec(substr($color,(2*$x),2)); | |
| 1452 | - } | |
| 1453 | - return (max($rgb) + min($rgb)) / 510; | |
| 1454 | - } | |
| 816 | + /** | |
| 817 | + * | |
| 818 | + * @param WP_Post object $post | |
| 819 | + * @return string | |
| 820 | + */ | |
| 821 | + public function print_categories($post=null, $context='') { | |
| 822 | + if ($post == null) | |
| 823 | + $post = get_post(); | |
| 824 | + elseif (is_numeric($post)) { | |
| 825 | + $post = get_post($post); | |
| 826 | + } | |
| 827 | + if (!isset($post->start)) { | |
| 828 | + $post = $this->retreive($post); | |
| 829 | + } | |
| 830 | + $cats = ''; | |
| 831 | + $categories = $post->categories; | |
| 832 | + if ($categories) { | |
| 833 | + $cats.="\t\t\t\t".'<span class="event_category"'; | |
| 834 | + $color = $post->color; | |
| 835 | + if ($color != '') { | |
| 836 | + $cats.=' style="color:#' . $color . '"'; | |
| 837 | + } | |
| 838 | + $cats.='>'; | |
| 839 | + foreach ($categories as $category) { | |
| 840 | + $cats .= $category->name . ' '; | |
| 841 | + } | |
| 842 | + $cats.='</span>'; | |
| 843 | + } | |
| 844 | + return $cats; | |
| 845 | + } | |
| 1455 | 846 | |
| 1456 | - /** | |
| 1457 | - * Outputs categories of an event | |
| 1458 | - * | |
| 1459 | - * @param WP_Post object $post | |
| 1460 | - * | |
| 1461 | - * @return string | |
| 1462 | - */ | |
| 1463 | - public function print_categories($post=null, $context='') { | |
| 1464 | - if ($post == null) | |
| 1465 | - $post = get_post(); | |
| 1466 | - elseif (is_numeric($post)) { | |
| 1467 | - $post = get_post($post); | |
| 1468 | - } | |
| 1469 | - if (!isset($post->start)) { | |
| 1470 | - $post = $this->retreive($post); | |
| 1471 | - } | |
| 1472 | - $cats = ''; | |
| 1473 | - if ($post != false){ | |
| 1474 | - $categories = $post->Taxonomies; | |
| 1475 | - if ($categories) { | |
| 1476 | - $cats.="\t\t\t\t".'<span class="event_categories">'; | |
| 847 | + /** | |
| 848 | + * Generate, return or output date event datas | |
| 849 | + * @param WP_Post object $post | |
| 850 | + * @param string $class | |
| 851 | + * @filter eventpost_get_single | |
| 852 | + * @return string | |
| 853 | + */ | |
| 854 | + public function get_single($post = null, $class = '', $context='') { | |
| 855 | + if ($post == null) { | |
| 856 | + $post = $this->retreive(); | |
| 857 | + } | |
| 858 | + $datas_date = $this->print_date($post, null, $context); | |
| 859 | + $datas_cat = $this->print_categories($post, $context); | |
| 860 | + $datas_loc = $this->print_location($post, $context); | |
| 861 | + if ($datas_date != '' || $datas_loc != '') { | |
| 862 | + $rgb = $this->hex2dec($post->color); | |
| 863 | + return '<div class="event_data ' . $class . '" style="border-left-color:#' . $post->color . ';background:rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ',0.1)" itemscope itemtype="http://microformats.org/profile/hcard">' | |
| 864 | + . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post) | |
| 865 | + . '</div>'; | |
| 866 | + } | |
| 867 | + return ''; | |
| 868 | + } | |
| 1477 | 869 | |
| 1478 | - foreach ($categories as $category) { | |
| 1479 | - $cats.="\t\t\t\t\t".'<span '; | |
| 1480 | - $classes = array('event-term', 'event_term_category'); | |
| 1481 | - $darkness = 0; | |
| 1482 | - $color = $this->Taxonomies->get_taxonomy_color($category->term_id); | |
| 1483 | - if ($color != '' && $color) { | |
| 1484 | - $cats.=' style="background-color:#' . $color . '"'; | |
| 870 | + /** | |
| 871 | + * Displays dates of a gieven post | |
| 872 | + * @param WP_Post object $post | |
| 873 | + * @param string $class | |
| 874 | + * @return string | |
| 875 | + */ | |
| 876 | + public function get_singledate($post = null, $class = '', $context='') { | |
| 877 | + return '<div class="event_data event_date ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_date($post, null, $context) . "\n\t\t\t\t\t".'</div><!-- .event_date -->'; | |
| 878 | + } | |
| 1485 | 879 | |
| 1486 | - $darkness = $this->color_darkness($color); | |
| 1487 | - if($darkness < 0.5){ | |
| 1488 | - array_push($classes, 'event-post-bg-dark'); | |
| 1489 | - } | |
| 1490 | - else{ | |
| 1491 | - array_push($classes, 'event-post-bg-light'); | |
| 1492 | - } | |
| 880 | + /** | |
| 881 | + * Displays coloured terms of a given post | |
| 882 | + * @param WP_Post object $post | |
| 883 | + * @param string $class | |
| 884 | + * @return string | |
| 885 | + */ | |
| 886 | + public function get_singlecat($post = null, $class = '', $context='') { | |
| 887 | + return '<div class="event_data event_category ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_categories($post, $context) . "\n\t\t\t\t\t".'</div><!-- .event_category -->'; | |
| 888 | + } | |
| 1493 | 889 | |
| 1494 | - } | |
| 1495 | - $cats.=' class="'.implode(' ', $classes).'">'; | |
| 1496 | - $cats .= $category->name . ' '; | |
| 1497 | - $cats.='</span>'; | |
| 1498 | - } | |
| 1499 | - $cats.='</span>'; | |
| 1500 | - } | |
| 1501 | - } | |
| 1502 | - return $cats; | |
| 1503 | - } | |
| 890 | + /** | |
| 891 | + * Displays location of a given post | |
| 892 | + * @param WP_Post object $post | |
| 893 | + * @param string $class | |
| 894 | + * @return string | |
| 895 | + */ | |
| 896 | + public function get_singleloc($post = null, $class = '', $context='') { | |
| 897 | + return '<div class="event_data event_location ' . $class . '" itemscope itemtype="http://microformats.org/profile/hcard">' . "\n\t\t".$this->print_location($post, $context) . "\n\t\t\t\t\t".'</div><!-- .event_location -->'; | |
| 898 | + } | |
| 1504 | 899 | |
| 1505 | - /** | |
| 1506 | - * Generate, return or output date event datas | |
| 1507 | - * | |
| 1508 | - * @param WP_Post object $post | |
| 1509 | - * @param string $class | |
| 1510 | - * | |
| 1511 | - * @filter eventpost_get_single | |
| 1512 | - * | |
| 1513 | - * @return string | |
| 1514 | - */ | |
| 1515 | - public function get_single($post = null, $class = '', $context='') { | |
| 1516 | - if ($post == null) { | |
| 1517 | - $post = $this->retreive(); | |
| 1518 | - } | |
| 1519 | - if ($post != null){ | |
| 1520 | - $datas_date = $this->print_date($post, null, $context); | |
| 1521 | - $datas_cat = $this->print_categories($post, $context); | |
| 1522 | - $datas_loc = $this->print_location($post, $context); | |
| 1523 | - $classes = array( | |
| 1524 | - 'event_data', | |
| 1525 | - 'status-'.strtolower(str_replace('Event', '', $post->status)), | |
| 1526 | - 'location-type-'.strtolower(str_replace('EventAttendanceMode', '', $post->attendance_mode)), | |
| 1527 | - $class | |
| 1528 | - ); | |
| 1529 | - if ($datas_date != '' || $datas_loc != '') { | |
| 1530 | - $rgb = $this->hex2dec($post->color); | |
| 1531 | - return '<div class="' . implode(' ', $classes) . '" style="border-left-color:#' . $post->color . ';background:rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ',0.1)" itemscope itemtype="http://microformats.org/profile/hcard">' | |
| 1532 | - . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post) | |
| 1533 | - . '</div>'; | |
| 1534 | - } | |
| 1535 | - } | |
| 1536 | - return ''; | |
| 1537 | - } | |
| 900 | + /** | |
| 901 | + * Uses `the_content` filter to add event details before or after the content of the current post | |
| 902 | + * @param string $content | |
| 903 | + * @return string | |
| 904 | + */ | |
| 905 | + public function display_single($content) { | |
| 906 | + if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){ | |
| 907 | + return $content; | |
| 908 | + } | |
| 1538 | 909 | |
| 1539 | - /** | |
| 1540 | - * Displays dates of a gieven post | |
| 1541 | - * | |
| 1542 | - * @param WP_Post object $post | |
| 1543 | - * @param string $class | |
| 1544 | - * | |
| 1545 | - * @return string | |
| 1546 | - */ | |
| 1547 | - public function get_singledate($post = null, $class = '', $context='') { | |
| 1548 | - 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 -->'; | |
| 1549 | - } | |
| 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(); | |
| 919 | + return $content; | |
| 920 | + } | |
| 1550 | 921 | |
| 1551 | - /** | |
| 1552 | - * Displays coloured terms of a given post | |
| 1553 | - * | |
| 1554 | - * @param WP_Post object $post | |
| 1555 | - * @param string $class | |
| 1556 | - * | |
| 1557 | - * @return string | |
| 1558 | - */ | |
| 1559 | - public function get_singlecat($post = null, $class = '', $context='') { | |
| 1560 | - 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 -->'; | |
| 1561 | - } | |
| 922 | + /** | |
| 923 | + * Outputs events details (dates, geoloc, terms) of given post | |
| 924 | + * @param WP_Post object $post | |
| 925 | + * @echoes string | |
| 926 | + * @return void | |
| 927 | + */ | |
| 928 | + public function print_single($post = null) { | |
| 929 | + echo $this->get_single($post); | |
| 930 | + } | |
| 1562 | 931 | |
| 1563 | - /** | |
| 1564 | - * Displays location of a given post | |
| 1565 | - * | |
| 1566 | - * @param WP_Post object $post | |
| 1567 | - * @param string $class | |
| 1568 | - * | |
| 1569 | - * @return string | |
| 1570 | - */ | |
| 1571 | - public function get_singleloc($post = null, $class = '', $context='') { | |
| 1572 | - 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 -->'; | |
| 1573 | - } | |
| 1574 | - | |
| 1575 | - /** | |
| 1576 | - * Uses `the_content` filter to add event details before or after the content of the current post | |
| 1577 | - * | |
| 1578 | - * @param string $content | |
| 1579 | - * | |
| 1580 | - * @return string | |
| 1581 | - */ | |
| 1582 | - public function display_single($content) { | |
| 1583 | - if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){ | |
| 1584 | - return $content; | |
| 1585 | - } | |
| 1586 | - | |
| 1587 | - $post = $this->retreive(); | |
| 1588 | - if($post != false){ | |
| 1589 | - // If the post is a product, don't display the event bar, use product tab instead | |
| 1590 | - if($post->post_type=='product'){ | |
| 1591 | - return $content; | |
| 1592 | - } | |
| 1593 | - | |
| 1594 | - $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post); | |
| 1595 | - if($this->settings['singlepos']=='before'){ | |
| 1596 | - $content=$eventbar.$content; | |
| 1597 | - } | |
| 1598 | - elseif($this->settings['singlepos']=='after'){ | |
| 1599 | - $content.=$eventbar; | |
| 1600 | - } | |
| 1601 | - $this->load_map_scripts(); | |
| 1602 | - } | |
| 1603 | - return $content; | |
| 1604 | - } | |
| 1605 | - | |
| 1606 | - /** | |
| 1607 | - * Outputs events details (dates, geoloc, terms) of given post | |
| 1608 | - * | |
| 1609 | - * @param WP_Post object $post | |
| 1610 | - * | |
| 1611 | - * @return void | |
| 1612 | - */ | |
| 1613 | - public function print_single($post = null) { | |
| 1614 | - echo wp_kses_post($this->get_single($post)); | |
| 1615 | - } | |
| 1616 | - | |
| 1617 | - /** | |
| 1618 | - * Alter the post title in order to add icons if needed | |
| 1619 | - * | |
| 1620 | - * @param string $title | |
| 1621 | - * | |
| 1622 | - * @return string | |
| 1623 | - */ | |
| 1624 | - public function the_title($title, $post_id = null){ | |
| 932 | + /** | |
| 933 | + * Alter the post title in order to add icons if needed | |
| 934 | + * @param string $title | |
| 935 | + * @return string | |
| 936 | + */ | |
| 937 | + public function the_title($title, $post_id = null){ | |
| 1625 | 938 | if(!$post_id || !in_the_loop() || !$this->settings['loopicons']){ |
| 1626 | - return $title; | |
| 939 | + return $title; | |
| 1627 | 940 | } |
| 1628 | - $icons_ = array( | |
| 1629 | - // Emojis | |
| 1630 | - 1=>array('🗓', '🗺'), | |
| 1631 | - // Dashicons | |
| 1632 | - 2=>array('<span class="dashicons dashicons-calendar"></span>', '<span class="dashicons dashicons-location"></span>'), | |
| 1633 | - ); | |
| 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 | + ); | |
| 1634 | 947 | |
| 1635 | 948 | $event = $this->retreive($post_id); |
| 1636 | - if ($event !== false){ | |
| 1637 | - if(!empty($event->start)){ | |
| 1638 | - $title .= ' '.$icons_[$this->settings['loopicons']][0]; | |
| 1639 | - } | |
| 1640 | - if(!empty($event->lat) && !empty($event->long)){ | |
| 1641 | - $title .= ' '.$icons_[$this->settings['loopicons']][1]; | |
| 1642 | - } | |
| 949 | + if(!empty($event->start)){ | |
| 950 | + $title .= ' '.$icons_[$this->settings['loopicons']][0]; | |
| 1643 | 951 | } |
| 952 | + if(!empty($event->lat) && !empty($event->long)){ | |
| 953 | + $title .= ' '.$icons_[$this->settings['loopicons']][1]; | |
| 954 | + } | |
| 1644 | 955 | return $title; |
| 1645 | - } | |
| 956 | + } | |
| 1646 | 957 | |
| 1647 | 958 | |
| 1648 | - function get_price($event,$html=false){ | |
| 1649 | - $price = ''; | |
| 1650 | - $text_price = $price; | |
| 1651 | - if($event->post_type == 'product'){ | |
| 1652 | - $product_id = $event->ID; | |
| 1653 | - $product = wc_get_product($product_id); | |
| 1654 | - $price = $product->get_price(); | |
| 1655 | - $currency = get_woocommerce_currency_symbol(); | |
| 1656 | - if($product->get_sale_price() != ""){ | |
| 1657 | - $old_price = $product->get_regular_price(); | |
| 1658 | - $text_price = '<span class="event_price"><del>'.$old_price . $currency . '</del> '.$price. $currency. '</span>'; | |
| 1659 | - } else { | |
| 1660 | - $text_price = '<span class="event_price"> '.$price . $currency.'</span>'; | |
| 1661 | - } | |
| 1662 | - } | |
| 1663 | - if ($html == true) { | |
| 1664 | - return $text_price; | |
| 1665 | - } else { | |
| 1666 | - return $price; | |
| 1667 | - } | |
| 1668 | - } | |
| 1669 | - | |
| 1670 | - /** | |
| 1671 | - * Return an HTML list of events | |
| 1672 | - * | |
| 1673 | - * @param array $atts | |
| 1674 | - * @param string $id | |
| 1675 | - * @param string $context | |
| 1676 | - * | |
| 1677 | - * @filter eventpost_params($defaults, 'list_events') | |
| 1678 | - * @filter eventpost_listevents | |
| 1679 | - * @filter eventpost_item_scheme_entities | |
| 1680 | - * @filter eventpost_item_scheme_values | |
| 1681 | - * | |
| 1682 | - * @return string | |
| 1683 | - */ | |
| 1684 | - public function list_events($atts, $id = 'event_list', $context='') { | |
| 959 | + /** | |
| 960 | + * Return an HTML list of events | |
| 961 | + * | |
| 962 | + * @filter eventpost_params($defaults, 'list_events') | |
| 963 | + * @filter eventpost_listevents | |
| 964 | + * @filter eventpost_item_scheme_entities | |
| 965 | + * @filter eventpost_item_scheme_values | |
| 966 | + * | |
| 967 | + * @param array $atts | |
| 968 | + * @param string $id | |
| 969 | + * @param string $context | |
| 970 | + * @return string | |
| 971 | + */ | |
| 972 | + public function list_events($atts, $id = 'event_list', $context='') { | |
| 1685 | 973 | $ep_settings = $this->settings; |
| 1686 | - $defaults = array( | |
| 1687 | - 'nb' => 0, | |
| 1688 | - 'nb_desktop' => 0, | |
| 1689 | - 'nb_tablet' => 0, | |
| 1690 | - 'nb_mobile' => 0, | |
| 1691 | - 'type' => 'div', | |
| 1692 | - 'future' => true, | |
| 1693 | - 'past' => false, | |
| 1694 | - 'geo' => 0, | |
| 1695 | - 'width' => '', | |
| 1696 | - 'height' => '', | |
| 1697 | - 'list' => 0, | |
| 1698 | - 'zoom' => '', | |
| 1699 | - 'map_position' => 'false', | |
| 1700 | - 'latitude' => '', | |
| 1701 | - 'longitude' => '', | |
| 1702 | - 'tile' => $ep_settings['tile'], | |
| 1703 | - 'pop_element_schema' => 'false', | |
| 1704 | - 'htmlPop_element_schema' => '', | |
| 1705 | - 'title' => '', | |
| 1706 | - 'before_title' => '<h3>', | |
| 1707 | - 'after_title' => '</h3>', | |
| 1708 | - 'cat' => '', | |
| 1709 | - 'tag' => '', | |
| 1710 | - 'tax_name' => '', | |
| 1711 | - 'tax_term' => '', | |
| 1712 | - 'events' => '', | |
| 1713 | - 'style' => '', | |
| 1714 | - 'thumbnail' => '', | |
| 1715 | - 'thumbnail_size' => '', | |
| 1716 | - 'excerpt' => '', | |
| 1717 | - 'orderby' => 'meta_value', | |
| 1718 | - 'order' => 'ASC', | |
| 1719 | - 'class' => '', | |
| 1720 | - 'align' => '', | |
| 1721 | - 'className' => '', | |
| 1722 | - 'container_schema' => $this->list_shema['container'], | |
| 1723 | - 'item_schema' => $this->list_shema['item'], | |
| 1724 | - 'pages' => false, | |
| 1725 | - 'paged' => '', | |
| 1726 | - 'separate_years' => false, | |
| 1727 | - 'separate_months' => false, | |
| 1728 | - ); | |
| 1729 | - // Map UI options | |
| 1730 | - foreach($this->map_interactions as $int_key=>$int_name){ | |
| 1731 | - $defaults[$int_key]=true; | |
| 1732 | - } | |
| 1733 | - $atts_old_nb = $defaults['nb']; | |
| 1734 | - if($id == "event_timeline"){ | |
| 1735 | - $atts_old_nb = intval($atts['nb']); | |
| 1736 | - $atts['nb'] = -1; | |
| 1737 | - } | |
| 974 | + $defaults = array( | |
| 975 | + 'nb' => 0, | |
| 976 | + 'type' => 'div', | |
| 977 | + 'future' => true, | |
| 978 | + 'past' => false, | |
| 979 | + 'geo' => 0, | |
| 980 | + 'width' => '', | |
| 981 | + 'height' => '', | |
| 982 | + 'zoom' => '', | |
| 983 | + 'tile' => $ep_settings['tile'], | |
| 984 | + 'title' => '', | |
| 985 | + 'before_title' => '<h3>', | |
| 986 | + 'after_title' => '</h3>', | |
| 987 | + 'cat' => '', | |
| 988 | + 'tag' => '', | |
| 989 | + 'events' => '', | |
| 990 | + 'style' => '', | |
| 991 | + 'thumbnail' => '', | |
| 992 | + 'thumbnail_size' => '', | |
| 993 | + 'excerpt' => '', | |
| 994 | + 'orderby' => 'meta_value', | |
| 995 | + 'order' => 'ASC', | |
| 996 | + 'class' => '', | |
| 997 | + 'container_schema' => $this->list_shema['container'], | |
| 998 | + 'item_schema' => $this->list_shema['item'], | |
| 999 | + ); | |
| 1000 | + // Map UI options | |
| 1001 | + foreach($this->map_interactions as $int_key=>$int_name){ | |
| 1002 | + $defaults[$int_key]=true; | |
| 1003 | + } | |
| 1004 | + $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events'), $atts); | |
| 1738 | 1005 | |
| 1739 | - $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events', $context), $atts); | |
| 1006 | + extract($atts); | |
| 1007 | + if (!is_array($events)) { | |
| 1008 | + $events = $this->get_events($atts); | |
| 1009 | + } | |
| 1010 | + $ret = ''; | |
| 1011 | + $this->list_id++; | |
| 1012 | + if (sizeof($events) > 0) { | |
| 1013 | + if (!empty($title)) { | |
| 1014 | + $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title); | |
| 1015 | + } | |
| 1740 | 1016 | |
| 1741 | - extract($atts); | |
| 1742 | - if (!is_array($events)) { | |
| 1743 | - $events = $this->get_events($atts); | |
| 1744 | - } | |
| 1017 | + $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div'; | |
| 1745 | 1018 | |
| 1746 | - $ret = ''; | |
| 1747 | - $this->list_id++; | |
| 1748 | - if (sizeof($events) > 0) { | |
| 1749 | - if (!empty($title)) { | |
| 1750 | - $ret .= wp_kses_post($before_title . esc_html($title) . $after_title); | |
| 1751 | - } | |
| 1019 | + $list = ''; | |
| 1752 | 1020 | |
| 1753 | - $type = in_array($type, ['div', 'ul', 'ol']) ? $type : 'div'; | |
| 1754 | - $child = in_array($type, ['ul', 'ol']) ? 'li' : 'div'; | |
| 1021 | + if($id=='event_geolist'){ | |
| 1022 | + $this->load_map_scripts(); | |
| 1023 | + $list.=sprintf('<%1$s class="event_geolist_icon_loader"><p><span class="dashicons dashicons-location-alt"></span></p><p class="screen-reader-text">'.__('An events map', 'event-post').'</p></%1$s>', $type); | |
| 1024 | + } | |
| 1755 | 1025 | |
| 1756 | - $html = ''; | |
| 1026 | + foreach ($events as $event) { | |
| 1027 | + $class_item = ($event->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past'; | |
| 1028 | + if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) { | |
| 1029 | + $event->permalink = '#' . $id . $this->list_id; | |
| 1030 | + } | |
| 1031 | + elseif(empty($ob->permalink)){ | |
| 1032 | + $event->permalink=$event->guid; | |
| 1033 | + } | |
| 1034 | + $list.=str_replace( | |
| 1035 | + apply_filters('eventpost_item_scheme_entities', array( | |
| 1036 | + '%child%', | |
| 1037 | + '%class%', | |
| 1038 | + '%color%', | |
| 1039 | + '%event_link%', | |
| 1040 | + '%event_thumbnail%', | |
| 1041 | + '%event_title%', | |
| 1042 | + '%event_date%', | |
| 1043 | + '%event_cat%', | |
| 1044 | + '%event_location%', | |
| 1045 | + '%event_excerpt%' | |
| 1046 | + )), apply_filters('eventpost_item_scheme_values', array( | |
| 1047 | + $child, | |
| 1048 | + $class_item, | |
| 1049 | + $event->color, | |
| 1050 | + $event->permalink, | |
| 1051 | + $thumbnail == true ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->root_ID, !empty($thumbnail_size) ? $thumbnail_size : 'thumbnail', array('class' => 'attachment-thumbnail wp-post-image event_thumbnail')) . '</span>' : '', | |
| 1052 | + $event->post_title, | |
| 1053 | + $this->get_singledate($event, '', $context), | |
| 1054 | + $this->get_singlecat($event, '', $context), | |
| 1055 | + $this->get_singleloc($event, '', $context), | |
| 1056 | + $excerpt == true && $event->post_excerpt!='' ? '<span class="event_exerpt">'.$event->post_excerpt.'</span>' : '', | |
| 1057 | + ), $event), $item_schema | |
| 1058 | + ); | |
| 1059 | + } | |
| 1060 | + $attributes = ''; | |
| 1061 | + if($id == 'event_geolist'){ | |
| 1062 | + $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-zoom="'.$zoom.'" data-disabled-interactions="'; | |
| 1063 | + foreach($this->map_interactions as $int_key=>$int_name){ | |
| 1064 | + $attributes.=$atts[$int_key]==false ? $int_key.', ' : ''; | |
| 1065 | + } | |
| 1066 | + $attributes.='"'; | |
| 1067 | + } | |
| 1068 | + $ret.=str_replace( | |
| 1069 | + array( | |
| 1070 | + '%type%', | |
| 1071 | + '%id%', | |
| 1072 | + '%class%', | |
| 1073 | + '%listid%', | |
| 1074 | + '%style%', | |
| 1075 | + '%attributes%', | |
| 1076 | + '%list%' | |
| 1077 | + ), array( | |
| 1078 | + $type, | |
| 1079 | + $id, | |
| 1080 | + $class, | |
| 1081 | + $id . $this->list_id, | |
| 1082 | + (!empty($width) ? 'width:' . $width . ';' : '') . (!empty($height) ? 'height:' . $height . ';' : '') . $style, | |
| 1083 | + $attributes, | |
| 1084 | + $list | |
| 1085 | + ), $container_schema | |
| 1086 | + ); | |
| 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 | + } | |
| 1091 | + return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context); | |
| 1092 | + } | |
| 1757 | 1093 | |
| 1758 | - if($id=='event_geolist'){ | |
| 1759 | - $this->load_map_scripts(); | |
| 1760 | - $html.=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); | |
| 1761 | - } | |
| 1762 | - $attributes = ''; | |
| 1763 | - $prev_arrow = ""; | |
| 1764 | - $next_arrow = ""; | |
| 1765 | - $item_child_style = ""; | |
| 1766 | - if($id == "event_timeline"){ | |
| 1767 | - $prev_arrow = '<div class="previous"><span class="screen-reader-text">'.__('« Previous Events', 'event-post')."</span></div>"; | |
| 1768 | - $next_arrow = '<div class="next"><span class="screen-reader-text">'.__('Next Events »', 'event-post')."</span></div>"; | |
| 1769 | - if($atts_old_nb != 0){ | |
| 1770 | - $item_child_style = 'width : '.((100/$atts_old_nb) - 2).'%;'; | |
| 1771 | - } | |
| 1772 | - $attributes .= ' data-nb="'.$atts_old_nb.'"'; | |
| 1773 | - $attributes .= ' data-nb-desktop="'.intval($atts['nb_desktop'] ?? 0).'"'; | |
| 1774 | - $attributes .= ' data-nb-tablet="'.intval($atts['nb_tablet'] ?? 0).'"'; | |
| 1775 | - $attributes .= ' data-nb-mobile="'.intval($atts['nb_mobile'] ?? 0).'"'; | |
| 1776 | - $attributes .= ' data-filter="'.http_build_query($atts).'" '; | |
| 1777 | - } | |
| 1094 | + /** | |
| 1095 | + * get_events | |
| 1096 | + * @param array $atts | |
| 1097 | + * @filter eventpost_params | |
| 1098 | + * @filter eventpost_get_items | |
| 1099 | + * @return array of post_ids wich are events | |
| 1100 | + */ | |
| 1101 | + public function get_events($atts) { | |
| 1102 | + $requete = (shortcode_atts(apply_filters('eventpost_params', array( | |
| 1103 | + 'nb' => 5, | |
| 1104 | + 'future' => true, | |
| 1105 | + 'past' => false, | |
| 1106 | + 'geo' => 0, | |
| 1107 | + 'cat' => '', | |
| 1108 | + 'tag' => '', | |
| 1109 | + 'date' => '', | |
| 1110 | + 'orderby' => 'meta_value', | |
| 1111 | + 'orderbykey' => $this->META_START, | |
| 1112 | + 'order' => 'ASC', | |
| 1113 | + 'tax_name' => '', | |
| 1114 | + 'tax_term' => '', | |
| 1115 | + 'post_type'=> $this->settings['posttypes'] | |
| 1116 | + ), 'get_events'), $atts)); | |
| 1117 | + extract($requete); | |
| 1118 | + wp_reset_query(); | |
| 1778 | 1119 | |
| 1779 | - if($id === 'event_timeline'){ | |
| 1780 | - $previous_year = $atts['separate_years'] ? true : false; | |
| 1781 | - $previous_month = $atts['separate_months'] ? true : false; | |
| 1782 | - } | |
| 1120 | + $arg = array( | |
| 1121 | + 'post_type' => $post_type, | |
| 1122 | + 'posts_per_page' => $nb, | |
| 1123 | + 'meta_key' => $orderbykey, | |
| 1124 | + 'orderby' => $orderby, | |
| 1125 | + 'order' => $order | |
| 1126 | + ); | |
| 1783 | 1127 | |
| 1784 | - foreach ($events as $event) { | |
| 1785 | - if($id === 'event_timeline'){ | |
| 1786 | - if($previous_year && $previous_year !== date('Y', $event->time_start)){ | |
| 1787 | - $html.= '<div class="event-timeline-separator event-timeline-year"><span class="event-timeline-year-text">'.date_i18n('Y', $event->time_start).'</span></div>'; | |
| 1788 | - $previous_year = date('Y', $event->time_start); | |
| 1789 | - } | |
| 1790 | - if($previous_month && $previous_month !== date('Ym', $event->time_start)){ | |
| 1791 | - $html.= '<div class="event-timeline-separator event-timeline-month"><span class="event-timeline-month-text">'.date_i18n('F', $event->time_start).'</span>'.($previous_year ? '' : ' <span class="event-timeline-year-text">'.date_i18n('Y', $event->time_start).'</span>').'</div>'; | |
| 1792 | - $previous_month = date('Ym', $event->time_start); | |
| 1793 | - } | |
| 1794 | - } | |
| 1795 | - $text_price = $this->get_price($event,true); | |
| 1796 | - $class_item = array( | |
| 1797 | - $this->is_future($event) ? 'event_future' : 'event_past', | |
| 1798 | - 'status-'.strtolower(str_replace('Event', '', $event->status)), | |
| 1799 | - 'location-type-'.strtolower(str_replace('EventAttendanceMode', '', $event->attendance_mode)), | |
| 1800 | - ); | |
| 1801 | - $taxonomies= get_taxonomies('','names'); | |
| 1802 | - $post_terms = []; | |
| 1803 | - $terms = wp_get_post_terms($event->ID, $taxonomies); | |
| 1804 | - foreach($terms as $term){ | |
| 1805 | - $class_item[] = $term->taxonomy.'-'.$term->slug; | |
| 1806 | - } | |
| 1807 | - if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) { | |
| 1808 | - $event->permalink = '#' . $id . $this->list_id; | |
| 1809 | - } | |
| 1810 | - elseif(empty($event->permalink)){ | |
| 1811 | - $event->permalink=$event->guid; | |
| 1812 | - } | |
| 1813 | - $html.=str_replace( | |
| 1814 | - apply_filters('eventpost_item_scheme_entities', array( | |
| 1815 | - '%child%', | |
| 1816 | - '%class%', | |
| 1817 | - '%color%', | |
| 1818 | - '%event_link%', | |
| 1819 | - '%event_thumbnail%', | |
| 1820 | - '%event_title%', | |
| 1821 | - '%event_price%', | |
| 1822 | - '%event_date%', | |
| 1823 | - '%event_cat%', | |
| 1824 | - '%event_location%', | |
| 1825 | - '%event_excerpt%', | |
| 1826 | - '%style%', | |
| 1827 | - )), apply_filters('eventpost_item_scheme_values', array( | |
| 1828 | - $child, | |
| 1829 | - implode(' ', $class_item), | |
| 1830 | - $this->get_post_color($event->ID, $this->settings['default_color'],true), | |
| 1831 | - $event->permalink, | |
| 1832 | - $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>' : '', | |
| 1833 | - $event->post_title, | |
| 1834 | - $event->post_type == 'product' ? $text_price : '', | |
| 1835 | - $this->get_singledate($event, '', $context), | |
| 1836 | - $this->get_singlecat($event, '', $context), | |
| 1837 | - $this->get_singleloc($event, '', $context), | |
| 1838 | - $excerpt == true && $event->description!='' ? '<span class="event_exerpt">'.$event->description.'</span>' : '', | |
| 1839 | - $item_child_style, | |
| 1840 | - ), $event), $item_schema | |
| 1841 | - ); | |
| 1128 | + if($tax_name=='category'){ | |
| 1129 | + $tax_name=''; | |
| 1130 | + $cat=$tax_term; | |
| 1131 | + } | |
| 1132 | + elseif($tax_name=='post-tag'){ | |
| 1133 | + $tax_name=''; | |
| 1134 | + $tag=$tax_term; | |
| 1135 | + } | |
| 1842 | 1136 | |
| 1843 | - } | |
| 1844 | - if($id == 'event_geolist'){ | |
| 1845 | - if($height==''){ | |
| 1846 | - $height = '300px'; | |
| 1847 | - } | |
| 1848 | - if($width==''){ | |
| 1849 | - $width = '100%'; | |
| 1850 | - } | |
| 1851 | - $attributes .= ' data-tile="'.esc_attr($tile).'" | |
| 1852 | - data-width="'.esc_attr($width).'" | |
| 1853 | - data-height="'.esc_attr($height).'" | |
| 1854 | - data-zoom="'.esc_attr($zoom).'" | |
| 1855 | - data-map_position="'.esc_attr($map_position).'" | |
| 1856 | - data-latitude="'.esc_attr($latitude).'" | |
| 1857 | - data-longitude="'.esc_attr($longitude).'" | |
| 1858 | - data-pop_element_schema="'.esc_attr($pop_element_schema).'" | |
| 1859 | - data-htmlPop_element_schema="'.esc_attr($htmlPop_element_schema).'" | |
| 1860 | - data-list="'.esc_attr($list).'" | |
| 1861 | - data-disabled-interactions="'; | |
| 1862 | - // add data-position avec ma variables | |
| 1863 | - foreach($this->map_interactions as $int_key=>$int_name){ | |
| 1864 | - $attributes.=$atts[$int_key]==false ? esc_attr($int_key).', ' : ''; | |
| 1865 | - } | |
| 1866 | - $attributes.='" '; | |
| 1867 | - } | |
| 1868 | - $pagination = ''; | |
| 1869 | - if($pages && $this->pagination){ | |
| 1870 | - global $wp_rewrite; | |
| 1871 | - $paged = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1; | |
| 1872 | - $pagination = paginate_links( array( | |
| 1873 | - 'prev_text' => __('« Previous Events', 'event-post'), | |
| 1874 | - 'next_text' => __('Next Events »', 'event-post'), | |
| 1875 | - 'current' => $paged, | |
| 1876 | - 'total' => $this->pagination['max_num_pages'], | |
| 1877 | - ) | |
| 1878 | - ); | |
| 1879 | - } | |
| 1137 | + // CUSTOM TAXONOMY | |
| 1138 | + if ($tax_name != '' && $tax_term != '') { | |
| 1139 | + $arg[$tax_name] = $tax_term; | |
| 1140 | + } | |
| 1141 | + // CAT | |
| 1142 | + if ($cat != '') { | |
| 1143 | + if (preg_match('/[a-zA-Z]/i', $cat)) { | |
| 1144 | + $arg['category_name'] = $cat; | |
| 1145 | + } else { | |
| 1146 | + $arg['cat'] = $cat; | |
| 1147 | + } | |
| 1148 | + } | |
| 1149 | + // TAG | |
| 1150 | + if ($tag != '') { | |
| 1151 | + $arg['tag'] = $tag; | |
| 1152 | + } | |
| 1153 | + // DATES | |
| 1154 | + $meta_query = array( | |
| 1155 | + array( | |
| 1156 | + 'key' => $this->META_END, | |
| 1157 | + 'value' => '', | |
| 1158 | + 'compare' => '!=' | |
| 1159 | + ), | |
| 1160 | + array( | |
| 1161 | + 'key' => $this->META_END, | |
| 1162 | + 'value' => '0:0:00 0:', | |
| 1163 | + 'compare' => '!=' | |
| 1164 | + ), | |
| 1165 | + array( | |
| 1166 | + 'key' => $this->META_END, | |
| 1167 | + 'value' => ':00', | |
| 1168 | + 'compare' => '!=' | |
| 1169 | + ), | |
| 1170 | + array( | |
| 1171 | + 'key' => $this->META_START, | |
| 1172 | + 'value' => '', | |
| 1173 | + 'compare' => '!=' | |
| 1174 | + ), | |
| 1175 | + array( | |
| 1176 | + 'key' => $this->META_START, | |
| 1177 | + 'value' => '0:0:00 0:', | |
| 1178 | + 'compare' => '!=' | |
| 1179 | + ) | |
| 1180 | + ); | |
| 1181 | + if ($future == 0 && $past == 0) { | |
| 1182 | + $meta_query = array(); | |
| 1183 | + $arg['meta_key'] = null; | |
| 1184 | + $arg['orderby'] = null; | |
| 1185 | + $arg['order'] = null; | |
| 1186 | + } elseif ($future == 1 && $past == 0) { | |
| 1187 | + $meta_query[] = array( | |
| 1188 | + 'key' => $this->META_END, | |
| 1189 | + 'value' => current_time('mysql'), | |
| 1190 | + 'compare' => '>=', | |
| 1191 | + //'type'=>'DATETIME' | |
| 1192 | + ); | |
| 1193 | + } elseif ($future == 0 && $past == 1) { | |
| 1194 | + $meta_query[] = array( | |
| 1195 | + 'key' => $this->META_END, | |
| 1196 | + 'value' => current_time('mysql'), | |
| 1197 | + 'compare' => '<=', | |
| 1198 | + //'type'=>'DATETIME' | |
| 1199 | + ); | |
| 1200 | + } | |
| 1201 | + if ($date != '') { | |
| 1202 | + $date = date('Y-m-d', $date); | |
| 1880 | 1203 | |
| 1881 | - if($context == 'events_only'){ | |
| 1882 | - $ret = $html; | |
| 1883 | - }else{ | |
| 1884 | - $classes = [ | |
| 1885 | - $class, | |
| 1886 | - $className, | |
| 1887 | - 'className', | |
| 1888 | - $id == 'event_geolist' && $list ? ' has-list list-'.esc_attr($list) : ' no-list', | |
| 1889 | - ]; | |
| 1890 | - if(!empty($align)){ | |
| 1891 | - $classes[] = 'align'.esc_attr($align); | |
| 1892 | - } | |
| 1893 | - if($id === 'event_timeline' && ($previous_year || $previous_month)){ | |
| 1894 | - $classes[] = 'has-time-separators'; | |
| 1895 | - } | |
| 1896 | - $ret.=str_replace( | |
| 1897 | - array( | |
| 1898 | - '%type%', | |
| 1899 | - '%id%', | |
| 1900 | - '%class%', | |
| 1901 | - '%listid%', | |
| 1902 | - '%style%', | |
| 1903 | - '%attributes%', | |
| 1904 | - '%list%', | |
| 1905 | - '%pagination%', | |
| 1906 | - '%prev_arrow%', | |
| 1907 | - '%next_arrow%', | |
| 1908 | - '%number%' | |
| 1909 | - ), array( | |
| 1910 | - $type, | |
| 1911 | - $id, | |
| 1912 | - esc_attr(implode(' ', $classes)), | |
| 1913 | - $id . $this->list_id, | |
| 1914 | - (!empty($width) ? 'width:' . esc_attr($width) . ';' : '') . (!empty($height) ? 'height:' . esc_attr($height) . ';' : '') . esc_attr($style), | |
| 1915 | - $attributes, | |
| 1916 | - $html, | |
| 1917 | - $pagination, | |
| 1918 | - $prev_arrow, | |
| 1919 | - $next_arrow | |
| 1920 | - ), $container_schema | |
| 1921 | - ); | |
| 1922 | - } | |
| 1204 | + $meta_query = array( | |
| 1205 | + array( | |
| 1206 | + 'key' => $this->META_END, | |
| 1207 | + 'value' => $date . ' 00:00:00', | |
| 1208 | + 'compare' => '>=', | |
| 1209 | + 'type' => 'DATETIME' | |
| 1210 | + ), | |
| 1211 | + array( | |
| 1212 | + 'key' => $this->META_START, | |
| 1213 | + 'value' => $date . ' 23:59:59', | |
| 1214 | + 'compare' => '<=', | |
| 1215 | + 'type' => 'DATETIME' | |
| 1216 | + ) | |
| 1217 | + ); | |
| 1218 | + } | |
| 1219 | + // GEO | |
| 1220 | + if ($geo == 1) { | |
| 1221 | + $meta_query[] = array( | |
| 1222 | + 'key' => $this->META_LAT, | |
| 1223 | + 'value' => '', | |
| 1224 | + 'compare' => '!=' | |
| 1225 | + ); | |
| 1226 | + $meta_query[] = array( | |
| 1227 | + 'key' => $this->META_LONG, | |
| 1228 | + 'value' => '', | |
| 1229 | + 'compare' => '!=' | |
| 1230 | + ); | |
| 1231 | + $arg['meta_key'] = $this->META_LAT; | |
| 1232 | + $arg['orderby'] = 'meta_value'; | |
| 1233 | + $arg['order'] = 'DESC'; | |
| 1234 | + } | |
| 1923 | 1235 | |
| 1924 | - } | |
| 1925 | - elseif(filter_input(INPUT_POST, 'action')=='bulk_do_shortcode'){ | |
| 1926 | - 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>'; | |
| 1927 | - } | |
| 1928 | - return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context); | |
| 1929 | - } | |
| 1236 | + $arg['meta_query'] = $meta_query; | |
| 1930 | 1237 | |
| 1238 | + $query_md5 = 'eventpost_' . md5(var_export($requete, true)); | |
| 1239 | + // Check if cache is activated | |
| 1240 | + if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) { | |
| 1241 | + return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg); | |
| 1242 | + } | |
| 1931 | 1243 | |
| 1932 | - /** | |
| 1933 | - * Get events | |
| 1934 | - * | |
| 1935 | - * @param array $atts | |
| 1936 | - * | |
| 1937 | - * @filter eventpost_params | |
| 1938 | - * @filter eventpost_get_items | |
| 1939 | - * | |
| 1940 | - * @return array of post_ids which are events | |
| 1941 | - */ | |
| 1942 | - public function get_events($atts) { | |
| 1943 | - if(isset($atts['future'])){ | |
| 1944 | - $atts['future'] = filter_var( $atts['future'], FILTER_VALIDATE_BOOLEAN); | |
| 1945 | - } | |
| 1946 | - if(isset($atts['past'])){ | |
| 1947 | - $atts['past'] = filter_var( $atts['past'], FILTER_VALIDATE_BOOLEAN); | |
| 1948 | - } | |
| 1949 | - if(isset($atts['geo'])){ | |
| 1950 | - $atts['geo'] = filter_var( $atts['geo'], FILTER_VALIDATE_BOOLEAN); | |
| 1951 | - } | |
| 1952 | - if(isset($atts['pages'])){ | |
| 1953 | - $atts['pages'] = filter_var( $atts['pages'], FILTER_VALIDATE_BOOLEAN); | |
| 1954 | - } | |
| 1955 | - | |
| 1956 | - | |
| 1957 | - | |
| 1958 | - $requete = (shortcode_atts(apply_filters('eventpost_params', array( | |
| 1959 | - 'nb' => 5, | |
| 1960 | - 'future' => true, | |
| 1961 | - 'past' => false, | |
| 1962 | - 'geo' => 0, | |
| 1963 | - 'cat' => '', | |
| 1964 | - 'tag' => '', | |
| 1965 | - 'date' => '', | |
| 1966 | - 'orderby' => 'meta_value', | |
| 1967 | - 'orderbykey' => $this->META_START, | |
| 1968 | - 'order' => 'ASC', | |
| 1969 | - 'tax_name' => '', | |
| 1970 | - 'tax_term' => '', | |
| 1971 | - 'paged' => 1, | |
| 1972 | - 'post_type'=> $this->settings['posttypes'] | |
| 1973 | - ), 'get_events'), $atts)); | |
| 1974 | - if(!isset($requete['paged']) || $requete['paged'] == ""){ | |
| 1975 | - $requete['paged'] = ( get_query_var( 'page' ) ) ? absint( get_query_var( 'page' ) ) : 1; | |
| 1976 | - } | |
| 1977 | - extract($requete); | |
| 1978 | - wp_reset_query(); | |
| 1979 | - | |
| 1980 | - | |
| 1981 | - $arg = array( | |
| 1982 | - 'post_status' => 'publish', | |
| 1983 | - 'post_type' => $post_type, | |
| 1984 | - 'posts_per_page' => $nb, | |
| 1985 | - 'paged' => $paged, | |
| 1986 | - 'meta_key' => $orderbykey, | |
| 1987 | - 'orderby' => $orderby, | |
| 1988 | - 'order' => $order | |
| 1989 | - ); | |
| 1990 | - | |
| 1991 | - if($tax_name=='category'){ | |
| 1992 | - $tax_name=''; | |
| 1993 | - $cat=$tax_term; | |
| 1994 | - } | |
| 1995 | - elseif($tax_name=='post-tag'){ | |
| 1996 | - $tax_name=''; | |
| 1997 | - $tag=$tax_term; | |
| 1998 | - } | |
| 1999 | - | |
| 2000 | - // CUSTOM TAXONOMY | |
| 2001 | - if ($tax_name != '' && $tax_term != '') { | |
| 2002 | - $arg['tax_query'] = array( | |
| 2003 | - array( | |
| 2004 | - 'taxonomy' => $tax_name, | |
| 2005 | - 'field' => 'slug', | |
| 2006 | - 'terms' => $tax_term, | |
| 2007 | - ), | |
| 2008 | - ); | |
| 2009 | - } | |
| 2010 | - // CAT | |
| 2011 | - if ($cat != '') { | |
| 2012 | - if (preg_match('/[a-zA-Z]/i', $cat)) { | |
| 2013 | - $arg['category_name'] = $cat; | |
| 2014 | - } else { | |
| 2015 | - $arg['cat'] = $cat; | |
| 2016 | - } | |
| 2017 | - } | |
| 2018 | - // TAG | |
| 2019 | - if ($tag != '') { | |
| 2020 | - $arg['tag'] = $tag; | |
| 2021 | - } | |
| 2022 | - // DATES | |
| 2023 | - $meta_query = array( | |
| 2024 | - array( | |
| 2025 | - 'key' => $this->META_END, | |
| 2026 | - 'value' => '', | |
| 2027 | - 'compare' => '!=' | |
| 2028 | - ), | |
| 2029 | - array( | |
| 2030 | - 'key' => $this->META_END, | |
| 2031 | - 'value' => '0:0:00 0:', | |
| 2032 | - 'compare' => '!=' | |
| 2033 | - ), | |
| 2034 | - array( | |
| 2035 | - 'key' => $this->META_END, | |
| 2036 | - 'value' => ':00', | |
| 2037 | - 'compare' => '!=' | |
| 2038 | - ), | |
| 2039 | - array( | |
| 2040 | - 'key' => $this->META_START, | |
| 2041 | - 'value' => '', | |
| 2042 | - 'compare' => '!=' | |
| 2043 | - ), | |
| 2044 | - array( | |
| 2045 | - 'key' => $this->META_START, | |
| 2046 | - 'value' => '0:0:00 0:', | |
| 2047 | - 'compare' => '!=' | |
| 2048 | - ) | |
| 2049 | - ); | |
| 2050 | - if ($future == 0 && $past == 0) { | |
| 2051 | - $meta_query = array(); | |
| 2052 | - $arg['meta_key'] = null; | |
| 2053 | - $arg['orderby'] = null; | |
| 2054 | - $arg['order'] = null; | |
| 2055 | - } | |
| 2056 | - elseif ($future == 1 && $past == 0) { | |
| 2057 | - $meta_query[] = array( | |
| 2058 | - 'key' => $this->META_END, | |
| 2059 | - 'value' => current_time('mysql'), | |
| 2060 | - 'compare' => '>=', | |
| 2061 | - //'type'=>'DATETIME' | |
| 2062 | - ); | |
| 2063 | - } | |
| 2064 | - elseif ($future == 0 && $past == 1) { | |
| 2065 | - $meta_query[] = array( | |
| 2066 | - 'key' => $this->META_END, | |
| 2067 | - 'value' => current_time('mysql'), | |
| 2068 | - 'compare' => '<=', | |
| 2069 | - //'type'=>'DATETIME' | |
| 2070 | - ); | |
| 2071 | - } | |
| 2072 | - if ($date != '') { | |
| 2073 | - $date = date('Y-m-d', $date); | |
| 2074 | - | |
| 2075 | - $meta_query = array( | |
| 2076 | - array( | |
| 2077 | - 'key' => $this->META_END, | |
| 2078 | - 'value' => $date . ' 00:00:00', | |
| 2079 | - 'compare' => '>=', | |
| 2080 | - 'type' => 'DATETIME' | |
| 2081 | - ), | |
| 2082 | - array( | |
| 2083 | - 'key' => $this->META_START, | |
| 2084 | - 'value' => $date . ' 23:59:59', | |
| 2085 | - 'compare' => '<=', | |
| 2086 | - 'type' => 'DATETIME' | |
| 2087 | - ) | |
| 2088 | - ); | |
| 2089 | - } | |
| 2090 | - // GEO | |
| 2091 | - if ($geo == 1) { | |
| 2092 | - $meta_query[] = array( | |
| 2093 | - 'key' => $this->META_LAT, | |
| 2094 | - 'value' => '', | |
| 2095 | - 'compare' => '!=' | |
| 2096 | - ); | |
| 2097 | - $meta_query[] = array( | |
| 2098 | - 'key' => $this->META_LONG, | |
| 2099 | - 'value' => '', | |
| 2100 | - 'compare' => '!=' | |
| 2101 | - ); | |
| 2102 | - $arg['meta_key'] = $this->META_LAT; | |
| 2103 | - $arg['orderby'] = 'meta_value'; | |
| 2104 | - $arg['order'] = 'DESC'; | |
| 2105 | - } | |
| 2106 | - | |
| 2107 | - $arg['meta_query'] = $meta_query; | |
| 2108 | - | |
| 2109 | - $query_md5 = 'eventpost_' . md5(wp_json_encode($requete, true)); | |
| 2110 | - // Check if cache is activated | |
| 2111 | - if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) { | |
| 2112 | - return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg); | |
| 2113 | - } | |
| 2114 | - | |
| 2115 | - $events = apply_filters('eventpost_get', '', $requete, $arg); | |
| 2116 | - if ('' === $events) { | |
| 2117 | - global $wpdb; | |
| 2118 | - $query = new WP_Query($arg); | |
| 2119 | - $events = $wpdb->get_col($query->request); | |
| 2120 | - $this->pagination = array( | |
| 2121 | - 'found_posts' => $query->found_posts, | |
| 2122 | - 'max_num_pages' => $query->max_num_pages, | |
| 2123 | - ); | |
| 2124 | - foreach ($events as $k => $post) { | |
| 2125 | - $event = $this->retreive($post); | |
| 2126 | - if ($event != false){ | |
| 2127 | - $events[$k] = $event; | |
| 2128 | - } | |
| 2129 | - } | |
| 2130 | - } | |
| 2131 | - if ($this->settings['cache'] == 1){ | |
| 2132 | - set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS); | |
| 2133 | - } | |
| 2134 | - return apply_filters('eventpost_get_items', $events, $requete, $arg); | |
| 1244 | + $events = apply_filters('eventpost_get', '', $requete, $arg); | |
| 1245 | + if ('' === $events) { | |
| 1246 | + global $wpdb; | |
| 1247 | + $query = new WP_Query($arg); | |
| 1248 | + $events = $wpdb->get_col($query->request); | |
| 1249 | + foreach ($events as $k => $post) { | |
| 1250 | + $event = $this->retreive($post); | |
| 1251 | + $events[$k] = $event; | |
| 1252 | + } | |
| 1253 | + } | |
| 1254 | + if ($this->settings['cache'] == 1){ | |
| 1255 | + set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS); | |
| 2135 | 1256 | } |
| 1257 | + return apply_filters('eventpost_get_items', $events, $requete, $arg); | |
| 1258 | + } | |
| 2136 | 1259 | |
| 2137 | - /** | |
| 2138 | - * Checks if the given event is in the future or not | |
| 2139 | - * | |
| 2140 | - * @param object $event | |
| 2141 | - * @param boolean $exact Future status has to be calculated against time or entire day | |
| 2142 | - * | |
| 2143 | - * @return boolean | |
| 2144 | - */ | |
| 2145 | - function is_future($event, $exact=false){ | |
| 2146 | - $match = current_time('timestamp'); | |
| 2147 | - // if EXACT is false, end date is set to begining of the current day | |
| 2148 | - if(!$exact){ | |
| 2149 | - $match = mktime(0, 0, 0, date('m', $match), date('d', $match), date('Y', $match)); | |
| 2150 | - } | |
| 2151 | - return ($event->time_end >= $match); | |
| 1260 | + /** | |
| 1261 | + * | |
| 1262 | + * @param object $event | |
| 1263 | + * @return object | |
| 1264 | + */ | |
| 1265 | + public function retreive($event = null) { | |
| 1266 | + global $EventPost_cache; | |
| 1267 | + $ob = get_post($event); | |
| 1268 | + if($ob->start){ | |
| 1269 | + return $ob; | |
| 1270 | + } | |
| 1271 | + if(isset($EventPost_cache[$ob->ID])){ | |
| 1272 | + return $EventPost_cache[$ob->ID]; | |
| 1273 | + } | |
| 1274 | + $ob->start = get_post_meta($ob->ID, $this->META_START, true); | |
| 1275 | + $ob->end = get_post_meta($ob->ID, $this->META_END, true); | |
| 1276 | + if (!$this->dateisvalid($ob->start)){ | |
| 1277 | + $ob->start = ''; | |
| 2152 | 1278 | } |
| 2153 | - | |
| 2154 | - /** | |
| 2155 | - * Checks if the given event is completed or not | |
| 2156 | - * | |
| 2157 | - * @param object $event | |
| 2158 | - * @param boolean $exact Past status has to be calculated against time or entire day | |
| 2159 | - * | |
| 2160 | - * @return boolean | |
| 2161 | - */ | |
| 2162 | - function is_past($event, $exact=false){ | |
| 2163 | - $match = current_time('timestamp'); | |
| 2164 | - // if EXACT is false or full day event, end date is set to end of the current day | |
| 2165 | - if(!$exact || ( date('H:i:s', $event->time_start) == '00:00:00' && date('H:i:s', $event->time_end) == '00:00:00' )){ | |
| 2166 | - $match = mktime(23, 59, 59, date('m', $match), date('d', $match), date('Y', $match)); | |
| 2167 | - } | |
| 2168 | - return ($event->time_end < $match); | |
| 1279 | + if (!$this->dateisvalid($ob->end)){ | |
| 1280 | + $ob->end = ''; | |
| 1281 | + } | |
| 1282 | + $ob->root_ID = $ob->ID; | |
| 1283 | + $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : ''; | |
| 1284 | + $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : ''; | |
| 1285 | + $ob->address = get_post_meta($ob->ID, $this->META_ADD, true); | |
| 1286 | + $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true); | |
| 1287 | + $ob->long = get_post_meta($ob->ID, $this->META_LONG, true); | |
| 1288 | + $ob->color = get_post_meta($ob->ID, $this->META_COLOR, true); | |
| 1289 | + $ob->categories = get_the_category($ob->ID); | |
| 1290 | + $ob->permalink = get_permalink($ob->ID); | |
| 1291 | + $ob->blog_id = get_current_blog_id(); | |
| 1292 | + if ($ob->color == ''){ | |
| 1293 | + $ob->color = '000000'; | |
| 2169 | 1294 | } |
| 2170 | 1295 | |
| 2171 | - /** | |
| 2172 | - * Checks if an event is online | |
| 2173 | - * | |
| 2174 | - * @param $event | |
| 2175 | - * | |
| 2176 | - * @return boolean | |
| 2177 | - */ | |
| 2178 | - function is_online($event){ | |
| 2179 | - return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OnlineEventAttendanceMode'))); | |
| 2180 | - } | |
| 1296 | + $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob); | |
| 1297 | + return $EventPost_cache[$ob->ID]; | |
| 1298 | + } | |
| 2181 | 1299 | |
| 2182 | - /** | |
| 2183 | - * Checks if an event is offline | |
| 2184 | - * | |
| 2185 | - * @param $event | |
| 2186 | - * | |
| 2187 | - * @return boolean | |
| 2188 | - */ | |
| 2189 | - function is_offline($event){ | |
| 2190 | - return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OfflineEventAttendanceMode'))); | |
| 2191 | - } | |
| 1300 | + /** | |
| 1301 | + * | |
| 1302 | + * @param mixte $_term | |
| 1303 | + * @param string $taxonomy | |
| 1304 | + * @param string $post_type | |
| 1305 | + */ | |
| 1306 | + public function retreive_term($_term=null, $taxonomy='category', $post_type='post') { | |
| 1307 | + $term = get_term($_term, $taxonomy); | |
| 2192 | 1308 | |
| 2193 | - /** | |
| 2194 | - * Populates a WP_Post object with event datas | |
| 2195 | - * | |
| 2196 | - * @param object $event | |
| 2197 | - * | |
| 2198 | - * @return object | |
| 2199 | - */ | |
| 2200 | - public function retreive($event = null) { | |
| 2201 | - global $EventPost_cache; | |
| 2202 | - $ob = get_post($event); | |
| 2203 | - if(!$ob){ | |
| 2204 | - return false; | |
| 2205 | - } | |
| 2206 | - if(is_object($ob) && $ob->start){ | |
| 2207 | - return $ob; | |
| 2208 | - } | |
| 2209 | - if(is_object($ob) && isset($EventPost_cache[$ob->ID])){ | |
| 2210 | - return $EventPost_cache[$ob->ID]; | |
| 2211 | - } | |
| 2212 | - $ob->start = get_post_meta($ob->ID, $this->META_START, true); | |
| 2213 | - $ob->end = get_post_meta($ob->ID, $this->META_END, true); | |
| 2214 | - if (!$this->dateisvalid($ob->start)){ | |
| 2215 | - $ob->start = ''; | |
| 2216 | - } | |
| 2217 | - if (!$this->dateisvalid($ob->end)){ | |
| 2218 | - $ob->end = ''; | |
| 2219 | - } | |
| 2220 | - $ob->root_ID = $ob->ID; | |
| 2221 | - $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : ''; | |
| 2222 | - $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : ''; | |
| 2223 | - $ob->virtual_location = get_post_meta($ob->ID, $this->META_VIRTUAL_LOCATION, true); | |
| 2224 | - $ob->virtual_location = esc_url($ob->virtual_location); | |
| 2225 | - $ob->organization = get_post_meta($ob->ID, $this->META_ORGANIZATION, true); | |
| 2226 | - $ob->offer = get_post_meta($ob->ID, $this->META_OFFER, true); | |
| 2227 | - if(empty($ob->offer)){ | |
| 2228 | - $ob->offer = array( | |
| 2229 | - 'url' => null, | |
| 2230 | - 'price' => null, | |
| 2231 | - 'currency' => null, | |
| 2232 | - ); | |
| 2233 | - } | |
| 2234 | - $ob->address = get_post_meta($ob->ID, $this->META_ADD, true); | |
| 2235 | - $ob->lat = $this->sanitize_coordinate(get_post_meta($ob->ID, $this->META_LAT, true)); | |
| 2236 | - $ob->long = $this->sanitize_coordinate(get_post_meta($ob->ID, $this->META_LONG, true)); | |
| 2237 | - $ob->attendance_mode = (null != $att_mod = get_post_meta($ob->ID, $this->META_ATTENDANCE_MODE, true)) ? $att_mod : array_keys($this->attendance_modes)[0]; | |
| 2238 | - $ob->status = (null != $status = get_post_meta($ob->ID, $this->META_STATUS, true)) ? $status : array_keys($this->statuses)[0]; | |
| 2239 | - $ob->color = $this->get_post_color($ob->ID); | |
| 2240 | - $ob->icon = $this->get_post_icon($ob->ID); | |
| 2241 | - $ob->Taxonomies = get_the_category($ob->ID); | |
| 2242 | - $ob->permalink = get_permalink($ob->ID); | |
| 2243 | - $ob->blog_id = get_current_blog_id(); | |
| 2244 | - $ob->description = $ob->post_excerpt ? $ob->post_excerpt : str_replace(' ', ' ', preg_replace("/\n+/", "\n", trim(wp_strip_all_tags(excerpt_remove_blocks($ob->post_content))))); | |
| 2245 | - $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob); | |
| 2246 | - return $EventPost_cache[$ob->ID]; | |
| 2247 | - } | |
| 1309 | + if(!$term){ | |
| 1310 | + return $term; | |
| 1311 | + } | |
| 2248 | 1312 | |
| 2249 | - /** | |
| 2250 | - * Fetch terms of a post | |
| 2251 | - * | |
| 2252 | - * @param mixed $_term | |
| 2253 | - * @param string $taxonomy | |
| 2254 | - * @param string $post_type | |
| 2255 | - */ | |
| 2256 | - public function retreive_term($_term=null, $taxonomy='category', $post_type='post') { | |
| 2257 | - $term = get_term($_term, $taxonomy); | |
| 1313 | + $term->start = $term->end = $term->time_start = $term->time_end = Null; | |
| 2258 | 1314 | |
| 2259 | - if(!$term){ | |
| 2260 | - return $term; | |
| 2261 | - } | |
| 1315 | + $request = array( | |
| 1316 | + 'post_type'=>$post_type, | |
| 1317 | + 'tax_name'=>$term->taxonomy, | |
| 1318 | + 'tax_term'=>$term->slug, | |
| 1319 | + 'future'=>true, | |
| 1320 | + 'past'=>true, | |
| 1321 | + 'nb'=>-1, | |
| 1322 | + 'order'=>'ASC' | |
| 1323 | + ); | |
| 2262 | 1324 | |
| 2263 | - $term->start = $term->end = $term->time_start = $term->time_end = Null; | |
| 1325 | + $events = $this->get_events($request); | |
| 2264 | 1326 | |
| 2265 | - $request = array( | |
| 2266 | - 'post_type'=>$post_type, | |
| 2267 | - 'tax_name'=>$term->taxonomy, | |
| 2268 | - 'tax_term'=>$term->slug, | |
| 2269 | - 'future'=>true, | |
| 2270 | - 'past'=>true, | |
| 2271 | - 'nb'=>-1, | |
| 2272 | - 'order'=>'ASC' | |
| 2273 | - ); | |
| 1327 | + $term->events_count = count($events); | |
| 1328 | + if($term->events_count){ | |
| 1329 | + $term->start = $events[0]->start; | |
| 1330 | + $term->time_start = $events[0]->time_start; | |
| 1331 | + $term->end = $events[$term->events_count-1]->end; | |
| 1332 | + $term->time_end = $events[$term->events_count-1]->time_end; | |
| 1333 | + } | |
| 2274 | 1334 | |
| 2275 | - $events = $this->get_events($request); | |
| 1335 | + $request['order']='DESC'; | |
| 1336 | + $request['nb']=1; | |
| 1337 | + $request['orderbykey']=$this->META_END; | |
| 1338 | + $events = $this->get_events($request); | |
| 1339 | + if(count($events)){ | |
| 1340 | + $term->end = $events[0]->end; | |
| 1341 | + $term->time_end = $events[0]->time_end; | |
| 1342 | + } | |
| 2276 | 1343 | |
| 2277 | - $term->events_count = count($events); | |
| 2278 | - if($term->events_count){ | |
| 2279 | - $term->start = $events[0]->start; | |
| 2280 | - $term->time_start = $events[0]->time_start; | |
| 2281 | - $term->end = $events[$term->events_count-1]->end; | |
| 2282 | - $term->time_end = $events[$term->events_count-1]->time_end; | |
| 2283 | - } | |
| 1344 | + return $term; | |
| 2284 | 1345 | |
| 2285 | - $request['order']='DESC'; | |
| 2286 | - $request['nb']=1; | |
| 2287 | - $request['orderbykey']=$this->META_END; | |
| 2288 | - $events = $this->get_events($request); | |
| 2289 | - if(count($events)){ | |
| 2290 | - $term->end = $events[0]->end; | |
| 2291 | - $term->time_end = $events[0]->time_end; | |
| 2292 | - } | |
| 1346 | + } | |
| 2293 | 1347 | |
| 2294 | - return $term; | |
| 1348 | + /** ADMIN ISSUES * */ | |
| 2295 | 1349 | |
| 1350 | + /** | |
| 1351 | + * add custom boxes in posts edit page | |
| 1352 | + */ | |
| 1353 | + public function add_custom_box() { | |
| 1354 | + foreach($this->settings['posttypes'] as $posttype){ | |
| 1355 | + add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core'); | |
| 1356 | + add_meta_box('event_post_loc', __('Location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core'); | |
| 1357 | + do_action('eventpost_add_custom_box', $posttype); | |
| 1358 | + } | |
| 1359 | + if(!function_exists('shortcode_ui_register_for_shortcode')){ | |
| 1360 | + add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page'); | |
| 2296 | 1361 | } |
| 1362 | + } | |
| 1363 | + /** | |
| 1364 | + * display the date custom box | |
| 1365 | + */ | |
| 1366 | + public function inner_custom_box_date() { | |
| 1367 | + wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); | |
| 1368 | + $post_id = get_the_ID(); | |
| 1369 | + $event = $this->retreive($post_id); | |
| 1370 | + $start_date = $event->start; | |
| 1371 | + $end_date = $event->end; | |
| 1372 | + $eventcolor = $event->color; | |
| 2297 | 1373 | |
| 2298 | - // ADMIN ISSUES | |
| 1374 | + $language = get_bloginfo('language'); | |
| 1375 | + if (strpos($language, '-') > -1) { | |
| 1376 | + $language = strtolower(substr($language, 0, 2)); | |
| 1377 | + } | |
| 1378 | + $colors = $this->get_colors(); | |
| 1379 | + ?> | |
| 2299 | 1380 | |
| 2300 | - /** | |
| 2301 | - * Add custom boxes in posts edit page | |
| 2302 | - */ | |
| 2303 | - public function add_custom_box() { | |
| 2304 | - foreach($this->settings['posttypes'] as $posttype){ | |
| 2305 | - add_meta_box( | |
| 2306 | - 'event_post_date', | |
| 2307 | - __('Event date', 'event-post'), | |
| 2308 | - array(&$this, 'inner_custom_box_date'), | |
| 2309 | - $posttype, | |
| 2310 | - apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), | |
| 2311 | - 'core', | |
| 2312 | - array( | |
| 2313 | - '__block_editor_compatible_meta_box' => true, | |
| 2314 | - ) | |
| 2315 | - ); | |
| 2316 | - add_meta_box( | |
| 2317 | - 'event_post_loc', | |
| 2318 | - __('Location', 'event-post'), | |
| 2319 | - array(&$this, 'inner_custom_box_loc'), | |
| 2320 | - $posttype, | |
| 2321 | - apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), | |
| 2322 | - 'core', | |
| 2323 | - array( | |
| 2324 | - '__block_editor_compatible_meta_box' => true, | |
| 2325 | - ) | |
| 2326 | - ); | |
| 2327 | - do_action('eventpost_add_custom_box', $posttype); | |
| 2328 | - } | |
| 2329 | - } | |
| 1381 | + <div class="eventpost-misc-pub-section"> | |
| 1382 | + <p> | |
| 1383 | + <label> | |
| 1384 | + <input type="checkbox" id="event-post-date-all-day" <?php checked( $event->time_start && $event->time_end && date('H:i:s', $event->time_start) == '00:00:00' && date('H:i:s', $event->time_end) == '00:00:00', true, true); ?>> | |
| 1385 | + <?php _e('All day event', 'event-post') ?> | |
| 1386 | + </label> | |
| 1387 | + </p> | |
| 1388 | + <p> | |
| 1389 | + <span class="dashicons dashicons-calendar eventpost-edit-icon"></span> | |
| 1390 | + <label for="<?php echo $this->META_START; ?>_date"> | |
| 1391 | + <?php _e('Begin:', 'event-post') ?> | |
| 1392 | + <span id="<?php echo $this->META_START; ?>_date_human" class="human_date"> | |
| 1393 | + <?php | |
| 1394 | + if ($event->time_start != '') { | |
| 1395 | + echo $this->human_date($event->time_start) . (date('H:i', $event->time_start)=='00:00'?'':date(' H:i', $event->time_start)); | |
| 1396 | + } | |
| 1397 | + else{ | |
| 1398 | + _e('Pick a date','event-post'); | |
| 1399 | + } | |
| 1400 | + ?> | |
| 1401 | + </span> | |
| 1402 | + <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value="<?php echo substr($start_date,0,16) ?>" name="<?php echo $this->META_START; ?>" id="<?php echo $this->META_START; ?>_date"/> | |
| 1403 | + </label> | |
| 1404 | + </p> | |
| 1405 | + <p> | |
| 1406 | + <span class="dashicons dashicons-calendar eventpost-edit-icon"></span> | |
| 1407 | + <label for="<?php echo $this->META_END; ?>_date"> | |
| 1408 | + <?php _e('End:', 'event-post') ?> | |
| 1409 | + <span id="<?php echo $this->META_END; ?>_date_human" class="human_date"> | |
| 1410 | + <?php | |
| 1411 | + if ($event->time_start != '') { | |
| 1412 | + echo $this->human_date($event->time_end) . (date('H:i', $event->time_end)=='00:00'?'':date(' H:i', $event->time_end)); | |
| 1413 | + } | |
| 1414 | + else{ | |
| 1415 | + _e('Pick a date','event-post'); | |
| 1416 | + } | |
| 1417 | + ?> | |
| 1418 | + </span> | |
| 1419 | + <input type="<?php echo ($this->settings['datepicker']=='browser'?'datetime':''); ?>" class="eventpost-datepicker-<?php echo $this->settings['datepicker']; ?>" data-lang="<?php echo $language; ?>" value ="<?php echo substr($end_date,0,16) ?>" name="<?php echo $this->META_END; ?>" id="<?php echo $this->META_END; ?>_date"/> | |
| 1420 | + </label> | |
| 1421 | + </p> | |
| 1422 | + </div> | |
| 1423 | + <?php if (sizeof($colors) > 0): ?> | |
| 1424 | + <div class="eventpost-misc-pub-section event-color-section"> | |
| 1425 | + <span class="screen-reader-text"><?php _e('Color:', 'event-post'); ?></span><?php echo $key_color; ?> | |
| 1426 | + <p> | |
| 1427 | + <img src="<?php echo $this->markurl.$eventcolor.'.png'; ?>" id="eventpost-color-preview" data-url="<?php echo $this->markurl; ?>"> | |
| 1428 | + <span id="eventpost-color-dropdown"> | |
| 1429 | + <?php foreach ($colors as $color => $file): ?> | |
| 1430 | + <label style="background:#<?php echo $color ?>" for="<?php echo $this->META_COLOR; ?><?php echo $color ?>" title="<?php echo $file; ?>"> | |
| 1431 | + <img src="<?php echo $this->markurl.$color.'.png'; ?>"> | |
| 1432 | + <input type="radio" value ="<?php echo $color ?>" name="<?php echo $this->META_COLOR; ?>" id="<?php echo $this->META_COLOR; ?><?php echo $color ?>" <?php checked($eventcolor, $color, true); ?>/> | |
| 1433 | + </label> | |
| 1434 | + <?php endforeach; ?> | |
| 1435 | + </span> | |
| 1436 | + </p> | |
| 1437 | + </div> | |
| 1438 | + <?php endif; ?> | |
| 1439 | + <?php | |
| 1440 | + do_action ('eventpost_custom_box_date', $event); | |
| 1441 | + } | |
| 1442 | + /** | |
| 1443 | + * displays the location custom box | |
| 1444 | + */ | |
| 1445 | + public function inner_custom_box_loc($post) { | |
| 1446 | + $event = $this->retreive($post); | |
| 1447 | + ?> | |
| 2330 | 1448 | |
| 2331 | - /** | |
| 2332 | - * Displays the date custom box | |
| 2333 | - */ | |
| 2334 | - public function inner_custom_box_date() { | |
| 1449 | + <div class="eventpost-misc-pub-section"> | |
| 1450 | + <label for="<?php echo $this->META_ADD; ?>"> | |
| 1451 | + <?php _e('Address, as it will be displayed:', 'event-post') ?> | |
| 1452 | + <textarea name="<?php echo $this->META_ADD; ?>" id="<?php echo $this->META_ADD; ?>" class="widefat"><?php echo $event->address; ?></textarea> | |
| 1453 | + </label> | |
| 1454 | + </div> | |
| 2335 | 1455 | |
| 1456 | + <div id="event_address_searchwrap"> | |
| 1457 | + <span class="dashicons dashicons-location eventpost-edit-icon"></span> | |
| 1458 | + <?php _e('GPS coordinates:', 'event-post') ?> | |
| 1459 | + <a id="event_address_search" title="<?php _e('Search or fill exact coordinates', 'event-post') ?>"> | |
| 1460 | + <?php _e('Search / Edit', 'event-post') ?> | |
| 1461 | + </a> | |
| 2336 | 1462 | |
| 1463 | + <div class="misc-pub-section" id="event_address_coords"> | |
| 1464 | + <p> | |
| 1465 | + <span id="eventaddress_result"></span> | |
| 1466 | + </p> | |
| 1467 | + <label for="<?php echo $this->META_LAT; ?>"> | |
| 1468 | + <?php _e('Latitude:', 'event-post') ?> | |
| 1469 | + <input type="text" value ="<?php echo $event->lat; ?>" name="<?php echo $this->META_LAT; ?>" id="<?php echo $this->META_LAT; ?>" class="widefat"/> | |
| 1470 | + </label> | |
| 2337 | 1471 | |
| 2338 | - wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); | |
| 2339 | - $post_id = get_the_ID(); | |
| 2340 | - $event = $this->retreive($post_id); | |
| 2341 | - if ($event != false){ | |
| 2342 | - $start_date = $event->start; | |
| 2343 | - $end_date = $event->end; | |
| 2344 | - $eventcolor = $event->color; | |
| 2345 | - $eventicon = $event->icon; | |
| 1472 | + <label for="<?php echo $this->META_LONG; ?>"> | |
| 1473 | + <?php _e('Longitude:', 'event-post') ?> | |
| 1474 | + <input type="text" value ="<?php echo $event->long; ?>" name="<?php echo $this->META_LONG; ?>" id="<?php echo $this->META_LONG; ?>" class="widefat"/> | |
| 1475 | + </label> | |
| 1476 | + <p> | |
| 1477 | + <a id="event_address_unsearch" class="button button-small"> | |
| 1478 | + <span class="dashicons dashicons-yes"></span> | |
| 1479 | + <?php _e('Done', 'event-post') ?> | |
| 1480 | + </a> | |
| 1481 | + </p> | |
| 1482 | + </div> | |
| 1483 | + </div> | |
| 2346 | 1484 | |
| 2347 | - $language = get_bloginfo('language'); | |
| 2348 | - if (strpos($language, '-') > -1) { | |
| 2349 | - $language = strtolower(substr($language, 0, 2)); | |
| 2350 | - } | |
| 2351 | - $colors = $this->get_colors(); | |
| 2352 | - include (plugin_dir_path(__FILE__) . 'views/admin/custombox-date.php'); | |
| 2353 | - do_action ('eventpost_custom_box_date', $event); | |
| 2354 | - } | |
| 2355 | - } | |
| 1485 | + <div class="eventpost-misc-pub-section"> | |
| 1486 | + <div id="event-post-map-preview" data-marker="<?php echo $this->get_marker($event->color); ?>"></div> | |
| 1487 | + </div> | |
| 1488 | + <?php | |
| 1489 | + do_action ('eventpost_custom_box_loc', $event); | |
| 1490 | + $this->load_map_scripts(); | |
| 1491 | + } | |
| 2356 | 1492 | |
| 2357 | - /** | |
| 2358 | - * Displays the location custom box | |
| 2359 | - */ | |
| 2360 | - public function inner_custom_box_loc($post) { | |
| 2361 | - $event = $this->retreive($post); | |
| 2362 | - if ($event != false){ | |
| 2363 | - include (plugin_dir_path(__FILE__) . 'views/admin/custombox-location.php'); | |
| 2364 | - do_action ('eventpost_custom_box_loc', $event); | |
| 2365 | - $this->load_map_scripts(); | |
| 2366 | - } | |
| 2367 | - } | |
| 1493 | + /** | |
| 1494 | + * display custombox containing shortcode wizard | |
| 1495 | + */ | |
| 1496 | + public function inner_custom_box_edit() { | |
| 1497 | + $ep_settings = $this->settings; | |
| 1498 | + ?> | |
| 1499 | + <?php do_action('before_eventpost_generator'); ?> | |
| 1500 | + <div class="all"> | |
| 1501 | + <p> | |
| 1502 | + <label for="ep_sce_type"><?php _e('Type :', 'event-post'); ?> | |
| 1503 | + <select id="ep_sce_type"> | |
| 1504 | + <option value='list'><?php _e('List', 'event-post') ?></option> | |
| 1505 | + <option value='map'><?php _e('Map', 'event-post') ?></option> | |
| 1506 | + </select> | |
| 1507 | + </label> | |
| 1508 | + </p> | |
| 2368 | 1509 | |
| 2369 | - public function icon_color_fields($item_id, $meta_color,$value_color,$meta_icon,$value_icon ){ | |
| 2370 | - ?> | |
| 2371 | - <div class="eventpost-misc-pub-section event-color-section"> | |
| 2372 | - <span class="screen-reader-text"><?php esc_html_e('Color:', 'event-post'); ?></span> | |
| 1510 | + <p> | |
| 1511 | + <label for="ep_sce_nb"><?php _e('Number of posts', 'event-post'); ?> | |
| 1512 | + <input id="ep_sce_nb" type="number" value="5" data-att="nb"/> | |
| 1513 | + <a class="button" id="ep_sce_nball"><?php _e('All', 'event-post'); ?></a> | |
| 1514 | + </label> | |
| 1515 | + </p> | |
| 2373 | 1516 | |
| 2374 | - <input class="color-field-post eventpost-colorpicker" | |
| 2375 | - type="text" | |
| 2376 | - name="<?php echo esc_attr($meta_color); ?>" | |
| 2377 | - value="<?php echo esc_attr($value_color); ?>" | |
| 2378 | - id="color-field<?php echo esc_attr($item_id); ?>"/> | |
| 1517 | + <p> | |
| 1518 | + <label for="ep_sce_cat"><?php _e('Only in :', 'event-post'); ?> | |
| 1519 | + <select id="ep_sce_cat" data-att="cat"> | |
| 1520 | + <option value=''><?php _e('All', 'event-post') ?></option> | |
| 1521 | + <?php | |
| 1522 | + $cats = get_categories(); | |
| 1523 | + foreach ($cats as $cat) { | |
| 1524 | + ?> | |
| 1525 | + <option value="<?php echo $cat->slug; ?>" <?php | |
| 1526 | + if ($cat->slug == $eventpost_cat) { | |
| 1527 | + echo'selected'; | |
| 1528 | + } | |
| 1529 | + ?>><?php echo $cat->cat_name; ?></option> | |
| 1530 | + <?php } ?> | |
| 1531 | + </select> | |
| 1532 | + </label> | |
| 1533 | + </p> | |
| 2379 | 1534 | |
| 2380 | - <select style="font-family : dashicons;" class="eventpost-iconpicker" name="<?php echo esc_attr($meta_icon); ?>"> | |
| 2381 | - <option value=""><?php esc_attr_e('None','event-post') ?></option> | |
| 2382 | - <?php | |
| 2383 | - foreach($this->DashIcons->icons as $class => $unicode){ | |
| 2384 | - ?> | |
| 2385 | - <option value="<?php echo esc_attr($class) ?>" <?php selected($value_icon, $class, true); ?>>&#x<?php esc_attr_e($unicode) ?>; <?php echo esc_html($class) ?></option><?php // phpcs:ignore WordPress.WP.I18n ?> | |
| 2386 | - <?php | |
| 2387 | - } | |
| 2388 | - ?> | |
| 2389 | - </select> | |
| 2390 | - <div class="custom-marker-container"> | |
| 2391 | - <p><?php esc_html_e('An image was found in your custom folder for this color', 'event-post')?> <span class="color-hex"></span> </p> | |
| 2392 | - <img src="" class="image-marker"> | |
| 2393 | - </div> | |
| 2394 | - </div> | |
| 1535 | + <p> | |
| 1536 | + <label for="ep_sce_future"><?php _e('Future events:', 'event-post'); ?> | |
| 1537 | + <select id="ep_sce_future" data-att="future"> | |
| 1538 | + <option value='1'><?php _e('Yes', 'event-post') ?></option> | |
| 1539 | + <option value='0'><?php _e('No', 'event-post') ?></option> | |
| 1540 | + </select> | |
| 1541 | + </label> | |
| 1542 | + <label for="ep_sce_past"><?php _e('Past events:', 'event-post'); ?> | |
| 1543 | + <select id="ep_sce_past" data-att="past"> | |
| 1544 | + <option value='0'><?php _e('No', 'event-post') ?></option> | |
| 1545 | + <option value='1'><?php _e('Yes', 'event-post') ?></option> | |
| 1546 | + </select> | |
| 1547 | + </label> | |
| 1548 | + </p> | |
| 2395 | 1549 | |
| 1550 | + <div id="ep_sce_listonly" class="list"> | |
| 1551 | + <p> | |
| 1552 | + <label for="ep_sce_geo"><?php _e('Only geotagged events:', 'event-post'); ?> | |
| 1553 | + <select id="ep_sce_geo" data-att="geo"> | |
| 1554 | + <option value='0'><?php _e('No', 'event-post') ?></option> | |
| 1555 | + <option value='1'><?php _e('Yes', 'event-post') ?></option> | |
| 1556 | + </select> | |
| 1557 | + </label> | |
| 1558 | + </p> | |
| 1559 | + </div> | |
| 1560 | + <div id="ep_sce_maponly" class="map"> | |
| 1561 | + <p> | |
| 1562 | + <label for="ep_sce_tile"><?php _e('Map background', 'event-post'); ?> | |
| 1563 | + <select id="ep_sce_tile" data-att="tile"> | |
| 1564 | + <?php foreach ($this->maps as $map): ?> | |
| 1565 | + <option value="<?php | |
| 1566 | + if ($ep_settings['tile'] != $map['id']) { | |
| 1567 | + echo $map['id']; | |
| 1568 | + } | |
| 1569 | + ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>> | |
| 1570 | + <?php echo $map['name']; ?><?php | |
| 1571 | + if ($ep_settings['tile'] == $map['id']) { | |
| 1572 | + echo' (default)'; | |
| 1573 | + } | |
| 1574 | + ?> | |
| 1575 | + </option> | |
| 1576 | + <?php endforeach; ?> | |
| 1577 | + </select> | |
| 1578 | + </label> | |
| 1579 | + </p> | |
| 1580 | + <p> | |
| 1581 | + <label for="ep_sce_width"><?php _e('Width', 'event-post'); ?> | |
| 1582 | + <input id="ep_sce_width" type="text" value="500px" data-att="width"/> | |
| 1583 | + </label> | |
| 1584 | + </p> | |
| 1585 | + <p> | |
| 1586 | + <label for="ep_sce_height"><?php _e('Height', 'event-post'); ?> | |
| 1587 | + <input id="ep_sce_height" type="text" value="500px" data-att="height"/> | |
| 1588 | + </label> | |
| 1589 | + </p> | |
| 1590 | + </div> | |
| 1591 | + <?php do_action('after_eventpost_generator'); ?> | |
| 1592 | + <div id="ep_sce_shortcode">[event_list]</div> | |
| 1593 | + <a class="button" id="ep_sce_submit"><?php _e('Insert shortcode', 'event-post'); ?></a> | |
| 1594 | + </div> | |
| 1595 | + <script> | |
| 1596 | + var IEbof = false; | |
| 1597 | + </script> | |
| 1598 | + <!--[if lt IE 9]> | |
| 1599 | + <script>IEbof=true;</script> | |
| 1600 | + <![endif]--> | |
| 1601 | + <?php | |
| 1602 | + } | |
| 2396 | 1603 | |
| 2397 | - <?php | |
| 2398 | - } | |
| 2399 | - | |
| 2400 | - /** | |
| 2401 | - * Quick edit | |
| 2402 | - * | |
| 2403 | - * @param string $column_name | |
| 2404 | - * @param boolean $bulk | |
| 2405 | - */ | |
| 1604 | + /** | |
| 1605 | + * | |
| 1606 | + * @param string $column_name | |
| 1607 | + * @param boolean $bulk | |
| 1608 | + */ | |
| 2406 | 1609 | function quick_edit( $column_name, $post_type, $bulk=false) { |
| 2407 | 1610 | |
| 2408 | 1611 | if ($bulk) { |
| 2409 | - static $eventpostprintNonceBulk = TRUE; | |
| 2410 | - if ($eventpostprintNonceBulk) { | |
| 2411 | - $eventpostprintNonceBulk = FALSE; | |
| 2412 | - } | |
| 2413 | - $fields = $this->bulk_edit_fields; | |
| 2414 | - echo '<input type="hidden" name="eventpost-bulk-editor" id="eventpost-bulk-editor" value="eventpost-bulk-editor">'; | |
| 2415 | - } | |
| 2416 | - else { | |
| 2417 | - static $eventpostprintNonce = TRUE; | |
| 2418 | - if ($eventpostprintNonce) { | |
| 2419 | - $eventpostprintNonce = FALSE; | |
| 2420 | - } | |
| 2421 | - $fields = $this->quick_edit_fields; | |
| 2422 | - } | |
| 2423 | - wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); | |
| 2424 | - if(isset($fields[$column_name])): ?> | |
| 2425 | - <fieldset class="inline-edit-col-left inline-edit-<?php echo esc_attr($column_name); ?>"> | |
| 2426 | - <div class="inline-edit-group"> | |
| 2427 | - <?php foreach ($fields[$column_name] as $fieldname=>$fieldlabel): ?> | |
| 2428 | - <fieldset class="inline-edit-col inline-edit-<?php echo esc_attr($fieldname); ?>"> | |
| 2429 | - <div class="inline-edit-col column-<?php echo esc_attr($fieldname); ?>"> | |
| 2430 | - <label class="inline-edit-group"> | |
| 2431 | - <span class="title"><?php echo esc_html($fieldlabel); ?></span> | |
| 2432 | - <span class="input-text-wrap"> | |
| 2433 | - <?php echo wp_kses($this->inline_field($fieldname, $bulk), $this->kses_tags); ?> | |
| 2434 | - </span> | |
| 2435 | - </label> | |
| 2436 | - </div> | |
| 2437 | - </fieldset> | |
| 2438 | - <?php endforeach; ?> | |
| 2439 | - </div> | |
| 2440 | - </fieldset> | |
| 2441 | - <?php endif; | |
| 2442 | - } | |
| 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 | + } | |
| 2443 | 1646 | |
| 2444 | - /** | |
| 2445 | - * Inline field in bulk edit | |
| 2446 | - * | |
| 2447 | - * @param type $fieldname | |
| 2448 | - * | |
| 2449 | - * @return string | |
| 2450 | - */ | |
| 2451 | - function inline_field($fieldname, $bulk){ | |
| 2452 | - return apply_filters('eventpost_inline_field', '<input name="'.esc_attr($fieldname).'" class="eventpost-inline-'.esc_attr($fieldname).'" value="" type="text">', $fieldname, $bulk); | |
| 2453 | - } | |
| 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 | + } | |
| 2454 | 1655 | |
| 2455 | - function inline_field_color($html, $fieldname, $bulk){ | |
| 2456 | - if($fieldname==$this->META_COLOR){ | |
| 2457 | - $html=''; | |
| 2458 | - if($bulk){ | |
| 2459 | - $html.= '<span class="eventpost-bulk-colorpicker-button link">'.esc_html(__('No Change', 'event-post')).'</span>'; | |
| 2460 | - } | |
| 2461 | - $html .= ' | |
| 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 | + } | |
| 2462 | 1674 | |
| 2463 | - <input class="eventpost-inline-colorpicker eventpost-inline-'.esc_attr($fieldname).' '.($bulk?'is-bulk':'no-bulk').'" type="color" name="'.esc_attr($fieldname).'" >'; | |
| 2464 | - } | |
| 2465 | - return $html; | |
| 1675 | + /** | |
| 1676 | + * | |
| 1677 | + * @param type $column_name | |
| 1678 | + * @param type $post_type | |
| 1679 | + */ | |
| 1680 | + function bulk_edit($column_name, $post_type){ | |
| 1681 | + $this->quick_edit($column_name, $post_type, true); | |
| 1682 | + } | |
| 1683 | + | |
| 1684 | + /** | |
| 1685 | + * | |
| 1686 | + */ | |
| 1687 | + function inline_save(){ | |
| 1688 | + $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); | |
| 1689 | + $this->save_postdata($post_id); | |
| 1690 | + } | |
| 1691 | + /** | |
| 1692 | + * When the post is saved, saves our custom data | |
| 1693 | + * @param int $post_id | |
| 1694 | + * @return void | |
| 1695 | + */ | |
| 1696 | + public function save_postdata($post_id) { | |
| 1697 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ | |
| 1698 | + return; | |
| 2466 | 1699 | } |
| 2467 | - function inline_field_icon($html, $fieldname, $bulk){ | |
| 2468 | - if($fieldname==$this->META_ICON){ | |
| 2469 | - if($bulk){ | |
| 2470 | - $html.= '<span class="eventpost-bulk-icon-button link">'.__('No Change', 'event-post').'</span>'; | |
| 2471 | - } | |
| 2472 | - $html = '<select class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'" | |
| 2473 | - type="text" | |
| 2474 | - name="'.$fieldname.'" | |
| 2475 | - style="font-family : dashicons"> | |
| 2476 | - <option value="">'.__("None", 'event-post').'</option>'; | |
| 2477 | - foreach($this->DashIcons->icons as $class => $unicode){ | |
| 2478 | - $html .= '<option value="'.$class.'">&#x'.$unicode.'; '.$class.'</option>'; | |
| 2479 | - } | |
| 2480 | - $html .= '</select>'; | |
| 2481 | 1700 | |
| 2482 | - } | |
| 2483 | - return $html; | |
| 1701 | + if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce', FILTER_SANITIZE_STRING), plugin_basename(__FILE__))){ | |
| 1702 | + return; | |
| 2484 | 1703 | } |
| 2485 | 1704 | |
| 1705 | + // Clean color or no color | |
| 1706 | + if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR, FILTER_SANITIZE_STRING)) { | |
| 1707 | + update_post_meta($post_id, $this->META_COLOR, $color); | |
| 1708 | + } | |
| 1709 | + // Clean date or no date | |
| 1710 | + if ((false !== $start = filter_input(INPUT_POST, $this->META_START, FILTER_SANITIZE_STRING)) && | |
| 1711 | + (false !== $end = filter_input(INPUT_POST, $this->META_END, FILTER_SANITIZE_STRING)) && | |
| 1712 | + '' != $start && | |
| 1713 | + '' != $end) { | |
| 1714 | + update_post_meta($post_id, $this->META_START, substr($start,0,16).':00'); | |
| 1715 | + update_post_meta($post_id, $this->META_END, substr($end,0,16).':00'); | |
| 1716 | + } | |
| 1717 | + else { | |
| 1718 | + delete_post_meta($post_id, $this->META_START); | |
| 1719 | + delete_post_meta($post_id, $this->META_END); | |
| 1720 | + } | |
| 2486 | 1721 | |
| 2487 | - /** | |
| 2488 | - * Bulk edit | |
| 2489 | - * | |
| 2490 | - * @param type $column_name | |
| 2491 | - * @param type $post_type | |
| 2492 | - */ | |
| 2493 | - function bulk_edit($column_name, $post_type){ | |
| 2494 | - $this->quick_edit($column_name, $post_type, true); | |
| 1722 | + // Clean location or no location | |
| 1723 | + if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT, FILTER_SANITIZE_STRING)) && | |
| 1724 | + (false !== $long = filter_input(INPUT_POST, $this->META_LONG, FILTER_SANITIZE_STRING)) && | |
| 1725 | + '' != $lat && | |
| 1726 | + '' != $long) { | |
| 1727 | + update_post_meta($post_id, $this->META_ADD, filter_input(INPUT_POST, $this->META_ADD, FILTER_SANITIZE_STRING)); | |
| 1728 | + update_post_meta($post_id, $this->META_LAT, $lat); | |
| 1729 | + update_post_meta($post_id, $this->META_LONG, $long); | |
| 2495 | 1730 | } |
| 2496 | - | |
| 2497 | - /** | |
| 2498 | - * Saves data from quick-edit via `wp_ajax_inline-save` action | |
| 2499 | - * | |
| 2500 | - * @return void | |
| 2501 | - */ | |
| 2502 | - function inline_save(){ | |
| 2503 | - $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); | |
| 2504 | - $this->save_postdata($post_id); | |
| 1731 | + else { | |
| 1732 | + delete_post_meta($post_id, $this->META_ADD); | |
| 1733 | + delete_post_meta($post_id, $this->META_LAT); | |
| 1734 | + delete_post_meta($post_id, $this->META_LONG); | |
| 2505 | 1735 | } |
| 2506 | - /** | |
| 2507 | - * When the post is saved, saves our custom data | |
| 2508 | - * | |
| 2509 | - * @param int $post_id | |
| 2510 | - * | |
| 2511 | - * @return void | |
| 2512 | - */ | |
| 2513 | - public function save_postdata($post_id) { | |
| 2514 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ | |
| 2515 | - return; | |
| 2516 | - } | |
| 2517 | 1736 | |
| 2518 | - if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce'), plugin_basename(__FILE__))){ | |
| 2519 | - return; | |
| 2520 | - } | |
| 1737 | + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array(); | |
| 1738 | + } | |
| 2521 | 1739 | |
| 2522 | - // Clean color or no color | |
| 2523 | - if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR)) { | |
| 2524 | - update_post_meta($post_id, $this->META_COLOR, sanitize_text_field($color)); | |
| 2525 | - } | |
| 2526 | - // Clean color or no color | |
| 2527 | - if (false !== $icon = filter_input(INPUT_POST, $this->META_ICON)) { | |
| 2528 | - update_post_meta($post_id, $this->META_ICON, sanitize_text_field($icon)); | |
| 2529 | - } | |
| 2530 | - if (false !== $attendance_mode = filter_input(INPUT_POST, $this->META_ATTENDANCE_MODE)) { | |
| 2531 | - update_post_meta($post_id, $this->META_ATTENDANCE_MODE, sanitize_text_field($attendance_mode)); | |
| 2532 | - } | |
| 2533 | - if (false !== $status = filter_input(INPUT_POST, $this->META_STATUS)) { | |
| 2534 | - update_post_meta($post_id, $this->META_STATUS, sanitize_text_field($status)); | |
| 2535 | - } | |
| 2536 | - $virtual_location = filter_input(INPUT_POST, $this->META_VIRTUAL_LOCATION, FILTER_SANITIZE_URL); | |
| 2537 | - if ($virtual_location !== null && $virtual_location !== false) { | |
| 2538 | - update_post_meta($post_id, $this->META_VIRTUAL_LOCATION, sanitize_url($virtual_location)); | |
| 2539 | - } | |
| 2540 | - if (false !== $organization = filter_input(INPUT_POST, $this->META_ORGANIZATION)) { | |
| 2541 | - update_post_meta($post_id, $this->META_ORGANIZATION, sanitize_text_field($organization)); | |
| 2542 | - } | |
| 2543 | - $offer_url = filter_input(INPUT_POST, "{$this->META_OFFER}_url", FILTER_SANITIZE_URL); | |
| 2544 | - $offer_price = filter_input(INPUT_POST, "{$this->META_OFFER}_price"); | |
| 2545 | - $offer_currency = filter_input(INPUT_POST, "{$this->META_OFFER}_currency"); | |
| 2546 | - if ($offer_url || ($offer_price && $offer_currency) ) { | |
| 2547 | - // Format floating | |
| 2548 | - $offer_price = $offer_price ? str_replace(',', '.', $offer_price) : null; | |
| 2549 | - update_post_meta($post_id, $this->META_OFFER, array( | |
| 2550 | - 'url' => $offer_url ? sanitize_text_field($offer_url) : null, | |
| 2551 | - 'price' => $offer_price ? (float) $offer_price : null, | |
| 2552 | - 'currency' => $offer_currency ? sanitize_text_field($offer_currency) : null, | |
| 2553 | - )); | |
| 2554 | - } | |
| 2555 | - else{ | |
| 2556 | - delete_post_meta($post_id, $this->META_OFFER); | |
| 2557 | - } | |
| 2558 | - // Clean date or no date | |
| 2559 | - if ((false !== $start = filter_input(INPUT_POST, $this->META_START)) && | |
| 2560 | - (false !== $end = filter_input(INPUT_POST, $this->META_END)) && | |
| 2561 | - '' != $start && | |
| 2562 | - '' != $end) { | |
| 2563 | - update_post_meta($post_id, $this->META_START, sanitize_text_field(substr($start,0,16).':00')); | |
| 2564 | - update_post_meta($post_id, $this->META_END, sanitize_text_field(substr($end,0,16).':00')); | |
| 2565 | - } | |
| 2566 | - else { | |
| 2567 | - delete_post_meta($post_id, $this->META_START); | |
| 2568 | - delete_post_meta($post_id, $this->META_END); | |
| 2569 | - } | |
| 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 | + } | |
| 2570 | 1760 | |
| 2571 | - // Clean location or no location | |
| 2572 | - if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT)) && | |
| 2573 | - (false !== $long = filter_input(INPUT_POST, $this->META_LONG)) && | |
| 2574 | - '' != $lat && | |
| 2575 | - '' != $long) { | |
| 2576 | - update_post_meta($post_id, $this->META_ADD, sanitize_text_field(filter_input(INPUT_POST, $this->META_ADD))); | |
| 2577 | - update_post_meta($post_id, $this->META_LAT, $this->sanitize_coordinate(sanitize_text_field($lat))); | |
| 2578 | - update_post_meta($post_id, $this->META_LONG, $this->sanitize_coordinate(sanitize_text_field($long))); | |
| 2579 | - } | |
| 2580 | - else { | |
| 2581 | - delete_post_meta($post_id, $this->META_ADD); | |
| 2582 | - delete_post_meta($post_id, $this->META_LAT); | |
| 2583 | - delete_post_meta($post_id, $this->META_LONG); | |
| 2584 | - } | |
| 1761 | + /** | |
| 1762 | + * | |
| 1763 | + * @param string $date | |
| 1764 | + * @param string $cat | |
| 1765 | + * @param boolean $display | |
| 1766 | + * @return boolean | |
| 1767 | + */ | |
| 1768 | + public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='') { | |
| 1769 | + $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true)); | |
| 1770 | + $nb = count($events); | |
| 1771 | + if ($display) { | |
| 1772 | + if ($nb > 0) { | |
| 1773 | + $ret.='<ul>'; | |
| 1774 | + foreach ($events as $event) { | |
| 1775 | + if ($this->settings['emptylink'] == 0 && empty($event->post_content)) { | |
| 1776 | + $event->guid = '#'; | |
| 1777 | + } | |
| 1778 | + $ret.='<li>' | |
| 1779 | + . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">' | |
| 1780 | + . '<h4>' . $event->post_title . '</h4>' | |
| 1781 | + .$this->get_single($event) | |
| 1782 | + . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '') | |
| 1783 | + .'</a>' | |
| 1784 | + . '</li>'; | |
| 1785 | + } | |
| 1786 | + $ret.='</ul>'; | |
| 1787 | + return $ret; | |
| 1788 | + } | |
| 1789 | + return''; | |
| 1790 | + } else { | |
| 1791 | + return $nb > 0 ? '<button data-date="' . date('Y-m-d', $date) . '" class="eventpost_cal_link"'.($colored?' style="background-color:#'.$events[0]->color.'"':'').' title="'.esc_attr(sprintf(_n('View %1$d event at date %2$s', 'View %1$d events at date %2$s', $nb, 'event-post'), $nb, $this->human_date($date, $this->settings['dateformat']))).'">' . date('j', $date) . '</button>' : date('j', $date); | |
| 1792 | + } | |
| 1793 | + } | |
| 2585 | 1794 | |
| 2586 | - $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array(); | |
| 2587 | - } | |
| 2588 | 1795 | |
| 2589 | - /** | |
| 2590 | - * Saves data from bulk-edit | |
| 2591 | - * Uses bulk_edit_posts hook | |
| 2592 | - * | |
| 2593 | - * @see https://developer.wordpress.org/reference/hooks/bulk_edit_posts/ | |
| 2594 | - * | |
| 2595 | - * @return void | |
| 2596 | - */ | |
| 2597 | - function save_bulkdatas(array $post_ids, array $shared_post_data) { | |
| 2598 | - if (!wp_verify_nonce(filter_input(INPUT_GET, 'eventpost_nonce'), plugin_basename(__FILE__))){ | |
| 2599 | - return; | |
| 2600 | - } | |
| 2601 | - $current_post_type = isset($shared_post_data['post_type']) ? $shared_post_data['post_type'] : 'post'; | |
| 2602 | - if (in_array($current_post_type, $this->settings['posttypes'])) { | |
| 2603 | - if (!empty($post_ids) && is_array($post_ids)) { | |
| 2604 | - foreach ($post_ids as $post_id) { | |
| 2605 | - if(! current_user_can( 'edit_post', $post_id )){ | |
| 2606 | - continue; | |
| 2607 | - } | |
| 2608 | - foreach ($this->bulk_edit_fields as $sets) { | |
| 2609 | - foreach ($sets as $fieldname => $fieldlabel) { | |
| 2610 | - if (isset($shared_post_data[$fieldname])) { | |
| 2611 | - update_post_meta($post_id, $fieldname, $shared_post_data[$fieldname]); | |
| 2612 | - } | |
| 2613 | - } | |
| 2614 | - } | |
| 2615 | - } | |
| 2616 | - } | |
| 2617 | - } | |
| 2618 | - } | |
| 1796 | + /** | |
| 1797 | + * @param array $atts | |
| 1798 | + * @filter eventpost_params | |
| 1799 | + * @return string | |
| 1800 | + */ | |
| 1801 | + public function calendar($atts) { | |
| 1802 | + extract(shortcode_atts(apply_filters('eventpost_params', array( | |
| 1803 | + 'date' => date('Y-n'), | |
| 1804 | + 'cat' => '', | |
| 1805 | + 'mondayfirst' => 0, //1 : weeks starts on monday | |
| 1806 | + 'datepicker' => 1, | |
| 1807 | + 'colored' => 1, | |
| 1808 | + 'thumbnail'=>'', | |
| 1809 | + ), 'calendar'), $atts)); | |
| 2619 | 1810 | |
| 2620 | - /** | |
| 2621 | - * Displays a date for calendar cell | |
| 2622 | - * | |
| 2623 | - * @param string $date | |
| 2624 | - * @param string $cat | |
| 2625 | - * @param boolean $display | |
| 2626 | - * | |
| 2627 | - * @return boolean | |
| 2628 | - */ | |
| 2629 | - public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='', $title='',$tax_name='' ,$tax_term='') { | |
| 2630 | - $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true,'tax_name' => $tax_name ,'tax_term' => $tax_term)); | |
| 2631 | - $nb = count($events); | |
| 2632 | - $ret = ""; | |
| 2633 | - $price = ""; | |
| 2634 | - if(!$display && !$nb){ | |
| 2635 | - $ret = date('j', $date); | |
| 2636 | - } | |
| 2637 | - $price = ''; | |
| 2638 | - if($nb){ | |
| 2639 | - if ($display || $title) { | |
| 2640 | - $ret='<ul>'; | |
| 2641 | - foreach ($events as $event) { | |
| 2642 | - $price = $this->get_price($event, true); | |
| 2643 | - if ($this->settings['emptylink'] == 0 && empty($event->post_content)) { | |
| 2644 | - $event->guid = '#'; | |
| 2645 | - } | |
| 2646 | - $ret.='<li>' | |
| 2647 | - // Translators: %s is the event title | |
| 2648 | - . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">' | |
| 2649 | - . '<h4>' . $event->post_title . '</h4>' | |
| 2650 | - . '<span class="event_price">' . $price . '</span>' | |
| 2651 | - .$this->get_single($event) | |
| 2652 | - . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '') | |
| 2653 | - .'</a>' | |
| 2654 | - . '</li>'; | |
| 2655 | - } | |
| 2656 | - $ret.='</ul>'; | |
| 2657 | - } | |
| 2658 | - if ($display) { | |
| 2659 | - // return $ret; | |
| 2660 | - } | |
| 2661 | - elseif($title) { | |
| 2662 | - $ret = '<span '.($colored?' style="color:#'.$events[0]->color.'"':'').'>'.date('j', $date).'</span>'.$ret; | |
| 2663 | - } | |
| 2664 | - else { | |
| 2665 | - $ret = '<button data-event="'. $tax_term .'" data-date="' . date('Y-m-d', $date).'"' | |
| 2666 | - .' class="'.apply_filters( 'event_post_class_calendar_link', 'eventpost_cal_link' ).'"'.($colored?' style="background-color:#'.$events[0]->color.'"':'') | |
| 2667 | - // Translators: %1$d is the number of events, %2$s is the date | |
| 2668 | - .' 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']))).'"' | |
| 2669 | - .'>' | |
| 2670 | - . date('j', $date) | |
| 2671 | - . '</button>'; | |
| 2672 | - } | |
| 2673 | - } | |
| 2674 | - return apply_filters('eventpost_display_caldate', $ret, $events, $date, $cat ,$price, $display ,$colored ,$thumbnail ,$title ,$tax_name ,$tax_term ); | |
| 2675 | - } | |
| 1811 | + $annee = substr($date, 0, 4); | |
| 1812 | + $mois = substr($date, 5); | |
| 2676 | 1813 | |
| 1814 | + $time = mktime(0, 0, 0, $mois, 1, $annee); | |
| 2677 | 1815 | |
| 2678 | - /** | |
| 2679 | - * Returns a calendar HTML | |
| 2680 | - * | |
| 2681 | - * @param array $atts | |
| 2682 | - * | |
| 2683 | - * @filter eventpost_params | |
| 2684 | - * | |
| 2685 | - * @return string | |
| 2686 | - */ | |
| 2687 | - public function calendar($atts) { | |
| 2688 | - extract(shortcode_atts(apply_filters('eventpost_params', array( | |
| 2689 | - 'date' => date('Y-n'), | |
| 2690 | - 'cat' => '', | |
| 2691 | - 'mondayfirst' => 0, //1 : weeks starts on monday | |
| 2692 | - 'datepicker' => 1, | |
| 2693 | - 'colored' => 1, | |
| 2694 | - 'display_title'=>0, | |
| 2695 | - 'tax_name' => '', | |
| 2696 | - 'tax_term' => '', | |
| 2697 | - 'thumbnail'=>'', | |
| 2698 | - ), 'calendar'), $atts)); | |
| 1816 | + $prev_year = strtotime('-1 Year', $time); | |
| 1817 | + $next_year = strtotime('+1 Year', $time); | |
| 1818 | + $prev_month = strtotime('-1 Month', $time); | |
| 1819 | + $next_month = strtotime('+1 Month', $time); | |
| 2699 | 1820 | |
| 2700 | - if($date && !preg_match('#[0-9][0-9][0-9][0-9]-[0-9][0-9]?#i', $date)){ | |
| 2701 | - $date = date('Y-n', strtotime($date)); | |
| 2702 | - } | |
| 2703 | - if(!$date){ | |
| 2704 | - $date = date('Y-n'); | |
| 2705 | - } | |
| 1821 | + $JourMax = date("t", $time); | |
| 1822 | + $NoJour = -date("w", $time); | |
| 1823 | + if ($mondayfirst == 0) { | |
| 1824 | + $NoJour +=1; | |
| 1825 | + } else { | |
| 1826 | + $NoJour +=2; | |
| 1827 | + $this->Week[] = array_shift($this->Week); | |
| 1828 | + } | |
| 1829 | + if ($NoJour > 0 && $mondayfirst == 1) { | |
| 1830 | + $NoJour -=7; | |
| 1831 | + } | |
| 1832 | + $ret = '<table class="event-post-calendar-table">' | |
| 1833 | + . '<caption class="screen-reader-text">' | |
| 1834 | + . __('A calendar of events', 'event-post') | |
| 1835 | + . '</caption>'; | |
| 1836 | + $ret.='<thead><tr><th colspan="7">'; | |
| 1837 | + if ($datepicker == 1) { | |
| 1838 | + $ret.='<div>'; | |
| 1839 | + $ret.='<button data-date="' . date('Y-n', $prev_year) . '" tabindex="0" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $prev_year)).'" class="eventpost_cal_bt"><<</button> '; | |
| 1840 | + $ret.=$annee; | |
| 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> '; | |
| 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> '; | |
| 1843 | + $ret.=$this->NomDuMois[abs($mois)]; | |
| 1844 | + $ret.='<button data-date="' . date('Y-n', $next_month) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date_i18n('F Y', $next_month)).'" class="eventpost_cal_bt">></button> '; | |
| 1845 | + $ret.='<button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button>'; | |
| 1846 | + $ret.='</div>'; | |
| 1847 | + } | |
| 1848 | + $ret.='</th></tr><tr class="event_post_cal_days">'; | |
| 1849 | + for ($w = 0; $w < 7; $w++) { | |
| 1850 | + $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>'; | |
| 1851 | + } | |
| 1852 | + $ret.='</tr>'; | |
| 1853 | + $ret.='</thead>'; | |
| 2706 | 1854 | |
| 2707 | - $annee = substr($date, 0, 4); | |
| 2708 | - $mois = substr($date, 5); | |
| 1855 | + $ret.='<tbody>'; | |
| 1856 | + $sqldate = date('Y-m', $time); | |
| 1857 | + $cejour = date('Y-m-d'); | |
| 1858 | + for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois | |
| 1859 | + $ret.='<tr>'; | |
| 1860 | + for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine | |
| 1861 | + if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher | |
| 1862 | + $td = '<td class="event_post_day">'; | |
| 1863 | + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) { | |
| 1864 | + $td = '<td class="event_post_day_now">'; | |
| 1865 | + } | |
| 1866 | + if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){ | |
| 1867 | + $td = '<td class="event_post_day_over">'; // Patch ahf | |
| 1868 | + } | |
| 1869 | + $ret.=$td; | |
| 2709 | 1870 | |
| 2710 | - $time = mktime(0, 0, 0, $mois, 1, $annee); | |
| 1871 | + $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail); | |
| 1872 | + $ret.='</td>'; | |
| 1873 | + } else { | |
| 1874 | + $ret.='<td></td>'; | |
| 1875 | + } | |
| 1876 | + $NoJour ++; | |
| 1877 | + } | |
| 1878 | + $ret.='</tr>'; | |
| 1879 | + } | |
| 1880 | + $ret.='</tbody></table>'; | |
| 1881 | + return $ret; | |
| 1882 | + } | |
| 2711 | 1883 | |
| 2712 | - $prev_year = strtotime('-1 Year', $time); | |
| 2713 | - $next_year = strtotime('+1 Year', $time); | |
| 2714 | - $prev_month = strtotime('-1 Month', $time); | |
| 2715 | - $next_month = strtotime('+1 Month', $time); | |
| 1884 | + /** | |
| 1885 | + * echoes the content of the calendar in ajax context | |
| 1886 | + */ | |
| 1887 | + public function ajaxcal() { | |
| 1888 | + echo $this->calendar(array( | |
| 1889 | + 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')), | |
| 1890 | + 'cat' => esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), | |
| 1891 | + 'mondayfirst' => esc_attr(FILTER_INPUT(INPUT_GET, 'mf')), | |
| 1892 | + 'datepicker' => esc_attr(FILTER_INPUT(INPUT_GET, 'dp')), | |
| 1893 | + 'colored' => esc_attr(FILTER_INPUT(INPUT_GET, 'color')), | |
| 1894 | + 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')), | |
| 1895 | + )); | |
| 1896 | + exit(); | |
| 1897 | + } | |
| 2716 | 1898 | |
| 2717 | - $JourMax = date("t", $time); | |
| 2718 | - $NoJour = -date("w", $time); | |
| 2719 | - if ($mondayfirst == 0) { | |
| 2720 | - $NoJour +=1; | |
| 2721 | - } else { | |
| 2722 | - $NoJour +=2; | |
| 2723 | - $this->Week[] = array_shift($this->Week); | |
| 2724 | - } | |
| 2725 | - if ($NoJour > 0 && $mondayfirst == 1) { | |
| 2726 | - $NoJour -=7; | |
| 2727 | - } | |
| 2728 | - $ret = '<table class="event-post-calendar-table">' | |
| 2729 | - . '<caption class="screen-reader-text">' | |
| 2730 | - . __('A calendar of events', 'event-post') | |
| 2731 | - . '</caption>'; | |
| 2732 | - $ret.='<thead><tr><th colspan="7">'; | |
| 2733 | - if ($datepicker == 1) { | |
| 2734 | - $ret.='<div class="eventpost-calendar-header">'; | |
| 2735 | - // Translators: %s is the year | |
| 2736 | - $ret.='<span class="eventpost-cal-year"><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 eventpost-cal-bt-prev">«</button><span class="eventpost-cal-header-text">'; | |
| 2737 | - $ret.=$annee; | |
| 2738 | - // Translators: %s is the year | |
| 2739 | - $ret.='</span><button data-date="' . date('Y-n', $next_year) . '" title="'.sprintf(__('Switch to %s', 'event-post'), date('Y', $next_year)).'" class="eventpost_cal_bt eventpost-cal-bt-next">»</button></span>'; | |
| 2740 | - // Translators: %s is the month name | |
| 2741 | - $ret.='<span class="eventpost-cal-month"><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 eventpost-cal-bt-prev eventpost-cal-bt-prev-month">«</button><span class="eventpost-cal-header-text">'; | |
| 2742 | - $ret.=$this->NomDuMois[abs($mois)]; | |
| 2743 | - // Translators: %s is the month name | |
| 2744 | - $ret.='</span><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 eventpost-cal-bt-next eventpost-cal-bt-next-month">»</button> </span>'; | |
| 2745 | - $ret.='<span class="eventpost-cal-today"><button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button></span>'; | |
| 2746 | - $ret.='</div>'; | |
| 2747 | - } | |
| 2748 | - $ret.='</th></tr><tr class="event_post_cal_days">'; | |
| 2749 | - for ($w = 0; $w < 7; $w++) { | |
| 2750 | - $ret.='<th scope="col">' . strtoupper(substr($this->Week[$w], 0, 1)) . '</th>'; | |
| 2751 | - } | |
| 2752 | - $ret.='</tr>'; | |
| 2753 | - $ret.='</thead>'; | |
| 1899 | + /** | |
| 1900 | + * echoes the date of the calendar in ajax context | |
| 1901 | + */ | |
| 1902 | + public function ajaxdate() { | |
| 1903 | + echo $this->display_caldate(strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))), esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), true, esc_attr(FILTER_INPUT(INPUT_GET, 'color')), esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail'))); | |
| 1904 | + exit(); | |
| 1905 | + } | |
| 2754 | 1906 | |
| 2755 | - $ret.='<tbody>'; | |
| 2756 | - $sqldate = date('Y-m', $time); | |
| 2757 | - $cejour = date('Y-m-d'); | |
| 2758 | - for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois | |
| 2759 | - $tr_row_content =''; | |
| 2760 | - for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine | |
| 2761 | - if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher | |
| 2762 | - $td = '<td class="event_post_day">'; | |
| 2763 | - if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) { | |
| 2764 | - $td = '<td class="event_post_day_now">'; | |
| 2765 | - } | |
| 2766 | - if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour < $cejour){ | |
| 2767 | - $td = '<td class="event_post_day_over">'; // Patch ahf | |
| 2768 | - } | |
| 2769 | - $tr_row_content.=$td; | |
| 2770 | - $tr_row_content.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail, $display_title ,$tax_name ,$tax_term); | |
| 2771 | - $tr_row_content.='</td>'; | |
| 2772 | - } else { | |
| 2773 | - $tr_row_content.='<td></td>'; | |
| 2774 | - } | |
| 2775 | - $NoJour ++; | |
| 2776 | - } | |
| 2777 | - if($tr_row_content){ | |
| 2778 | - $ret.='<tr>'.$tr_row_content.'</tr>'; | |
| 2779 | - } | |
| 1907 | + /** | |
| 1908 | + * echoes a date in ajax context | |
| 1909 | + */ | |
| 1910 | + public function HumanDate() { | |
| 1911 | + if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) { | |
| 1912 | + $date = strtotime($_REQUEST['date']); | |
| 1913 | + echo $this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date)); | |
| 1914 | + exit(); | |
| 1915 | + } | |
| 1916 | + } | |
| 2780 | 1917 | |
| 2781 | - } | |
| 2782 | - $ret.='</tbody></table>'; | |
| 2783 | - return $ret; | |
| 2784 | - } | |
| 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++; | |
| 2785 | 1931 | |
| 2786 | - /** | |
| 2787 | - * Echoes a list of event, should be called via AJAX | |
| 2788 | - * | |
| 2789 | - * @return void | |
| 2790 | - */ | |
| 2791 | - public function ajaxlist(){ | |
| 2792 | - echo wp_kses($this->list_events(array( | |
| 2793 | - 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')), | |
| 2794 | - 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')), | |
| 2795 | - 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')), | |
| 2796 | - 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')), | |
| 2797 | - 'width' => esc_attr(FILTER_INPUT(INPUT_POST, 'width')), | |
| 2798 | - 'height' => esc_attr(FILTER_INPUT(INPUT_POST, 'height')), | |
| 2799 | - 'zoom' => esc_attr(FILTER_INPUT(INPUT_POST, 'zoom')), | |
| 2800 | - 'tile' => esc_attr(FILTER_INPUT(INPUT_POST, 'tile')), | |
| 2801 | - 'title' => esc_attr(FILTER_INPUT(INPUT_POST, 'title')), | |
| 2802 | - 'before_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'before_title')), | |
| 2803 | - 'after_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'after_title')), | |
| 2804 | - 'cat' => esc_attr(FILTER_INPUT(INPUT_POST, 'cat')), | |
| 2805 | - 'tag' => esc_attr(FILTER_INPUT(INPUT_POST, 'tag')), | |
| 2806 | - 'events' => esc_attr(FILTER_INPUT(INPUT_POST, 'events')), | |
| 2807 | - 'style' => esc_attr(FILTER_INPUT(INPUT_POST, 'style')), | |
| 2808 | - 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail')), | |
| 2809 | - 'thumbnail_size' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail_size')), | |
| 2810 | - 'excerpt' => esc_attr(FILTER_INPUT(INPUT_POST, 'excerpt')), | |
| 2811 | - 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')), | |
| 2812 | - 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')), | |
| 2813 | - 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')), | |
| 2814 | - 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')), | |
| 2815 | - ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags); | |
| 2816 | - exit; | |
| 2817 | - } | |
| 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 : ''; | |
| 2818 | 1937 | |
| 2819 | - /** | |
| 2820 | - * Echoes a list of event, should be called via AJAX | |
| 2821 | - * | |
| 2822 | - * @return void | |
| 2823 | - */ | |
| 2824 | - public function ajaxTimeline(){ | |
| 2825 | - echo wp_kses($this->list_events(array( | |
| 2826 | - 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')), | |
| 2827 | - 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')), | |
| 2828 | - 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')), | |
| 2829 | - 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')), | |
| 2830 | - 'width' => esc_attr(FILTER_INPUT(INPUT_POST, 'width')), | |
| 2831 | - 'height' => esc_attr(FILTER_INPUT(INPUT_POST, 'height')), | |
| 2832 | - 'zoom' => esc_attr(FILTER_INPUT(INPUT_POST, 'zoom')), | |
| 2833 | - 'tile' => esc_attr(FILTER_INPUT(INPUT_POST, 'tile')), | |
| 2834 | - 'title' => esc_attr(FILTER_INPUT(INPUT_POST, 'title')), | |
| 2835 | - 'before_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'before_title')), | |
| 2836 | - 'after_title' => esc_attr(FILTER_INPUT(INPUT_POST, 'after_title')), | |
| 2837 | - 'cat' => esc_attr(FILTER_INPUT(INPUT_POST, 'cat')), | |
| 2838 | - 'tag' => esc_attr(FILTER_INPUT(INPUT_POST, 'tag')), | |
| 2839 | - 'events' => esc_attr(FILTER_INPUT(INPUT_POST, 'events')), | |
| 2840 | - 'style' => esc_attr(FILTER_INPUT(INPUT_POST, 'style')), | |
| 2841 | - 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail')), | |
| 2842 | - 'thumbnail_size' => esc_attr(FILTER_INPUT(INPUT_POST, 'thumbnail_size')), | |
| 2843 | - 'excerpt' => esc_attr(FILTER_INPUT(INPUT_POST, 'excerpt')), | |
| 2844 | - 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')), | |
| 2845 | - 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')), | |
| 2846 | - 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')), | |
| 2847 | - 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')), | |
| 2848 | - ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags); | |
| 2849 | - exit; | |
| 2850 | - } | |
| 2851 | - /** | |
| 2852 | - * Echoes next page of events, should be called via AJAX | |
| 2853 | - * | |
| 2854 | - * @return void | |
| 2855 | - */ | |
| 2856 | - public function ajaxGetNextPage(){ | |
| 2857 | - $response = [ | |
| 2858 | - "success" => false, | |
| 2859 | - "next_query" => false, | |
| 2860 | - ]; | |
| 2861 | - if(isset($_POST['query'])){ | |
| 2862 | - parse_str($_POST['query'],$query); | |
| 2863 | - foreach($query as $key => $value){ | |
| 2864 | - $query[$key] = esc_attr($value); | |
| 2865 | - } | |
| 2866 | - if(isset($_POST['paged'])){ | |
| 2867 | - $query["paged"] = esc_attr($_POST['paged']); | |
| 2868 | - }else{ | |
| 2869 | - $response['message'] = __('Page number missing', 'event-post'); | |
| 2870 | - } | |
| 2871 | - $query['container_schema'] = $this->timeline_shema['container']; | |
| 2872 | - $query['item_schema'] = $this->timeline_shema['item']; | |
| 2873 | - $html = $this->list_events($query,'event_timeline','events_only'); | |
| 2874 | - if($html == ""){ | |
| 2875 | - $response['message'] = __('No more to load', 'event-post'); | |
| 2876 | - }else{ | |
| 2877 | - $query["paged"] = $query["paged"] + 1; | |
| 2878 | - $next_html = $this->list_events($query,'event_timeline','events_only'); | |
| 2879 | - $response = [ | |
| 2880 | - "success" => true, | |
| 2881 | - "html" => $html, | |
| 2882 | - "next_query" => $next_html == "" ? false : true, | |
| 2883 | - ]; | |
| 2884 | - } | |
| 2885 | - }else{ | |
| 2886 | - $response['message'] = __('Query missing', 'event-post'); | |
| 2887 | - } | |
| 2888 | - wp_send_json($response); | |
| 2889 | - exit; | |
| 2890 | - } | |
| 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 | + } | |
| 2891 | 1946 | |
| 2892 | - /** | |
| 2893 | - * Echoes the content of the calendar in ajax context | |
| 2894 | - * | |
| 2895 | - * @return void | |
| 2896 | - */ | |
| 2897 | - public function ajaxcal() { | |
| 2898 | - $method = isset($_GET['action']) ? INPUT_GET : INPUT_POST; | |
| 2899 | - echo wp_kses($this->calendar(array( | |
| 2900 | - 'date' => esc_attr(FILTER_INPUT($method, 'date')), | |
| 2901 | - 'cat' => esc_attr(FILTER_INPUT($method, 'cat')), | |
| 2902 | - 'mondayfirst' => esc_attr(FILTER_INPUT($method, 'mf')), | |
| 2903 | - 'datepicker' => esc_attr(FILTER_INPUT($method, 'dp')), | |
| 2904 | - 'colored' => esc_attr(FILTER_INPUT($method, 'color')), | |
| 2905 | - 'display_title' => esc_attr(FILTER_INPUT($method, 'display_title')), | |
| 2906 | - 'thumbnail' => esc_attr(FILTER_INPUT($method, 'thumbnail')), | |
| 2907 | - 'tax_name' => esc_attr(FILTER_INPUT($method, 'tax_name')), | |
| 2908 | - 'tax_term' => esc_attr(FILTER_INPUT($method, 'tax_term')), | |
| 2909 | - )), $this->kses_tags); | |
| 2910 | - exit(); | |
| 2911 | - } | |
| 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'); | |
| 2912 | 1951 | |
| 2913 | - /** | |
| 2914 | - * Echoes the date of the calendar in ajax context | |
| 2915 | - */ | |
| 2916 | - public function ajaxdate() { | |
| 2917 | - echo wp_kses($this->display_caldate( | |
| 2918 | - strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))), | |
| 2919 | - esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), | |
| 2920 | - true, | |
| 2921 | - esc_attr(FILTER_INPUT(INPUT_GET, 'color')), | |
| 2922 | - esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')), | |
| 2923 | - esc_attr(FILTER_INPUT(INPUT_GET, 'display_title')), | |
| 2924 | - esc_attr(FILTER_INPUT(INPUT_GET, 'tax_name')), | |
| 2925 | - esc_attr(FILTER_INPUT(INPUT_GET, 'tax_term')) | |
| 2926 | - ), $this->kses_tags); | |
| 2927 | - exit(); | |
| 2928 | - } | |
| 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 | + } | |
| 2929 | 1964 | |
| 2930 | - /** | |
| 2931 | - * Echoes a date in ajax context | |
| 2932 | - */ | |
| 2933 | - public function HumanDate() { | |
| 2934 | - if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) { | |
| 2935 | - $date = strtotime($_REQUEST['date']); | |
| 2936 | - echo esc_html($this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date))); | |
| 2937 | - exit(); | |
| 2938 | - } | |
| 2939 | - } | |
| 1965 | + if ($from || $to) { | |
| 2940 | 1966 | |
| 2941 | - /** | |
| 2942 | - * Displays a search form | |
| 2943 | - * | |
| 2944 | - * @param type $atts | |
| 2945 | - * | |
| 2946 | - * @return type | |
| 2947 | - */ | |
| 2948 | - public function search($atts) { | |
| 2949 | - $params = shortcode_atts(apply_filters('eventpost_params', array( | |
| 2950 | - 'dates' => true, | |
| 2951 | - 'q' => true, | |
| 2952 | - 'tax' => false, | |
| 2953 | - ), 'search'), $atts); | |
| 2954 | - $this->list_id++; | |
| 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 | + } | |
| 2955 | 1992 | |
| 2956 | - $list_id = $this->list_id; | |
| 2957 | - $q = (false !== $q = filter_input(INPUT_GET, 'q')) ? $q : ''; | |
| 2958 | - $from = (false !== $from = filter_input(INPUT_GET, 'from')) ? $from : ''; | |
| 2959 | - $to = (false !== $to = filter_input(INPUT_GET, 'to')) ? $to : ''; | |
| 2960 | - $tax = (false !== $tax = filter_input(INPUT_GET, 'tax')) ? $tax : ''; | |
| 1993 | + /** | |
| 1994 | + * AJAX Get lat long from address | |
| 1995 | + */ | |
| 1996 | + public function GetLatLong() { | |
| 1997 | + if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { | |
| 1998 | + // verifier le cache | |
| 1999 | + $q = $_REQUEST['q']; | |
| 2000 | + header('Content-Type: application/json'); | |
| 2001 | + $transient_name = 'eventpost_osquery_' . $q; | |
| 2002 | + $val = get_transient($transient_name); | |
| 2003 | + if (false === $val || empty($val) || !is_string($val)) { | |
| 2004 | + $language = get_bloginfo('language'); | |
| 2005 | + if (strpos($language, '-') > -1) { | |
| 2006 | + $language = strtolower(substr($language, 0, 2)); | |
| 2007 | + } | |
| 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 | + } | |
| 2012 | + set_transient($transient_name, $val, 30 * DAY_IN_SECONDS); | |
| 2013 | + } | |
| 2014 | + echo $val; | |
| 2015 | + exit(); | |
| 2016 | + } | |
| 2017 | + } | |
| 2961 | 2018 | |
| 2962 | - $cleaned_from = $this->date_cleanup($from); | |
| 2963 | - $cleaned_to = $this->date_cleanup($to); | |
| 2964 | - if(empty($cleaned_from)){ | |
| 2965 | - $from=false; | |
| 2966 | - } | |
| 2967 | - if(empty($cleaned_to)){ | |
| 2968 | - $to=false; | |
| 2969 | - } | |
| 2019 | + /** | |
| 2020 | + * alters columns | |
| 2021 | + * @param array $defaults | |
| 2022 | + * @return array | |
| 2023 | + * @filter eventpost_columns_head | |
| 2024 | + */ | |
| 2025 | + public function columns_head($defaults) { | |
| 2026 | + $defaults['event'] = __('Event', 'event-post'); | |
| 2027 | + $defaults['location'] = __('Location', 'event-post'); | |
| 2028 | + return apply_filters('eventpost_columns_head', $defaults); | |
| 2029 | + } | |
| 2970 | 2030 | |
| 2971 | - // Search form | |
| 2972 | - $this->admin_scripts(null, true); | |
| 2973 | - wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, filemtime( "/$block_js" )); | |
| 2974 | - include (plugin_dir_path(__FILE__) . 'views/search-form.php'); | |
| 2031 | + /** | |
| 2032 | + * echoes content of a row in a given column | |
| 2033 | + * @param string $column_name | |
| 2034 | + * @param int $post_id | |
| 2035 | + * @action eventpost_columns_content | |
| 2036 | + */ | |
| 2037 | + public function columns_content($column_name, $post_id) { | |
| 2038 | + if ($column_name == 'location') { | |
| 2039 | + $lat = get_post_meta($post_id, $this->META_LAT, true); | |
| 2040 | + $lon = get_post_meta($post_id, $this->META_LONG, true); | |
| 2975 | 2041 | |
| 2976 | - // Results | |
| 2977 | - if ($list_id == filter_input(INPUT_GET, 'evenpost_search')) { | |
| 2978 | - $arg = array( | |
| 2979 | - 'post_type' => $this->settings['posttypes'], | |
| 2980 | - 'meta_key' => $this->META_START, | |
| 2981 | - 'orderby' => 'meta_value', | |
| 2982 | - 'order' => 'ASC', | |
| 2983 | - 's' => $q | |
| 2984 | - ); | |
| 2985 | - if ($tax) { | |
| 2986 | - $arg['cat'] = $tax; | |
| 2987 | - } | |
| 2042 | + if (!empty($lat) && !empty($lon)) { | |
| 2043 | + add_thickbox(); | |
| 2044 | + $color = get_post_meta($post_id, $this->META_COLOR, true); | |
| 2045 | + if ($color == ''){ | |
| 2046 | + $color = '777777'; | |
| 2047 | + } | |
| 2048 | + echo '<a href="https://www.openstreetmap.org/export/embed.html?bbox='.($lon-0.005).'%2C'.($lat-0.005).'%2C'.($lon+0.005).'%2C'.($lat+0.005).'&TB_iframe=true&width=600&height=550" class="thickbox" target="_blank">' | |
| 2049 | + . '<i class="dashicons dashicons-location" style="color:#'.$color.';"></i>' | |
| 2050 | + . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>' | |
| 2051 | + . get_post_meta($post_id, $this->META_ADD, true) | |
| 2052 | + . '</a> '; | |
| 2053 | + } | |
| 2054 | + $this->column_edit_hidden_fields($post_id, 'location'); | |
| 2055 | + } | |
| 2056 | + if ($column_name == 'event') { | |
| 2057 | + echo $this->print_date($post_id, false); | |
| 2058 | + $this->column_edit_hidden_fields($post_id, 'event'); | |
| 2059 | + } | |
| 2060 | + do_action('eventpost_columns_content', $column_name, $post_id); | |
| 2061 | + } | |
| 2988 | 2062 | |
| 2989 | - if ($from || $to) { | |
| 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 | + } | |
| 2990 | 2071 | |
| 2991 | - $arg['meta_query'] = array(); | |
| 2992 | - if ($from) { | |
| 2993 | - $arg['meta_query'][] = array( | |
| 2994 | - 'key' => $this->META_START, | |
| 2995 | - 'value' => $from, | |
| 2996 | - 'compare' => '>=', | |
| 2997 | - 'type' => 'DATETIME' | |
| 2998 | - ); | |
| 2999 | - } | |
| 3000 | - if ($to) { | |
| 3001 | - $arg['meta_query'][] = $meta_query = array( | |
| 3002 | - array( | |
| 3003 | - 'key' => $this->META_END, | |
| 3004 | - 'value' => $to, | |
| 3005 | - 'compare' => '<=', | |
| 3006 | - 'type' => 'DATETIME' | |
| 3007 | - ), | |
| 3008 | - ); | |
| 3009 | - } | |
| 3010 | - } | |
| 3011 | - $events = new WP_Query($arg); | |
| 3012 | - include (plugin_dir_path(__FILE__) . 'views/search-results.php'); | |
| 3013 | - wp_reset_query(); | |
| 3014 | - } | |
| 3015 | - } | |
| 2072 | + /** ADMIN PAGES **/ | |
| 3016 | 2073 | |
| 3017 | - /** | |
| 3018 | - * Geocodes an address using OpenStreetMap Nominatim API and cache the result in a transient for 30 days | |
| 3019 | - * | |
| 3020 | - * @param string $address | |
| 3021 | - * @param boolean $single_result Whether to return only the first result or all results | |
| 3022 | - * | |
| 3023 | - * @return array|false|string The geocoding result(s) or false on failure | |
| 3024 | - */ | |
| 3025 | - public function geocode(string $address, bool $single_result = false){ | |
| 3026 | - $transient_name = 'eventpost_osquery_' . $address; | |
| 3027 | - $val = get_transient($transient_name); | |
| 3028 | - if (false === $val || empty($val) || !is_string($val)) { | |
| 3029 | - $language = get_bloginfo('language'); | |
| 3030 | - if (strpos($language, '-') > -1) { | |
| 3031 | - $language = strtolower(substr($language, 0, 2)); | |
| 3032 | - } | |
| 3033 | - $remote_val = wp_safe_remote_request('https://nominatim.openstreetmap.org/search?q=' . rawurlencode($address) . '&format=json&accept-language=' . $language, [ | |
| 3034 | - 'user-agent' => getenv('HTTP_USER_AGENT') ?? 'WordPress/' . get_bloginfo('version') . '; ' . get_bloginfo('url'), | |
| 3035 | - 'headers' => [ | |
| 3036 | - 'Referer' => get_bloginfo('url'), | |
| 3037 | - ], | |
| 3038 | - 'timeout' => 5, | |
| 3039 | - ]); | |
| 3040 | - $remote_body = wp_remote_retrieve_body($remote_val); | |
| 3041 | - if(strstr($remote_body, '<html>')){ | |
| 3042 | - $val = [ | |
| 3043 | - [ | |
| 3044 | - 'lat' => '', | |
| 3045 | - 'lon' => '', | |
| 3046 | - 'display_name' => strip_tags($remote_body), | |
| 3047 | - ] | |
| 3048 | - ]; | |
| 3049 | - } | |
| 3050 | - else{ | |
| 3051 | - $val = json_decode($remote_body); | |
| 3052 | - if($val){ | |
| 3053 | - set_transient($transient_name, $val, 30 * DAY_IN_SECONDS); | |
| 3054 | - } | |
| 3055 | - } | |
| 3056 | - } | |
| 3057 | - if($single_result && is_array($val) && count($val) > 0){ | |
| 3058 | - $val = $val[0]; | |
| 3059 | - } | |
| 3060 | - return $val; | |
| 3061 | - } | |
| 2074 | + /** | |
| 2075 | + * Settings link on the plugins page | |
| 2076 | + */ | |
| 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); | |
| 2096 | + } | |
| 2097 | + return $plugin_meta; | |
| 2098 | + } | |
| 3062 | 2099 | |
| 3063 | - /** | |
| 3064 | - * AJAX Get lat long from address | |
| 3065 | - */ | |
| 3066 | - public function GetLatLong() { | |
| 3067 | - if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { | |
| 3068 | - // verifier le cache | |
| 3069 | - $q = $_REQUEST['q']; | |
| 3070 | - header('Content-Type: application/json'); | |
| 3071 | - $val = $this->geocode($q); | |
| 3072 | - wp_send_json( $val ); | |
| 3073 | - exit(); | |
| 3074 | - } | |
| 3075 | - } | |
| 2100 | + /** | |
| 2101 | + * adds menu items | |
| 2102 | + */ | |
| 2103 | + public function manage_options() { | |
| 2104 | + add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings')); | |
| 2105 | + } | |
| 2106 | + /** | |
| 2107 | + * adds items to the native "right now" dashboard widget | |
| 2108 | + * @param array $elements | |
| 2109 | + * @return array | |
| 2110 | + */ | |
| 2111 | + public function dashboard_right_now($elements){ | |
| 2112 | + $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))); | |
| 2113 | + $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1))); | |
| 2114 | + if($nb_date){ | |
| 2115 | + array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','event-post'), $nb_date)."</i>"); | |
| 2116 | + } | |
| 2117 | + if($nb_geo){ | |
| 2118 | + array_push($elements, '<i class="dashicons dashicons-location"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Geolocalized events','event-post'), $nb_geo)."</i>"); | |
| 2119 | + } | |
| 2120 | + return $elements; | |
| 2121 | + } | |
| 3076 | 2122 | |
| 3077 | - /** | |
| 3078 | - * Alters columns | |
| 3079 | - * | |
| 3080 | - * @param array $defaults | |
| 3081 | - * | |
| 3082 | - * @filter eventpost_columns_head | |
| 3083 | - * | |
| 3084 | - * @return array | |
| 3085 | - */ | |
| 3086 | - public function columns_head($defaults) { | |
| 3087 | - $defaults['event'] = __('Event', 'event-post'); | |
| 3088 | - $defaults['location'] = __('Location', 'event-post'); | |
| 3089 | - return apply_filters('eventpost_columns_head', $defaults); | |
| 3090 | - } | |
| 2123 | + /** | |
| 2124 | + * @action eventpost_register_settings | |
| 2125 | + */ | |
| 2126 | + public function register_settings(){ | |
| 2127 | + register_setting( 'eventpost-settings', 'ep_settings' ); | |
| 3091 | 2128 | |
| 3092 | - /** | |
| 3093 | - * Echoes content of a row in a given column | |
| 3094 | - * | |
| 3095 | - * @param string $column_name | |
| 3096 | - * @param int $post_id | |
| 3097 | - * | |
| 3098 | - * @action eventpost_columns_content | |
| 3099 | - */ | |
| 3100 | - public function columns_content($column_name, $post_id) { | |
| 3101 | - if ($column_name == 'location') { | |
| 3102 | - $lat = $this->sanitize_coordinate(get_post_meta($post_id, $this->META_LAT, true)); | |
| 3103 | - $lon = $this->sanitize_coordinate(get_post_meta($post_id, $this->META_LONG, true)); | |
| 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 | + ); | |
| 3104 | 2184 | |
| 3105 | - if (!empty($lat) && !empty($lon)) { | |
| 3106 | - add_thickbox(); | |
| 3107 | - $color = $this->get_post_color($post_id, $this->settings['default_color'], true); | |
| 3108 | - $icon = $this->get_post_icon($post_id, $this->settings['default_icon'], true); | |
| 3109 | - if ($color == ''){ | |
| 3110 | - $color = '777777'; | |
| 3111 | - } | |
| 3112 | - if ($icon == ''){ | |
| 3113 | - $icon = 'location'; | |
| 3114 | - } | |
| 3115 | - echo wp_kses( '<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">' | |
| 3116 | - . '<i class="dashicons dashicons-'.$icon.'" style="color:#'.$color.';"></i>' | |
| 3117 | - . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>' | |
| 3118 | - . get_post_meta($post_id, $this->META_ADD, true) | |
| 3119 | - . '</a> ', $this->kses_tags); | |
| 3120 | - } | |
| 3121 | - $this->column_edit_hidden_fields($post_id, 'location'); | |
| 3122 | - } | |
| 3123 | - if ($column_name == 'event') { | |
| 3124 | - echo wp_kses($this->print_date($post_id, false), $this->kses_tags); | |
| 3125 | - $this->column_edit_hidden_fields($post_id, 'event'); | |
| 3126 | - } | |
| 3127 | - do_action('eventpost_columns_content', $column_name, $post_id); | |
| 3128 | - } | |
| 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 | + ); | |
| 3129 | 2235 | |
| 3130 | - function column_edit_hidden_fields($post_id, $set){ | |
| 3131 | - $event = $this->retreive($post_id); | |
| 3132 | - $html = '<div class="hidden">'; | |
| 3133 | - if ($event != false){ | |
| 3134 | - foreach($this->quick_edit_fields[$set] as $fieldname=>$fieldlabel){ | |
| 3135 | - $html .= '<span class="inline-edit-value '.$fieldname.'">'.esc_attr($event->$fieldname).'</span>'; | |
| 3136 | - } | |
| 3137 | - } | |
| 3138 | - $html .= '</div>'; | |
| 3139 | - echo wp_kses($html, $this->kses_tags); | |
| 3140 | - } | |
| 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 | + ); | |
| 3141 | 2260 | |
| 3142 | - // ADMIN PAGES | |
| 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 | + ); | |
| 3143 | 2305 | |
| 3144 | - /** | |
| 3145 | - * Adds items to the native "right now" dashboard widget | |
| 3146 | - * | |
| 3147 | - * @param array $elements | |
| 3148 | - * | |
| 3149 | - * @return array | |
| 3150 | - */ | |
| 3151 | - public function dashboard_right_now($elements){ | |
| 3152 | - $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))); | |
| 3153 | - $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1))); | |
| 3154 | - if($nb_date){ | |
| 3155 | - // Translators: %d is the number of events | |
| 3156 | - array_push($elements, '<i class="dashicons dashicons-calendar"></i> <i href="edit.php?post_type=post">'.sprintf(__('%d Events','event-post'), $nb_date)."</i>"); | |
| 3157 | - } | |
| 3158 | - if($nb_geo){ | |
| 3159 | - // Translators: %d is the number of geolocalized events | |
| 3160 | - 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>"); | |
| 3161 | - } | |
| 3162 | - return $elements; | |
| 3163 | - } | |
| 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 | + ); | |
| 3164 | 2354 | |
| 3165 | - /* | |
| 3166 | - * Feed | |
| 3167 | - * generate ICS or VCS files from a category | |
| 3168 | - */ | |
| 2355 | + do_action('eventpost_register_settings'); | |
| 2356 | + } | |
| 2357 | + function settings_section_callback( $arg ) { | |
| 2358 | + echo '<hr>'; | |
| 2359 | + } | |
| 3169 | 2360 | |
| 3170 | - /** | |
| 3171 | - * Get a date formatted for ICS | |
| 3172 | - * | |
| 3173 | - * @param timestamp $timestamp | |
| 3174 | - * | |
| 3175 | - * @return string | |
| 3176 | - */ | |
| 3177 | - public function ics_date($timestamp){ | |
| 3178 | - return date("Ymd",$timestamp).'T'.date("His",$timestamp); | |
| 3179 | - } | |
| 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(); ?> | |
| 2448 | + </form> | |
| 2449 | + </div> | |
| 2450 | + <?php | |
| 2451 | + do_action('eventpost_after_settings_form'); | |
| 2452 | + } | |
| 3180 | 2453 | |
| 3181 | - public function get_gmt_offset(){ | |
| 3182 | - $gmt_offset = get_option('gmt_offset '); | |
| 3183 | - $codegmt = 0; | |
| 3184 | - if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') { | |
| 3185 | - $codegmt = $gmt_offset * -1; | |
| 3186 | - $gmt_offset = '+' . $gmt_offset; | |
| 3187 | - } | |
| 3188 | - if(abs($gmt_offset < 10)){ | |
| 3189 | - $gmt_offset = substr($gmt_offset, 0, 1).'0'.substr($gmt_offset, 1); | |
| 3190 | - } | |
| 3191 | - return $gmt_offset; | |
| 3192 | - } | |
| 2454 | + /* | |
| 2455 | + * feed | |
| 2456 | + * generate ICS or VCS files from a category | |
| 2457 | + */ | |
| 3193 | 2458 | |
| 3194 | - /** | |
| 3195 | - * Outputs an ICS or VCS file for a given event | |
| 3196 | - * | |
| 3197 | - * @param int $event_id | |
| 3198 | - * @param string $format | |
| 3199 | - * | |
| 3200 | - * @return void | |
| 3201 | - */ | |
| 3202 | - private function generate_ics($event_id, $format){ | |
| 3203 | - $allowed_formats = array('ics', 'vcs'); | |
| 3204 | - $event_id = intval($event_id); | |
| 3205 | - $format = sanitize_text_field($format); | |
| 3206 | - if (in_array($format, $allowed_formats)) { | |
| 3207 | - $export_file = plugin_dir_path(__FILE__) . 'inc/export/' . $format . '.php'; | |
| 3208 | - if (is_numeric($event_id) && file_exists($export_file)) { | |
| 3209 | - $event = $this->retreive($event_id); | |
| 3210 | - if($event->post_status != 'publish'){ | |
| 3211 | - wp_die(esc_html__('Event not found.', 'event-post'), 404); | |
| 3212 | - } | |
| 3213 | - include $export_file; | |
| 3214 | - exit; | |
| 3215 | - } | |
| 3216 | - } | |
| 3217 | - wp_die(esc_html__('Invalid request.', 'event-post'), 400); | |
| 3218 | - } | |
| 3219 | - | |
| 2459 | + /** | |
| 2460 | + * | |
| 2461 | + * @param timestamp $timestamp | |
| 2462 | + * @return string | |
| 2463 | + */ | |
| 2464 | + public function ics_date($timestamp){ | |
| 2465 | + return date("Ymd",$timestamp).'T'.date("His",$timestamp); | |
| 2466 | + } | |
| 3220 | 2467 | |
| 3221 | - public function parse_request(){ | |
| 3222 | - global $wp; | |
| 3223 | - if (preg_match('#^event-feed#i', $wp->request, $match)) { | |
| 3224 | - $this->feed(); | |
| 3225 | - exit; | |
| 3226 | - } | |
| 3227 | - if (preg_match('#^eventpost/([0-9]*)\.(ics|vcs)#i', $wp->request, $match)) { | |
| 3228 | - $this->generate_ics($match[1], $match[2]); | |
| 3229 | - } | |
| 3230 | - } | |
| 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 | + } | |
| 3231 | 2480 | |
| 3232 | - public function export(){ | |
| 3233 | - if(false !== $event_id=\filter_input(INPUT_GET, 'event_id',FILTER_SANITIZE_NUMBER_INT)){ | |
| 3234 | - $format = \filter_input(INPUT_GET, 'format'); | |
| 3235 | - $this->generate_ics($event_id, $format); | |
| 3236 | - } | |
| 3237 | - } | |
| 2481 | + /** | |
| 2482 | + * outputs an ICS document | |
| 2483 | + */ | |
| 2484 | + public function feed(){ | |
| 2485 | + if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){ | |
| 2486 | + $vtz = get_option('timezone_string'); | |
| 2487 | + $gmt = $this->get_gmt_offset(); | |
| 2488 | + date_default_timezone_set($vtz); | |
| 2489 | + $separator = "\n"; | |
| 3238 | 2490 | |
| 2491 | + header("content-type:text/x-icalendar"); | |
| 2492 | + header("Pragma: public"); | |
| 2493 | + header("Expires: 0"); | |
| 2494 | + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
| 2495 | + header("Cache-Control: public"); | |
| 2496 | + header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" ); | |
| 3239 | 2497 | |
| 3240 | - /** | |
| 3241 | - * Outputs an ICS document | |
| 3242 | - * | |
| 3243 | - * Filters can be applied to the criteria used to retrieve events in GET parameters: | |
| 3244 | - * - cat : category slug | |
| 3245 | - * - tag : tag slug | |
| 3246 | - * - tax_name : custom taxonomy name | |
| 3247 | - * - tax_term : custom taxonomy term slug | |
| 3248 | - * - nb : number of events to retrieve (default 10) | |
| 3249 | - * - future : retreive future events | |
| 3250 | - * - past : retreive past events | |
| 3251 | - * | |
| 3252 | - * @return void | |
| 3253 | - */ | |
| 3254 | - public function feed(){ | |
| 3255 | - $criteria = array( | |
| 3256 | - 'nb'=>10, | |
| 3257 | - ); | |
| 3258 | - if(false !== $cat=\filter_input(INPUT_GET, 'cat')){ | |
| 3259 | - $criteria['cat'] = sanitize_text_field($cat); | |
| 3260 | - } | |
| 3261 | - if(false !== $tag=\filter_input(INPUT_GET, 'tag')){ | |
| 3262 | - $criteria['tag'] = sanitize_text_field($tag); | |
| 3263 | - } | |
| 3264 | - if(false !== $tax_name=\filter_input(INPUT_GET, 'tax_name')){ | |
| 3265 | - $criteria['tax_name'] = sanitize_text_field($tax_name); | |
| 3266 | - } | |
| 3267 | - if(false !== $tax_term=\filter_input(INPUT_GET, 'tax_term')){ | |
| 3268 | - $criteria['tax_term'] = sanitize_text_field($tax_term); | |
| 3269 | - } | |
| 3270 | - if(false !== $nb=\filter_input(INPUT_GET, 'nb', FILTER_SANITIZE_NUMBER_INT)){ | |
| 3271 | - $criteria['nb'] = sanitize_text_field($nb); | |
| 3272 | - } | |
| 3273 | - if(false !== $future=\filter_input(INPUT_GET, 'future', FILTER_SANITIZE_NUMBER_INT)){ | |
| 3274 | - $criteria['future'] = sanitize_text_field($future); | |
| 3275 | - } | |
| 3276 | - if(false !== $past=\filter_input(INPUT_GET, 'past', FILTER_SANITIZE_NUMBER_INT)){ | |
| 3277 | - $criteria['past'] = sanitize_text_field($past); | |
| 3278 | - } | |
| 3279 | - $vtz = get_option('timezone_string'); | |
| 3280 | - $gmt = $this->get_gmt_offset(); | |
| 3281 | - date_default_timezone_set($vtz); | |
| 3282 | - $separator = "\n"; | |
| 2498 | + $props = array(); | |
| 3283 | 2499 | |
| 3284 | - header("content-type:text/calendar"); | |
| 3285 | - header("Pragma: public"); | |
| 3286 | - header("Expires: 0"); | |
| 3287 | - header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
| 3288 | - header("Cache-Control: public"); | |
| 3289 | - header("Content-Disposition: attachment; filename=". str_replace('+','-',rawurlencode(get_option('blogname').'-'.$cat)).".ics;" ); | |
| 2500 | + // General | |
| 2501 | + $props[] = 'BEGIN:VCALENDAR'; | |
| 2502 | + $props[] = 'PRODID://WordPress//Event-Post V'. file_get_contents(('VERSION')).'//EN'; | |
| 2503 | + $props[] = 'VERSION:2.0'; | |
| 3290 | 2504 | |
| 3291 | - $props = array(); | |
| 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 | + } | |
| 3292 | 2526 | |
| 3293 | - // General | |
| 3294 | - $props[] = 'BEGIN:VCALENDAR'; | |
| 3295 | - $props[] = 'PRODID://WordPress//Event-Post-V'.$this->version.'//EN'; | |
| 3296 | - $props[] = 'VERSION:2.0'; | |
| 3297 | - // Timezone | |
| 3298 | - if(!empty($vtz)){ | |
| 3299 | - array_push($props, | |
| 3300 | - 'BEGIN:VTIMEZONE', | |
| 3301 | - 'TZID:'.$vtz, | |
| 3302 | - 'BEGIN:DAYLIGHT', | |
| 3303 | - 'TZOFFSETFROM:+0100', | |
| 3304 | - 'TZOFFSETTO:'.($gmt).'00', | |
| 3305 | - 'DTSTART:19700329T020000', | |
| 3306 | - 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3', | |
| 3307 | - 'END:DAYLIGHT', | |
| 3308 | - 'BEGIN:STANDARD', | |
| 3309 | - 'TZOFFSETFROM:'.($gmt).'00', | |
| 3310 | - 'TZOFFSETTO:+0100', | |
| 3311 | - 'TZNAME:CET', | |
| 3312 | - 'DTSTART:19701025T030000', | |
| 3313 | - 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10', | |
| 3314 | - 'END:STANDARD', | |
| 3315 | - 'END:VTIMEZONE' | |
| 3316 | - ); | |
| 3317 | - } | |
| 2527 | + // Events | |
| 2528 | + $events=$this->get_events(array('cat'=>$cat,'nb'=>-1)); | |
| 2529 | + foreach ($events as $event) { | |
| 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 | + } | |
| 3318 | 2543 | |
| 3319 | - // Events | |
| 3320 | - $events=$this->get_events($criteria); | |
| 3321 | - foreach ($events as $event) { | |
| 3322 | - if($event->time_start && $event->time_end){ | |
| 3323 | - $description = wordwrap( | |
| 3324 | - str_replace( | |
| 3325 | - ['\\', ';', ',', "\r", "\n"], | |
| 3326 | - ['\\\\', '\;', '\,', '', '\n'], | |
| 3327 | - wp_strip_all_tags($event->description . "\n\n" . $event->permalink) | |
| 3328 | - ), | |
| 3329 | - 70, | |
| 3330 | - "\n ", | |
| 3331 | - true | |
| 3332 | - ); | |
| 3333 | - array_push($props, | |
| 3334 | - 'BEGIN:VEVENT', | |
| 3335 | - 'CREATED:'.$this->ics_date(strtotime($event->post_date)).'Z', | |
| 3336 | - 'LAST-MODIFIED:'.$this->ics_date(strtotime($event->post_modified)).'Z', | |
| 3337 | - 'SUMMARY:'.$event->post_title, | |
| 3338 | - 'UID:'.md5(site_url()."_eventpost_".$event->ID), | |
| 3339 | - 'LOCATION:'.str_replace(',','\,',$event->address), | |
| 3340 | - 'DTSTAMP:'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'), | |
| 3341 | - 'DTSTART'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'), | |
| 3342 | - 'DTEND'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_end).(!empty($vtz)?'':'Z'), | |
| 3343 | - 'DESCRIPTION:'.$description, | |
| 3344 | - 'END:VEVENT' | |
| 3345 | - ); | |
| 3346 | - } | |
| 3347 | - } | |
| 2544 | + // End | |
| 2545 | + $props[] = 'END:VCALENDAR'; | |
| 3348 | 2546 | |
| 3349 | - // End | |
| 3350 | - $props[] = 'END:VCALENDAR'; | |
| 3351 | - | |
| 3352 | - echo esc_html(implode($separator, $props)); | |
| 3353 | - exit; | |
| 2547 | + echo implode($separator, $props); | |
| 2548 | + exit; | |
| 3354 | 2549 | } |
| 2550 | + } | |
| 3355 | 2551 | } |