Changeset 2738474
- Timestamp:
- 06/07/2022 08:39:35 AM (4 years ago)
- Location:
- eventilla-events/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/class-eventilla-wp-admin.php (modified) (8 diffs)
-
eventilla-wp.php (modified) (1 diff)
-
includes/class-eventilla-wp-api-request-v2.php (modified) (11 diffs)
-
includes/class-eventilla-wp-cron.php (modified) (5 diffs)
-
includes/class-eventilla-wp-form-type.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
eventilla-events/trunk/README.txt
r2734284 r2738474 6 6 Tested up to: 5.9.3 7 7 Requires PHP: 7.3 8 Stable tag: 1. 5.28 Stable tag: 1.6.1 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 46 46 47 47 == Changelog == 48 = 1.5.2 = 49 Updated Finnish translations. 48 = 1.6.1 = 49 Fixed event fetching for events that have no ending date. They are considered ongoing events for as long they don't have an end date. 50 = 1.6 = 51 Added support for batch processsing large amount of events. Also added a setting to require all "Allowed tags" to exist in an event to be included, default behaviour is check if one of them exists. 50 52 = 1.5.1 = 51 53 Fixed event update process that checked for allowed tags in events. Option name was incorrectly handled and tag check did not work properly. -
eventilla-events/trunk/admin/class-eventilla-wp-admin.php
r2711342 r2738474 224 224 ); 225 225 add_settings_field( 226 $this->option_name . '_batchsize', 227 __( 'Processing batch size', 'eventilla-wp' ), 228 array( $this, $this->option_name . '_batchsize' ), 229 $this->plugin_name, 230 $this->option_name . '_general', 231 array( 'label_for' => $this->option_name . '_batchsize' ) 232 ); 233 add_settings_field( 234 $this->option_name . '_delay', 235 __( 'Interval', 'eventilla-wp' ), 236 array( $this, $this->option_name . '_delay' ), 237 $this->plugin_name, 238 $this->option_name . '_general', 239 array( 'label_for' => $this->option_name . '_delay' ) 240 ); 241 add_settings_field( 226 242 $this->option_name . '_download_images', 227 243 __( 'Do not save event images', 'eventilla-wp' ), … … 241 257 __( 'Delete past events', 'eventilla-wp' ), 242 258 array( $this, $this->option_name . '_delete_past_events' ), 259 $this->plugin_name, 260 $this->option_name . '_general' 261 ); 262 add_settings_field( 263 $this->option_name . '_delete_all_events', 264 __( 'Delete ALL events', 'eventilla-wp' ), 265 array( $this, $this->option_name . '_delete_all_events' ), 243 266 $this->plugin_name, 244 267 $this->option_name . '_general' … … 285 308 $this->option_name . '_general', 286 309 array( 'label_for' => $this->option_name . '_allowed_tags' ) 310 ); 311 add_settings_field( 312 $this->option_name . '_match_all', 313 __( 'Require all tags', 'eventilla-wp' ), 314 array( $this, $this->option_name . '_match_all' ), 315 $this->plugin_name, 316 $this->option_name . '_general' 287 317 ); 288 318 add_settings_field( … … 302 332 array( 'label_for' => $this->option_name . '_current_lang' ) 303 333 ); 334 register_setting( $this->plugin_name, $this->option_name . '_batchsize', array( $this, $this->option_name . '_sanitize_batchsize' ), false, 30 ); 335 register_setting( $this->plugin_name, $this->option_name . '_delay', array( $this, $this->option_name . '_sanitize_delay' ), false, 0); 304 336 register_setting( $this->plugin_name, $this->option_name . '_position', array( $this, $this->option_name . '_sanitize_position' ) ); 305 337 register_setting( $this->plugin_name, $this->option_name . '_apikey', array( $this, $this->option_name . '_sanitize_apikey' ) ); … … 307 339 register_setting( $this->plugin_name, $this->option_name . '_download_images'); 308 340 register_setting( $this->plugin_name, $this->option_name . '_delete_past_events'); 341 register_setting( $this->plugin_name, $this->option_name . '_delete_all_events'); 342 register_setting( $this->plugin_name, $this->option_name . '_reset'); 343 register_setting( $this->plugin_name, $this->option_name . '_pause'); 309 344 register_setting( $this->plugin_name, $this->option_name . '_dont_import_past_events'); 345 register_setting( $this->plugin_name, $this->option_name . '_match_all'); 310 346 register_setting( $this->plugin_name, $this->option_name . $css_editor, array( $this, $this->option_name . '_sanitize_css_editor' ) ); 311 347 register_setting( $this->plugin_name, $this->option_name . $template_editor . '_list', array( $this, $this->option_name . '_sanitize_template_editor' ) ); … … 368 404 */ 369 405 public function eventilla_opt_general_cb() { 370 echo '<p>' . __( 'To use this plugin, you must have a valid API key and Account ID from Eventilla.com. Please change the settings accordingly.', 'eventilla-wp' ) . '</p>'; 406 $synced = get_option('eventilla_opt_last_sync', false); 407 $is_restarting = (bool) get_option('eventilla_opt_reset', false); 408 $is_paused = (bool) get_option('eventilla_opt_pause', false); 409 $is_deleting = (bool) get_option('eventilla_opt_delete_all_events', false); 410 $count = count(get_option('eventilla_opt_eventsdata', [])); 411 $queue = (int) get_option('eventilla_opt_queue', 0); 412 $processed = $count - $queue; 413 if(!$is_deleting) { 414 echo '<p>' . __( 'To use this plugin, you must have a valid API key and Account ID from Eventilla.com. Please change the settings accordingly.', 'eventilla-wp' ) . '</p>'; 415 echo '<p>' . __( 'Events processed: ', 'eventilla-wp' ) . $processed . " / " . $count . "<br>"; 416 if($synced) { 417 echo __( 'Last syncronization: ', 'eventilla-wp' ) . date('d.m.Y H:i:s', (int) $synced). "<br>"; 418 } 419 else { 420 echo __( 'Last syncronization: never', 'eventilla-wp' ). "<br>"; 421 } 422 if($is_restarting) { 423 echo __( 'Event processing is restarting in a moment.', 'eventilla-wp' ) .'<br>'; 424 } 425 else { 426 echo '<input type="checkbox" name="eventilla_opt_reset" value="1">' . __( 'Restart processing.', 'eventilla-wp' ) .'<br>'; 427 } 428 if($is_paused) { 429 echo __( 'Event processing is currently paused.', 'eventilla-wp' ) .'<br>'; 430 echo '<input type="checkbox" name="eventilla_opt_pause" value="">' . __( 'Continue processing.', 'eventilla-wp' ) .'<br>'; 431 } 432 else { 433 echo '<input type="checkbox" name="eventilla_opt_pause" value="1">' . __( 'Pause processing.', 'eventilla-wp' ) .'<br>'; 434 } 435 echo '</p>'; 436 } 437 else { 438 echo "<p>" . __( 'Deleting all events...', 'eventilla-wp' ) . "</p>"; 439 } 440 371 441 } 372 442 /** … … 621 691 return implode(',', $allowedTags); 622 692 } 693 694 public function eventilla_opt_sanitize_batchsize( $batchsize ) { 695 if(is_numeric($batchsize)) { 696 return (int) $batchsize; 697 } 698 return 30; 699 } 700 701 public function eventilla_opt_sanitize_delay( $delay ) { 702 if(is_numeric($delay)) { 703 return (int) $delay; 704 } 705 return 15; 706 } 707 623 708 /** 624 709 * The Logger option and logs viewer … … 693 778 } 694 779 695 780 /** 781 * Option to not to import past events 782 * 783 * @since 1.6 784 */ 785 public function eventilla_opt_batchsize() { 786 $batchsize = get_option( $this->option_name . '_batchsize', 50); 787 echo '<input type="text" name="' . $this->option_name . '_batchsize' . '" id="' . $this->option_name . '_batchsize' . '" value="' . $batchsize . '"> ' . __( 'Events to process in a single cron job.', 'eventilla-wp' ); 788 } 789 public function eventilla_opt_delay() { 790 $delay = get_option( $this->option_name . '_delay', 15); 791 echo '<input type="text" name="' . $this->option_name . '_delay' . '" id="' . $this->option_name . '_delay' . '" value="' . $delay . '"> ' . __( 'Minutes between syncronizations.', 'eventilla-wp' ); 792 } 793 public function eventilla_opt_delete_all_events() { 794 $is_checked = get_option($this->option_name . '_delete_all_events'); 795 796 ?> 797 <input type="checkbox" name="<?php echo $this->option_name . '_delete_all_events' ?>" value="1" <?php checked(1, $is_checked, true); ?> /> 798 <?php 799 echo __( 'Start background process to delete all events from Wordpress.', 'eventilla-wp' ); 800 } 801 public function eventilla_opt_match_all() { 802 $is_checked = get_option($this->option_name . '_match_all'); 803 804 ?> 805 <input type="checkbox" name="<?php echo $this->option_name . '_match_all' ?>" value="1" <?php checked(1, $is_checked, true); ?> /> 806 <?php 807 echo __( 'Every tag above must be tagged to event.', 'eventilla-wp' ); 808 } 809 696 810 /** 697 811 * Option to not to import past events -
eventilla-events/trunk/eventilla-wp.php
r2734284 r2738474 16 16 * Plugin URI: https://www.eventilla.com/ 17 17 * Description: Eventilla Events brings your event information from eventilla.com to WordPress as custom posts. 18 * Version: 1. 5.218 * Version: 1.6.1 19 19 * Author: Eventilla 20 20 * Author URI: http://www.eventilla.com -
eventilla-events/trunk/includes/class-eventilla-wp-api-request-v2.php
r2711342 r2738474 187 187 * @return Response of the POST request or false. 188 188 */ 189 public function post_curl( $action_type , $event_id = '', $post_body_array, $return_raw = false ) {189 public function post_curl( $action_type = '', $event_id = '', $post_body_array = false, $return_raw = false ) { 190 190 // Set the url to the API endpoint for request. 191 191 $endpoint_url = $this->set_enpoint_url( $this->api_url, $action_type, $event_id ); … … 260 260 * @return Response of the POST request or false. 261 261 */ 262 public function post( $action_type , $event_id = '', $post_body_array, $return_raw = false ) {262 public function post( $action_type = '', $event_id = '', $post_body_array = false, $return_raw = false ) { 263 263 // Set the url to the API endpoint for request. 264 264 $endpoint_url = $this->set_enpoint_url( $this->api_url, $action_type, $event_id ); … … 368 368 $endpoint_url .= "fields=id,name,organization,organization_id,starts,ends,short_description,timezone,title,url,tabs,datafields,description,forms,languages,location,logo,max_attendees,modified,registration_open,status,tags,template,tickets"; 369 369 } 370 371 if(!get_option('eventilla_opt_match_all', false) && get_option('eventilla_opt_allowed_tags', false) && $event_id == '') { 372 $endpoint_url .= "&tag=" . get_option('eventilla_opt_allowed_tags', ''); 373 } 370 374 371 375 // Generate Authentication String as per required by Eventilla API. … … 387 391 //echo "Kutsu:\n" . $endpoint_url . "\n\nVastaus:\n"; 388 392 $response = wp_remote_get( $endpoint_url, $args ); 393 //var_dump($response); 394 //die(); 389 395 $response_code = wp_remote_retrieve_response_code( $response ); 390 396 $response_body = wp_remote_retrieve_body( $response ); 391 //var_dump($response_body);392 //die();397 //var_dump($response_body); 398 // die(); 393 399 //echo "\n\n"; 394 400 $this->log_date('GET', $endpoint_url, $response_code, $response_body); … … 745 751 $eventilla_json = ''; 746 752 $eventilla_common = new Eventilla_WP_Common(); 747 753 //echo "\n\nevents_to_posts\n"; 754 //var_dump($event_list_json); 748 755 // Get events from Eventilla if not empty. 749 756 if ( empty( $event_list_json ) ) { … … 753 760 } 754 761 755 if (! is_string($event_list_json) ) {762 if (! is_string($event_list_json) && ! is_array($event_list_json)) { 756 763 $message = 'Eventilla API v2 was empty in ' . __METHOD__ . ' on line:' . __LINE__; 757 764 $eventilla_common->log_error('api_v2', $message); … … 759 766 return false; 760 767 } 761 $eventilla_json_ob = json_decode($event_list_json); 762 if (! empty($eventilla_json_ob->events)) { 763 $eventilla_json_ob = $eventilla_json_ob->events; 768 769 if (!is_array($event_list_json)) { 770 $eventilla_json_ob = json_decode($event_list_json); 771 if (! empty($eventilla_json_ob->events)) { 772 $eventilla_json_ob = $eventilla_json_ob->events; 773 } 774 } 775 else { 776 $eventilla_json_ob = $event_list_json; 764 777 } 765 778 … … 775 788 } 776 789 } 777 790 //var_dump($allowedTags); 778 791 /** 779 792 * Init vars for saving the data. … … 864 877 } 865 878 $event = $event->event; 866 867 868 if( strtotime($event->ends) < strtotime('today') && get_option('eventilla_opt_dont_import_past_events', false)) {879 //var_dump($event); 880 881 if($event->ends && $event->ends != "" && strtotime($event->ends) != 0 && strtotime($event->ends) < strtotime('today') && get_option('eventilla_opt_dont_import_past_events', false)) { 869 882 continue; 870 883 } 871 if(count($allowedTags) > 0) { 884 $should_skip = false; 885 886 if(count($allowedTags) > 0 && get_option('eventilla_opt_match_all', false)) { 887 872 888 if(!is_array($event->tags)) { 873 continue; 874 } 889 $event_tags = trim($event->tags); 890 $event_tags = explode(',', $event_tags); 891 } else { 892 $event_tags = $event->tags; 893 } 894 $should_skip = false; 895 //var_dump($event_tags); 875 896 foreach($allowedTags as $allowedTag) { 876 if(!in_array($allowedTag, $event->tags)) {877 continue;897 if(!in_array($allowedTag, $event_tags)) { 898 $should_skip = true; 878 899 } 879 900 } 880 901 } 902 903 if($should_skip) { 904 echo "Skipataan"; 905 continue; 906 } 907 881 908 $is_modified = false; 882 909 $postid = 0; // This will be set to post_id when updating an event. … … 1251 1278 ), 1252 1279 'fields' => 'ids', 1280 'posts_per_page' => -1, 1281 'post_status' => 'any' 1253 1282 ); 1254 1283 // perform the query 1255 1284 $uid_query = new WP_Query( $args ); 1256 1285 //var_dump($uid_query); 1257 1286 $uid_ids = $uid_query->posts; 1258 1287 // If UID does not match any in the meta, we can continue … … 1290 1319 */ 1291 1320 public function update_event() { 1292 if ($this->api_credentials['account_id'] != false && $this->api_credentials['apikey'] != false) { 1321 $delete_all_events = get_option('eventilla_opt_delete_all_events', false); 1322 if($delete_all_events) { 1323 update_option('eventilla_opt_abort', true, false); 1324 update_option('eventilla_opt_queue', 0, false); 1325 update_option('eventilla_opt_pause', true, false); 1326 $this->delete_unsync_events(['fake-id']); 1327 update_option('eventilla_opt_delete_all_events', false, false); 1328 die("\nAll events deleted.\n"); 1329 } 1330 1331 $reset = get_option('eventilla_opt_reset', false); 1332 if($reset) { 1333 update_option('eventilla_opt_abort', true, false); 1334 update_option('eventilla_opt_queue', 0, false); 1335 update_option('eventilla_opt_reset', false, false); 1336 update_option('eventilla_opt_isprocessing', false, false); 1337 echo "\nQueue reseted.\n"; 1338 } 1339 1340 $pause = get_option('eventilla_opt_pause', false); 1341 if($pause) { 1342 update_option('eventilla_opt_abort', true, false); 1343 die("\nProcessing paused.\n"); 1344 } 1345 1346 $synced = get_option('eventilla_opt_last_sync', false); 1347 if($synced) { 1348 $interval = (int) get_option('eventilla_opt_delay', 0); 1349 $next_time = $interval * 60 + (int) $synced; 1350 if(time() < $next_time) { 1351 die("\nSleeping until:" . date('Y-m-d H:i:s',$next_time)."\n"); 1352 } 1353 } 1354 1355 $queue = (int) get_option('eventilla_opt_queue', 0); 1356 if ($queue == 0 && $this->api_credentials['account_id'] != false && $this->api_credentials['apikey'] != false) { 1357 echo "\nFetching eventlist from Eventilla.\n"; 1293 1358 $response = $this->get('events', '', false, false, true); 1294 //var_dump($response); 1295 $this->events_to_posts($response); 1359 1360 $eventilla_json_ob = json_decode($response); 1361 if (! empty($eventilla_json_ob->events)) { 1362 $eventilla_json_ob = $eventilla_json_ob->events; 1363 } 1364 //var_dump($eventilla_json_ob); 1365 //die(); 1366 update_option('eventilla_opt_queue', count($eventilla_json_ob), false); 1367 update_option('eventilla_opt_eventsdata', (array) $eventilla_json_ob, false); 1368 echo count($eventilla_json_ob) . " events added to process queue.\n"; 1369 $this->process_event_batch(); 1370 } else { 1371 $this->process_event_batch(); 1372 } 1373 } 1374 1375 public function process_event_batch() { 1376 $is_processing = (bool) get_option('eventilla_opt_isprocessing', false); 1377 if(!$is_processing) { 1378 update_option('eventilla_opt_isprocessing', true, false); 1379 $eventsdata = get_option('eventilla_opt_eventsdata', []); 1380 $batchsize = (int) get_option('eventilla_opt_batchsize', 50); 1381 $queue = (int) get_option('eventilla_opt_queue', 0); 1382 //echo "\n\n" . $queue . "\n\n"; 1383 $do_removal = false; 1384 if($queue <= $batchsize) { 1385 $batchsize = $queue; 1386 $do_removal = true; 1387 } 1388 $processed = count($eventsdata) - $queue; 1389 $batch = array_slice($eventsdata, $processed, $batchsize); 1390 echo "\nProsessing batch of ".$batchsize." events. There are " . $queue . " events left in queue.\n"; 1391 foreach($batch as $event) { 1392 $abort = get_option('eventilla_opt_abort', false); 1393 if($abort) { 1394 update_option('eventilla_opt_isprocessing', false, false); 1395 update_option('eventilla_opt_abort', false, false); 1396 die("\nProcess aborted because of option change at admin panel!"); 1397 } 1398 echo "Processing event: " . $event->id . "\n"; 1399 $event_from_api = $this->get('events', $event->id); 1400 //var_dump($event); 1401 //var_dump($event_from_api); 1402 $this->events_to_posts($event_from_api, false, true); 1403 $queue--; 1404 update_option('eventilla_opt_queue', $queue, false); 1405 if($do_removal) { 1406 $eventilla_ids = []; 1407 foreach($eventsdata as $event) { 1408 array_push($eventilla_ids, $event->id); 1409 } 1410 //var_dump($eventilla_ids); 1411 $this->delete_unsync_events( $eventilla_ids ); 1412 update_option('eventilla_opt_last_sync', time(), false); 1413 } 1414 } 1415 update_option('eventilla_opt_isprocessing', false, false); 1416 } else { 1417 echo "\nSkipping cron because previous one is still running.\n\n"; 1296 1418 } 1297 1419 } -
eventilla-events/trunk/includes/class-eventilla-wp-cron.php
r2734050 r2738474 14 14 public static function set_cron() { 15 15 if ( ! wp_next_scheduled( 'eventilla_wp_update_from_eventilla' ) ) { 16 wp_schedule_event(time(), 'every_ five_min','eventilla_wp_update_from_eventilla');16 wp_schedule_event(time(), 'every_min','eventilla_wp_update_from_eventilla'); 17 17 } 18 18 … … 36 36 'value' => strtotime('today'), 37 37 'compare' => '<', 38 ], 39 [ 40 'key' => 'eventilla_end_unix', 41 'value' => 0, 42 'compare' => '!=', 38 43 ] 39 44 ] … … 45 50 } 46 51 47 if(get_option('eventilla_opt_allowed_tags', false) ) {52 if(get_option('eventilla_opt_allowed_tags', false) && get_option('eventilla_opt_match_all', false)) { 48 53 $allowedTags = trim(get_option('eventilla_opt_allowed_tags')); 49 54 … … 65 70 66 71 foreach($localEvents as $localEvent) { 72 $event_tags = trim($localEvent->tags); 73 $event_tags = explode(',', $event_tags); 67 74 foreach($allowedTags as $allowedTag) { 68 if(!in_array($allowedTag, $localEvent->tags)) {75 if(!in_array($allowedTag, $event_tags)) { 69 76 wp_delete_post($localEvent->ID, true); 70 77 } … … 89 96 'display' => __( 'Every 5 mins', 'eventilla_wp' ), 90 97 ); 98 $schedules['every_min'] = array( 99 'interval' => 60, 100 'display' => __( 'Every min', 'eventilla_wp' ), 101 ); 91 102 return $schedules; 92 103 } -
eventilla-events/trunk/includes/class-eventilla-wp-form-type.php
r2542377 r2738474 19 19 * @return string HTML of the form field 20 20 */ 21 public function get_text_input( $index = 0, $field ) {21 public function get_text_input( $index = 0, $field = '' ) { 22 22 return $this->get_input( $index, $field, 'text' ); 23 23 } … … 29 29 * @return string HTML of the form field 30 30 */ 31 public function get_email_input( $index = 0, $field ) {31 public function get_email_input( $index = 0, $field = '' ) { 32 32 return $this->get_input( $index, $field, 'email' ); 33 33 } … … 39 39 * @return string HTML of the form field 40 40 */ 41 public function get_number( $index = 0, $field ) {41 public function get_number( $index = 0, $field = '' ) { 42 42 $choices = ''; 43 43 … … 82 82 * @return string HTML of the form field 83 83 */ 84 private function get_input( $index = 0, $field , $input_type = 'text' ) {84 private function get_input( $index = 0, $field = '', $input_type = 'text' ) { 85 85 $required = $field->required == true ? '*' : ''; 86 86 $required_attribute = $field->required == true ? ' required="required"' : ''; … … 107 107 * @return string html 108 108 */ 109 public function get_title( $index = 0, $field ) {109 public function get_title( $index = 0, $field = '' ) { 110 110 $options = ''; 111 111 … … 140 140 * @return string html 141 141 */ 142 public function get_telephone( $index = 0, $field ) {142 public function get_telephone( $index = 0, $field = '') { 143 143 $filename = dirname( __FILE__ ) . '/../data/country_codes.json'; 144 144 $phone_codes_filedata = file_get_contents( $filename ); … … 187 187 * @return string html 188 188 */ 189 public function get_checkbox( $index = 0, $field ) {189 public function get_checkbox( $index = 0, $field = '' ) { 190 190 $options = ''; 191 191 … … 230 230 * @return string html 231 231 */ 232 public function get_select( $index = 0, $field ) {232 public function get_select( $index = 0, $field = '' ) { 233 233 $options = ''; 234 234 … … 269 269 * @return string html 270 270 */ 271 public function get_radio( $index = 0, $field ) {271 public function get_radio( $index = 0, $field = '') { 272 272 $options = ''; 273 273 … … 312 312 * @return string html 313 313 */ 314 public function get_textarea( $index = 0, $field ) {314 public function get_textarea( $index = 0, $field = '') { 315 315 $html = '<div id="field_div_0_' . $field->id . '" class="field"> 316 316 <label>' . $field->label . ' </label>
Note: See TracChangeset
for help on using the changeset viewer.