| @@ -1,23 +1,23 @@ | ||
| 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 | |
| 5 | + Description: Add calendar and/or geolocation metadata on any posts. | |
| 6 | + Version: 5.7 | |
| 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 | |
| 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 | + | |
| 2 | 16 | /** |
| 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 | 17 | * |
| 15 | 18 | * @package event-post |
| 16 | 19 | */ |
| 17 | - | |
| 18 | -if ( ! defined( 'ABSPATH' ) ) exit; | |
| 19 | - | |
| 20 | 20 | global $EventPost; |
| 21 | 21 | $EventPost = new EventPost(); |
| 22 | 22 | |
| 23 | 23 | $EventPost_cache=array(); |
| @@ -41,333 +41,46 @@ | ||
| 41 | 41 | * |
| 42 | 42 | * Add calendar and/or geolocation metadata on posts |
| 43 | 43 | */ |
| 44 | 44 | class EventPost { |
| 45 | - /** | |
| 46 | - * The current version | |
| 47 | - * | |
| 48 | - * @var array | |
| 49 | - */ | |
| 50 | - public $version = '5.9.2'; | |
| 45 | + const META_START = 'event_begin'; | |
| 46 | + const META_END = 'event_end'; | |
| 47 | + const META_COLOR = 'event_color'; | |
| 48 | + const META_ICON = 'event_icon'; | |
| 49 | + // http://codex.wordpress.org/Geodata | |
| 50 | + const META_ADD = 'geo_address'; | |
| 51 | + const META_LAT = 'geo_latitude'; | |
| 52 | + const META_LONG = 'geo_longitude'; | |
| 53 | + // https://schema.org/eventStatus | |
| 54 | + const META_STATUS = 'event_status'; | |
| 55 | + // https://schema.org/location | |
| 56 | + const META_VIRTUAL_LOCATION = 'event_virtual_location'; | |
| 57 | + // https://pending.schema.org/eventAttendanceMode | |
| 58 | + const META_ATTENDANCE_MODE = 'event_attendance_mode'; | |
| 51 | 59 | |
| 52 | - // -------------------------------------------------------------------------------- | |
| 53 | - // Post metas | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * The meta name for event start date | |
| 57 | - * | |
| 58 | - * @var string | |
| 59 | - */ | |
| 60 | - public $META_START = 'event_begin'; | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * The meta name for event end date | |
| 64 | - * | |
| 65 | - * @var string | |
| 66 | - */ | |
| 67 | - public $META_END = 'event_end'; | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * The meta name for event color | |
| 71 | - * | |
| 72 | - * @var string | |
| 73 | - */ | |
| 74 | - public $META_COLOR = 'event_color'; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * The meta name for event icon | |
| 78 | - * | |
| 79 | - * @var string | |
| 80 | - */ | |
| 81 | - public $META_ICON = 'event_icon'; | |
| 82 | - | |
| 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'; | |
| 92 | - | |
| 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'; | |
| 101 | - | |
| 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'; | |
| 110 | - | |
| 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'; | |
| 140 | - | |
| 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'; | |
| 149 | - | |
| 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 | |
| 160 | - | |
| 161 | - /** | |
| 162 | - * ID of the current list | |
| 163 | - * | |
| 164 | - * @var int | |
| 165 | - */ | |
| 166 | 60 | public $list_id; |
| 167 | - | |
| 168 | - /** | |
| 169 | - * ID of the current map | |
| 170 | - * | |
| 171 | - * @var int | |
| 172 | - */ | |
| 173 | - public $map_id=0; | |
| 174 | - | |
| 175 | - /** | |
| 176 | - * Schema as been outputed or not | |
| 177 | - * | |
| 178 | - * @var bool | |
| 179 | - */ | |
| 180 | - private $is_schema_output=false; | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * Month names | |
| 184 | - * | |
| 185 | - * @var array | |
| 186 | - */ | |
| 187 | 61 | public $NomDuMois; |
| 188 | - | |
| 189 | - /** | |
| 190 | - * Week days | |
| 191 | - * | |
| 192 | - * @var array | |
| 193 | - */ | |
| 194 | 62 | public $Week; |
| 195 | - | |
| 196 | - /** | |
| 197 | - * Currencies | |
| 198 | - * | |
| 199 | - * @var array | |
| 200 | - */ | |
| 201 | - public $currencies = array(); | |
| 202 | - | |
| 203 | - /** | |
| 204 | - * Date format | |
| 205 | - * | |
| 206 | - * @var string | |
| 207 | - */ | |
| 63 | + public $settings; | |
| 208 | 64 | public $dateformat; |
| 209 | 65 | |
| 210 | - /** | |
| 211 | - * Pagination | |
| 212 | - * | |
| 213 | - * @var array | |
| 214 | - */ | |
| 215 | 66 | private $pagination; |
| 216 | - | |
| 217 | - /** | |
| 218 | - * Plugin path | |
| 219 | - * | |
| 220 | - * @var string | |
| 221 | - */ | |
| 222 | - public $plugin_path; | |
| 223 | - | |
| 224 | - /** | |
| 225 | - * Script suffix | |
| 226 | - * | |
| 227 | - * @var string | |
| 228 | - */ | |
| 67 | + public $version = '5.7'; | |
| 68 | + public $plugin_path ; | |
| 229 | 69 | private $script_sufix; |
| 230 | 70 | |
| 231 | - /** | |
| 232 | - * Settings values | |
| 233 | - * | |
| 234 | - * @var array | |
| 235 | - */ | |
| 236 | - public $settings; | |
| 237 | - | |
| 238 | - // -------------------------------------------------------------------------------- | |
| 239 | - // Option values | |
| 240 | - | |
| 241 | - /** | |
| 242 | - * Map interractions (from openlayers) | |
| 243 | - * | |
| 244 | - * @var array | |
| 245 | - */ | |
| 246 | 71 | public $map_interactions; |
| 247 | - | |
| 248 | - /** | |
| 249 | - * Fields supported by quick-edit | |
| 250 | - * | |
| 251 | - * @var array | |
| 252 | - */ | |
| 253 | 72 | public $quick_edit_fields; |
| 254 | 73 | |
| 255 | - /** | |
| 256 | - * Fields supported by bulk-edit | |
| 257 | - * | |
| 258 | - * @var array | |
| 259 | - */ | |
| 260 | - public $bulk_edit_fields; | |
| 74 | + public $Shortcodes; | |
| 261 | 75 | |
| 262 | - /** | |
| 263 | - * Supported attendance modes | |
| 264 | - * | |
| 265 | - * @var array | |
| 266 | - */ | |
| 267 | 76 | public $attendance_modes; |
| 268 | - | |
| 269 | - /** | |
| 270 | - * Supported statuses | |
| 271 | - * | |
| 272 | - * @var array | |
| 273 | - */ | |
| 274 | 77 | public $statuses; |
| 78 | + private $is_schema_output=false; | |
| 275 | 79 | |
| 276 | - /** | |
| 277 | - * Default list schema (HTML template) | |
| 278 | - * | |
| 279 | - * @var string | |
| 280 | - */ | |
| 281 | - public $default_list_shema; | |
| 282 | - | |
| 283 | - /** | |
| 284 | - * Default timeline schema (HTML template) | |
| 285 | - * | |
| 286 | - * @var string | |
| 287 | - */ | |
| 288 | - public $default_timeline_shema; | |
| 289 | - | |
| 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 | 80 | public function __construct() { |
| 366 | 81 | 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 | - | |
| 82 | + add_action('widgets_init', array(&$this,'widgets_init'), 1); | |
| 370 | 83 | add_action('save_post', array(&$this, 'save_postdata')); |
| 371 | 84 | add_filter('dashboard_glance_items', array(&$this, 'dashboard_right_now')); |
| 372 | 85 | |
| 373 | 86 | // Scripts |
| @@ -373,10 +86,8 @@ | ||
| 373 | 86 | // Scripts |
| 374 | 87 | add_action( 'admin_init', array(&$this, 'editor_styles')); |
| 375 | 88 | add_action('admin_enqueue_scripts', array(&$this, 'admin_head')); |
| 376 | 89 | 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 | 90 | add_action('wp_enqueue_scripts', array(&$this, 'load_styles')); |
| 380 | 91 | |
| 381 | 92 | // Single |
| 382 | 93 | add_filter('the_content', array(&$this, 'display_single'), 9999); |
| @@ -404,37 +115,40 @@ | ||
| 404 | 115 | add_action('wp_ajax_nopriv_EventPostExport', array(&$this, 'export')); |
| 405 | 116 | add_action('wp_ajax_EventPostFeed', array(&$this, 'feed')); |
| 406 | 117 | add_action('wp_ajax_nopriv_EventPostFeed', array(&$this, 'feed')); |
| 407 | 118 | |
| 408 | - // Internal filters | |
| 119 | + // | |
| 409 | 120 | add_filter('eventpost_list_shema',array(&$this, 'custom_shema'),10,1); |
| 410 | 121 | |
| 122 | + | |
| 123 | + add_action('widgets_init', array(&$this, 'register_widgets'),1,1); | |
| 124 | + | |
| 411 | 125 | // Quick edit |
| 412 | 126 | add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit' ), 10, 2 ); |
| 413 | 127 | add_action( 'quick_edit_custom_box', array( &$this, 'quick_edit' ), 10, 2 ); |
| 414 | 128 | add_action( 'admin_print_scripts-edit.php', array(&$this, 'scripts_edit') ); |
| 415 | 129 | add_action( 'wp_ajax_inline-save', array(&$this, 'inline_save'), 1 ); |
| 416 | - add_action( 'bulk_edit_posts', array(&$this, 'save_bulkdatas'), 10, 2 ); | |
| 130 | + add_action( 'wp_ajax_eventpost_save_bulk', array(&$this, 'save_bulkdatas') ); | |
| 417 | 131 | add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_color'), 10, 3); |
| 418 | 132 | add_filter( 'eventpost_inline_field', array(&$this, 'inline_field_icon'), 10, 3); |
| 419 | 133 | |
| 420 | 134 | $inc_path = plugin_dir_path(__FILE__).'inc/'; |
| 421 | 135 | $this->plugin_path = plugin_dir_path(__FILE__); |
| 422 | - include_once ($inc_path . 'class-settings.php'); | |
| 136 | + include_once ($inc_path . 'settings.php'); | |
| 423 | 137 | 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'); | |
| 138 | + include_once ($inc_path . 'widget.php'); | |
| 139 | + include_once ($inc_path . 'widget.cal.php'); | |
| 140 | + include_once ($inc_path . 'widget.map.php'); | |
| 141 | + include_once ($inc_path . 'multisite.php'); | |
| 142 | + include_once ($inc_path . 'shortcodes.php'); | |
| 429 | 143 | 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'); | |
| 144 | + include_once ($inc_path . 'children.php'); | |
| 145 | + include_once ($inc_path . 'icons.php'); | |
| 146 | + include_once ($inc_path . 'taxonomies.php'); | |
| 433 | 147 | |
| 434 | - $this->DashIcons = new EventPost\Icons(); | |
| 148 | + $this->DashIcons = new EventPost\DashIcons(); | |
| 435 | 149 | $this->Settings = new EventPost\Settings($this->DashIcons); |
| 436 | - $this->Taxonomies = new EventPost\Taxonomies($this->DashIcons); | |
| 150 | + $this->Categories = new EventPost\Categories($this->DashIcons); | |
| 437 | 151 | } |
| 438 | 152 | |
| 439 | 153 | /** |
| 440 | 154 | * PHP4 constructor |
| @@ -443,15 +157,34 @@ | ||
| 443 | 157 | $this->__construct(); |
| 444 | 158 | } |
| 445 | 159 | |
| 446 | 160 | 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 | - | |
| 161 | + add_rewrite_rule('event-feed/?', admin_url('admin-ajax.php?action=EventPostFeed'), 'top'); | |
| 162 | + add_rewrite_rule('eventpost/([0-9]*)\.(ics|vcs)?', plugins_url('export/ics.php', __FILE__), 'top'); | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * Init all variables when WP is ready | |
| 167 | + * | |
| 168 | + * @action evenpost_init | |
| 169 | + * @filter eventpost_default_list_shema | |
| 170 | + * @filter eventpost_list_shema | |
| 171 | + */ | |
| 172 | + public function widgets_init(){ | |
| 173 | + $this->META_START = 'event_begin'; | |
| 174 | + $this->META_END = 'event_end'; | |
| 175 | + $this->META_COLOR = 'event_color'; | |
| 176 | + $this->META_ICON = 'event_icon'; | |
| 177 | + // http://codex.wordpress.org/Geodata | |
| 178 | + $this->META_ADD = 'geo_address'; | |
| 179 | + $this->META_LAT = 'geo_latitude'; | |
| 180 | + $this->META_LONG = 'geo_longitude'; | |
| 181 | + // https://schema.org/eventStatus | |
| 182 | + $this->META_STATUS = 'event_status'; | |
| 183 | + // https://schema.org/location | |
| 184 | + $this->META_VIRTUAL_LOCATION = 'event_virtual_location'; | |
| 185 | + // https://pending.schema.org/eventAttendanceMode | |
| 186 | + $this->META_ATTENDANCE_MODE = 'event_attendance_mode'; | |
| 454 | 187 | $this->list_id = 0; |
| 455 | 188 | $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 | 189 | $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 | 190 | $this->attendance_modes = array( |
| @@ -459,21 +192,31 @@ | ||
| 459 | 192 | 'MixedEventAttendanceMode' => _x('Mixed', 'Attendance Mode', 'event-post'), |
| 460 | 193 | 'OnlineEventAttendanceMode' => _x('Online', 'Attendance Mode', 'event-post'), |
| 461 | 194 | ); |
| 462 | 195 | $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'), | |
| 196 | + 'EventScheduled' =>_x('Scheduled', 'Event Status', 'event-post'), | |
| 197 | + 'EventCancelled'=>_x('Cancelled', 'Event Status', 'event-post'), | |
| 198 | + 'EventMovedOnline'=>_x('Moved Online', 'Event Status', 'event-post'), | |
| 199 | + 'EventPostponed'=>_x('Postoned', 'Event Status', 'event-post'), | |
| 200 | + 'EventRescheduled'=>_x('Rescheduled', 'Event Status', 'event-post'), | |
| 469 | 201 | ); |
| 470 | - | |
| 202 | + | |
| 471 | 203 | $this->maps = $this->get_maps(); |
| 472 | 204 | $this->settings = $this->get_settings(); |
| 473 | - | |
| 205 | + | |
| 474 | 206 | do_action('evenpost_init', $this); |
| 475 | 207 | |
| 208 | + $this->Shortcodes = new EventPost_Shortcodes(); | |
| 209 | + | |
| 210 | + if(function_exists('register_block_type')){ | |
| 211 | + $block_path = plugin_dir_path(__FILE__).'inc/blocks/'; | |
| 212 | + include_once ($block_path . 'eventslist.php'); | |
| 213 | + include_once ($block_path . 'eventstimeline.php'); | |
| 214 | + include_once ($block_path . 'eventsmap.php'); | |
| 215 | + include_once ($block_path . 'eventscalendar.php'); | |
| 216 | + include_once ($block_path . 'eventdetails.php'); | |
| 217 | + } | |
| 218 | + | |
| 476 | 219 | // Edit |
| 477 | 220 | add_action('add_meta_boxes', array(&$this, 'add_custom_box')); |
| 478 | 221 | foreach($this->settings['posttypes'] as $posttype){ |
| 479 | 222 | add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2); |
| @@ -478,9 +221,9 @@ | ||
| 478 | 221 | foreach($this->settings['posttypes'] as $posttype){ |
| 479 | 222 | add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2); |
| 480 | 223 | add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2); |
| 481 | 224 | } |
| 482 | - $this->Taxonomies->add_fields_to_taxonomies($this->settings['posttypes']); | |
| 225 | + $this->Categories->add_fields_to_taxonomies($this->settings['posttypes']); | |
| 483 | 226 | |
| 484 | 227 | $this->markpath = ''; |
| 485 | 228 | $this->markurl = ''; |
| 486 | 229 | if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) { |
| @@ -490,10 +233,8 @@ | ||
| 490 | 233 | // $this->markpath = plugin_dir_path(__FILE__) . 'markers/'; |
| 491 | 234 | // $this->markurl = plugins_url('/markers/', __FILE__); |
| 492 | 235 | } |
| 493 | 236 | |
| 494 | - $this->currencies = include (plugin_dir_path(__FILE__) . 'inc/data/currencies.php'); | |
| 495 | - | |
| 496 | 237 | $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post')); |
| 497 | 238 | |
| 498 | 239 | $this->default_list_shema = apply_filters('eventpost_default_list_shema', array( |
| 499 | 240 | 'container' => '<%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>'. |
| @@ -502,11 +243,10 @@ | ||
| 502 | 243 | '</%type%><!-- .event_loop -->', |
| 503 | 244 | 'item' => '<%child% class="event_item %class%" data-color="%color%" style="%style%">'. |
| 504 | 245 | '<a href="%event_link%">'. |
| 505 | 246 | '%event_thumbnail%'. |
| 506 | - '<h5>%event_title% </h5>'. | |
| 247 | + '<h5>%event_title%</h5>'. | |
| 507 | 248 | '</a>'. |
| 508 | - '%event_price%'. | |
| 509 | 249 | '%event_date%'. |
| 510 | 250 | '%event_cat%'. |
| 511 | 251 | '%event_location%'. |
| 512 | 252 | '%event_excerpt%'. |
| @@ -532,9 +272,8 @@ | ||
| 532 | 272 | <a href="%event_link%"> |
| 533 | 273 | %event_thumbnail% |
| 534 | 274 | <h5>%event_title%</h5> |
| 535 | 275 | </a> |
| 536 | - %event_price% | |
| 537 | 276 | </%child%><!-- .event_item -->' |
| 538 | 277 | )); |
| 539 | 278 | $this->timeline_shema = apply_filters('eventpost_timeline_shema',$this->default_timeline_shema); |
| 540 | 279 | |
| @@ -571,42 +310,10 @@ | ||
| 571 | 310 | ), |
| 572 | 311 | ) |
| 573 | 312 | ); |
| 574 | 313 | |
| 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 | - | |
| 581 | 314 | } |
| 582 | 315 | |
| 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(); | |
| 592 | - | |
| 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 | - } | |
| 601 | - | |
| 602 | - | |
| 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 | - } | |
| 608 | - | |
| 609 | 316 | public function register_widgets(){ |
| 610 | 317 | register_widget('EventPost_List'); |
| 611 | 318 | register_widget('EventPost_Map'); |
| 612 | 319 | register_widget('EventPost_Cal'); |
| @@ -613,32 +320,24 @@ | ||
| 613 | 320 | } |
| 614 | 321 | |
| 615 | 322 | /** |
| 616 | 323 | * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color. |
| 617 | - * | |
| 618 | 324 | * @param string $color |
| 619 | - * | |
| 620 | 325 | * @return array $color($R, $G, $B) |
| 621 | 326 | */ |
| 622 | 327 | public function hex2dec($color = '000000') { |
| 623 | 328 | $tbl_color = array(); |
| 624 | - if(!is_string($color) || empty($color)){ | |
| 625 | - $color = '000000'; | |
| 626 | - } | |
| 627 | - if (substr($color, 0, 1)!='#'){ | |
| 329 | + if (!strstr('#', $color)){ | |
| 628 | 330 | $color = '#' . $color; |
| 629 | - } | |
| 331 | + } | |
| 630 | 332 | $tbl_color['R'] = hexdec(substr($color, 1, 2)); |
| 631 | 333 | $tbl_color['G'] = hexdec(substr($color, 3, 2)); |
| 632 | 334 | $tbl_color['B'] = hexdec(substr($color, 5, 2)); |
| 633 | 335 | return $tbl_color; |
| 634 | 336 | } |
| 635 | - | |
| 636 | 337 | /** |
| 637 | 338 | * Fetch all registered image sizes |
| 638 | - * | |
| 639 | 339 | * @global array $_wp_additional_image_sizes |
| 640 | - * | |
| 641 | 340 | * @return array |
| 642 | 341 | */ |
| 643 | 342 | function get_thumbnail_sizes(){ |
| 644 | 343 | global $_wp_additional_image_sizes; |
| @@ -651,13 +350,12 @@ | ||
| 651 | 350 | |
| 652 | 351 | /** |
| 653 | 352 | * Get blog settings, load and saves default settings if needed. Can be filterred using |
| 654 | 353 | * |
| 655 | - * @example `<?php add_filter('eventpost_getsettings', 'some_function'); ?>` | |
| 354 | + * `<?php add_filter('eventpost_getsettings', 'some_function'); ?>` | |
| 656 | 355 | * |
| 657 | 356 | * @action eventpost_getsettings_action |
| 658 | 357 | * @filter eventpost_getsettings |
| 659 | - * | |
| 660 | 358 | * @return array |
| 661 | 359 | */ |
| 662 | 360 | public function get_settings() { |
| 663 | 361 | $ep_settings = $this->Settings->get_settings(); |
| @@ -665,11 +363,9 @@ | ||
| 665 | 363 | } |
| 666 | 364 | |
| 667 | 365 | /** |
| 668 | 366 | * Checks if HTML schemas are not empty |
| 669 | - * | |
| 670 | 367 | * @param array $shema |
| 671 | - * | |
| 672 | 368 | * @return array |
| 673 | 369 | */ |
| 674 | 370 | public function custom_shema($shema){ |
| 675 | 371 | if(!empty($this->settings['container_shema'])){ |
| @@ -702,9 +398,8 @@ | ||
| 702 | 398 | * ?> |
| 703 | 399 | * ``` |
| 704 | 400 | * |
| 705 | 401 | * @filter eventpost_maps |
| 706 | - * | |
| 707 | 402 | * @return array of map arrays ['name', 'id', 'urls'] |
| 708 | 403 | */ |
| 709 | 404 | public function get_maps() { |
| 710 | 405 | $maps = array(); |
| @@ -720,10 +415,9 @@ | ||
| 720 | 415 | return $maps; |
| 721 | 416 | } |
| 722 | 417 | |
| 723 | 418 | /** |
| 724 | - * Get colors | |
| 725 | - * | |
| 419 | + * | |
| 726 | 420 | * @return array |
| 727 | 421 | */ |
| 728 | 422 | public function get_colors() { |
| 729 | 423 | $colors = array(); |
| @@ -738,15 +432,10 @@ | ||
| 738 | 432 | return $colors; |
| 739 | 433 | } |
| 740 | 434 | |
| 741 | 435 | /** |
| 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 | |
| 436 | + * | |
| 437 | + * @return color | |
| 749 | 438 | */ |
| 750 | 439 | public function get_post_color($post_id, $default = false, $check_taxo = false) { |
| 751 | 440 | $color = get_post_meta($post_id, $this->META_COLOR,true); |
| 752 | 441 | if($color && !empty($color)){ |
| @@ -753,9 +442,9 @@ | ||
| 753 | 442 | return event_post_format_color($color); |
| 754 | 443 | }else{ |
| 755 | 444 | if($check_taxo){ |
| 756 | 445 | foreach(event_post_get_all_terms($post_id) as $term){ |
| 757 | - $taxo_color = $this->Taxonomies->get_taxonomy_color($term->term_id); | |
| 446 | + $taxo_color = $this->Categories->get_taxonomy_color($term->term_id); | |
| 758 | 447 | if($taxo_color){ |
| 759 | 448 | return event_post_format_color($taxo_color); |
| 760 | 449 | } |
| 761 | 450 | } |
| @@ -764,15 +453,10 @@ | ||
| 764 | 453 | return event_post_format_color($default); |
| 765 | 454 | } |
| 766 | 455 | |
| 767 | 456 | /** |
| 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 | |
| 457 | + * | |
| 458 | + * @return class | |
| 775 | 459 | */ |
| 776 | 460 | public function get_post_icon($post_id, $default = false, $check_taxo = false) { |
| 777 | 461 | $icon = get_post_meta($post_id, $this->META_ICON,true); |
| 778 | 462 | if($icon && !empty($icon)){ |
| @@ -779,9 +463,9 @@ | ||
| 779 | 463 | return $icon; |
| 780 | 464 | }else{ |
| 781 | 465 | if($check_taxo){ |
| 782 | 466 | foreach(event_post_get_all_terms($post_id) as $term){ |
| 783 | - $taxo_icon = $this->Taxonomies->get_taxonomy_icon($term->term_id); | |
| 467 | + $taxo_icon = $this->Categories->get_taxonomy_icon($term->term_id); | |
| 784 | 468 | if($taxo_icon){ |
| 785 | 469 | return event_post_format_color($taxo_icon); |
| 786 | 470 | } |
| 787 | 471 | } |
| @@ -790,12 +474,10 @@ | ||
| 790 | 474 | return $default; |
| 791 | 475 | } |
| 792 | 476 | |
| 793 | 477 | /** |
| 794 | - * Get the URL of a marker | |
| 795 | - * | |
| 478 | + * | |
| 796 | 479 | * @param string $color |
| 797 | - * | |
| 798 | 480 | * @return sring |
| 799 | 481 | */ |
| 800 | 482 | public function get_marker($color) { |
| 801 | 483 | if (is_file($this->markpath . $color . '.png')) { |
| @@ -806,9 +488,9 @@ | ||
| 806 | 488 | |
| 807 | 489 | /** |
| 808 | 490 | * Enqueue CSS files |
| 809 | 491 | */ |
| 810 | - public function load_styles($deps = null) { | |
| 492 | + public function load_styles() { | |
| 811 | 493 | //CSS |
| 812 | 494 | if(!empty($this->settings['customcss'])){ |
| 813 | 495 | wp_enqueue_style('event-post-custom', $this->settings['customcss']); |
| 814 | 496 | } |
| @@ -815,28 +497,30 @@ | ||
| 815 | 497 | elseif(is_file(get_stylesheet_directory().'/event-post.css') || is_file(get_template_directory().'/event-post.css')){ |
| 816 | 498 | wp_enqueue_style('event-post-custom', get_theme_file_uri('event-post.css')); |
| 817 | 499 | } |
| 818 | 500 | else{ |
| 819 | - wp_register_style('event-post', plugins_url('/build/front/front.css', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/front/front.css" )); | |
| 501 | + wp_register_style('event-post', plugins_url('/css/event-post.css', __FILE__), false, filemtime( "{$this->plugin_path}/css/event-post.css" )); | |
| 820 | 502 | wp_enqueue_style('event-post'); |
| 821 | 503 | } |
| 822 | 504 | |
| 823 | 505 | // Lib scripts |
| 506 | + wp_enqueue_style('openlayers', plugins_url('/css/ol.css', __FILE__), false, filemtime( "{$this->plugin_path}/css/ol.css" )); | |
| 824 | 507 | wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css')); |
| 825 | 508 | } |
| 826 | - | |
| 827 | 509 | /** |
| 828 | 510 | * Enqueue Editor style |
| 829 | 511 | */ |
| 830 | 512 | public function editor_styles() { |
| 831 | - add_editor_style( plugins_url('/build/front/front.css', __FILE__) ); | |
| 513 | + add_editor_style( plugins_url('/css/event-post.css', __FILE__) ); | |
| 832 | 514 | } |
| 833 | 515 | |
| 834 | 516 | /** |
| 835 | 517 | * Enqueue JS files |
| 836 | 518 | */ |
| 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); | |
| 519 | + public function load_scripts($deps = array('jquery')) { | |
| 520 | + // JS | |
| 521 | + wp_enqueue_script('jquery', false, false, false, true); | |
| 522 | + wp_enqueue_script('event-post', plugins_url('/js/event-post.min.js', __FILE__), $deps, filemtime( "{$this->plugin_path}/js/event-post.min.js" ), true); | |
| 839 | 523 | $maps = $this->maps; |
| 840 | 524 | foreach($maps as $m=>$map){ |
| 841 | 525 | if(isset($map['api_param']) && $this->settings['tile_api_key']){ |
| 842 | 526 | foreach($map['urls'] as $i=>$url){ |
| @@ -843,12 +527,9 @@ | ||
| 843 | 527 | $maps[$m]['urls'][$i] = add_query_arg($map['api_param'], $this->settings['tile_api_key'], $url); |
| 844 | 528 | } |
| 845 | 529 | } |
| 846 | 530 | } |
| 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 | - ), | |
| 531 | + wp_localize_script('event-post', 'eventpost_params', array( | |
| 851 | 532 | 'imgpath' => plugins_url('/img/', __FILE__), |
| 852 | 533 | 'maptiles' => $maps, |
| 853 | 534 | 'defaulttile' => $this->settings['tile'], |
| 854 | 535 | 'zoom' => $this->settings['zoom'], |
| @@ -853,18 +534,19 @@ | ||
| 853 | 534 | 'defaulttile' => $this->settings['tile'], |
| 854 | 535 | 'zoom' => $this->settings['zoom'], |
| 855 | 536 | 'ajaxurl' => admin_url() . 'admin-ajax.php', |
| 856 | 537 | 'map_interactions'=>$this->map_interactions, |
| 857 | - )), 'before'); | |
| 538 | + )); | |
| 858 | 539 | } |
| 859 | 540 | /** |
| 860 | 541 | * Enqueue JS files for maps |
| 861 | 542 | */ |
| 862 | 543 | public function load_map_scripts() { |
| 863 | - $this->load_styles(array('event-post-map')); | |
| 864 | 544 | // JS |
| 545 | + wp_enqueue_script('openlayers', plugins_url('/js/ol.js', __FILE__), false, filemtime( "{$this->plugin_path}/js/ol.js" ), true); | |
| 546 | + $this->load_scripts(array('jquery', 'openlayers')); | |
| 865 | 547 | if(is_admin()){ |
| 866 | - $this->admin_scripts(array('jquery', 'event-post-map')); | |
| 548 | + $this->admin_scripts(array('jquery', 'openlayers')); | |
| 867 | 549 | } |
| 868 | 550 | } |
| 869 | 551 | |
| 870 | 552 | /** |
| @@ -874,9 +556,11 @@ | ||
| 874 | 556 | $page = basename($_SERVER['SCRIPT_NAME']); |
| 875 | 557 | 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 | 558 | return; |
| 877 | 559 | } |
| 878 | - wp_enqueue_style('event-post-admin', plugins_url('/build/admin/admin.css', __FILE__), false, filemtime( "{$this->plugin_path}/build/admin/admin.css" )); | |
| 560 | + wp_enqueue_style('openlayers', plugins_url('/css/ol.css', __FILE__), false, filemtime( "{$this->plugin_path}/css/ol.css" )); | |
| 561 | + wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, filemtime( "{$this->plugin_path}/css/jquery-ui.css" )); | |
| 562 | + wp_enqueue_style('event-post-admin', plugins_url('/css/event-post-admin.css', __FILE__), false, filemtime( "{$this->plugin_path}/css/event-post-admin.css" )); | |
| 879 | 563 | } |
| 880 | 564 | |
| 881 | 565 | /** |
| 882 | 566 | * Enqueue JS files in admin |
| @@ -895,9 +579,9 @@ | ||
| 895 | 579 | wp_enqueue_script('jquery'); |
| 896 | 580 | wp_enqueue_script('jquery-effects-core'); |
| 897 | 581 | wp_enqueue_script('jquery-effects-shake'); |
| 898 | 582 | wp_enqueue_style( 'wp-color-picker'); |
| 899 | - wp_enqueue_script( 'wp-color-picker'); | |
| 583 | + wp_enqueue_script( 'wp-color-picker'); | |
| 900 | 584 | if(!is_array($deps)){ |
| 901 | 585 | $deps = array('jquery','wp-color-picker'); |
| 902 | 586 | } |
| 903 | 587 | if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){ |
| @@ -903,14 +587,14 @@ | ||
| 903 | 587 | if($this->settings['datepicker']=='simple' || !is_admin() || (isset($_GET['page']) && $_GET['page']=='event-settings')){ |
| 904 | 588 | wp_enqueue_script('jquery-ui-datepicker'); |
| 905 | 589 | $deps[] = 'jquery-ui-datepicker'; |
| 906 | 590 | } |
| 907 | - wp_enqueue_script('event-post-admin', plugins_url('/build/admin/admin.js', __FILE__), $deps, filemtime( "{$this->plugin_path}/build/admin/admin.js" ), true); | |
| 591 | + wp_enqueue_script('event-post-admin', plugins_url('/js/event-post-admin.min.js', __FILE__), $deps, filemtime( "{$this->plugin_path}/js/event-post-admin.min.js" ), true); | |
| 908 | 592 | $language = get_bloginfo('language'); |
| 909 | 593 | if (strpos($language, '-') > -1) { |
| 910 | 594 | $language = strtolower(substr($language, 0, 2)); |
| 911 | 595 | } |
| 912 | - wp_add_inline_script('event-post-admin', 'var EventPost = EventPost || {}; EventPost.admin='.wp_json_encode(array( | |
| 596 | + wp_localize_script('event-post-admin', 'eventpost', array( | |
| 913 | 597 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 914 | 598 | 'imgpath' => plugins_url('/img/', __FILE__), |
| 915 | 599 | 'date_choose' => __('Choose', 'event-post'), |
| 916 | 600 | 'date_format' => __('yy-mm-dd', 'event-post'), |
| @@ -919,13 +603,10 @@ | ||
| 919 | 603 | 'use_current_location'=>__('Use my current location','event-post'), |
| 920 | 604 | 'start_drag'=>__('Click to<br>drag the map<br>and change location','event-post'), |
| 921 | 605 | 'empty_address'=>__('Be kind to fill a non empty address:)', 'event-post'), |
| 922 | 606 | '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 | 607 | 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'), |
| 926 | 608 | '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 | 609 | 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'), |
| 929 | 610 | 'day'=>__('Day', 'event-post'), |
| 930 | 611 | 'month'=>__('Month', 'event-post'), |
| 931 | 612 | 'year'=>__('Day', 'event-post'), |
| @@ -948,24 +629,24 @@ | ||
| 948 | 629 | 'maptiles' => $this->maps, |
| 949 | 630 | 'defaulttile' => $this->settings['tile'], |
| 950 | 631 | 'palette' => $this->get_theme_palette("hex"), |
| 951 | 632 | 'available_images' => $this->get_colors(), |
| 952 | - ))); | |
| 633 | + )); | |
| 953 | 634 | } |
| 954 | 635 | function scripts_edit() { |
| 955 | 636 | // load only when editing a supported post type |
| 956 | 637 | $current_post_type = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; |
| 957 | 638 | 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( | |
| 639 | + wp_enqueue_script( 'eventpost-inline-edit', plugins_url( 'js/inline-edit.min.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), '', true ); | |
| 640 | + wp_localize_script('eventpost-inline-edit', 'eventpost_inline_edit', array( | |
| 960 | 641 | 'quick'=>$this->quick_edit_fields, |
| 961 | 642 | 'bulk'=>$this->bulk_edit_fields, |
| 962 | - ))); | |
| 643 | + )); | |
| 963 | 644 | } |
| 964 | 645 | } |
| 965 | 646 | |
| 966 | 647 | function get_rich_result($event){ |
| 967 | - /* | |
| 648 | + /** | |
| 968 | 649 | * https://search.google.com/test/rich-results |
| 969 | 650 | { |
| 970 | 651 | "@context": "https://schema.org", |
| 971 | 652 | "@type": "Event", |
| @@ -1017,9 +698,9 @@ | ||
| 1017 | 698 | $absmin = abs($min); |
| 1018 | 699 | $gmt_offset = sprintf("%s%02d:%02d", $sign, $absmin/60, $absmin%60); |
| 1019 | 700 | $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 | 701 | |
| 1021 | - $rich_data = array( | |
| 702 | + return apply_filters('event-post-rich-result', array( | |
| 1022 | 703 | '@context'=>'https://schema.org', |
| 1023 | 704 | '@type'=>'event', |
| 1024 | 705 | 'name'=>$event->post_title, |
| 1025 | 706 | 'datePublished'=>str_replace(' ', 'T', $event->post_date_gmt).$gmt_offset, |
| @@ -1034,44 +715,18 @@ | ||
| 1034 | 715 | get_the_post_thumbnail_url($event->ID, 'medium'), |
| 1035 | 716 | get_the_post_thumbnail_url($event->ID, 'large'), |
| 1036 | 717 | get_the_post_thumbnail_url($event->ID, 'full'), |
| 1037 | 718 | ) : 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); | |
| 719 | + 'description'=>$event->post_excerpt, | |
| 720 | + ), $event); | |
| 1064 | 721 | } |
| 1065 | 722 | |
| 1066 | 723 | function wpseo_schema_webpage($rich_result){ |
| 1067 | 724 | $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; | |
| 725 | + if ($event->time_start != '' && $event->time_end != '') { | |
| 726 | + $rich_result = array_merge($rich_result, $this->get_rich_result($event)); | |
| 1073 | 727 | } |
| 728 | + $this->is_schema_output = true; | |
| 1074 | 729 | return $rich_result; |
| 1075 | 730 | } |
| 1076 | 731 | |
| 1077 | 732 | function get_theme_palette($return = "hex"){ |
| @@ -1099,51 +754,47 @@ | ||
| 1099 | 754 | if (is_single()) { |
| 1100 | 755 | $twitter_label_id=0; |
| 1101 | 756 | $event = $this->retreive(); |
| 1102 | 757 | $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) ?>"/> | |
| 758 | + if ($event->address != '' || ($event->lat != '' && $event->long != '')) { | |
| 759 | + $twitter_label_id++; | |
| 760 | + $has_location = true; | |
| 761 | + ?> | |
| 762 | +<meta name="geo.placename" content="<?php echo esc_attr($event->address) ?>" /> | |
| 763 | +<meta name="geo.position" content="<?php echo esc_attr($event->lat) ?>;<?php echo esc_attr($event->long) ?>" /> | |
| 764 | +<meta name="ICBM" content="<?php echo $event->lat ?>;<?php echo esc_attr($event->long) ?>" /> | |
| 765 | +<meta property="place:location:latitude" content="<?php echo esc_attr($event->lat) ?>" /> | |
| 766 | +<meta property="place:location:longitude" content="<?php echo esc_attr($event->long) ?>" /> | |
| 767 | +<meta name="twitter:label<?php echo $twitter_label_id; ?>" content="<?php _e('Location', 'event-post'); ?>"/> | |
| 768 | +<meta name="twitter:data<?php echo $twitter_label_id; ?>" content="<?php echo esc_attr($event->address) ?>"/> | |
| 1115 | 769 | <?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)) ?>"/> | |
| 770 | + } | |
| 771 | + if ($event->start != '' && $event->end != '') { | |
| 772 | + $has_time = true; | |
| 773 | + $twitter_label_id++; | |
| 774 | + ?> | |
| 775 | +<meta name="datetime-coverage-start" content="<?php echo date('c', $event->time_start) ?>" /> | |
| 776 | +<meta name="datetime-coverage-end" content="<?php echo date('c', $event->time_end) ?>" /> | |
| 777 | +<meta name="twitter:label<?php echo $twitter_label_id; ?>" content="<?php _e('Date', 'event-post'); ?>"/> | |
| 778 | +<meta name="twitter:data<?php echo $twitter_label_id; ?>" content="<?php echo esc_attr($this->human_date($event->time_start)) ?>"/> | |
| 1125 | 779 | <?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 | 780 | } |
| 781 | + if(($has_location || $has_time) && !$this->is_schema_output){ | |
| 782 | + $rich_result = $this->get_rich_result($event); | |
| 783 | + $this->is_schema_output = true; | |
| 784 | + ?> | |
| 785 | + <script type="application/ld+json"><?php echo json_encode($rich_result); ?></script> | |
| 786 | + <?php | |
| 787 | + } | |
| 788 | + | |
| 1135 | 789 | } |
| 1136 | 790 | } |
| 1137 | 791 | |
| 1138 | 792 | /** |
| 1139 | - * Cleanups a date | |
| 1140 | - * | |
| 793 | + * | |
| 1141 | 794 | * @param type $str |
| 1142 | - * | |
| 795 | + * @return string | |
| 1143 | 796 | * @since 5.0.1 |
| 1144 | - * | |
| 1145 | - * @return string | |
| 1146 | 797 | */ |
| 1147 | 798 | public function date_cleanup($str){ |
| 1148 | 799 | return trim(str_replace(array('0', ' ', ':', '-'), '', $str)); |
| 1149 | 800 | } |
| @@ -1148,12 +799,10 @@ | ||
| 1148 | 799 | return trim(str_replace(array('0', ' ', ':', '-'), '', $str)); |
| 1149 | 800 | } |
| 1150 | 801 | |
| 1151 | 802 | /** |
| 1152 | - * Checks if a date is valid or not | |
| 1153 | - * | |
| 803 | + * | |
| 1154 | 804 | * @param string $str |
| 1155 | - * | |
| 1156 | 805 | * @return boolean |
| 1157 | 806 | */ |
| 1158 | 807 | public function dateisvalid($str) { |
| 1159 | 808 | return is_string($str) && $this->date_cleanup($str) != ''; |
| @@ -1159,13 +808,11 @@ | ||
| 1159 | 808 | return is_string($str) && $this->date_cleanup($str) != ''; |
| 1160 | 809 | } |
| 1161 | 810 | |
| 1162 | 811 | /** |
| 1163 | - * Parse a date from a string | |
| 1164 | - * | |
| 812 | + * | |
| 1165 | 813 | * @param string $date |
| 1166 | 814 | * @param string $sep |
| 1167 | - * | |
| 1168 | 815 | * @return string |
| 1169 | 816 | */ |
| 1170 | 817 | public function parsedate($date, $sep = '') { |
| 1171 | 818 | if (!empty($date)) { |
| @@ -1175,27 +822,11 @@ | ||
| 1175 | 822 | } |
| 1176 | 823 | } |
| 1177 | 824 | |
| 1178 | 825 | /** |
| 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 | - } | |
| 1191 | - | |
| 1192 | - /** | |
| 1193 | - * Format a date for humans | |
| 1194 | - * | |
| 826 | + * | |
| 1195 | 827 | * @param mixed $date |
| 1196 | 828 | * @param string $format |
| 1197 | - * | |
| 1198 | 829 | * @return type |
| 1199 | 830 | */ |
| 1200 | 831 | public function human_date($date, $format = 'l j F Y') { |
| 1201 | 832 | if($this->settings['dateforhumans']){ |
| @@ -1210,13 +841,11 @@ | ||
| 1210 | 841 | return date_i18n($format, $date); |
| 1211 | 842 | } |
| 1212 | 843 | |
| 1213 | 844 | /** |
| 1214 | - * Returns a range of dates | |
| 1215 | - * | |
| 845 | + * | |
| 1216 | 846 | * @param timestamp $time_start |
| 1217 | 847 | * @param timestamp $time_end |
| 1218 | - * | |
| 1219 | 848 | * @return string |
| 1220 | 849 | */ |
| 1221 | 850 | public function delta_date($time_start, $time_end){ |
| 1222 | 851 | if(!$time_start || !$time_end){ |
| @@ -1222,15 +851,11 @@ | ||
| 1222 | 851 | if(!$time_start || !$time_end){ |
| 1223 | 852 | return; |
| 1224 | 853 | } |
| 1225 | 854 | |
| 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 | 855 | $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 | 856 | $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 | 857 | $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 | 858 | $at_time = _x('%1$sat%2$s %3$s', 'Time', 'event-post'); |
| 1234 | 859 | |
| 1235 | 860 | //Display dates |
| 1236 | 861 | $dates="\t\t\t\t".'<div class="event_date" data-start="' . $this->human_date($time_start) . '" data-end="' . $this->human_date($time_end) . '">'; |
| @@ -1285,93 +910,89 @@ | ||
| 1285 | 910 | return $dates; |
| 1286 | 911 | } |
| 1287 | 912 | |
| 1288 | 913 | /** |
| 1289 | - * Displays a date | |
| 1290 | - * | |
| 914 | + * | |
| 1291 | 915 | * @param WP_Post object $post |
| 1292 | 916 | * @param mixed $links |
| 1293 | - * | |
| 1294 | 917 | * @return string |
| 1295 | 918 | */ |
| 1296 | 919 | public function print_date($post = null, $links = 'deprecated', $context='') { |
| 1297 | 920 | $dates = ''; |
| 1298 | 921 | $event = $this->retreive($post); |
| 1299 | - if ($event != false){ | |
| 1300 | - if ($event->start != '' && $event->end != '') { | |
| 922 | + if ($event->start != '' && $event->end != '') { | |
| 1301 | 923 | |
| 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(); | |
| 924 | + $dates.=$this->delta_date($event->time_start, $event->time_end); | |
| 925 | + if( // Status setting | |
| 926 | + $this->settings['displaystatus'] == 'both' || | |
| 927 | + ($this->settings['displaystatus'] == 'single' && is_single() ) || | |
| 928 | + ($this->settings['displaystatus'] == 'list' && !is_single() ) | |
| 929 | + ){ | |
| 930 | + $dates.='<span class="eventpost-status">'.$this->statuses[$event->status].'</span>'; | |
| 931 | + } | |
| 932 | + $timezone_string = get_option('timezone_string'); | |
| 933 | + $gmt_offset = $gmt = $this->get_gmt_offset(); | |
| 1312 | 934 | |
| 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; | |
| 935 | + if ( | |
| 936 | + !is_admin() | |
| 937 | + && ( // Export when setting | |
| 938 | + $this->settings['export_when'] == 'both' || | |
| 939 | + ( $this->settings['export_when'] == 'future' && $this->is_future($event) ) || | |
| 940 | + ( $this->settings['export_when'] == 'past' && $this->is_past($event) ) | |
| 941 | + ) | |
| 942 | + && ( // Export setting | |
| 943 | + $this->settings['export'] == 'both' || | |
| 944 | + ($this->settings['export'] == 'single' && is_single() ) || | |
| 945 | + ($this->settings['export'] == 'list' && !is_single() ) | |
| 946 | + ) | |
| 947 | + ) { | |
| 948 | + // Export event | |
| 949 | + $title = urlencode($post->post_title); | |
| 950 | + $address = urlencode($post->address); | |
| 951 | + $desc = urlencode($event->post_excerpt."\n\n".$post->permalink); | |
| 952 | + $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'); | |
| 953 | + $d_s = date("Ymd", $event->time_start) . ($allday ? '' : 'T' . date("His", $event->time_start)); | |
| 954 | + $d_e = date("Ymd", $event->time_end) . ($allday ? '' : 'T' . date("His", $event->time_end)); | |
| 955 | + $uid = $post->ID . '-' . $post->blog_id; | |
| 956 | + $url = $event->permalink; | |
| 1335 | 957 | |
| 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')); | |
| 958 | + // format de date ICS | |
| 959 | + $permalink_structure = get_option( 'permalink_structure' ); | |
| 960 | + if($permalink_structure != ""){ | |
| 961 | + $ics_url = site_url('eventpost/'.$event->ID.'.ics'); | |
| 962 | + $vcs_url = site_url('eventpost/'.$event->ID.'.vcs'); | |
| 963 | + } | |
| 964 | + else{ | |
| 965 | + $ics_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'ics'), admin_url('admin-ajax.php')); | |
| 966 | + $vcs_url = add_query_arg(array('action'=>'EventPostExport', 'event_id'=>$event->ID, 'format'=>'vcs'), admin_url('admin-ajax.php')); | |
| 1345 | 967 | |
| 1346 | - } | |
| 968 | + } | |
| 1347 | 969 | |
| 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 | - } | |
| 970 | + // format de date Google cal | |
| 971 | + //$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'; | |
| 972 | + $google_url = add_query_arg(array( | |
| 973 | + 'action'=>'TEMPLATE', | |
| 974 | + 'trp'=>'false', | |
| 975 | + 'sprop'=>'name', | |
| 976 | + 'text'=>$title, | |
| 977 | + 'dates'=>$d_s.'/'.$d_e.'', // Removed Z to fix TZ issue | |
| 978 | + 'location'=>$address, | |
| 979 | + 'details'=>$desc, | |
| 980 | + 'gmt'=> urlencode($gmt_offset) | |
| 981 | + ), 'https://www.google.com/calendar/event'); | |
| 982 | + if(!empty($timezone_string)){ | |
| 983 | + $google_url = add_query_arg(array( | |
| 984 | + 'ctz'=>$timezone_string, | |
| 985 | + ), $google_url); | |
| 986 | + } | |
| 1365 | 987 | |
| 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 | - } | |
| 988 | + $dates.=' | |
| 989 | + <span class="eventpost-date-export"> | |
| 990 | + <a href="' . $ics_url . '" class="event_link event-export ics" target="_blank" title="' . __('Download ICS file', 'event-post') . '">ical</a> | |
| 991 | + <a href="' . $google_url . '" class="event_link event-export gcal" target="_blank" title="' . __('Add to Google calendar', 'event-post') . '">Google</a> | |
| 992 | + <a href="' . $vcs_url . '" class="event_link event-export vcs" target="_blank" title="' . __('Add to Outlook', 'event-post') . '">outlook</a> | |
| 993 | + <i class="dashicons-before dashicons-calendar"></i> | |
| 994 | + </span>'; | |
| 1374 | 995 | } |
| 1375 | 996 | } |
| 1376 | 997 | return apply_filters('eventpost_printdate', $dates); |
| 1377 | 998 | } |
| @@ -1376,12 +997,10 @@ | ||
| 1376 | 997 | return apply_filters('eventpost_printdate', $dates); |
| 1377 | 998 | } |
| 1378 | 999 | |
| 1379 | 1000 | /** |
| 1380 | - * Outputs location of an event | |
| 1381 | - * | |
| 1001 | + * | |
| 1382 | 1002 | * @param WP_Post object $post |
| 1383 | - * | |
| 1384 | 1003 | * @return string |
| 1385 | 1004 | */ |
| 1386 | 1005 | public function print_location($post=null, $context='') { |
| 1387 | 1006 | $location = ''; |
| @@ -1392,73 +1011,52 @@ | ||
| 1392 | 1011 | } |
| 1393 | 1012 | if (!isset($post->start)) { |
| 1394 | 1013 | $post = $this->retreive($post); |
| 1395 | 1014 | } |
| 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; | |
| 1015 | + $address = $post->address; | |
| 1016 | + $lat = $post->lat; | |
| 1017 | + $long = $post->long; | |
| 1018 | + $color = $this->get_post_color($post->ID, $this->settings['default_color'], true); | |
| 1019 | + $icon = $this->DashIcons->icons[$this->get_post_icon($post->ID, $this->settings['default_icon'], true)]; | |
| 1020 | + $virtual_location = $post->virtual_location; | |
| 1021 | + $attendance_mode = $post->attendance_mode; | |
| 1405 | 1022 | |
| 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"; | |
| 1023 | + if ($this->is_online($post) && $virtual_location) { | |
| 1024 | + $location.="\t\t\t\t".'<div><a href="'.esc_url($virtual_location).'" class="eventpost-virtual-location-link" target="_blank" rel="noopener">' | |
| 1025 | + .__('Join link', 'event-post') | |
| 1026 | + .'</a></div>' | |
| 1027 | + ."\n"; | |
| 1028 | + } | |
| 1029 | + if ($this->is_offline($post) && ($address != '' || ($lat != '' && $long != ''))) { | |
| 1030 | + $location.="\t\t\t\t".'<address'; | |
| 1031 | + if ($lat != '' && $long != '') { | |
| 1032 | + $location.=' data-id="' . $post->ID . '" | |
| 1033 | + data-latitude="' . $lat . '" | |
| 1034 | + data-longitude="' . $long . '" | |
| 1035 | + data-marker="' . $this->get_marker($color) . '" | |
| 1036 | + data-iconcode="' .$icon. '" | |
| 1037 | + data-icon="' . mb_convert_encoding('&#x'.$icon.';', 'UTF-8', 'HTML-ENTITIES'). '" | |
| 1038 | + data-color="#' . $color. '"'; | |
| 1411 | 1039 | } |
| 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 | - } | |
| 1040 | + $location.=' itemprop="adr" class="eventpost-address">' | |
| 1041 | + . "\n\t\t\t\t\t\t\t".'<span>' | |
| 1042 | + . "\n".$address | |
| 1043 | + . "\n\t\t\t\t\t\t\t". '</span>'; | |
| 1044 | + if ($context=='single' && $lat != '' && $long != '') { | |
| 1045 | + $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>'; | |
| 1435 | 1046 | } |
| 1047 | + $location.="\n\t\t\t\t\t\t".'</address>'; | |
| 1048 | + if (wp_is_mobile() && $lat != '' && $long != '') { | |
| 1049 | + $location.="\n\t\t\t\t\t\t".'<a class="event_link gps-geo-link" href="geo:' . $lat . ',' . $long . '" target="_blank" itemprop="geo"><i class="dashicons-before dashicons-location"></i> ' . __('Open in app', 'event-post') . '</a>'; | |
| 1050 | + } | |
| 1436 | 1051 | } |
| 1052 | + | |
| 1437 | 1053 | return apply_filters('eventpost_printlocation', $location); |
| 1438 | 1054 | } |
| 1439 | 1055 | |
| 1440 | 1056 | /** |
| 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 | - } | |
| 1455 | - | |
| 1456 | - /** | |
| 1457 | - * Outputs categories of an event | |
| 1458 | - * | |
| 1057 | + * | |
| 1459 | 1058 | * @param WP_Post object $post |
| 1460 | - * | |
| 1461 | 1059 | * @return string |
| 1462 | 1060 | */ |
| 1463 | 1061 | public function print_categories($post=null, $context='') { |
| 1464 | 1062 | if ($post == null) |
| @@ -1469,36 +1067,23 @@ | ||
| 1469 | 1067 | if (!isset($post->start)) { |
| 1470 | 1068 | $post = $this->retreive($post); |
| 1471 | 1069 | } |
| 1472 | 1070 | $cats = ''; |
| 1473 | - if ($post != false){ | |
| 1474 | - $categories = $post->Taxonomies; | |
| 1475 | - if ($categories) { | |
| 1476 | - $cats.="\t\t\t\t".'<span class="event_categories">'; | |
| 1071 | + $categories = $post->categories; | |
| 1072 | + if ($categories) { | |
| 1073 | + $cats.="\t\t\t\t".'<span class="event_categories">'; | |
| 1477 | 1074 | |
| 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 . '"'; | |
| 1485 | - | |
| 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 | - } | |
| 1493 | - | |
| 1494 | - } | |
| 1495 | - $cats.=' class="'.implode(' ', $classes).'">'; | |
| 1496 | - $cats .= $category->name . ' '; | |
| 1497 | - $cats.='</span>'; | |
| 1075 | + foreach ($categories as $category) { | |
| 1076 | + $cats.="\t\t\t\t\t".'<span class="event_category"'; | |
| 1077 | + $color = $this->Categories->get_taxonomy_color($category->term_id); | |
| 1078 | + if ($color != '' && $color) { | |
| 1079 | + $cats.=' style="color:#' . $color . '"'; | |
| 1498 | 1080 | } |
| 1081 | + $cats.='>'; | |
| 1082 | + $cats .= $category->name . ' '; | |
| 1499 | 1083 | $cats.='</span>'; |
| 1500 | 1084 | } |
| 1085 | + $cats.='</span>'; | |
| 1501 | 1086 | } |
| 1502 | 1087 | return $cats; |
| 1503 | 1088 | } |
| 1504 | 1089 | |
| @@ -1503,14 +1088,11 @@ | ||
| 1503 | 1088 | } |
| 1504 | 1089 | |
| 1505 | 1090 | /** |
| 1506 | 1091 | * Generate, return or output date event datas |
| 1507 | - * | |
| 1508 | 1092 | * @param WP_Post object $post |
| 1509 | 1093 | * @param string $class |
| 1510 | - * | |
| 1511 | 1094 | * @filter eventpost_get_single |
| 1512 | - * | |
| 1513 | 1095 | * @return string |
| 1514 | 1096 | */ |
| 1515 | 1097 | public function get_single($post = null, $class = '', $context='') { |
| 1516 | 1098 | if ($post == null) { |
| @@ -1515,24 +1097,22 @@ | ||
| 1515 | 1097 | public function get_single($post = null, $class = '', $context='') { |
| 1516 | 1098 | if ($post == null) { |
| 1517 | 1099 | $post = $this->retreive(); |
| 1518 | 1100 | } |
| 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 | - } | |
| 1101 | + $datas_date = $this->print_date($post, null, $context); | |
| 1102 | + $datas_cat = $this->print_categories($post, $context); | |
| 1103 | + $datas_loc = $this->print_location($post, $context); | |
| 1104 | + $classes = array( | |
| 1105 | + 'event_data', | |
| 1106 | + 'status-'.$post->status, | |
| 1107 | + 'location-type-'.$post->attendance_mode, | |
| 1108 | + $class | |
| 1109 | + ); | |
| 1110 | + if ($datas_date != '' || $datas_loc != '') { | |
| 1111 | + $rgb = $this->hex2dec($post->color); | |
| 1112 | + 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">' | |
| 1113 | + . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post) | |
| 1114 | + . '</div>'; | |
| 1535 | 1115 | } |
| 1536 | 1116 | return ''; |
| 1537 | 1117 | } |
| 1538 | 1118 | |
| @@ -1537,12 +1117,10 @@ | ||
| 1537 | 1117 | } |
| 1538 | 1118 | |
| 1539 | 1119 | /** |
| 1540 | 1120 | * Displays dates of a gieven post |
| 1541 | - * | |
| 1542 | 1121 | * @param WP_Post object $post |
| 1543 | 1122 | * @param string $class |
| 1544 | - * | |
| 1545 | 1123 | * @return string |
| 1546 | 1124 | */ |
| 1547 | 1125 | public function get_singledate($post = null, $class = '', $context='') { |
| 1548 | 1126 | 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,12 +1127,10 @@ | ||
| 1549 | 1127 | } |
| 1550 | 1128 | |
| 1551 | 1129 | /** |
| 1552 | 1130 | * Displays coloured terms of a given post |
| 1553 | - * | |
| 1554 | 1131 | * @param WP_Post object $post |
| 1555 | 1132 | * @param string $class |
| 1556 | - * | |
| 1557 | 1133 | * @return string |
| 1558 | 1134 | */ |
| 1559 | 1135 | public function get_singlecat($post = null, $class = '', $context='') { |
| 1560 | 1136 | 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,12 +1137,10 @@ | ||
| 1561 | 1137 | } |
| 1562 | 1138 | |
| 1563 | 1139 | /** |
| 1564 | 1140 | * Displays location of a given post |
| 1565 | - * | |
| 1566 | 1141 | * @param WP_Post object $post |
| 1567 | 1142 | * @param string $class |
| 1568 | - * | |
| 1569 | 1143 | * @return string |
| 1570 | 1144 | */ |
| 1571 | 1145 | public function get_singleloc($post = null, $class = '', $context='') { |
| 1572 | 1146 | 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,11 +1147,9 @@ | ||
| 1573 | 1147 | } |
| 1574 | 1148 | |
| 1575 | 1149 | /** |
| 1576 | 1150 | * Uses `the_content` filter to add event details before or after the content of the current post |
| 1577 | - * | |
| 1578 | 1151 | * @param string $content |
| 1579 | - * | |
| 1580 | 1152 | * @return string |
| 1581 | 1153 | */ |
| 1582 | 1154 | public function display_single($content) { |
| 1583 | 1155 | if (is_page() || !is_single() || is_home() || !in_the_loop() || !is_main_query()){ |
| @@ -1584,42 +1156,32 @@ | ||
| 1584 | 1156 | return $content; |
| 1585 | 1157 | } |
| 1586 | 1158 | |
| 1587 | 1159 | $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(); | |
| 1160 | + $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post); | |
| 1161 | + if($this->settings['singlepos']=='before'){ | |
| 1162 | + $content=$eventbar.$content; | |
| 1602 | 1163 | } |
| 1164 | + elseif($this->settings['singlepos']=='after'){ | |
| 1165 | + $content.=$eventbar; | |
| 1166 | + } | |
| 1167 | + $this->load_map_scripts(); | |
| 1603 | 1168 | return $content; |
| 1604 | 1169 | } |
| 1605 | 1170 | |
| 1606 | 1171 | /** |
| 1607 | 1172 | * Outputs events details (dates, geoloc, terms) of given post |
| 1608 | - * | |
| 1609 | 1173 | * @param WP_Post object $post |
| 1610 | - * | |
| 1174 | + * @echoes string | |
| 1611 | 1175 | * @return void |
| 1612 | 1176 | */ |
| 1613 | 1177 | public function print_single($post = null) { |
| 1614 | - echo wp_kses_post($this->get_single($post)); | |
| 1178 | + echo $this->get_single($post); | |
| 1615 | 1179 | } |
| 1616 | 1180 | |
| 1617 | 1181 | /** |
| 1618 | 1182 | * Alter the post title in order to add icons if needed |
| 1619 | - * | |
| 1620 | 1183 | * @param string $title |
| 1621 | - * | |
| 1622 | 1184 | * @return string |
| 1623 | 1185 | */ |
| 1624 | 1186 | public function the_title($title, $post_id = null){ |
| 1625 | 1187 | if(!$post_id || !in_the_loop() || !$this->settings['loopicons']){ |
| @@ -1632,54 +1194,29 @@ | ||
| 1632 | 1194 | 2=>array('<span class="dashicons dashicons-calendar"></span>', '<span class="dashicons dashicons-location"></span>'), |
| 1633 | 1195 | ); |
| 1634 | 1196 | |
| 1635 | 1197 | $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 | - } | |
| 1198 | + if(!empty($event->start)){ | |
| 1199 | + $title .= ' '.$icons_[$this->settings['loopicons']][0]; | |
| 1643 | 1200 | } |
| 1201 | + if(!empty($event->lat) && !empty($event->long)){ | |
| 1202 | + $title .= ' '.$icons_[$this->settings['loopicons']][1]; | |
| 1203 | + } | |
| 1644 | 1204 | return $title; |
| 1645 | 1205 | } |
| 1646 | 1206 | |
| 1647 | 1207 | |
| 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 | 1208 | /** |
| 1671 | 1209 | * Return an HTML list of events |
| 1672 | 1210 | * |
| 1673 | - * @param array $atts | |
| 1674 | - * @param string $id | |
| 1675 | - * @param string $context | |
| 1676 | - * | |
| 1677 | 1211 | * @filter eventpost_params($defaults, 'list_events') |
| 1678 | 1212 | * @filter eventpost_listevents |
| 1679 | 1213 | * @filter eventpost_item_scheme_entities |
| 1680 | 1214 | * @filter eventpost_item_scheme_values |
| 1681 | - * | |
| 1215 | + * | |
| 1216 | + * @param array $atts | |
| 1217 | + * @param string $id | |
| 1218 | + * @param string $context | |
| 1682 | 1219 | * @return string |
| 1683 | 1220 | */ |
| 1684 | 1221 | public function list_events($atts, $id = 'event_list', $context='') { |
| 1685 | 1222 | $ep_settings = $this->settings; |
| @@ -1684,11 +1221,8 @@ | ||
| 1684 | 1221 | public function list_events($atts, $id = 'event_list', $context='') { |
| 1685 | 1222 | $ep_settings = $this->settings; |
| 1686 | 1223 | $defaults = array( |
| 1687 | 1224 | 'nb' => 0, |
| 1688 | - 'nb_desktop' => 0, | |
| 1689 | - 'nb_tablet' => 0, | |
| 1690 | - 'nb_mobile' => 0, | |
| 1691 | 1225 | 'type' => 'div', |
| 1692 | 1226 | 'future' => true, |
| 1693 | 1227 | 'past' => false, |
| 1694 | 1228 | 'geo' => 0, |
| @@ -1716,29 +1250,20 @@ | ||
| 1716 | 1250 | 'excerpt' => '', |
| 1717 | 1251 | 'orderby' => 'meta_value', |
| 1718 | 1252 | 'order' => 'ASC', |
| 1719 | 1253 | 'class' => '', |
| 1720 | - 'align' => '', | |
| 1721 | 1254 | 'className' => '', |
| 1722 | 1255 | 'container_schema' => $this->list_shema['container'], |
| 1723 | 1256 | 'item_schema' => $this->list_shema['item'], |
| 1724 | 1257 | 'pages' => false, |
| 1725 | 1258 | 'paged' => '', |
| 1726 | - 'separate_years' => false, | |
| 1727 | - 'separate_months' => false, | |
| 1728 | 1259 | ); |
| 1729 | 1260 | // Map UI options |
| 1730 | 1261 | foreach($this->map_interactions as $int_key=>$int_name){ |
| 1731 | 1262 | $defaults[$int_key]=true; |
| 1732 | 1263 | } |
| 1733 | - $atts_old_nb = $defaults['nb']; | |
| 1734 | - if($id == "event_timeline"){ | |
| 1735 | - $atts_old_nb = intval($atts['nb']); | |
| 1736 | - $atts['nb'] = -1; | |
| 1737 | - } | |
| 1264 | + $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events'), $atts); | |
| 1738 | 1265 | |
| 1739 | - $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events', $context), $atts); | |
| 1740 | - | |
| 1741 | 1266 | extract($atts); |
| 1742 | 1267 | if (!is_array($events)) { |
| 1743 | 1268 | $events = $this->get_events($atts); |
| 1744 | 1269 | } |
| @@ -1746,13 +1271,12 @@ | ||
| 1746 | 1271 | $ret = ''; |
| 1747 | 1272 | $this->list_id++; |
| 1748 | 1273 | if (sizeof($events) > 0) { |
| 1749 | 1274 | if (!empty($title)) { |
| 1750 | - $ret .= wp_kses_post($before_title . esc_html($title) . $after_title); | |
| 1275 | + $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title); | |
| 1751 | 1276 | } |
| 1752 | 1277 | |
| 1753 | - $type = in_array($type, ['div', 'ul', 'ol']) ? $type : 'div'; | |
| 1754 | - $child = in_array($type, ['ul', 'ol']) ? 'li' : 'div'; | |
| 1278 | + $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div'; | |
| 1755 | 1279 | |
| 1756 | 1280 | $html = ''; |
| 1757 | 1281 | |
| 1758 | 1282 | if($id=='event_geolist'){ |
| @@ -1763,48 +1287,29 @@ | ||
| 1763 | 1287 | $prev_arrow = ""; |
| 1764 | 1288 | $next_arrow = ""; |
| 1765 | 1289 | $item_child_style = ""; |
| 1766 | 1290 | 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).'%;'; | |
| 1291 | + $prev_arrow = '<div class="previous">'.__('« Previous Events', 'event-post')."</div>"; | |
| 1292 | + $next_arrow = '<div class="next">'.__('Next Events »', 'event-post')."</div>"; | |
| 1293 | + if($nb != 0){ | |
| 1294 | + $item_child_style = 'width : '.((100/$nb) - 2).'%;'; | |
| 1771 | 1295 | } |
| 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).'" '; | |
| 1296 | + $attributes .= ' data-nb="'.$nb.'" data-filter="'.http_build_query($atts).'" '; | |
| 1777 | 1297 | } |
| 1778 | 1298 | |
| 1779 | - if($id === 'event_timeline'){ | |
| 1780 | - $previous_year = $atts['separate_years'] ? true : false; | |
| 1781 | - $previous_month = $atts['separate_months'] ? true : false; | |
| 1782 | - } | |
| 1299 | + foreach ($events as $event) { | |
| 1783 | 1300 | |
| 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 | 1301 | $class_item = array( |
| 1797 | 1302 | $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)), | |
| 1303 | + 'status-'.$event->status, | |
| 1304 | + 'location-type-'.$event->attendance_mode, | |
| 1800 | 1305 | ); |
| 1801 | 1306 | $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 | - } | |
| 1307 | + $post_terms = []; | |
| 1308 | + $terms = wp_get_post_terms($event->ID, $taxonomies); | |
| 1309 | + foreach($terms as $term){ | |
| 1310 | + $class_item[] = $term->taxonomy.'-'.$term->name; | |
| 1311 | + } | |
| 1807 | 1312 | if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) { |
| 1808 | 1313 | $event->permalink = '#' . $id . $this->list_id; |
| 1809 | 1314 | } |
| 1810 | 1315 | elseif(empty($event->permalink)){ |
| @@ -1817,9 +1322,8 @@ | ||
| 1817 | 1322 | '%color%', |
| 1818 | 1323 | '%event_link%', |
| 1819 | 1324 | '%event_thumbnail%', |
| 1820 | 1325 | '%event_title%', |
| 1821 | - '%event_price%', | |
| 1822 | 1326 | '%event_date%', |
| 1823 | 1327 | '%event_cat%', |
| 1824 | 1328 | '%event_location%', |
| 1825 | 1329 | '%event_excerpt%', |
| @@ -1830,13 +1334,12 @@ | ||
| 1830 | 1334 | $this->get_post_color($event->ID, $this->settings['default_color'],true), |
| 1831 | 1335 | $event->permalink, |
| 1832 | 1336 | $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 | 1337 | $event->post_title, |
| 1834 | - $event->post_type == 'product' ? $text_price : '', | |
| 1835 | 1338 | $this->get_singledate($event, '', $context), |
| 1836 | 1339 | $this->get_singlecat($event, '', $context), |
| 1837 | 1340 | $this->get_singleloc($event, '', $context), |
| 1838 | - $excerpt == true && $event->description!='' ? '<span class="event_exerpt">'.$event->description.'</span>' : '', | |
| 1341 | + $excerpt == true && $event->post_excerpt!='' ? '<span class="event_exerpt">'.$event->post_excerpt.'</span>' : '', | |
| 1839 | 1342 | $item_child_style, |
| 1840 | 1343 | ), $event), $item_schema |
| 1841 | 1344 | ); |
| 1842 | 1345 | |
| @@ -1847,22 +1350,22 @@ | ||
| 1847 | 1350 | } |
| 1848 | 1351 | if($width==''){ |
| 1849 | 1352 | $width = '100%'; |
| 1850 | 1353 | } |
| 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="'; | |
| 1354 | + $attributes .= ' data-tile="'.$tile.'" | |
| 1355 | + data-width="'.$width.'" | |
| 1356 | + data-height="'.$height.'" | |
| 1357 | + data-zoom="'.$zoom.'" | |
| 1358 | + data-map_position="'.$map_position.'" | |
| 1359 | + data-latitude="'.$latitude.'" | |
| 1360 | + data-longitude="'.$longitude.'" | |
| 1361 | + data-pop_element_schema="'.$pop_element_schema.'" | |
| 1362 | + data-htmlPop_element_schema="'.esc_attr($htmlPop_element_schema).'" | |
| 1363 | + data-list="'.$list.'" | |
| 1364 | + data-disabled-interactions="'; | |
| 1862 | 1365 | // add data-position avec ma variables |
| 1863 | 1366 | foreach($this->map_interactions as $int_key=>$int_name){ |
| 1864 | - $attributes.=$atts[$int_key]==false ? esc_attr($int_key).', ' : ''; | |
| 1367 | + $attributes.=$atts[$int_key]==false ? $int_key.', ' : ''; | |
| 1865 | 1368 | } |
| 1866 | 1369 | $attributes.='" '; |
| 1867 | 1370 | } |
| 1868 | 1371 | $pagination = ''; |
| @@ -1880,20 +1383,8 @@ | ||
| 1880 | 1383 | |
| 1881 | 1384 | if($context == 'events_only'){ |
| 1882 | 1385 | $ret = $html; |
| 1883 | 1386 | }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 | 1387 | $ret.=str_replace( |
| 1897 | 1388 | array( |
| 1898 | 1389 | '%type%', |
| 1899 | 1390 | '%id%', |
| @@ -1908,11 +1399,11 @@ | ||
| 1908 | 1399 | '%number%' |
| 1909 | 1400 | ), array( |
| 1910 | 1401 | $type, |
| 1911 | 1402 | $id, |
| 1912 | - esc_attr(implode(' ', $classes)), | |
| 1403 | + $class.($className ? ' '.$className : '').($id == 'event_geolist' && $list ? ' has-list list-'.$list : ' no-list'), | |
| 1913 | 1404 | $id . $this->list_id, |
| 1914 | - (!empty($width) ? 'width:' . esc_attr($width) . ';' : '') . (!empty($height) ? 'height:' . esc_attr($height) . ';' : '') . esc_attr($style), | |
| 1405 | + (!empty($width) ? 'width:' . $width . ';' : '') . (!empty($height) ? 'height:' . $height . ';' : '') . $style, | |
| 1915 | 1406 | $attributes, |
| 1916 | 1407 | $html, |
| 1917 | 1408 | $pagination, |
| 1918 | 1409 | $prev_arrow, |
| @@ -1929,15 +1420,12 @@ | ||
| 1929 | 1420 | } |
| 1930 | 1421 | |
| 1931 | 1422 | |
| 1932 | 1423 | /** |
| 1933 | - * Get events | |
| 1934 | - * | |
| 1424 | + * get_events | |
| 1935 | 1425 | * @param array $atts |
| 1936 | - * | |
| 1937 | 1426 | * @filter eventpost_params |
| 1938 | 1427 | * @filter eventpost_get_items |
| 1939 | - * | |
| 1940 | 1428 | * @return array of post_ids which are events |
| 1941 | 1429 | */ |
| 1942 | 1430 | public function get_events($atts) { |
| 1943 | 1431 | if(isset($atts['future'])){ |
| @@ -2105,9 +1593,9 @@ | ||
| 2105 | 1593 | } |
| 2106 | 1594 | |
| 2107 | 1595 | $arg['meta_query'] = $meta_query; |
| 2108 | 1596 | |
| 2109 | - $query_md5 = 'eventpost_' . md5(wp_json_encode($requete, true)); | |
| 1597 | + $query_md5 = 'eventpost_' . md5(var_export($requete, true)); | |
| 2110 | 1598 | // Check if cache is activated |
| 2111 | 1599 | if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) { |
| 2112 | 1600 | return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg); |
| 2113 | 1601 | } |
| @@ -2122,11 +1610,9 @@ | ||
| 2122 | 1610 | 'max_num_pages' => $query->max_num_pages, |
| 2123 | 1611 | ); |
| 2124 | 1612 | foreach ($events as $k => $post) { |
| 2125 | 1613 | $event = $this->retreive($post); |
| 2126 | - if ($event != false){ | |
| 2127 | - $events[$k] = $event; | |
| 2128 | - } | |
| 1614 | + $events[$k] = $event; | |
| 2129 | 1615 | } |
| 2130 | 1616 | } |
| 2131 | 1617 | if ($this->settings['cache'] == 1){ |
| 2132 | 1618 | set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS); |
| @@ -2136,11 +1622,10 @@ | ||
| 2136 | 1622 | |
| 2137 | 1623 | /** |
| 2138 | 1624 | * Checks if the given event is in the future or not |
| 2139 | 1625 | * |
| 2140 | - * @param object $event | |
| 2141 | - * @param boolean $exact Future status has to be calculated against time or entire day | |
| 2142 | - * | |
| 1626 | + * @param object $event | |
| 1627 | + * @param boolean $exact Future status has to be calculated against time or entire day | |
| 2143 | 1628 | * @return boolean |
| 2144 | 1629 | */ |
| 2145 | 1630 | function is_future($event, $exact=false){ |
| 2146 | 1631 | $match = current_time('timestamp'); |
| @@ -2153,11 +1638,10 @@ | ||
| 2153 | 1638 | |
| 2154 | 1639 | /** |
| 2155 | 1640 | * Checks if the given event is completed or not |
| 2156 | 1641 | * |
| 2157 | - * @param object $event | |
| 2158 | - * @param boolean $exact Past status has to be calculated against time or entire day | |
| 2159 | - * | |
| 1642 | + * @param object $event | |
| 1643 | + * @param boolean $exact Past status has to be calculated against time or entire day | |
| 2160 | 1644 | * @return boolean |
| 2161 | 1645 | */ |
| 2162 | 1646 | function is_past($event, $exact=false){ |
| 2163 | 1647 | $match = current_time('timestamp'); |
| @@ -2169,11 +1653,9 @@ | ||
| 2169 | 1653 | } |
| 2170 | 1654 | |
| 2171 | 1655 | /** |
| 2172 | 1656 | * Checks if an event is online |
| 2173 | - * | |
| 2174 | - * @param $event | |
| 2175 | - * | |
| 1657 | + * @param $event | |
| 2176 | 1658 | * @return boolean |
| 2177 | 1659 | */ |
| 2178 | 1660 | function is_online($event){ |
| 2179 | 1661 | return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OnlineEventAttendanceMode'))); |
| @@ -2180,11 +1662,9 @@ | ||
| 2180 | 1662 | } |
| 2181 | 1663 | |
| 2182 | 1664 | /** |
| 2183 | 1665 | * Checks if an event is offline |
| 2184 | - * | |
| 2185 | - * @param $event | |
| 2186 | - * | |
| 1666 | + * @param $event | |
| 2187 | 1667 | * @return boolean |
| 2188 | 1668 | */ |
| 2189 | 1669 | function is_offline($event){ |
| 2190 | 1670 | return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OfflineEventAttendanceMode'))); |
| @@ -2189,21 +1669,17 @@ | ||
| 2189 | 1669 | function is_offline($event){ |
| 2190 | 1670 | return (in_array($event->attendance_mode, array('MixedEventAttendanceMode', 'OfflineEventAttendanceMode'))); |
| 2191 | 1671 | } |
| 2192 | 1672 | |
| 1673 | + | |
| 2193 | 1674 | /** |
| 2194 | - * Populates a WP_Post object with event datas | |
| 2195 | - * | |
| 1675 | + * | |
| 2196 | 1676 | * @param object $event |
| 2197 | - * | |
| 2198 | 1677 | * @return object |
| 2199 | 1678 | */ |
| 2200 | 1679 | public function retreive($event = null) { |
| 2201 | 1680 | global $EventPost_cache; |
| 2202 | 1681 | $ob = get_post($event); |
| 2203 | - if(!$ob){ | |
| 2204 | - return false; | |
| 2205 | - } | |
| 2206 | 1682 | if(is_object($ob) && $ob->start){ |
| 2207 | 1683 | return $ob; |
| 2208 | 1684 | } |
| 2209 | 1685 | if(is_object($ob) && isset($EventPost_cache[$ob->ID])){ |
| @@ -2220,37 +1696,26 @@ | ||
| 2220 | 1696 | $ob->root_ID = $ob->ID; |
| 2221 | 1697 | $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : ''; |
| 2222 | 1698 | $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : ''; |
| 2223 | 1699 | $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 | 1700 | $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)); | |
| 1701 | + $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true); | |
| 1702 | + $ob->long = get_post_meta($ob->ID, $this->META_LONG, true); | |
| 2237 | 1703 | $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 | 1704 | $ob->status = (null != $status = get_post_meta($ob->ID, $this->META_STATUS, true)) ? $status : array_keys($this->statuses)[0]; |
| 2239 | 1705 | $ob->color = $this->get_post_color($ob->ID); |
| 2240 | 1706 | $ob->icon = $this->get_post_icon($ob->ID); |
| 2241 | - $ob->Taxonomies = get_the_category($ob->ID); | |
| 1707 | + $ob->categories = get_the_category($ob->ID); | |
| 2242 | 1708 | $ob->permalink = get_permalink($ob->ID); |
| 2243 | 1709 | $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))))); | |
| 1710 | + | |
| 2245 | 1711 | $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob); |
| 2246 | 1712 | return $EventPost_cache[$ob->ID]; |
| 2247 | 1713 | } |
| 2248 | 1714 | |
| 2249 | 1715 | /** |
| 2250 | - * Fetch terms of a post | |
| 2251 | - * | |
| 2252 | - * @param mixed $_term | |
| 1716 | + * | |
| 1717 | + * @param mixte $_term | |
| 2253 | 1718 | * @param string $taxonomy |
| 2254 | 1719 | * @param string $post_type |
| 2255 | 1720 | */ |
| 2256 | 1721 | public function retreive_term($_term=null, $taxonomy='category', $post_type='post') { |
| @@ -2294,12 +1759,12 @@ | ||
| 2294 | 1759 | return $term; |
| 2295 | 1760 | |
| 2296 | 1761 | } |
| 2297 | 1762 | |
| 2298 | - // ADMIN ISSUES | |
| 1763 | + /** ADMIN ISSUES * */ | |
| 2299 | 1764 | |
| 2300 | 1765 | /** |
| 2301 | - * Add custom boxes in posts edit page | |
| 1766 | + * add custom boxes in posts edit page | |
| 2302 | 1767 | */ |
| 2303 | 1768 | public function add_custom_box() { |
| 2304 | 1769 | foreach($this->settings['posttypes'] as $posttype){ |
| 2305 | 1770 | add_meta_box( |
| @@ -2326,11 +1791,10 @@ | ||
| 2326 | 1791 | ); |
| 2327 | 1792 | do_action('eventpost_add_custom_box', $posttype); |
| 2328 | 1793 | } |
| 2329 | 1794 | } |
| 2330 | - | |
| 2331 | 1795 | /** |
| 2332 | - * Displays the date custom box | |
| 1796 | + * display the date custom box | |
| 2333 | 1797 | */ |
| 2334 | 1798 | public function inner_custom_box_date() { |
| 2335 | 1799 | |
| 2336 | 1800 | |
| @@ -2337,59 +1801,54 @@ | ||
| 2337 | 1801 | |
| 2338 | 1802 | wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); |
| 2339 | 1803 | $post_id = get_the_ID(); |
| 2340 | 1804 | $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; | |
| 1805 | + $start_date = $event->start; | |
| 1806 | + $end_date = $event->end; | |
| 1807 | + $eventcolor = $event->color; | |
| 1808 | + $eventicon = $event->icon; | |
| 2346 | 1809 | |
| 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); | |
| 1810 | + $language = get_bloginfo('language'); | |
| 1811 | + if (strpos($language, '-') > -1) { | |
| 1812 | + $language = strtolower(substr($language, 0, 2)); | |
| 2354 | 1813 | } |
| 1814 | + $colors = $this->get_colors(); | |
| 1815 | + include (plugin_dir_path(__FILE__) . 'views/admin/custombox-date.php'); | |
| 1816 | + do_action ('eventpost_custom_box_date', $event); | |
| 2355 | 1817 | } |
| 2356 | - | |
| 2357 | 1818 | /** |
| 2358 | - * Displays the location custom box | |
| 1819 | + * displays the location custom box | |
| 2359 | 1820 | */ |
| 2360 | 1821 | public function inner_custom_box_loc($post) { |
| 2361 | 1822 | $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 | - } | |
| 1823 | + include (plugin_dir_path(__FILE__) . 'views/admin/custombox-location.php'); | |
| 1824 | + do_action ('eventpost_custom_box_loc', $event); | |
| 1825 | + $this->load_map_scripts(); | |
| 2367 | 1826 | } |
| 2368 | 1827 | |
| 2369 | 1828 | public function icon_color_fields($item_id, $meta_color,$value_color,$meta_icon,$value_icon ){ |
| 2370 | 1829 | ?> |
| 2371 | 1830 | <div class="eventpost-misc-pub-section event-color-section"> |
| 2372 | - <span class="screen-reader-text"><?php esc_html_e('Color:', 'event-post'); ?></span> | |
| 1831 | + <span class="screen-reader-text"><?php _e('Color:', 'event-post'); ?></span> | |
| 2373 | 1832 | |
| 2374 | 1833 | <input class="color-field-post eventpost-colorpicker" |
| 2375 | 1834 | 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); ?>"/> | |
| 1835 | + name="<?php echo $meta_color; ?>" | |
| 1836 | + value="<?php echo $value_color; ?>" | |
| 1837 | + id="color-field<?php echo $item_id; ?>"/> | |
| 2379 | 1838 | |
| 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> | |
| 1839 | + <select style="font-family : dashicons;" class="eventpost-iconpicker" name="<?php echo $meta_icon; ?>"> | |
| 1840 | + <option value=""><?php echo __('None','event-post') ?></option> | |
| 2382 | 1841 | <?php |
| 2383 | 1842 | foreach($this->DashIcons->icons as $class => $unicode){ |
| 2384 | 1843 | ?> |
| 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 ?> | |
| 1844 | + <option value="<?php echo $class ?>" <?php selected($value_icon, $class, true); ?>>&#x<?php echo $unicode ?>; <?php echo $class ?></option> | |
| 2386 | 1845 | <?php |
| 2387 | 1846 | } |
| 2388 | 1847 | ?> |
| 2389 | 1848 | </select> |
| 2390 | 1849 | <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> | |
| 1850 | + <p><?php echo __('An image was found in your custom folder for this color', 'event-post')?> <span class="color-hex"></span> </p> | |
| 2392 | 1851 | <img src="" class="image-marker"> |
| 2393 | 1852 | </div> |
| 2394 | 1853 | </div> |
| 2395 | 1854 | |
| @@ -2397,13 +1856,12 @@ | ||
| 2397 | 1856 | <?php |
| 2398 | 1857 | } |
| 2399 | 1858 | |
| 2400 | 1859 | /** |
| 2401 | - * Quick edit | |
| 2402 | - * | |
| 2403 | - * @param string $column_name | |
| 2404 | - * @param boolean $bulk | |
| 2405 | - */ | |
| 1860 | + * | |
| 1861 | + * @param string $column_name | |
| 1862 | + * @param boolean $bulk | |
| 1863 | + */ | |
| 2406 | 1864 | function quick_edit( $column_name, $post_type, $bulk=false) { |
| 2407 | 1865 | |
| 2408 | 1866 | if ($bulk) { |
| 2409 | 1867 | static $eventpostprintNonceBulk = TRUE; |
| @@ -2421,17 +1879,17 @@ | ||
| 2421 | 1879 | $fields = $this->quick_edit_fields; |
| 2422 | 1880 | } |
| 2423 | 1881 | wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); |
| 2424 | 1882 | if(isset($fields[$column_name])): ?> |
| 2425 | - <fieldset class="inline-edit-col-left inline-edit-<?php echo esc_attr($column_name); ?>"> | |
| 1883 | + <fieldset class="inline-edit-col-left inline-edit-<?php echo $column_name; ?>"> | |
| 2426 | 1884 | <div class="inline-edit-group"> |
| 2427 | 1885 | <?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); ?>"> | |
| 1886 | + <fieldset class="inline-edit-col inline-edit-<?php echo $fieldname; ?>"> | |
| 1887 | + <div class="inline-edit-col column-<?php echo $fieldname; ?>"> | |
| 2430 | 1888 | <label class="inline-edit-group"> |
| 2431 | - <span class="title"><?php echo esc_html($fieldlabel); ?></span> | |
| 1889 | + <span class="title"><?php echo $fieldlabel; ?></span> | |
| 2432 | 1890 | <span class="input-text-wrap"> |
| 2433 | - <?php echo wp_kses($this->inline_field($fieldname, $bulk), $this->kses_tags); ?> | |
| 1891 | + <?php echo $this->inline_field($fieldname, $bulk); ?> | |
| 2434 | 1892 | </span> |
| 2435 | 1893 | </label> |
| 2436 | 1894 | </div> |
| 2437 | 1895 | </fieldset> |
| @@ -2441,16 +1899,14 @@ | ||
| 2441 | 1899 | <?php endif; |
| 2442 | 1900 | } |
| 2443 | 1901 | |
| 2444 | 1902 | /** |
| 2445 | - * Inline field in bulk edit | |
| 2446 | - * | |
| 1903 | + * | |
| 2447 | 1904 | * @param type $fieldname |
| 2448 | - * | |
| 2449 | - * @return string | |
| 1905 | + * @return type | |
| 2450 | 1906 | */ |
| 2451 | 1907 | 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); | |
| 1908 | + return apply_filters('eventpost_inline_field', '<input name="'.$fieldname.'" class="eventpost-inline-'.$fieldname.'" value="" type="text">', $fieldname, $bulk); | |
| 2453 | 1909 | } |
| 2454 | 1910 | |
| 2455 | 1911 | function inline_field_color($html, $fieldname, $bulk){ |
| 2456 | 1912 | if($fieldname==$this->META_COLOR){ |
| @@ -2455,13 +1911,13 @@ | ||
| 2455 | 1911 | function inline_field_color($html, $fieldname, $bulk){ |
| 2456 | 1912 | if($fieldname==$this->META_COLOR){ |
| 2457 | 1913 | $html=''; |
| 2458 | 1914 | if($bulk){ |
| 2459 | - $html.= '<span class="eventpost-bulk-colorpicker-button link">'.esc_html(__('No Change', 'event-post')).'</span>'; | |
| 1915 | + $html.= '<span class="eventpost-bulk-colorpicker-button link">'.__('No Change', 'event-post').'</span>'; | |
| 2460 | 1916 | } |
| 2461 | 1917 | $html .= ' |
| 2462 | 1918 | |
| 2463 | - <input class="eventpost-inline-colorpicker eventpost-inline-'.esc_attr($fieldname).' '.($bulk?'is-bulk':'no-bulk').'" type="color" name="'.esc_attr($fieldname).'" >'; | |
| 1919 | + <input class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'" type="text" name="'.$fieldname.'" >'; | |
| 2464 | 1920 | } |
| 2465 | 1921 | return $html; |
| 2466 | 1922 | } |
| 2467 | 1923 | function inline_field_icon($html, $fieldname, $bulk){ |
| @@ -2468,16 +1924,17 @@ | ||
| 2468 | 1924 | if($fieldname==$this->META_ICON){ |
| 2469 | 1925 | if($bulk){ |
| 2470 | 1926 | $html.= '<span class="eventpost-bulk-icon-button link">'.__('No Change', 'event-post').'</span>'; |
| 2471 | 1927 | } |
| 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>'; | |
| 1928 | + $html = '<select class="eventpost-inline-colorpicker eventpost-inline-'.$fieldname.' '.($bulk?'is-bulk':'no-bulk').'" | |
| 1929 | + type="text" | |
| 1930 | + name="'.$fieldname.'" | |
| 1931 | + style="font-family : dashicons"> | |
| 1932 | + <option value="">'.__("None", 'event-post').'</option>'; | |
| 2477 | 1933 | foreach($this->DashIcons->icons as $class => $unicode){ |
| 2478 | - $html .= '<option value="'.$class.'">&#x'.$unicode.'; '.$class.'</option>'; | |
| 2479 | - } | |
| 1934 | + $html .= '<option value="'.$class.'">&#x'.$unicode.'; '.$class.'</option>'; | |
| 1935 | + | |
| 1936 | + } | |
| 2480 | 1937 | $html .= '</select>'; |
| 2481 | 1938 | |
| 2482 | 1939 | } |
| 2483 | 1940 | return $html; |
| @@ -2484,10 +1941,9 @@ | ||
| 2484 | 1941 | } |
| 2485 | 1942 | |
| 2486 | 1943 | |
| 2487 | 1944 | /** |
| 2488 | - * Bulk edit | |
| 2489 | - * | |
| 1945 | + * | |
| 2490 | 1946 | * @param type $column_name |
| 2491 | 1947 | * @param type $post_type |
| 2492 | 1948 | */ |
| 2493 | 1949 | function bulk_edit($column_name, $post_type){ |
| @@ -2495,9 +1951,8 @@ | ||
| 2495 | 1951 | } |
| 2496 | 1952 | |
| 2497 | 1953 | /** |
| 2498 | 1954 | * Saves data from quick-edit via `wp_ajax_inline-save` action |
| 2499 | - * | |
| 2500 | 1955 | * @return void |
| 2501 | 1956 | */ |
| 2502 | 1957 | function inline_save(){ |
| 2503 | 1958 | $post_id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); |
| @@ -2504,11 +1959,9 @@ | ||
| 2504 | 1959 | $this->save_postdata($post_id); |
| 2505 | 1960 | } |
| 2506 | 1961 | /** |
| 2507 | 1962 | * When the post is saved, saves our custom data |
| 2508 | - * | |
| 2509 | 1963 | * @param int $post_id |
| 2510 | - * | |
| 2511 | 1964 | * @return void |
| 2512 | 1965 | */ |
| 2513 | 1966 | public function save_postdata($post_id) { |
| 2514 | 1967 | if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
| @@ -2514,55 +1967,36 @@ | ||
| 2514 | 1967 | if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
| 2515 | 1968 | return; |
| 2516 | 1969 | } |
| 2517 | 1970 | |
| 2518 | - if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce'), plugin_basename(__FILE__))){ | |
| 1971 | + if (!wp_verify_nonce(filter_input(INPUT_POST, 'eventpost_nonce', FILTER_SANITIZE_STRING), plugin_basename(__FILE__))){ | |
| 2519 | 1972 | return; |
| 2520 | 1973 | } |
| 2521 | 1974 | |
| 2522 | 1975 | // 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)); | |
| 1976 | + if (false !== $color = filter_input(INPUT_POST, $this->META_COLOR, FILTER_SANITIZE_STRING)) { | |
| 1977 | + update_post_meta($post_id, $this->META_COLOR, $color); | |
| 2525 | 1978 | } |
| 2526 | 1979 | // 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)); | |
| 1980 | + if (false !== $icon = filter_input(INPUT_POST, $this->META_ICON, FILTER_SANITIZE_STRING)) { | |
| 1981 | + update_post_meta($post_id, $this->META_ICON, $icon); | |
| 2529 | 1982 | } |
| 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)); | |
| 1983 | + if (false !== $attendance_mode = filter_input(INPUT_POST, $this->META_ATTENDANCE_MODE, FILTER_SANITIZE_STRING)) { | |
| 1984 | + update_post_meta($post_id, $this->META_ATTENDANCE_MODE, $attendance_mode); | |
| 2532 | 1985 | } |
| 2533 | - if (false !== $status = filter_input(INPUT_POST, $this->META_STATUS)) { | |
| 2534 | - update_post_meta($post_id, $this->META_STATUS, sanitize_text_field($status)); | |
| 1986 | + if (false !== $status = filter_input(INPUT_POST, $this->META_STATUS, FILTER_SANITIZE_STRING)) { | |
| 1987 | + update_post_meta($post_id, $this->META_STATUS, $status); | |
| 2535 | 1988 | } |
| 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)); | |
| 1989 | + if (false !== $virtual_location = filter_input(INPUT_POST, $this->META_VIRTUAL_LOCATION, FILTER_SANITIZE_URL)) { | |
| 1990 | + update_post_meta($post_id, $this->META_VIRTUAL_LOCATION, $virtual_location); | |
| 2539 | 1991 | } |
| 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 | 1992 | // 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)) && | |
| 1993 | + if ((false !== $start = filter_input(INPUT_POST, $this->META_START, FILTER_SANITIZE_STRING)) && | |
| 1994 | + (false !== $end = filter_input(INPUT_POST, $this->META_END, FILTER_SANITIZE_STRING)) && | |
| 2561 | 1995 | '' != $start && |
| 2562 | 1996 | '' != $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')); | |
| 1997 | + update_post_meta($post_id, $this->META_START, substr($start,0,16).':00'); | |
| 1998 | + update_post_meta($post_id, $this->META_END, substr($end,0,16).':00'); | |
| 2565 | 1999 | } |
| 2566 | 2000 | else { |
| 2567 | 2001 | delete_post_meta($post_id, $this->META_START); |
| 2568 | 2002 | delete_post_meta($post_id, $this->META_END); |
| @@ -2568,15 +2002,15 @@ | ||
| 2568 | 2002 | delete_post_meta($post_id, $this->META_END); |
| 2569 | 2003 | } |
| 2570 | 2004 | |
| 2571 | 2005 | // 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)) && | |
| 2006 | + if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT, FILTER_SANITIZE_STRING)) && | |
| 2007 | + (false !== $long = filter_input(INPUT_POST, $this->META_LONG, FILTER_SANITIZE_STRING)) && | |
| 2574 | 2008 | '' != $lat && |
| 2575 | 2009 | '' != $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))); | |
| 2010 | + update_post_meta($post_id, $this->META_ADD, filter_input(INPUT_POST, $this->META_ADD, FILTER_SANITIZE_STRING)); | |
| 2011 | + update_post_meta($post_id, $this->META_LAT, $lat); | |
| 2012 | + update_post_meta($post_id, $this->META_LONG, $long); | |
| 2579 | 2013 | } |
| 2580 | 2014 | else { |
| 2581 | 2015 | delete_post_meta($post_id, $this->META_ADD); |
| 2582 | 2016 | delete_post_meta($post_id, $this->META_LAT); |
| @@ -2587,44 +2021,39 @@ | ||
| 2587 | 2021 | } |
| 2588 | 2022 | |
| 2589 | 2023 | /** |
| 2590 | 2024 | * Saves data from bulk-edit |
| 2591 | - * Uses bulk_edit_posts hook | |
| 2592 | - * | |
| 2593 | - * @see https://developer.wordpress.org/reference/hooks/bulk_edit_posts/ | |
| 2594 | - * | |
| 2025 | + * Should be used via AJAX | |
| 2026 | + * | |
| 2027 | + * outputs JSON | |
| 2595 | 2028 | * @return void |
| 2596 | 2029 | */ |
| 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'; | |
| 2030 | + function save_bulkdatas() { | |
| 2031 | + $current_post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 'post'; | |
| 2602 | 2032 | if (in_array($current_post_type, $this->settings['posttypes'])) { |
| 2033 | + $post_ids = (!empty($_POST['post_ids']) ) ? $_POST['post_ids'] : array(); | |
| 2603 | 2034 | 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]); | |
| 2035 | + foreach ($this->bulk_edit_fields as $sets) { | |
| 2036 | + foreach ($sets as $fieldname => $fieldlabel) { | |
| 2037 | + if ((false != $value = filter_input(INPUT_POST, $fieldname))) { | |
| 2038 | + foreach ($post_ids as $post_id) { | |
| 2039 | + update_post_meta($post_id, $fieldname, $value); | |
| 2612 | 2040 | } |
| 2613 | 2041 | } |
| 2614 | 2042 | } |
| 2615 | 2043 | } |
| 2616 | 2044 | } |
| 2045 | + wp_send_json(true); | |
| 2046 | + exit; | |
| 2617 | 2047 | } |
| 2048 | + wp_send_json(false); | |
| 2618 | 2049 | } |
| 2619 | 2050 | |
| 2620 | 2051 | /** |
| 2621 | - * Displays a date for calendar cell | |
| 2622 | - * | |
| 2052 | + * | |
| 2623 | 2053 | * @param string $date |
| 2624 | 2054 | * @param string $cat |
| 2625 | 2055 | * @param boolean $display |
| 2626 | - * | |
| 2627 | 2056 | * @return boolean |
| 2628 | 2057 | */ |
| 2629 | 2058 | public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='', $title='',$tax_name='' ,$tax_term='') { |
| 2630 | 2059 | $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true,'tax_name' => $tax_name ,'tax_term' => $tax_term)); |
| @@ -2629,26 +2058,21 @@ | ||
| 2629 | 2058 | public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='', $title='',$tax_name='' ,$tax_term='') { |
| 2630 | 2059 | $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true,'tax_name' => $tax_name ,'tax_term' => $tax_term)); |
| 2631 | 2060 | $nb = count($events); |
| 2632 | 2061 | $ret = ""; |
| 2633 | - $price = ""; | |
| 2634 | 2062 | if(!$display && !$nb){ |
| 2635 | 2063 | $ret = date('j', $date); |
| 2636 | 2064 | } |
| 2637 | - $price = ''; | |
| 2638 | 2065 | if($nb){ |
| 2639 | 2066 | if ($display || $title) { |
| 2640 | 2067 | $ret='<ul>'; |
| 2641 | 2068 | foreach ($events as $event) { |
| 2642 | - $price = $this->get_price($event, true); | |
| 2643 | 2069 | if ($this->settings['emptylink'] == 0 && empty($event->post_content)) { |
| 2644 | 2070 | $event->guid = '#'; |
| 2645 | 2071 | } |
| 2646 | 2072 | $ret.='<li>' |
| 2647 | - // Translators: %s is the event title | |
| 2648 | 2073 | . '<a href="' . $event->permalink . '" title="'.esc_attr(sprintf(__('View event: %s', 'event-post'), $event->post_title)).'">' |
| 2649 | 2074 | . '<h4>' . $event->post_title . '</h4>' |
| 2650 | - . '<span class="event_price">' . $price . '</span>' | |
| 2651 | 2075 | .$this->get_single($event) |
| 2652 | 2076 | . (!empty($thumbnail) ? '<span class="event_thumbnail_wrap">' . get_the_post_thumbnail($event->ID, $thumbnail) . '</span>' : '') |
| 2653 | 2077 | .'</a>' |
| 2654 | 2078 | . '</li>'; |
| @@ -2663,9 +2087,8 @@ | ||
| 2663 | 2087 | } |
| 2664 | 2088 | else { |
| 2665 | 2089 | $ret = '<button data-event="'. $tax_term .'" data-date="' . date('Y-m-d', $date).'"' |
| 2666 | 2090 | .' 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 | 2091 | .' 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 | 2092 | .'>' |
| 2670 | 2093 | . date('j', $date) |
| 2671 | 2094 | . '</button>'; |
| @@ -2670,19 +2093,16 @@ | ||
| 2670 | 2093 | . date('j', $date) |
| 2671 | 2094 | . '</button>'; |
| 2672 | 2095 | } |
| 2673 | 2096 | } |
| 2674 | - return apply_filters('eventpost_display_caldate', $ret, $events, $date, $cat ,$price, $display ,$colored ,$thumbnail ,$title ,$tax_name ,$tax_term ); | |
| 2097 | + | |
| 2098 | + return apply_filters('eventpost_display_caldate', $ret, $events, $date, $cat ,$display ,$colored ,$thumbnail ,$title ,$tax_name ,$tax_term ); | |
| 2675 | 2099 | } |
| 2676 | 2100 | |
| 2677 | 2101 | |
| 2678 | 2102 | /** |
| 2679 | - * Returns a calendar HTML | |
| 2680 | - * | |
| 2681 | 2103 | * @param array $atts |
| 2682 | - * | |
| 2683 | 2104 | * @filter eventpost_params |
| 2684 | - * | |
| 2685 | 2105 | * @return string |
| 2686 | 2106 | */ |
| 2687 | 2107 | public function calendar($atts) { |
| 2688 | 2108 | extract(shortcode_atts(apply_filters('eventpost_params', array( |
| @@ -2731,18 +2151,14 @@ | ||
| 2731 | 2151 | . '</caption>'; |
| 2732 | 2152 | $ret.='<thead><tr><th colspan="7">'; |
| 2733 | 2153 | if ($datepicker == 1) { |
| 2734 | 2154 | $ret.='<div class="eventpost-calendar-header">'; |
| 2735 | - // Translators: %s is the year | |
| 2736 | 2155 | $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 | 2156 | $ret.=$annee; |
| 2738 | - // Translators: %s is the year | |
| 2739 | 2157 | $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">'; | |
| 2158 | + $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">«</button><span class="eventpost-cal-header-text">'; | |
| 2742 | 2159 | $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>'; | |
| 2160 | + $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">»</button> </span>'; | |
| 2745 | 2161 | $ret.='<span class="eventpost-cal-today"><button data-date="' . date('Y-n') . '" class="eventpost_cal_bt">' . __('Today', 'event-post') . '</button></span>'; |
| 2746 | 2162 | $ret.='</div>'; |
| 2747 | 2163 | } |
| 2748 | 2164 | $ret.='</th></tr><tr class="event_post_cal_days">'; |
| @@ -2783,14 +2199,14 @@ | ||
| 2783 | 2199 | return $ret; |
| 2784 | 2200 | } |
| 2785 | 2201 | |
| 2786 | 2202 | /** |
| 2787 | - * Echoes a list of event, should be called via AJAX | |
| 2203 | + * echoes a list of event, should be called via AJAX | |
| 2788 | 2204 | * |
| 2789 | 2205 | * @return void |
| 2790 | 2206 | */ |
| 2791 | 2207 | public function ajaxlist(){ |
| 2792 | - echo wp_kses($this->list_events(array( | |
| 2208 | + echo $this->list_events(array( | |
| 2793 | 2209 | 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')), |
| 2794 | 2210 | 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')), |
| 2795 | 2211 | 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')), |
| 2796 | 2212 | 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')), |
| @@ -2811,19 +2227,19 @@ | ||
| 2811 | 2227 | 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')), |
| 2812 | 2228 | 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')), |
| 2813 | 2229 | 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')), |
| 2814 | 2230 | 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')), |
| 2815 | - ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags); | |
| 2231 | + ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))); | |
| 2816 | 2232 | exit; |
| 2817 | 2233 | } |
| 2818 | 2234 | |
| 2819 | 2235 | /** |
| 2820 | - * Echoes a list of event, should be called via AJAX | |
| 2236 | + * echoes a list of event, should be called via AJAX | |
| 2821 | 2237 | * |
| 2822 | 2238 | * @return void |
| 2823 | 2239 | */ |
| 2824 | 2240 | public function ajaxTimeline(){ |
| 2825 | - echo wp_kses($this->list_events(array( | |
| 2241 | + echo $this->list_events(array( | |
| 2826 | 2242 | 'nb' => esc_attr(FILTER_INPUT(INPUT_POST, 'nb')), |
| 2827 | 2243 | 'future' => esc_attr(FILTER_INPUT(INPUT_POST, 'future')), |
| 2828 | 2244 | 'past' => esc_attr(FILTER_INPUT(INPUT_POST, 'past')), |
| 2829 | 2245 | 'geo' => esc_attr(FILTER_INPUT(INPUT_POST, 'geo')), |
| @@ -2844,13 +2260,13 @@ | ||
| 2844 | 2260 | 'orderby' => esc_attr(FILTER_INPUT(INPUT_POST, 'orderby')), |
| 2845 | 2261 | 'order' => esc_attr(FILTER_INPUT(INPUT_POST, 'order')), |
| 2846 | 2262 | 'class' => esc_attr(FILTER_INPUT(INPUT_POST, 'class')), |
| 2847 | 2263 | 'pages' => esc_attr(FILTER_INPUT(INPUT_POST, 'pages')), |
| 2848 | - ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))), $this->kses_tags); | |
| 2264 | + ), esc_attr(FILTER_INPUT(INPUT_POST, 'list_type'))); | |
| 2849 | 2265 | exit; |
| 2850 | 2266 | } |
| 2851 | 2267 | /** |
| 2852 | - * Echoes next page of events, should be called via AJAX | |
| 2268 | + * echoes next page of events, should be called via AJAX | |
| 2853 | 2269 | * |
| 2854 | 2270 | * @return void |
| 2855 | 2271 | */ |
| 2856 | 2272 | public function ajaxGetNextPage(){ |
| @@ -2865,15 +2281,15 @@ | ||
| 2865 | 2281 | } |
| 2866 | 2282 | if(isset($_POST['paged'])){ |
| 2867 | 2283 | $query["paged"] = esc_attr($_POST['paged']); |
| 2868 | 2284 | }else{ |
| 2869 | - $response['message'] = __('Page number missing', 'event-post'); | |
| 2285 | + $response['message'] = __('Page number missing'); | |
| 2870 | 2286 | } |
| 2871 | 2287 | $query['container_schema'] = $this->timeline_shema['container']; |
| 2872 | 2288 | $query['item_schema'] = $this->timeline_shema['item']; |
| 2873 | 2289 | $html = $this->list_events($query,'event_timeline','events_only'); |
| 2874 | 2290 | if($html == ""){ |
| 2875 | - $response['message'] = __('No more to load', 'event-post'); | |
| 2291 | + $response['message'] = __('No more to load'); | |
| 2876 | 2292 | }else{ |
| 2877 | 2293 | $query["paged"] = $query["paged"] + 1; |
| 2878 | 2294 | $next_html = $this->list_events($query,'event_timeline','events_only'); |
| 2879 | 2295 | $response = [ |
| @@ -2882,9 +2298,9 @@ | ||
| 2882 | 2298 | "next_query" => $next_html == "" ? false : true, |
| 2883 | 2299 | ]; |
| 2884 | 2300 | } |
| 2885 | 2301 | }else{ |
| 2886 | - $response['message'] = __('Query missing', 'event-post'); | |
| 2302 | + $response['message'] = __('Query missing'); | |
| 2887 | 2303 | } |
| 2888 | 2304 | wp_send_json($response); |
| 2889 | 2305 | exit; |
| 2890 | 2306 | } |
| @@ -2889,15 +2305,14 @@ | ||
| 2889 | 2305 | exit; |
| 2890 | 2306 | } |
| 2891 | 2307 | |
| 2892 | 2308 | /** |
| 2893 | - * Echoes the content of the calendar in ajax context | |
| 2894 | - * | |
| 2309 | + * echoes the content of the calendar in ajax context | |
| 2895 | 2310 | * @return void |
| 2896 | 2311 | */ |
| 2897 | 2312 | public function ajaxcal() { |
| 2898 | 2313 | $method = isset($_GET['action']) ? INPUT_GET : INPUT_POST; |
| 2899 | - echo wp_kses($this->calendar(array( | |
| 2314 | + echo $this->calendar(array( | |
| 2900 | 2315 | 'date' => esc_attr(FILTER_INPUT($method, 'date')), |
| 2901 | 2316 | 'cat' => esc_attr(FILTER_INPUT($method, 'cat')), |
| 2902 | 2317 | 'mondayfirst' => esc_attr(FILTER_INPUT($method, 'mf')), |
| 2903 | 2318 | 'datepicker' => esc_attr(FILTER_INPUT($method, 'dp')), |
| @@ -2905,17 +2320,17 @@ | ||
| 2905 | 2320 | 'display_title' => esc_attr(FILTER_INPUT($method, 'display_title')), |
| 2906 | 2321 | 'thumbnail' => esc_attr(FILTER_INPUT($method, 'thumbnail')), |
| 2907 | 2322 | 'tax_name' => esc_attr(FILTER_INPUT($method, 'tax_name')), |
| 2908 | 2323 | 'tax_term' => esc_attr(FILTER_INPUT($method, 'tax_term')), |
| 2909 | - )), $this->kses_tags); | |
| 2324 | + )); | |
| 2910 | 2325 | exit(); |
| 2911 | 2326 | } |
| 2912 | 2327 | |
| 2913 | 2328 | /** |
| 2914 | - * Echoes the date of the calendar in ajax context | |
| 2329 | + * echoes the date of the calendar in ajax context | |
| 2915 | 2330 | */ |
| 2916 | 2331 | public function ajaxdate() { |
| 2917 | - echo wp_kses($this->display_caldate( | |
| 2332 | + echo $this->display_caldate( | |
| 2918 | 2333 | strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))), |
| 2919 | 2334 | esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), |
| 2920 | 2335 | true, |
| 2921 | 2336 | esc_attr(FILTER_INPUT(INPUT_GET, 'color')), |
| @@ -2922,19 +2337,19 @@ | ||
| 2922 | 2337 | esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')), |
| 2923 | 2338 | esc_attr(FILTER_INPUT(INPUT_GET, 'display_title')), |
| 2924 | 2339 | esc_attr(FILTER_INPUT(INPUT_GET, 'tax_name')), |
| 2925 | 2340 | esc_attr(FILTER_INPUT(INPUT_GET, 'tax_term')) |
| 2926 | - ), $this->kses_tags); | |
| 2341 | + ); | |
| 2927 | 2342 | exit(); |
| 2928 | 2343 | } |
| 2929 | 2344 | |
| 2930 | 2345 | /** |
| 2931 | - * Echoes a date in ajax context | |
| 2346 | + * echoes a date in ajax context | |
| 2932 | 2347 | */ |
| 2933 | 2348 | public function HumanDate() { |
| 2934 | 2349 | if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) { |
| 2935 | 2350 | $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))); | |
| 2351 | + echo $this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date)); | |
| 2937 | 2352 | exit(); |
| 2938 | 2353 | } |
| 2939 | 2354 | } |
| 2940 | 2355 | |
| @@ -2941,9 +2356,8 @@ | ||
| 2941 | 2356 | /** |
| 2942 | 2357 | * Displays a search form |
| 2943 | 2358 | * |
| 2944 | 2359 | * @param type $atts |
| 2945 | - * | |
| 2946 | 2360 | * @return type |
| 2947 | 2361 | */ |
| 2948 | 2362 | public function search($atts) { |
| 2949 | 2363 | $params = shortcode_atts(apply_filters('eventpost_params', array( |
| @@ -3014,54 +2428,8 @@ | ||
| 3014 | 2428 | } |
| 3015 | 2429 | } |
| 3016 | 2430 | |
| 3017 | 2431 | /** |
| 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 | - } | |
| 3062 | - | |
| 3063 | - /** | |
| 3064 | 2432 | * AJAX Get lat long from address |
| 3065 | 2433 | */ |
| 3066 | 2434 | public function GetLatLong() { |
| 3067 | 2435 | if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { |
| @@ -3067,22 +2435,31 @@ | ||
| 3067 | 2435 | if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { |
| 3068 | 2436 | // verifier le cache |
| 3069 | 2437 | $q = $_REQUEST['q']; |
| 3070 | 2438 | header('Content-Type: application/json'); |
| 3071 | - $val = $this->geocode($q); | |
| 3072 | - wp_send_json( $val ); | |
| 2439 | + $transient_name = 'eventpost_osquery_' . $q; | |
| 2440 | + $val = get_transient($transient_name); | |
| 2441 | + if (false === $val || empty($val) || !is_string($val)) { | |
| 2442 | + $language = get_bloginfo('language'); | |
| 2443 | + if (strpos($language, '-') > -1) { | |
| 2444 | + $language = strtolower(substr($language, 0, 2)); | |
| 2445 | + } | |
| 2446 | + $remote_val = wp_safe_remote_request('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language); | |
| 2447 | + if(json_decode($remote_val['body'])){ | |
| 2448 | + $val = $remote_val['body']; | |
| 2449 | + } | |
| 2450 | + set_transient($transient_name, $val, 30 * DAY_IN_SECONDS); | |
| 2451 | + } | |
| 2452 | + echo $val; | |
| 3073 | 2453 | exit(); |
| 3074 | 2454 | } |
| 3075 | 2455 | } |
| 3076 | 2456 | |
| 3077 | 2457 | /** |
| 3078 | - * Alters columns | |
| 3079 | - * | |
| 2458 | + * alters columns | |
| 3080 | 2459 | * @param array $defaults |
| 3081 | - * | |
| 2460 | + * @return array | |
| 3082 | 2461 | * @filter eventpost_columns_head |
| 3083 | - * | |
| 3084 | - * @return array | |
| 3085 | 2462 | */ |
| 3086 | 2463 | public function columns_head($defaults) { |
| 3087 | 2464 | $defaults['event'] = __('Event', 'event-post'); |
| 3088 | 2465 | $defaults['location'] = __('Location', 'event-post'); |
| @@ -3089,19 +2466,17 @@ | ||
| 3089 | 2466 | return apply_filters('eventpost_columns_head', $defaults); |
| 3090 | 2467 | } |
| 3091 | 2468 | |
| 3092 | 2469 | /** |
| 3093 | - * Echoes content of a row in a given column | |
| 3094 | - * | |
| 2470 | + * echoes content of a row in a given column | |
| 3095 | 2471 | * @param string $column_name |
| 3096 | 2472 | * @param int $post_id |
| 3097 | - * | |
| 3098 | 2473 | * @action eventpost_columns_content |
| 3099 | 2474 | */ |
| 3100 | 2475 | public function columns_content($column_name, $post_id) { |
| 3101 | 2476 | 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)); | |
| 2477 | + $lat = get_post_meta($post_id, $this->META_LAT, true); | |
| 2478 | + $lon = get_post_meta($post_id, $this->META_LONG, true); | |
| 3104 | 2479 | |
| 3105 | 2480 | if (!empty($lat) && !empty($lon)) { |
| 3106 | 2481 | add_thickbox(); |
| 3107 | 2482 | $color = $this->get_post_color($post_id, $this->settings['default_color'], true); |
| @@ -3111,18 +2486,18 @@ | ||
| 3111 | 2486 | } |
| 3112 | 2487 | if ($icon == ''){ |
| 3113 | 2488 | $icon = 'location'; |
| 3114 | 2489 | } |
| 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">' | |
| 2490 | + 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">' | |
| 3116 | 2491 | . '<i class="dashicons dashicons-'.$icon.'" style="color:#'.$color.';"></i>' |
| 3117 | 2492 | . '<span class="screen-reader-text">'.__('View on a map', 'event-post').'</span>' |
| 3118 | 2493 | . get_post_meta($post_id, $this->META_ADD, true) |
| 3119 | - . '</a> ', $this->kses_tags); | |
| 2494 | + . '</a> '; | |
| 3120 | 2495 | } |
| 3121 | 2496 | $this->column_edit_hidden_fields($post_id, 'location'); |
| 3122 | 2497 | } |
| 3123 | 2498 | if ($column_name == 'event') { |
| 3124 | - echo wp_kses($this->print_date($post_id, false), $this->kses_tags); | |
| 2499 | + echo $this->print_date($post_id, false); | |
| 3125 | 2500 | $this->column_edit_hidden_fields($post_id, 'event'); |
| 3126 | 2501 | } |
| 3127 | 2502 | do_action('eventpost_columns_content', $column_name, $post_id); |
| 3128 | 2503 | } |
| @@ -3128,25 +2503,20 @@ | ||
| 3128 | 2503 | } |
| 3129 | 2504 | |
| 3130 | 2505 | function column_edit_hidden_fields($post_id, $set){ |
| 3131 | 2506 | $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 | - } | |
| 2507 | + echo '<div class="hidden">'; | |
| 2508 | + foreach($this->quick_edit_fields[$set] as $fieldname=>$fieldlabel){ | |
| 2509 | + echo'<span class="inline-edit-value '.$fieldname.'">'.esc_attr($event->$fieldname).'</span>'; | |
| 3137 | 2510 | } |
| 3138 | - $html .= '</div>'; | |
| 3139 | - echo wp_kses($html, $this->kses_tags); | |
| 2511 | + echo '</div>'; | |
| 3140 | 2512 | } |
| 3141 | 2513 | |
| 3142 | - // ADMIN PAGES | |
| 2514 | + /** ADMIN PAGES **/ | |
| 3143 | 2515 | |
| 3144 | 2516 | /** |
| 3145 | - * Adds items to the native "right now" dashboard widget | |
| 3146 | - * | |
| 2517 | + * adds items to the native "right now" dashboard widget | |
| 3147 | 2518 | * @param array $elements |
| 3148 | - * | |
| 3149 | 2519 | * @return array |
| 3150 | 2520 | */ |
| 3151 | 2521 | public function dashboard_right_now($elements){ |
| 3152 | 2522 | $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))); |
| @@ -3151,13 +2521,11 @@ | ||
| 3151 | 2521 | public function dashboard_right_now($elements){ |
| 3152 | 2522 | $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))); |
| 3153 | 2523 | $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1))); |
| 3154 | 2524 | if($nb_date){ |
| 3155 | - // Translators: %d is the number of events | |
| 3156 | 2525 | 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 | 2526 | } |
| 3158 | 2527 | if($nb_geo){ |
| 3159 | - // Translators: %d is the number of geolocalized events | |
| 3160 | 2528 | 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 | 2529 | } |
| 3162 | 2530 | return $elements; |
| 3163 | 2531 | } |
| @@ -3162,21 +2530,19 @@ | ||
| 3162 | 2530 | return $elements; |
| 3163 | 2531 | } |
| 3164 | 2532 | |
| 3165 | 2533 | /* |
| 3166 | - * Feed | |
| 2534 | + * feed | |
| 3167 | 2535 | * generate ICS or VCS files from a category |
| 3168 | 2536 | */ |
| 3169 | 2537 | |
| 3170 | 2538 | /** |
| 3171 | - * Get a date formatted for ICS | |
| 3172 | - * | |
| 2539 | + * | |
| 3173 | 2540 | * @param timestamp $timestamp |
| 3174 | - * | |
| 3175 | 2541 | * @return string |
| 3176 | 2542 | */ |
| 3177 | 2543 | public function ics_date($timestamp){ |
| 3178 | - return date("Ymd",$timestamp).'T'.date("His",$timestamp); | |
| 2544 | + return date("Ymd",$timestamp).'T'.date("His",$timestamp); | |
| 3179 | 2545 | } |
| 3180 | 2546 | |
| 3181 | 2547 | public function get_gmt_offset(){ |
| 3182 | 2548 | $gmt_offset = get_option('gmt_offset '); |
| @@ -3190,34 +2556,16 @@ | ||
| 3190 | 2556 | } |
| 3191 | 2557 | return $gmt_offset; |
| 3192 | 2558 | } |
| 3193 | 2559 | |
| 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 | 2560 | 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 | - } | |
| 2561 | + $export_file = plugin_dir_path(__FILE__).'inc/export/'.$format.'.php'; | |
| 2562 | + if(is_numeric($event_id) && file_exists($export_file)){ | |
| 2563 | + $event = $this->retreive($event_id); | |
| 2564 | + include $export_file; | |
| 2565 | + exit; | |
| 3216 | 2566 | } |
| 3217 | - wp_die(esc_html__('Invalid request.', 'event-post'), 400); | |
| 3218 | 2567 | } |
| 3219 | - | |
| 3220 | 2568 | |
| 3221 | 2569 | public function parse_request(){ |
| 3222 | 2570 | global $wp; |
| 3223 | 2571 | if (preg_match('#^event-feed#i', $wp->request, $match)) { |
| @@ -3230,9 +2578,9 @@ | ||
| 3230 | 2578 | } |
| 3231 | 2579 | |
| 3232 | 2580 | public function export(){ |
| 3233 | 2581 | if(false !== $event_id=\filter_input(INPUT_GET, 'event_id',FILTER_SANITIZE_NUMBER_INT)){ |
| 3234 | - $format = \filter_input(INPUT_GET, 'format'); | |
| 2582 | + $format = \filter_input(INPUT_GET, 'format',FILTER_SANITIZE_STRING); | |
| 3235 | 2583 | $this->generate_ics($event_id, $format); |
| 3236 | 2584 | } |
| 3237 | 2585 | } |
| 3238 | 2586 | |
| @@ -3237,119 +2585,77 @@ | ||
| 3237 | 2585 | } |
| 3238 | 2586 | |
| 3239 | 2587 | |
| 3240 | 2588 | /** |
| 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 | |
| 2589 | + * outputs an ICS document | |
| 3253 | 2590 | */ |
| 3254 | 2591 | 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"; | |
| 2592 | + if(false !== $cat=\filter_input(INPUT_GET, 'cat',FILTER_SANITIZE_STRING)){ | |
| 2593 | + $vtz = get_option('timezone_string'); | |
| 2594 | + $gmt = $this->get_gmt_offset(); | |
| 2595 | + date_default_timezone_set($vtz); | |
| 2596 | + $separator = "\n"; | |
| 3283 | 2597 | |
| 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;" ); | |
| 2598 | + header("content-type:text/calendar"); | |
| 2599 | + header("Pragma: public"); | |
| 2600 | + header("Expires: 0"); | |
| 2601 | + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
| 2602 | + header("Cache-Control: public"); | |
| 2603 | + header("Content-Disposition: attachment; filename=". str_replace('+','-',urlencode(get_option('blogname').'-'.$cat)).".ics;" ); | |
| 3290 | 2604 | |
| 3291 | - $props = array(); | |
| 2605 | + $props = array(); | |
| 3292 | 2606 | |
| 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 | - } | |
| 2607 | + // General | |
| 2608 | + $props[] = 'BEGIN:VCALENDAR'; | |
| 2609 | + $props[] = 'PRODID://WordPress//Event-Post-V'. file_get_contents(('VERSION')).'//EN'; | |
| 2610 | + $props[] = 'VERSION:2.0'; | |
| 3318 | 2611 | |
| 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 | - ); | |
| 2612 | + // Timezone | |
| 2613 | + if(!empty($vtz)){ | |
| 2614 | + array_push($props, | |
| 2615 | + 'BEGIN:VTIMEZONE', | |
| 2616 | + 'TZID:'.$vtz, | |
| 2617 | + 'BEGIN:DAYLIGHT', | |
| 2618 | + 'TZOFFSETFROM:+0100', | |
| 2619 | + 'TZOFFSETTO:'.($gmt).'00', | |
| 2620 | + 'DTSTART:19700329T020000', | |
| 2621 | + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3', | |
| 2622 | + 'END:DAYLIGHT', | |
| 2623 | + 'BEGIN:STANDARD', | |
| 2624 | + 'TZOFFSETFROM:'.($gmt).'00', | |
| 2625 | + 'TZOFFSETTO:+0100', | |
| 2626 | + 'TZNAME:CET', | |
| 2627 | + 'DTSTART:19701025T030000', | |
| 2628 | + 'RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10', | |
| 2629 | + 'END:STANDARD', | |
| 2630 | + 'END:VTIMEZONE' | |
| 2631 | + ); | |
| 2632 | + } | |
| 2633 | + | |
| 2634 | + // Events | |
| 2635 | + $events=$this->get_events(array('cat'=>$cat,'nb'=>-1)); | |
| 2636 | + foreach ($events as $event) { | |
| 2637 | + if($event->time_start && $event->time_end){ | |
| 2638 | + array_push($props, | |
| 2639 | + 'BEGIN:VEVENT', | |
| 2640 | + 'CREATED:'.$this->ics_date(strtotime($event->post_date)).'Z', | |
| 2641 | + 'LAST-MODIFIED:'.$this->ics_date(strtotime($event->post_modified)).'Z', | |
| 2642 | + 'SUMMARY:'.$event->post_title, | |
| 2643 | + 'UID:'.md5(site_url()."_eventpost_".$event->ID), | |
| 2644 | + 'LOCATION:'.str_replace(',','\,',$event->address), | |
| 2645 | + 'DTSTAMP:'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'), | |
| 2646 | + 'DTSTART'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_start).(!empty($vtz)?'':'Z'), | |
| 2647 | + 'DTEND'.(!empty($vtz)?';TZID='.$vtz:'').':'.$this->ics_date($event->time_end).(!empty($vtz)?'':'Z'), | |
| 2648 | + 'DESCRIPTION:'.trim(chunk_split($event->post_excerpt."\\n\\n".$event->permalink, 60, "\n")), | |
| 2649 | + 'END:VEVENT' | |
| 2650 | + ); | |
| 2651 | + } | |
| 3346 | 2652 | } |
| 3347 | - } | |
| 3348 | 2653 | |
| 3349 | - // End | |
| 3350 | - $props[] = 'END:VCALENDAR'; | |
| 2654 | + // End | |
| 2655 | + $props[] = 'END:VCALENDAR'; | |
| 3351 | 2656 | |
| 3352 | - echo esc_html(implode($separator, $props)); | |
| 3353 | - exit; | |
| 2657 | + echo implode($separator, $props); | |
| 2658 | + exit; | |
| 2659 | + } | |
| 3354 | 2660 | } |
| 3355 | 2661 | } |