Plugin Directory

Changeset 2224460


Ignore:
Timestamp:
01/08/2020 07:49:49 PM (6 years ago)
Author:
socialrocket
Message:

Version 1.2.5 update

Location:
social-rocket/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • social-rocket/trunk/includes/class-social-rocket-background-process.php

    r2200280 r2224460  
    33if ( ! defined('ABSPATH') ) { exit; }
    44
    5 class Social_Rocket_Background_Process extends WP_Background_Process  {
    6 
    7     /**
     5class Social_Rocket_Background_Process {
     6   
     7    /**
     8     * Action
     9     *
     10     * (default value: 'async_request')
     11     *
    812     * @var string
     13     * @access protected
    914     */
    1015    protected $action = 'social_rocket_background_process';
    1116   
     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   
    1279   
    1380    /**
     
    1582     */
    1683    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' ) );
    1891        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   
    21603   
    22604    /**
     
    31613   
    32614    /**
    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   
    67642    /**
    68643     * Task
     
    93668       
    94669            case 'update_share_count':
    95            
     670               
    96671                $network = isset( $item['network'] ) ? $item['network'] : '';
    97672                $id      = isset( $item['id'] )      ? $item['id']      : '';
     
    99674                $url     = isset( $item['url'] )     ? $item['url']     : '';
    100675                $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                }
    101691               
    102692                // api throttling
     
    134724        return $item;
    135725    }
     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    }
    136777
    137778}
  • social-rocket/trunk/includes/class-social-rocket.php

    r2172087 r2224460  
    9090    public static function _isset( &$var, $default = null ) {
    9191        return isset( $var ) ? $var : $default;
     92    }
     93   
     94   
     95    public static function _return_false() {
     96        return false;
    9297    }
    9398   
     
    23002305        $code = '';
    23012306       
     2307        $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data );
     2308       
    23022309        // don't insert buttons again if already done (allows for fallbacks)
    23032310        if ( isset( $this->data['floating_bottom_done'] ) && $this->data['floating_bottom_done'] ) {
     
    23472354   
    23482355    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         }
    23552356        return $content . $this->insert_floating_buttons_bottom_content( false );
    23562357    }
     
    23612362        $args = array( 'placement' => 'left' );
    23622363        $code = '';
     2364       
     2365        $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data );
    23632366       
    23642367        // don't insert buttons again if already done (allows for fallbacks)
     
    24092412   
    24102413    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         }
    24172414        return $content . $this->insert_floating_buttons_left_content( false );
    24182415    }
     
    24232420        $args = array( 'placement' => 'right' );
    24242421        $code = '';
     2422       
     2423        $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data );
    24252424       
    24262425        // don't insert buttons again if already done (allows for fallbacks)
     
    24712470   
    24722471    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         }
    24792472        return $content . $this->insert_floating_buttons_right_content( false );
    24802473    }
     
    24852478        $args = array( 'placement' => 'top' );
    24862479        $code = '';
     2480       
     2481        $this->data = apply_filters( 'social_rocket_insert_floating_data', $this->data );
    24872482       
    24882483        // don't insert buttons again if already done (allows for fallbacks)
     
    25332528   
    25342529    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         }
    25412530        return $content . $this->insert_floating_buttons_top_content( false );
    25422531    }
     
    25472536        $args = array();
    25482537        $code = '';
     2538       
     2539        $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data );
    25492540       
    25502541        // don't insert buttons again if already done (allows for fallbacks)
     
    26102601   
    26112602    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         }
    26182603        return $content . $this->insert_inline_buttons_after_content( false );
    26192604    }
     
    26242609        $args = array();
    26252610        $code = '';
     2611       
     2612        $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data );
    26262613       
    26272614        // don't insert buttons again if already done (allows for fallbacks)
     
    26872674   
    26882675    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         }
    26952676        return $this->insert_inline_buttons_before_content( false ) . $content;
    26962677    }
     
    27032684        $loc  = $this->where_we_at();
    27042685       
     2686        $this->data = apply_filters( 'social_rocket_insert_inline_data', $this->data );
     2687       
    27052688        // don't insert buttons again if already done (allows for fallbacks)
    27062689        if ( isset( $this->data['inline_item_done'] ) && $this->data['inline_item_done'] === $loc['id'] ) {
    27072690            return;
    27082691        }
     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' ) );
    27092700       
    27102701        // get buttons code
     
    27262717        }
    27272718       
     2719        // restore filter
     2720        remove_filter( 'social_rocket_archives_url_use_first_page', array( $this, '_return_false' ) );
     2721       
    27282722        // done
    27292723        $this->data['inline_item_done'] = $loc['id'];
     
    27372731   
    27382732    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         }
    27432733        return $content . $this->insert_inline_buttons_item_content( false );
    27442734    }
    27452735   
    27462736
    2747    
    27482737    /*
    27492738     * Determine if current request is for some non-countable WordPress thing, like
     
    36973686                $SRN = call_user_func( array( 'Social_Rocket_'.ucfirst($network), 'get_instance' ) );
    36983687                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                    );
    37073699                }
    37083700               
     
    39213913        $exists = $wpdb->get_row(
    39223914            $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",
    39243916                $id
    39253917            ),
     
    39703962    public function update_share_count( $network, $id = 0, $type = 'post', $url = '', $force = false ) {
    39713963       
     3964        global $srp_debug_message;
     3965       
    39723966        if ( ! $id ) {
    39733967            $loc  = Social_Rocket::where_we_at();
     
    39963990            $SRN = call_user_func( array( 'Social_Rocket_'.ucfirst($network), 'get_instance' ) );
    39973991            $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            }
    39983995        }
    39993996       
     
    40714068        }
    40724069
    4073         if ( ! in_array( $_SERVER['SERVER_PORT'], array('80', '443') ) ) {
     4070        if ( ! in_array( $_SERVER['SERVER_PORT'], array( '80', '8080', '443' ) ) ) {
    40744071            $url .= ':'.$_SERVER["SERVER_PORT"];
    40754072        }
     
    40954092       
    40964093        // 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'
    41044097        if ( in_the_loop() || is_page() || is_single() || is_attachment() ) {
    41054098            // catches pages, posts, and attachments
    41064099            // get_queried_object_id = ID in posts table
     4100            $result['id']   = in_the_loop() ? get_the_ID() : get_queried_object_id();
    41074101            $result['type'] = 'post';
    41084102        } elseif ( is_home() || is_date() || is_post_type_archive() ) {
     
    41104104            // or date-based archives, or CPT-based archives
    41114105            // get_queried_object_id = always 0
    4112             $result['id'] = $url;
     4106            $result['id']   = $url;
    41134107            $result['type'] = 'url';
    41144108        } elseif ( is_author() ) {
    41154109            // author archives
    41164110            // get_queried_object_id = ID in users table
     4111            $result['id']   = in_the_loop() ? get_the_ID() : get_queried_object_id();
    41174112            $result['type'] = 'user';
    41184113        } elseif ( is_archive() ) {
     
    41204115            // are category, tag, and taxonomy archives
    41214116            // get_queried_object_id = ID in terms table
     4117            $result['id']   = in_the_loop() ? get_the_ID() : get_queried_object_id();
    41224118            $result['type'] = 'term';
    41234119        } else {
    41244120            // if all else fails, just use the URL
    4125             $result['id'] = $url;
     4121            $result['id']   = $url;
    41264122            $result['type'] = 'url';
    41274123        }
     4124       
     4125        // determine 'url'
     4126        $result['url'] = in_the_loop() ? get_the_permalink() : $url;
    41284127       
    41294128        // consider paged requests as requests for original url (page 1)
     
    41604159        }
    41614160       
     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       
    41624168        return $result;
    41634169    }
  • social-rocket/trunk/includes/social-rocket-activate.php

    r2200280 r2224460  
    154154
    155155function social_rocket_activate_db_delta() {
     156   
    156157    global $wpdb;
     158   
     159    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     160   
    157161    $charset_collate = $wpdb->get_charset_collate();
     162   
     163    // counts table
    158164    $table_name = $wpdb->prefix . 'social_rocket_count_data';
    159165    $sql = "CREATE TABLE $table_name (
     
    171177        KEY url (url)
    172178    ) $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 );
    175192}
  • social-rocket/trunk/includes/social-rocket-deactivate.php

    r2189610 r2224460  
    2727    }
    2828   
    29     // clear background queue
    30     $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         DELETE
    46         FROM {$table}
    47         WHERE {$column} LIKE %s
    48     ", $key ) );
    49    
    5029}
    5130
     
    5736    $settings = get_option( 'social_rocket_settings' );
    5837   
     38    $table_name = $wpdb->prefix . 'social_rocket_count_queue';
     39    $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
     40   
    5941    if ( isset( $settings['delete_settings'] ) && $settings['delete_settings'] ) {
    6042   
    6143        $table_name = $wpdb->prefix . 'social_rocket_count_data';
     44        $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
    6245       
    63         $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
    6446        $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' )" );
    6547        $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  
    125125    }
    126126   
     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   
    127168    // Done
    128169    $settings['db_version'] = SOCIAL_ROCKET_DBVERSION;
  • social-rocket/trunk/readme.txt

    r2200280 r2224460  
    66Tested up to: 5.3
    77Requires PHP: 5.5
    8 Stable tag: 1.2.4
     8Stable tag: 1.2.5
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8383
    8484== 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
    8591= 1.2.4 =
    8692* FIX: compatibility issue with Gutenberg 5.3.
  • social-rocket/trunk/social-rocket.php

    r2200280 r2224460  
    33 * Plugin Name: Social Rocket
    44 * Description: Social Sharing... to the Moon!
    5  * Version: 1.2.4
     5 * Version: 1.2.5
    66 * Author: Social Rocket
    77 * Author URI: http://wpsocialrocket.com/
     
    1717}
    1818
    19 define( 'SOCIAL_ROCKET_VERSION', '1.2.4' );
    20 define( 'SOCIAL_ROCKET_DBVERSION', '3' );
     19define( 'SOCIAL_ROCKET_VERSION', '1.2.5' );
     20define( 'SOCIAL_ROCKET_DBVERSION', '4' );
    2121define( 'SOCIAL_ROCKET_PATH', plugin_dir_path( __FILE__ ) );
    2222define( 'SOCIAL_ROCKET_FILE', __FILE__ );
     
    5555    require_once( SOCIAL_ROCKET_PATH . 'vendor/wp-background-processing/wp-background-processing.php' );
    5656    require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-background-process.php' );
     57    require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-compatibility.php' );
    5758    require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket-cron.php' );
    5859    require_once( SOCIAL_ROCKET_PATH . 'includes/class-social-rocket.php' );
     
    6869    }
    6970   
     71    Social_Rocket_Compatibility::get_instance();
     72   
    7073    do_action( 'social_rocket_loaded' );
    7174   
Note: See TracChangeset for help on using the changeset viewer.