Changeset 2224460
- Timestamp:
- 01/08/2020 07:49:49 PM (6 years ago)
- Location:
- social-rocket/trunk
- Files:
-
- 1 added
- 7 edited
-
includes/class-social-rocket-background-process.php (modified) (6 diffs)
-
includes/class-social-rocket-compatibility.php (added)
-
includes/class-social-rocket.php (modified) (25 diffs)
-
includes/social-rocket-activate.php (modified) (2 diffs)
-
includes/social-rocket-deactivate.php (modified) (2 diffs)
-
includes/social-rocket-update.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
social-rocket.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
social-rocket/trunk/includes/class-social-rocket-background-process.php
r2200280 r2224460 3 3 if ( ! defined('ABSPATH') ) { exit; } 4 4 5 class Social_Rocket_Background_Process extends WP_Background_Process { 6 7 /** 5 class Social_Rocket_Background_Process { 6 7 /** 8 * Action 9 * 10 * (default value: 'async_request') 11 * 8 12 * @var string 13 * @access protected 9 14 */ 10 15 protected $action = 'social_rocket_background_process'; 11 16 17 /** 18 * Cron_hook_identifier 19 * 20 * @var mixed 21 * @access protected 22 */ 23 protected $cron_hook_identifier; 24 25 /** 26 * Cron_interval_identifier 27 * 28 * @var mixed 29 * @access protected 30 */ 31 protected $cron_interval_identifier; 32 33 /** 34 * Data 35 * 36 * (default value: array()) 37 * 38 * @var array 39 * @access protected 40 */ 41 protected $data = array(); 42 43 /** 44 * Handle() initialized 45 * 46 * @var bool 47 * @access protected 48 */ 49 protected $handle_init = false; 50 51 /** 52 * Identifier 53 * 54 * @var mixed 55 * @access protected 56 */ 57 protected $identifier; 58 59 /** 60 * Prefix 61 * 62 * (default value: 'wp') 63 * 64 * @var string 65 * @access protected 66 */ 67 protected $prefix = 'wp'; 68 69 /** 70 * Start time of current process. 71 * 72 * (default value: 0) 73 * 74 * @var int 75 * @access protected 76 */ 77 protected $start_time = 0; 78 12 79 13 80 /** … … 15 82 */ 16 83 public function __construct() { 17 parent::__construct(); 84 85 $this->identifier = $this->prefix . '_' . $this->action; 86 $this->cron_hook_identifier = $this->identifier . '_cron'; 87 $this->cron_interval_identifier = $this->identifier . '_cron_interval'; 88 89 add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); 90 add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); 18 91 add_action( 'shutdown', array( $this, 'dispatch_queue' ) ); 19 } 20 92 add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); 93 add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); 94 95 } 96 97 98 /** 99 * Cancel Process 100 * 101 * Stop processing queue items, clear cronjob and delete batch. 102 * 103 * Not used, may remove in the future. 104 * 105 */ 106 public function cancel_process() { 107 wp_clear_scheduled_hook( $this->cron_hook_identifier ); 108 } 109 110 111 /** 112 * Clear scheduled event 113 */ 114 protected function clear_scheduled_event() { 115 $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); 116 117 if ( $timestamp ) { 118 wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); 119 } 120 } 121 122 123 /** 124 * Complete. 125 * 126 * Override if applicable, but ensure that the below actions are 127 * performed, or, call parent::complete(). 128 */ 129 protected function complete() { 130 // Unschedule the cron healthcheck. 131 $this->clear_scheduled_event(); 132 } 133 134 135 /** 136 * Set data used during the request 137 * 138 * Not used, may remove in the future. 139 * 140 * @param array $data Data. 141 * 142 * @return $this 143 */ 144 public function data( $data ) { 145 $this->data = $data; 146 147 return $this; 148 } 149 150 151 /** 152 * Delete queue item 153 * 154 * @param string $key Key. 155 * 156 * @return $this 157 */ 158 public function delete( $key ) { 159 160 global $wpdb; 161 162 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 163 $result = $wpdb->delete( 164 $table_name, 165 array( 166 'id' => $key, 167 ) 168 ); 169 170 return $result; 171 } 172 173 174 /** 175 * Dispatch the async request 176 * 177 * @return array|WP_Error 178 */ 179 public function dispatch() { 180 // Schedule the cron healthcheck. 181 $this->schedule_event(); 182 183 $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); 184 $args = $this->get_post_args(); 185 186 return wp_remote_post( esc_url_raw( $url ), $args ); 187 } 188 189 190 /** 191 * Save and run queue. 192 */ 193 public function dispatch_queue() { 194 if ( ! empty( $this->data ) ) { 195 $this->save()->dispatch(); 196 } 197 } 198 199 200 /** 201 * Get batch 202 * 203 * @return stdClass Return the first batch from the queue 204 */ 205 protected function get_batch() { 206 207 global $wpdb; 208 209 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 210 $results = $wpdb->get_results( 211 "SELECT * FROM $table_name 212 ORDER BY request_time ASC 213 LIMIT 20", 214 ARRAY_A 215 ); 216 217 $batch = new stdClass(); 218 $batch->data = array(); 219 220 foreach ( $results as $result ) { 221 $key = $result['id']; 222 $value = unserialize( $result['data'] ); 223 $batch->data[$key] = $value; 224 } 225 226 return $batch; 227 } 228 229 230 /** 231 * Get memory limit 232 * 233 * @return int 234 */ 235 protected function get_memory_limit() { 236 if ( function_exists( 'ini_get' ) ) { 237 $memory_limit = ini_get( 'memory_limit' ); 238 } else { 239 // Sensible default. 240 $memory_limit = '128M'; 241 } 242 243 if ( ! $memory_limit || -1 === intval( $memory_limit ) ) { 244 // Unlimited, set to 32GB. 245 $memory_limit = '32000M'; 246 } 247 248 return intval( $memory_limit ) * 1024 * 1024; 249 } 250 251 252 /** 253 * Get post args 254 * 255 * @return array 256 */ 257 protected function get_post_args() { 258 if ( property_exists( $this, 'post_args' ) ) { 259 return $this->post_args; 260 } 261 262 return array( 263 'timeout' => 0.01, 264 'blocking' => false, 265 'body' => $this->data, 266 'cookies' => $_COOKIE, 267 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), 268 ); 269 } 270 271 272 /** 273 * Get query args 274 * 275 * @return array 276 */ 277 protected function get_query_args() { 278 if ( property_exists( $this, 'query_args' ) ) { 279 return $this->query_args; 280 } 281 282 return array( 283 'action' => $this->identifier, 284 'nonce' => wp_create_nonce( $this->identifier ), 285 ); 286 } 287 288 289 /** 290 * Get query URL 291 * 292 * @return string 293 */ 294 protected function get_query_url() { 295 if ( property_exists( $this, 'query_url' ) ) { 296 return $this->query_url; 297 } 298 299 return admin_url( 'admin-ajax.php' ); 300 } 301 302 303 /** 304 * Get time limit 305 * 306 * @return int 307 */ 308 protected function get_time_limit() { 309 if ( function_exists( 'ini_get' ) ) { 310 $time_limit = ini_get( 'max_execution_time' ); 311 } else { 312 // Sensible default. 313 $time_limit = '30'; 314 } 315 316 if ( ! $time_limit || -1 === intval( $time_limit ) ) { 317 // Unlimited, set to 300. 318 $time_limit = '300'; 319 } 320 321 return apply_filters( $this->identifier . '_default_time_limit', $time_limit ); 322 } 323 324 325 /** 326 * Handle 327 * 328 * Pass each queue item to the task handler, while remaining 329 * within server memory and time limit constraints. 330 */ 331 protected function handle() { 332 $this->lock_process(); 333 $this->set_limits(); 334 $this->handle_init = true; 335 336 do { 337 $batch = $this->get_batch(); 338 339 foreach ( $batch->data as $key => $value ) { 340 $task = $this->task( $value ); 341 342 if ( $task === false ) { 343 // task completed, we can delete it from the queue. 344 $this->delete( $key ); 345 } 346 347 if ( $this->time_exceeded() || $this->memory_exceeded() ) { 348 // Batch limits reached. 349 break; 350 } 351 } 352 353 } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); 354 355 $this->unlock_process(); 356 357 // Start next batch or complete process. 358 if ( ! $this->is_queue_empty() ) { 359 $this->dispatch(); 360 } else { 361 $this->complete(); 362 } 363 364 wp_die(); 365 } 366 367 368 /** 369 * Handle cron healthcheck 370 * 371 * Restart the background process if not already running 372 * and data exists in the queue. 373 */ 374 public function handle_cron_healthcheck() { 375 if ( $this->is_process_running() ) { 376 // Background process already running. 377 exit; 378 } 379 380 if ( $this->is_queue_empty() ) { 381 // No data to process. 382 $this->clear_scheduled_event(); 383 exit; 384 } 385 386 $this->handle(); 387 388 exit; 389 } 390 391 392 /** 393 * Are we idle? (i.e. is queue empty) 394 */ 395 public function is_idle() { 396 return $this->is_queue_empty(); 397 } 398 399 400 /** 401 * Is process running 402 * 403 * Check whether the current process is already running 404 * in a background process. 405 */ 406 public function is_process_running() { 407 408 $pid = get_site_transient( $this->identifier . '_process_lock' ); 409 410 if ( $pid === 'unknown' ) { 411 // Can't check PID, so assume process is already running. 412 return true; 413 } 414 415 if ( $pid && $pid !== 'unknown' ) { 416 417 // If we are on *nix and posix functions are not disabled, we can do a quick 418 // check to make sure the process hasn't died: 419 if ( function_exists( 'posix_getsid' ) ) { 420 if ( posix_getsid( $pid ) === false ) { 421 // process has died! 422 return false; 423 } 424 } 425 426 // If we are on Windows, then we're S.O.L. because doing this would require 427 // an exec call, which would raise false security alarms, and it just isn't 428 // worth the hassle. 429 430 // Process is already running. 431 return true; 432 } 433 434 return false; 435 } 436 437 438 /** 439 * Is queue empty 440 * 441 * @return bool 442 */ 443 protected function is_queue_empty() { 444 445 global $wpdb; 446 447 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 448 449 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); 450 451 return ( $count > 0 ) ? false : true; 452 } 453 454 455 /** 456 * Lock process 457 * 458 * Lock the process so that multiple instances can't run simultaneously. 459 * Override if applicable, but the duration should be greater than that 460 * defined in the time_exceeded() method. 461 */ 462 protected function lock_process() { 463 $this->start_time = time(); // Set start time of current process. 464 465 $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 3600; // 60 minutes 466 $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); 467 468 $pid = getmypid(); 469 if ( $pid === false ) { 470 $pid = 'unknown'; 471 } 472 473 set_site_transient( $this->identifier . '_process_lock', $pid, $lock_duration ); 474 } 475 476 477 /** 478 * Maybe process queue 479 * 480 * Checks whether data exists within the queue and that 481 * the process is not already running. 482 */ 483 public function maybe_handle() { 484 // Don't lock up other requests while processing 485 session_write_close(); 486 487 if ( $this->is_process_running() ) { 488 // Background process already running. 489 wp_die(); 490 } 491 492 if ( $this->is_queue_empty() ) { 493 // No data to process. 494 wp_die(); 495 } 496 497 check_ajax_referer( $this->identifier, 'nonce' ); 498 499 $this->handle(); 500 501 wp_die(); 502 } 503 504 505 /** 506 * Memory exceeded 507 * 508 * Ensures the batch process never exceeds 90% 509 * of the maximum WordPress memory. 510 * 511 * @return bool 512 */ 513 protected function memory_exceeded() { 514 $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory 515 $current_memory = memory_get_usage( true ); 516 $return = false; 517 518 if ( $current_memory >= $memory_limit ) { 519 $return = true; 520 } 521 522 return apply_filters( $this->identifier . '_memory_exceeded', $return ); 523 } 524 525 526 /** 527 * Push to queue 528 */ 529 public function push_to_queue( $hash, $data = false ) { 530 531 // Begin compatibility for SR Pro < 1.2.5 532 if ( ! $data ) { 533 $data = $hash; 534 $hash = md5( $data['url'] . '|' . $data['network'] ); 535 } 536 // End compatibility for SR Pro < 1.2.5 537 538 $this->data[ $hash ] = $data; 539 return $this; 540 } 541 542 543 /** 544 * Save queue 545 * 546 * @return $this 547 */ 548 public function save() { 549 550 global $wpdb; 551 552 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 553 554 if ( ! empty( $this->data ) ) { 555 556 $query = "INSERT IGNORE INTO $table_name (hash, data) VALUES "; 557 $values = array(); 558 $rows = count( $this->data ); 559 560 $i = 0; 561 foreach ( $this->data as $hash => $data ) { 562 $i++; 563 564 $query .= "(%s, %s)"; 565 $query .= ( $i < $rows ? "," : '' ); 566 567 $values[] = $hash; 568 $values[] = serialize( $data ); 569 } 570 571 $result = $wpdb->query( 572 $wpdb->prepare( $query, $values ) 573 ); 574 } 575 576 return $this; 577 } 578 579 580 /** 581 * Schedule cron healthcheck 582 * 583 * @access public 584 * @param mixed $schedules Schedules. 585 * @return mixed 586 */ 587 public function schedule_cron_healthcheck( $schedules ) { 588 $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); 589 590 if ( property_exists( $this, 'cron_interval' ) ) { 591 $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); 592 } 593 594 // Adds every 5 minutes to the existing schedules. 595 $schedules[ $this->identifier . '_cron_interval' ] = array( 596 'interval' => MINUTE_IN_SECONDS * $interval, 597 'display' => sprintf( __( 'Every %d Minutes' ), $interval ), 598 ); 599 600 return $schedules; 601 } 602 21 603 22 604 /** … … 31 613 32 614 /** 33 * Save and run queue. 34 */ 35 public function dispatch_queue() { 36 if ( ! empty( $this->data ) ) { 37 $this->save()->dispatch(); 38 } 39 } 40 41 42 /** 43 * Are we idle? (i.e. is queue empty) 44 */ 45 public function is_idle() { 46 return $this->is_queue_empty(); 47 } 48 49 50 /** 51 * Push to queue, only if not duplicate task 52 */ 53 public function push_to_queue( $data ) { 54 $duplicate = false; 55 foreach ( $this->data as $array ) { 56 if ( $array === $data ) { 57 $duplicate = true; 58 } 59 } 60 if ( ! $duplicate ) { 61 $this->data[] = $data; 62 } 63 return $this; 64 } 65 66 615 * Try to give ourselves reasonable limits. 616 * 617 * May not always work, but worth a try. 618 */ 619 protected function set_limits() { 620 621 if ( $this->handle_init ) { 622 return; 623 } 624 625 if ( ! function_exists( 'ini_set' ) ) { 626 return; 627 } 628 629 $memory_limit = $this->get_memory_limit(); 630 if ( $memory_limit < ( 256 * 1024 * 1024 ) ) { 631 ini_set( 'memory_limit', '256M' ); 632 } 633 634 $time_limit = $this->get_time_limit(); 635 if ( $time_limit < 300 ) { 636 ini_set( 'max_execution_time', 300 ); 637 } 638 639 } 640 641 67 642 /** 68 643 * Task … … 93 668 94 669 case 'update_share_count': 95 670 96 671 $network = isset( $item['network'] ) ? $item['network'] : ''; 97 672 $id = isset( $item['id'] ) ? $item['id'] : ''; … … 99 674 $url = isset( $item['url'] ) ? $item['url'] : ''; 100 675 $force = isset( $item['force'] ) ? $item['force'] : false; 676 677 // validate we have the bare minimum required, in case we are given something screwy 678 if ( 679 ( $type === 'url' && $id > '' ) || 680 ( $type !== 'url' && intval( $id ) > 0 ) 681 ) { 682 // okay 683 } else { 684 // we don't have a valid ID. Dump the task. 685 return false; 686 } 687 if ( ! $network > '' ) { 688 // we don't have a valid network. Dump the task. 689 return false; 690 } 101 691 102 692 // api throttling … … 134 724 return $item; 135 725 } 726 727 728 /** 729 * Time exceeded. 730 * 731 * Ensures the batch never exceeds a sensible time limit. 732 * A timeout limit of 30s is common on shared hosting. 733 * 734 * @return bool 735 */ 736 protected function time_exceeded() { 737 $time_limit = $this->get_time_limit(); 738 739 $finish = $this->start_time + $time_limit - ( $time_limit > 10 ? 10 : 1 ); // try not to go within 10 seconds of limit 740 $return = false; 741 742 if ( time() >= $finish ) { 743 $return = true; 744 } 745 746 return apply_filters( $this->identifier . '_time_exceeded', $return ); 747 } 748 749 750 /** 751 * Unlock process 752 * 753 * Unlock the process so that other instances can spawn. 754 * 755 * @return $this 756 */ 757 protected function unlock_process() { 758 delete_site_transient( $this->identifier . '_process_lock' ); 759 760 return $this; 761 } 762 763 764 /** 765 * Update queue 766 * 767 * Not used, may remove in the future. 768 * 769 * @param string $key Key. 770 * @param array $data Data. 771 * 772 * @return $this 773 */ 774 public function update( $key, $data ) { 775 return $this; 776 } 136 777 137 778 } -
social-rocket/trunk/includes/class-social-rocket.php
r2172087 r2224460 90 90 public static function _isset( &$var, $default = null ) { 91 91 return isset( $var ) ? $var : $default; 92 } 93 94 95 public static function _return_false() { 96 return false; 92 97 } 93 98 … … 2300 2305 $code = ''; 2301 2306 2307 $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data ); 2308 2302 2309 // don't insert buttons again if already done (allows for fallbacks) 2303 2310 if ( isset( $this->data['floating_bottom_done'] ) && $this->data['floating_bottom_done'] ) { … … 2347 2354 2348 2355 public function insert_floating_buttons_bottom_content_filter( $content ) { 2349 if ( isset( $this->data['floating_bottom_done'] ) && $this->data['floating_bottom_done'] ) {2350 return $content;2351 }2352 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2353 return $content;2354 }2355 2356 return $content . $this->insert_floating_buttons_bottom_content( false ); 2356 2357 } … … 2361 2362 $args = array( 'placement' => 'left' ); 2362 2363 $code = ''; 2364 2365 $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data ); 2363 2366 2364 2367 // don't insert buttons again if already done (allows for fallbacks) … … 2409 2412 2410 2413 public function insert_floating_buttons_left_content_filter( $content ) { 2411 if ( isset( $this->data['floating_left_done'] ) && $this->data['floating_left_done'] ) {2412 return $content;2413 }2414 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2415 return $content;2416 }2417 2414 return $content . $this->insert_floating_buttons_left_content( false ); 2418 2415 } … … 2423 2420 $args = array( 'placement' => 'right' ); 2424 2421 $code = ''; 2422 2423 $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data ); 2425 2424 2426 2425 // don't insert buttons again if already done (allows for fallbacks) … … 2471 2470 2472 2471 public function insert_floating_buttons_right_content_filter( $content ) { 2473 if ( isset( $this->data['floating_right_done'] ) && $this->data['floating_right_done'] ) {2474 return $content;2475 }2476 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2477 return $content;2478 }2479 2472 return $content . $this->insert_floating_buttons_right_content( false ); 2480 2473 } … … 2485 2478 $args = array( 'placement' => 'top' ); 2486 2479 $code = ''; 2480 2481 $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data ); 2487 2482 2488 2483 // don't insert buttons again if already done (allows for fallbacks) … … 2533 2528 2534 2529 public function insert_floating_buttons_top_content_filter( $content ) { 2535 if ( isset( $this->data['floating_top_done'] ) && $this->data['floating_top_done'] ) {2536 return $content;2537 }2538 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2539 return $content;2540 }2541 2530 return $content . $this->insert_floating_buttons_top_content( false ); 2542 2531 } … … 2547 2536 $args = array(); 2548 2537 $code = ''; 2538 2539 $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data ); 2549 2540 2550 2541 // don't insert buttons again if already done (allows for fallbacks) … … 2610 2601 2611 2602 public function insert_inline_buttons_after_content_filter( $content ) { 2612 if ( isset( $this->data['inline_after_done'] ) && $this->data['inline_after_done'] ) {2613 return $content;2614 }2615 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2616 return $content;2617 }2618 2603 return $content . $this->insert_inline_buttons_after_content( false ); 2619 2604 } … … 2624 2609 $args = array(); 2625 2610 $code = ''; 2611 2612 $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data ); 2626 2613 2627 2614 // don't insert buttons again if already done (allows for fallbacks) … … 2687 2674 2688 2675 public function insert_inline_buttons_before_content_filter( $content ) { 2689 if ( isset( $this->data['inline_before_done'] ) && $this->data['inline_before_done'] ) {2690 return $content;2691 }2692 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) {2693 return $content;2694 }2695 2676 return $this->insert_inline_buttons_before_content( false ) . $content; 2696 2677 } … … 2703 2684 $loc = $this->where_we_at(); 2704 2685 2686 $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data ); 2687 2705 2688 // don't insert buttons again if already done (allows for fallbacks) 2706 2689 if ( isset( $this->data['inline_item_done'] ) && $this->data['inline_item_done'] === $loc['id'] ) { 2707 2690 return; 2708 2691 } 2692 2693 // don't insert buttons if we're in the excerpt 2694 if ( isset( $this->data['doing_excerpt'] ) && $this->data['doing_excerpt'] ) { 2695 return; 2696 } 2697 2698 // disable paged requests link to first page, for this item only 2699 add_filter( 'social_rocket_archives_url_use_first_page', array( $this, '_return_false' ) ); 2709 2700 2710 2701 // get buttons code … … 2726 2717 } 2727 2718 2719 // restore filter 2720 remove_filter( 'social_rocket_archives_url_use_first_page', array( $this, '_return_false' ) ); 2721 2728 2722 // done 2729 2723 $this->data['inline_item_done'] = $loc['id']; … … 2737 2731 2738 2732 public function insert_inline_buttons_item_content_filter( $content ) { 2739 $loc = $this->where_we_at();2740 if ( isset( $this->data['inline_item_done'] ) && $this->data['inline_item_done'] === $loc['id'] ) {2741 return $content;2742 }2743 2733 return $content . $this->insert_inline_buttons_item_content( false ); 2744 2734 } 2745 2735 2746 2736 2747 2748 2737 /* 2749 2738 * Determine if current request is for some non-countable WordPress thing, like … … 3697 3686 $SRN = call_user_func( array( 'Social_Rocket_'.ucfirst($network), 'get_instance' ) ); 3698 3687 if ( isset( $SRN->countable ) && $SRN->countable ) { 3699 $this->background_processor->push_to_queue( array( 3700 'task' => 'update_share_count', 3701 'network' => $network, 3702 'id' => $id, 3703 'type' => $type, 3704 'url' => $url, 3705 'force' => $force, 3706 ) ); 3688 $this->background_processor->push_to_queue( 3689 md5( $url . '|' . $network ), 3690 array( 3691 'task' => 'update_share_count', 3692 'network' => $network, 3693 'id' => $id, 3694 'type' => $type, 3695 'url' => $url, 3696 'force' => $force, 3697 ) 3698 ); 3707 3699 } 3708 3700 … … 3921 3913 $exists = $wpdb->get_row( 3922 3914 $wpdb->prepare( 3923 "SELECT * FROM {$table_prefix}social_rocket_count_data WHERE {$where} = % d",3915 "SELECT * FROM {$table_prefix}social_rocket_count_data WHERE {$where} = %s", 3924 3916 $id 3925 3917 ), … … 3970 3962 public function update_share_count( $network, $id = 0, $type = 'post', $url = '', $force = false ) { 3971 3963 3964 global $srp_debug_message; 3965 3972 3966 if ( ! $id ) { 3973 3967 $loc = Social_Rocket::where_we_at(); … … 3996 3990 $SRN = call_user_func( array( 'Social_Rocket_'.ucfirst($network), 'get_instance' ) ); 3997 3991 $total = $SRN->get_count_from_api( $url ); 3992 if ( defined( 'SRP_DEBUG' ) && SRP_DEBUG ) { 3993 $srp_debug_message = 'got from api: ' . var_export( $total, true ); 3994 } 3998 3995 } 3999 3996 … … 4071 4068 } 4072 4069 4073 if ( ! in_array( $_SERVER['SERVER_PORT'], array( '80', '443') ) ) {4070 if ( ! in_array( $_SERVER['SERVER_PORT'], array( '80', '8080', '443' ) ) ) { 4074 4071 $url .= ':'.$_SERVER["SERVER_PORT"]; 4075 4072 } … … 4095 4092 4096 4093 // now figure out where we are within the WP universe... 4097 $result = array( 4098 'id' => in_the_loop() ? get_the_ID() : get_queried_object_id(), 4099 'settings_key' => '', 4100 'type' => 'i dunno', // hey, let's be honest 4101 'url' => in_the_loop() ? get_the_permalink() : $url, 4102 ); 4103 4094 $result = array(); 4095 4096 // determine 'id' and 'type' 4104 4097 if ( in_the_loop() || is_page() || is_single() || is_attachment() ) { 4105 4098 // catches pages, posts, and attachments 4106 4099 // get_queried_object_id = ID in posts table 4100 $result['id'] = in_the_loop() ? get_the_ID() : get_queried_object_id(); 4107 4101 $result['type'] = 'post'; 4108 4102 } elseif ( is_home() || is_date() || is_post_type_archive() ) { … … 4110 4104 // or date-based archives, or CPT-based archives 4111 4105 // get_queried_object_id = always 0 4112 $result['id'] = $url;4106 $result['id'] = $url; 4113 4107 $result['type'] = 'url'; 4114 4108 } elseif ( is_author() ) { 4115 4109 // author archives 4116 4110 // get_queried_object_id = ID in users table 4111 $result['id'] = in_the_loop() ? get_the_ID() : get_queried_object_id(); 4117 4112 $result['type'] = 'user'; 4118 4113 } elseif ( is_archive() ) { … … 4120 4115 // are category, tag, and taxonomy archives 4121 4116 // get_queried_object_id = ID in terms table 4117 $result['id'] = in_the_loop() ? get_the_ID() : get_queried_object_id(); 4122 4118 $result['type'] = 'term'; 4123 4119 } else { 4124 4120 // if all else fails, just use the URL 4125 $result['id'] = $url;4121 $result['id'] = $url; 4126 4122 $result['type'] = 'url'; 4127 4123 } 4124 4125 // determine 'url' 4126 $result['url'] = in_the_loop() ? get_the_permalink() : $url; 4128 4127 4129 4128 // consider paged requests as requests for original url (page 1) … … 4160 4159 } 4161 4160 4161 // lastly validate our result, in case we are given something screwy 4162 if ( ! $result['id'] > 0 && ! $result['id'] > '' ) { 4163 // we don't have a valid ID. Fallback to URL. 4164 $result['id'] = $url; 4165 $result['type'] = 'url'; 4166 } 4167 4162 4168 return $result; 4163 4169 } -
social-rocket/trunk/includes/social-rocket-activate.php
r2200280 r2224460 154 154 155 155 function social_rocket_activate_db_delta() { 156 156 157 global $wpdb; 158 159 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 160 157 161 $charset_collate = $wpdb->get_charset_collate(); 162 163 // counts table 158 164 $table_name = $wpdb->prefix . 'social_rocket_count_data'; 159 165 $sql = "CREATE TABLE $table_name ( … … 171 177 KEY url (url) 172 178 ) $charset_collate;"; 173 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 174 return dbDelta( $sql ); 179 dbDelta( $sql ); 180 181 // queue table 182 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 183 $sql = "CREATE TABLE $table_name ( 184 id bigint(20) unsigned NOT NULL AUTO_INCREMENT, 185 hash varchar(32) NOT NULL, 186 data text NOT NULL, 187 request_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 188 PRIMARY KEY (id), 189 UNIQUE KEY hash (hash) 190 ) $charset_collate;"; 191 dbDelta( $sql ); 175 192 } -
social-rocket/trunk/includes/social-rocket-deactivate.php
r2189610 r2224460 27 27 } 28 28 29 // clear background queue30 $table = $wpdb->options;31 $column = 'option_name';32 $key_column = 'option_id';33 $value_column = 'option_value';34 35 if ( is_multisite() ) {36 $table = $wpdb->sitemeta;37 $column = 'meta_key';38 $key_column = 'meta_id';39 $value_column = 'meta_value';40 }41 42 $key = $wpdb->esc_like( 'wp_social_rocket_background_process_batch_' ) . '%';43 44 $wpdb->query( $wpdb->prepare( "45 DELETE46 FROM {$table}47 WHERE {$column} LIKE %s48 ", $key ) );49 50 29 } 51 30 … … 57 36 $settings = get_option( 'social_rocket_settings' ); 58 37 38 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 39 $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); 40 59 41 if ( isset( $settings['delete_settings'] ) && $settings['delete_settings'] ) { 60 42 61 43 $table_name = $wpdb->prefix . 'social_rocket_count_data'; 44 $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); 62 45 63 $wpdb->query( "DROP TABLE IF EXISTS $table_name" );64 46 $wpdb->get_results( "DELETE FROM $wpdb->postmeta WHERE meta_key IN ( 'social_rocket_og_description', 'social_rocket_og_image', 'social_rocket_og_title', 'social_rocket_pinterest_browser_extension', 'social_rocket_pinterest_browser_extension_location', 'social_rocket_pinterest_description', 'social_rocket_pinterest_image', 'social_rocket_twitter_message', 'social_rocket_floating_position', 'social_rocket_inline_position', 'social_rocket_total_shares' )" ); 65 47 $wpdb->get_results( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ( 'social_rocket_facebook_profile_url', 'social_rocket_twitter_username' )" ); -
social-rocket/trunk/includes/social-rocket-update.php
r2146054 r2224460 125 125 } 126 126 127 128 // upgrade from v3 to 4 129 if ( ! isset( $settings['db_version'] ) || $settings['db_version'] < 4 ) { 130 131 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 132 133 // create new queue table 134 $charset_collate = $wpdb->get_charset_collate(); 135 $table_name = $wpdb->prefix . 'social_rocket_count_queue'; 136 $sql = "CREATE TABLE $table_name ( 137 id bigint(20) unsigned NOT NULL AUTO_INCREMENT, 138 hash varchar(32) NOT NULL, 139 data text NOT NULL, 140 request_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 141 PRIMARY KEY (id), 142 UNIQUE KEY hash (hash) 143 ) $charset_collate;"; 144 dbDelta( $sql ); 145 146 // clear old background queue 147 $table = $wpdb->options; 148 $column = 'option_name'; 149 $key_column = 'option_id'; 150 $value_column = 'option_value'; 151 152 if ( is_multisite() ) { 153 $table = $wpdb->sitemeta; 154 $column = 'meta_key'; 155 $key_column = 'meta_id'; 156 $value_column = 'meta_value'; 157 } 158 159 $key = $wpdb->esc_like( 'wp_social_rocket_background_process_batch_' ) . '%'; 160 161 $wpdb->query( $wpdb->prepare( " 162 DELETE 163 FROM {$table} 164 WHERE {$column} LIKE %s 165 ", $key ) ); 166 } 167 127 168 // Done 128 169 $settings['db_version'] = SOCIAL_ROCKET_DBVERSION; -
social-rocket/trunk/readme.txt
r2200280 r2224460 6 6 Tested up to: 5.3 7 7 Requires PHP: 5.5 8 Stable tag: 1.2. 48 Stable tag: 1.2.5 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 83 83 84 84 == Changelog == 85 = 1.2.5 = 86 * FIX: issues with archives pages when display type set to "item" 87 * UPDATE: add compatibility for Tasty Recipes plugin. 88 * UPDATE: add 8080 to list of accepted ports when determining URLs. 89 * UPDATE: new background processing system. (Stopped using 3rd-party wp-background-processing library, now using our own. This should make processing more efficient). 90 85 91 = 1.2.4 = 86 92 * FIX: compatibility issue with Gutenberg 5.3. -
social-rocket/trunk/social-rocket.php
r2200280 r2224460 3 3 * Plugin Name: Social Rocket 4 4 * Description: Social Sharing... to the Moon! 5 * Version: 1.2. 45 * Version: 1.2.5 6 6 * Author: Social Rocket 7 7 * Author URI: http://wpsocialrocket.com/ … … 17 17 } 18 18 19 define( 'SOCIAL_ROCKET_VERSION', '1.2. 4' );20 define( 'SOCIAL_ROCKET_DBVERSION', ' 3' );19 define( 'SOCIAL_ROCKET_VERSION', '1.2.5' ); 20 define( 'SOCIAL_ROCKET_DBVERSION', '4' ); 21 21 define( 'SOCIAL_ROCKET_PATH', plugin_dir_path( __FILE__ ) ); 22 22 define( 'SOCIAL_ROCKET_FILE', __FILE__ ); … … 55 55 require_once( SOCIAL_ROCKET_PATH . 'vendor/wp-background-processing/wp-background-processing.php' ); 56 56 require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-background-process.php' ); 57 require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-compatibility.php' ); 57 58 require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-cron.php' ); 58 59 require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket.php' ); … … 68 69 } 69 70 71 Social_Rocket_Compatibility::get_instance(); 72 70 73 do_action( 'social_rocket_loaded' ); 71 74
Note: See TracChangeset
for help on using the changeset viewer.