Plugin Directory

Changeset 2144962


Ignore:
Timestamp:
08/25/2019 12:14:03 AM (6 years ago)
Author:
carllockett3
Message:

Update version 2.1.4.4

Location:
auto-post-woocommerce-products/trunk
Files:
189 added
33 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • auto-post-woocommerce-products/trunk/README.txt

    r2134375 r2144962  
    55Requires at least: 5.0
    66Tested up to: 5.2.2
    7 Stable tag: 2.1.4.3
    8 Requires PHP at least: 5.6.35 Recommended 7.2
     7Stable tag: 2.1.4.4
     8Requires PHP at least: 7.0 Recommended 7.2
    99WC requires at least: 3.3.0
    10 WC tested up to: 3.6.5
     10WC tested up to: 3.7
    1111License: GPLv2 or later
    1212License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7676
    7777== Changelog ==
     78= 2.1.4.4 =
     79* 24-AUG-2019
     80* Corrected Twitter auto posting issue.
     81* Updated to use new Bitly API v4 and corrected previous Bitly errors.
     82* Fixed issue with "sharing buttons" not showing on the individual sharing page.
     83* Pinterest should now show the sale price when product is on sale.
     84* Moved the RESET AUTO POST PRODUCTS box from the categories tab to the STATUS tab.
     85
    7886= 2.1.4.3 =
    7987* 05-AUG-2019
  • auto-post-woocommerce-products/trunk/admin/apwp-functions-admin.php

    r2134375 r2144962  
    531531
    532532/**
    533  * Load script async
    534  *
    535  * @param string $url The java url to load.
    536  * @since 2.1.3.2
    537  *
    538  * @return mixed
    539  */
    540 function apwp_async_scripts( $url )
    541 {
    542    
    543     if ( strpos( $url, '#asyncload' ) === false ) {
    544         return $url;
    545     } else {
    546         return str_replace( '#asyncload', '', $url ) . "' async='async 'defer='defer";
    547     }
    548 
    549 }
    550 
    551 add_filter(
    552     'clean_url',
    553     'apwp_async_scripts',
    554     11,
    555     1
    556 );
    557 /**
    558533 * Get the current user default admin WordPress theme
    559534 *
     
    664639    $labels = new Apwp_Labels();
    665640    $_setup = new Apwp_Check_Setup();
     641    $products = new WC_Product_factory();
    666642    $id = get_the_ID();
     643    $product = $products->get_product( $id );
    667644    $sale = false;
    668645    $_onsale1 = '';
     
    671648    $price = get_post_meta( $id, '_price', true );
    672649    $reg = get_post_meta( $id, '_regular_price', true );
     650    $date_to = get_post_meta( $id, '_sale_price_dates_to', true );
     651    $date_from = get_post_meta( $id, '_sale_price_dates_from', true );
    673652    $sh_desc = apwp_get_excerpt( $id );
    674653    $card_type = 'summary';
    675     if ( false === $reg ) {
     654    if ( '' === $reg ) {
    676655        $reg = $price;
    677656    }
     
    682661    // If on sale add on sale to title.
    683662    $check_disc_setting = get_option( 'apwp_discount' );
    684     if ( $price < $reg ) {
     663   
     664    if ( $product->is_on_sale() ) {
    685665        $sale = true;
    686     }
     666        $price = get_post_meta( $id, '_sale_price', true );
     667    }
     668   
    687669   
    688670    if ( $sale && 'checked' === $check_disc_setting ) {
     
    967949function apwp_display_header()
    968950{
     951    $beta = get_option( 'apwp_is_beta_version' );
    969952    $labels = new Apwp_Labels();
    970953    $_type = apwp_get_fs_plan_title();
    971954    $url = esc_url( 'https://www.cilcreations.com/apwp' );
     955    $beta_desc = '';
     956    if ( $beta ) {
     957        $beta_desc = '<span style="color: red;"> beta</span>';
     958    }
    972959    ?>
    973960    <a href="<?php
     
    988975    <div class="description logo-title">
    989976        <?php
    990     echo  $labels->product_list_labels['version'] . ' ' . APWP_VERSION . $_type . '</b>' ;
     977    echo  $labels->product_list_labels['version'] . ' ' . APWP_VERSION . ' ' . $beta_desc . $_type . '</b>' ;
    991978    echo  ' ' . $labels->product_list_labels['by'] ;
    992979    ?>
     
    12031190
    12041191/**
     1192 * Get file size for log
     1193 *
     1194 * @param int $bytes File size in bytes.
     1195 * @param int $decimals Number of decimal places.
     1196 * @since  2.1.4.4
     1197 *
     1198 * @return string
     1199 */
     1200function apwp_filesize( $bytes, $decimals = 2 )
     1201{
     1202    return sprintf( "%.{$decimals}f", $bytes ) . ' bytes';
     1203}
     1204
     1205/**
    12051206 * FUNCTION TO TRUNCATE LOG FILES
    12061207 *
     
    12161217    }
    12171218    $size = filesize( $path );
    1218     $max_size = 10485760;
    1219    
    1220     if ( $size > $max_size ) {
    1221         // Greater than 10MB.
     1219    $_size = $size;
     1220    if ( 0 === $size ) {
     1221        return;
     1222    }
     1223    $_size = apwp_filesize( $size );
     1224   
     1225    if ( $size > 524880 ) {
    12221226        rename( $path, $path . '.old-' . time() );
    12231227        file_put_contents( $path, '', FILE_APPEND );
    12241228        // Create empty log file.
     1229        apwp_add_to_debug( 'Trim log file "' . wp_basename( $path ) . '" Filesize: ' . $_size, '<span style="color: purple;">APWCP</span>' );
    12251230    }
    12261231   
     
    12641269        return;
    12651270    }
    1266     $local_time = date_i18n( get_option( 'time_format' ), $time + APWP_TIME_OFFSET );
     1271    $local_time = date_i18n( get_option( 'time_format' ), $time );
    12671272    return $local_time;
    12681273}
     
    15441549function apwp_reset_plugin()
    15451550{
    1546     $cron = new Apwp_Cron_Functions();
    1547     $cron->atwc_delete_schedule();
     1551    apwp_deactivate_apwp_cron();
    15481552    update_option( APWP_SCHEDULE_PAGE, 'pause_schedule' );
    15491553    delete_option( 'apwp_view_all' );
     
    15591563    delete_transient( 'apwp_prod_list_data' );
    15601564    delete_transient( 'apwp_prod_list_data_check' );
    1561     apwp_set_onetime_cron( [
    1562         'create',
    1563         'data',
    1564         'trash',
    1565         'rebuild'
    1566     ] );
     1565    apwp_set_onetime_cron( [ 'create', 'data', 'trash' ] );
    15671566    apwp_set_products_array();
    15681567    apwp_add_to_debug( 'APWCP plugin has been reset.', '<span style="color: green;">INFO</span>' );
  • auto-post-woocommerce-products/trunk/admin/apwp-schedule-tab.php

    r2134375 r2144962  
    4545        $show_if_local = '';
    4646    }
    47     $next_post = apwp_convert_time( $cron->get_next_cron_run() + APWP_TIME_OFFSET );
    48     $next_post_diff = human_time_diff( $cron->get_next_cron_run(), time() );
     47    $next_post = apwp_convert_time( wp_next_scheduled( 'auto_post_woo_prod_cron' ) + APWP_TIME_OFFSET );
     48    $next_post_diff = human_time_diff( wp_next_scheduled( 'auto_post_woo_prod_cron' ), time() );
    4949    // The following will check if the tweet has been sent and next tweet scheduled.
    5050    // Each step involves JS timer to refresh the page until completed.
     
    9696            }
    9797            $next_post = apwp_convert_time( get_option( 'apwp_next_time_cron_runs' ) + APWP_TIME_OFFSET );
    98             $next_post_diff = human_time_diff( $cron->get_next_cron_run(), time() );
     98            $next_post_diff = human_time_diff( wp_next_scheduled( 'auto_post_woo_prod_cron' ), time() );
    9999        } elseif ( $last_tweet && false === $last_tweet['last_post_successful'] ) {
    100100            $_update = $labels->schedule_labels['last-post-failed'];
     
    105105        }
    106106       
    107         $next_ = $cron->get_next_cron_run();
     107        $next_ = wp_next_scheduled( 'auto_post_woo_prod_cron' );
    108108       
    109109        if ( !$next_ ) {
     
    112112           
    113113            if ( $next_post > time() + 30 ) {
    114                 $next_post = apwp_convert_time( $cron->get_next_cron_run() + APWP_TIME_OFFSET );
    115                 $next_post_diff = human_time_diff( $cron->get_next_cron_run(), time() );
     114                $next_post = apwp_convert_time( wp_next_scheduled( 'auto_post_woo_prod_cron' ) + APWP_TIME_OFFSET );
     115                $next_post_diff = human_time_diff( wp_next_scheduled( 'auto_post_woo_prod_cron' ), time() );
    116116                delete_option( 'apwp_next_time_cron_runs' );
    117117                set_transient( 'apwp_cron_check', 'done', HOUR_IN_SECONDS );
     
    456456        $a[$ck2] = 'checked';
    457457    }
    458     $opt = get_option( APWP_SCHEDULE_PAGE );
    459     $apwp_current_sched = $opt;
    460    
    461     if ( !$cron->get_next_cron_run() ) {
    462         update_option( $opt, 'pause_schedule' );
     458    $apwp_current_sched = get_option( APWP_SCHEDULE_PAGE );
     459   
     460    if ( !wp_next_scheduled( 'auto_post_woo_prod_cron' ) ) {
     461        update_option( $apwp_current_sched, 'pause_schedule' );
    463462        $apwp_current_sched = 'pause_schedule';
    464463        update_option( 'atwc_previous_selection', '' );
  • auto-post-woocommerce-products/trunk/admin/apwp-twitter-tab.php

    r2134375 r2144962  
    259259    } else {
    260260        $current = 0;
    261         update_option( 'apwp_current_status', 'posted' );
    262         // Prevent issue if installing and not using autopost.
    263261    }
    264262
  • auto-post-woocommerce-products/trunk/admin/apwp-woocommerce-tab.php

    r2122132 r2144962  
    2828 */
    2929function apwp_display_tab_two() {
    30     global $apwp_theme;
    3130    $labels       = new Apwp_Labels();
    3231    $prod_to_post = 0;
     
    5352                ?>
    5453            </form>
    55             <?php
    56             if ( get_option( 'atwc_products_post' ) ) {
    57                 $prod_to_post = get_option( 'atwc_products_post' );
    58                 if ( empty( $prod_to_post ) ) {
    59                     $prod_to_post = 0;
    60                     apwp_set_onetime_cron( [ 'create' ] );
    61                 } else {
    62                     $prod_to_post = count( get_option( 'atwc_products_post' ) );
    63                 }
    64             }
    65             ?>
    66             <div class="auto-post-cue-note b shadows-upper">
    67                 <div class="subtitle-apwp" style="text-align: center; background: gainsboro; padding: 8px; padding-bottom: 10px; border-bottom: 1px solid gray;">
    68                     <?php
    69                     echo $labels->other_tabs_labels['current-post-data'];
    70                     ?>
    71                     </div>
    72                 <table style="width: 100%;">
    73                     <tr>
    74                         <td style="width: 50%; text-align: center;">
    75                             <div class="other-items-clicks-green">
    76                                 <span class="other-numbers2">
    77                                     <?php echo number_format_i18n( $ttl ); ?></span></div>
    78                             <br /><span class="dash2">
    79                                 <?php
    80                                 echo _n( 'Product to Tweet', 'Products to Tweet', $ttl, 'auto-post-woocommerce-products' );
    81                                 ?>
    82                                 </span>
    83                         </td>
    84                         <td style="width: 50%; text-align: center;">
    85                             <div class="low-items">
    86                                 <span class="other-numbers2">
    87                                     <?php echo number_format_i18n( $prod_to_post ); ?></span></div>
    88                             <br /><span class="dash2">
    89                                 <?php
    90                                 echo $labels->other_tabs_labels['scheduled-tweet'];
    91                                 ?>
    92                                 </span>
    93                         </td>
    94                     </tr>
    95                 </table>
    96                 <hr />
    97                 <div style="margin: 10px;">
    98                     <?php
    99                     echo $labels->other_tabs_labels['auto-post-desc'];
    100                     ?>
    101                     <br /><br />
    102                     <?php
    103                     echo $labels->other_tabs_labels['posting-info'];
    104                     ?>
    105                     <hr />
    106                     <div class="subtitle-apwp" style="text-align: center; padding-bottom: 10px;">
    107                         <?php
    108                         echo $labels->other_tabs_labels['reset-list'];
    109                         ?>
    110                         </div>
    111                     <form method="post" action="admin.php?page=atwc_products_options&tab=woocom_settings" style="text-align: center;">
    112                         <button type="submit" class="<?php echo $apwp_theme; ?> shadows-btn" value="" id="reset_pr_tweet" name="reset_pr_tweet">
    113                             <?php echo $labels->other_tabs_labels['reset-button-txt']; ?></button>
    114                     </form>
    115                 </div>
    116             </div>
    117         </div>
    11854    </div>
    11955    <?php
  • auto-post-woocommerce-products/trunk/admin/auto-post-woocommerce-products-cron.php

    r2134375 r2144962  
    7171     * @return array
    7272     */
    73     private $in_cue_array;
     73    private $cued;
    7474
    7575    /**
     
    9292     */
    9393    private $product;
     94
     95    /**
     96     * Is this an automated cron posting or manual.
     97     *
     98     * @var bool
     99     * @since  2.1.4.1
     100     *
     101     * @return mixed
     102     */
     103    private $auto;
    94104
    95105    /**
     
    107117        $cued             = get_option( 'atwc_products_post' );
    108118
    109         if ( ! $posted ) {
     119        if ( ! $posted || null === $posted ) {
    110120            $posted = [];
    111121        }
    112         if ( ! $cued ) {
     122        if ( ! $cued || null === $cued ) {
    113123            $cued = [];
    114124        }
    115125
    116         $this->set_posted_array( $posted );
    117         $this->set_in_cue_array( $cued );
     126        $this->posted = $posted;
     127        $this->cued   = $cued;
    118128    }
    119129
     
    128138     */
    129139    public function apwp_run_auto_cron( $auto ) {
    130         if ( empty( $this->get_in_cue_array() ) ) {
    131             $this->set_in_cue_array( apwp_rebuild_products_array() );
    132         }
    133 
    134         $this->set_item_to_tweet( $this->in_cue_array[0] );
    135 
     140        $this->auto = $auto;
     141        $is_auto    = ( true === $auto ) ? 'true' : 'false';
     142        apwp_add_to_debug( 'Starting auto cron Twitter posting. auto = ' . $is_auto, '<span style="color: green;">CRON</span>' );
     143
     144        if ( empty( $this->cued ) ) {
     145            $_new       = apwp_set_products_array();
     146            $this->cued = $_new['prod_ids'];
     147        }
     148
     149        $_temp = $this->cued;
     150        $this->set_item_to_tweet( $_temp['0'] );
    136151        // Get woocommerce info on product.
    137152        $item = $this->product->get_product( $this->get_item_to_tweet() );
     
    140155        if ( ! $item->is_in_stock() ) {
    141156            while ( ! $item->is_in_stock() ) :
    142                 $this->remove_id_from_array( 0 );
     157                $this->remove_id_from_array();
    143158                apwp_add_to_debug( 'OUT OF STOCK! ID: ' . $this->get_item_to_tweet() . ' - ' . $item->get_title(), '<span style="color: chocolate;">CRON</span>' );
    144159                $item = $this->apwp_find_new_product();
    145 
    146                 if ( ! $item ) {
    147                     apwp_add_to_debug( 'Resetting product array.', '<span style="color: green;">CRON</span>' );
    148                     $this->set_in_cue_array( apwp_rebuild_products_array() );
    149                     $item = $this->apwp_find_new_product();
    150                 }
    151 
    152160            endwhile;
    153161        }
     
    155163        $hash  = $this->get_hashtags();
    156164        $title = $this->get_title( $item );
    157         $this->remove_id_from_array( 0 );
     165        $this->remove_id_from_array();
    158166        $_on_sale = $this->set_on_sale_percentage( $item );
    159167        $url      = $this->apwp_get_bitly_link();
    160168        $status   = $this->get_status_message( $title, $_on_sale, $hash, $url );
    161         $this->send_tweet( $status, $auto );
     169        $this->send_tweet( $status );
    162170    }
    163171
     
    170178     */
    171179    private function apwp_find_new_product() {
    172         $temp = $this->get_in_cue_array();
     180        $temp = $this->cued;
    173181
    174182        if ( count( $temp ) >= 1 ) {
     
    176184            $item = $this->product->get_product( $this->get_item_to_tweet() );
    177185        } else {
    178             apwp_set_onetime_cron( [ 'create' ] );
    179             return false;
     186            $_new = apwp_set_products_array();
     187            $temp = $_new['prod_ids'];
     188            $this->set_item_to_tweet( $temp[0] );
     189            $item       = $this->product->get_product( $temp[0] );
     190            $this->cued = $temp;
    180191        }
    181192
     
    200211     * Remove the product from the cue and place it in posted
    201212     *
    202      * @param  int $_num Number corresponds to in_cue_array[$KEY].
    203213     * @since      2.1.3.0
    204214     *
    205215     * @return mixed
    206216     */
    207     private function remove_id_from_array( $_num ) {
    208         $temp = $this->get_in_cue_array();
    209         unset( $temp[ $_num ] );
    210         $this->set_in_cue_array( array_merge( $temp ) );
    211         $temp = $this->get_posted_array();
    212         array_push( $temp, $this->get_item_to_tweet() );
    213         $this->set_posted_array( $temp );
    214         update_option( 'atwc_products_post', $this->get_in_cue_array() );
     217    private function remove_id_from_array() {
     218        apwp_add_to_debug( 'CUED: ' . count( $this->cued ) . ' POSTED: ' . count( $this->posted ) );
     219        unset( $this->cued[0] );
     220        array_push( $this->posted, $this->get_item_to_tweet() );
     221        update_option( 'atwc_products_post', array_merge( $this->cued ) );
    215222        update_option( 'atwc_last_item_tweeted', $this->get_item_to_tweet() );
    216         update_option( 'atwc_products_posted', $this->get_posted_array() );
     223        update_option( 'atwc_products_posted', $this->posted );
     224        apwp_add_to_debug( 'CUED: ' . count( $this->cued ) . ' POSTED: ' . count( $this->posted ) );
    217225    }
    218226
     
    301309            $url = get_permalink( $this->get_item_to_tweet() );
    302310            if ( ! apwp_check_local_host() ) {
    303                 apwp_add_to_debug( 'BITLY short link for #' . $this->get_item_to_tweet() . ' is empty do to invalid response from Bitly...using product url.', '<span style="color: red;">CRON</span>' );
     311                apwp_add_to_debug( 'BITLY short link for #' . $this->get_item_to_tweet() . ' is empty do to invalid response from Bitly...using long product url.', '<span style="color: chocolate;">CRON</span>' );
    304312            }
    305313        }
     
    325333     *
    326334     * @param string $status The completed posting.
    327      * @param bool   $auto Tell function if this is an automated posting or manual.
    328335     * @since        2.1.3.0
    329336     *
    330337     * @return void
    331338     */
    332     private function send_tweet( $status, $auto ) {
     339    private function send_tweet( $status ) {
    333340        $time_date = apwp_convert_time_log( time() );
     341        // Maintain logs.
     342        apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'post_log', 0, 100 );
     343        apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'error_log', 0, 300 );
     344
     345        if ( $this->auto ) { // If wp_cron initiated.
     346            set_transient( 'apwp_cron_check', 'no', HOUR_IN_SECONDS );
     347        }
     348
    334349        if ( apwp_check_local_host() ) {
    335             $this->simulate_tweet_on_localhost( $time_date, $status, $auto );
    336         } elseif ( get_option( 'atwc_twitter' ) ) {
    337             $tweet = $this->twitter_post( $status, $this->get_item_to_tweet(), $time_date );
    338 
    339             if ( $tweet ) {
    340                 // update the shared date.
    341                 apwp_update_last_shared_date( $this->get_item_to_tweet() );
    342             } else {
    343                 update_option( 'atwc_twitter_success', false );
    344             }
    345         }
    346 
    347         if ( $auto ) { // If wp_cron initiated.
    348             set_transient( 'apwp_cron_check', 'no', DAY_IN_SECONDS );
    349         }
    350 
    351         // Maintain post log.
    352         apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'post_log', 0, 100 );
    353         apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'debug.log', 0, 200 );
    354 
    355         // Install complete - prevents the refresh message from showing after activation.
    356         if ( get_option( 'apwp_current_status' ) === 'installing' ) {
    357             update_option( 'apwp_current_status', 'posted' );
    358         }
    359 
    360         apwp_set_onetime_cron( [ 'data', 'rebuild' ] );
     350            $this->simulate_tweet_on_localhost( $time_date, $status );
     351            return;
     352        }
     353
     354        $tweet = $this->twitter_post( $status, $this->get_item_to_tweet(), $time_date );
     355
     356        if ( $tweet ) {
     357            // update the shared date.
     358            apwp_update_last_shared_date( $this->get_item_to_tweet() );
     359        } else {
     360            update_option( 'atwc_twitter_success', false );
     361        }
     362        apwp_set_onetime_cron( [ 'data' ] );
    361363    }
    362364
     
    394396        }
    395397
     398        apwp_set_onetime_cron( [ 'data' ] );
    396399        file_put_contents( __DIR__ . '/post_log', '[<b>' . $time_date . '</b>] TWEETED PROD ID #' . $id . ': ' . $status . PHP_EOL, FILE_APPEND | LOCK_EX );
    397400        apwp_add_to_debug( 'TWITTER post sent successfully.', '<span style="color: green;">CRON</span>' );
     
    404407     * @param  string $time_date Current time/date for log entry.
    405408     * @param  string $status The post that was "sent".
    406      * @param  bool   $auto Manual or auto posting.
    407409     * @since         2.1.3.0
    408410     *
    409411     * @return void
    410412     */
    411     private function simulate_tweet_on_localhost( $time_date, $status, $auto ) {
     413    private function simulate_tweet_on_localhost( $time_date, $status ) {
    412414        // For testing and debugging.
    413415        apwp_update_last_shared_date( $this->get_item_to_tweet() );
    414 
    415         if ( get_option( 'apwp_current_status' ) === 'installing' ) {
    416             update_option( 'apwp_current_status', 'completed' );
    417         }
    418 
    419416        file_put_contents( APWP_PLUGIN_PATH . 'post_log', '[<b>' . $time_date . '</b>] {<span style="color: chocolate;">localhost</span>} TWEETED PROD ID #' . $this->get_item_to_tweet() . ': ' . $status . PHP_EOL, FILE_APPEND | LOCK_EX );
    420417        apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'post_log', 0, 100 );
    421         apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'debug.log', 0, 200 );
     418        apwp_trim_log_to_length( APWP_PLUGIN_PATH . 'error_log', 0, 300 );
    422419        apwp_trim_log_to_length( WP_CONTENT_DIR . '\debug.log', 0, 800 );
    423         if ( $auto ) { // If wp_cron initiated.
    424             set_transient( 'apwp_cron_check', 'no', DAY_IN_SECONDS );
    425         }
    426 
    427         apwp_set_onetime_cron( [ 'data', 'rebuild' ] );
     420        apwp_set_onetime_cron( [ 'data' ] );
    428421        apwp_add_to_debug( 'TWITTER simulated post completed.', '<span style="color: green;">CRON</span>' );
    429422    }
    430 
    431     /**
    432      * Get array holding our posted products
    433      *
    434      * @return  array
    435      */
    436     public function get_posted_array() {
    437         return $this->posted_array;
    438     }
    439 
    440     /**
    441      * Set array holding our posted products
    442      *
    443      * @param   array $posted_array  Array holding our posted products.
    444      *
    445      * @return  self
    446      */
    447     public function set_posted_array( array $posted_array ) {
    448         $this->posted_array = $posted_array;
    449         return $this;
    450     }
    451 
    452     /**
    453      * Get array holding our cued products
    454      *
    455      * @return  array
    456      */
    457     public function get_in_cue_array() {
    458         return $this->in_cue_array;
    459     }
    460 
    461     /**
    462      * Set array holding our cued products
    463      *
    464      * @param array $array_data Array holding our cued products.
    465      *
    466      * @return self
    467      */
    468     public function set_in_cue_array( $array_data ) {
    469         $this->in_cue_array = $array_data;
    470 
    471         return $this;
    472     }
    473 
    474 
    475423
    476424    /**
     
    490438     * @return self
    491439     */
    492     public function set_item_to_tweet( int $item_to_tweet ) {
    493         $this->item_to_tweet = $item_to_tweet;
     440    public function set_item_to_tweet( $item_to_tweet ) {
     441        $this->item_to_tweet = (string) $item_to_tweet;
    494442
    495443        return $this;
    496444    }
     445
    497446}
  • auto-post-woocommerce-products/trunk/admin/auto-post-woocommerce-products-settings.php

    r2134375 r2144962  
    249249    if ( !get_option( 'apwp_delete_all_settings' ) ) {
    250250        update_option( 'apwp_delete_all_settings', 'unchecked' );
    251     }
    252     if ( !get_option( 'apwp_current_status' ) ) {
    253         update_option( 'apwp_current_status', 'installing' );
    254251    }
    255252   
     
    336333        delete_post_meta_by_key( '_product_cost_other_apwp' );
    337334        delete_post_meta_by_key( '_product_cost_apwp' );
     335        delete_post_meta_by_key( '_stats_referrers_last_seven_apwp' );
     336        delete_post_meta_by_key( '_stats_referrers_today_apwp' );
     337        delete_post_meta_by_key( '_stats_referrers_last_month_apwp' );
     338        delete_post_meta_by_key( '_stats_referrers_all_time_apwp' );
    338339    }
    339340
  • auto-post-woocommerce-products/trunk/admin/auto-post-woocommerce-products-tabs.php

    r2134375 r2144962  
    2222
    2323require_once APWP_INCLUDES_PATH . 'class-apwp-hashtag.php';
     24require_once APWP_INCLUDES_PATH . 'apwp-add-social-icons.php';
    2425/**
    2526 * Display the page header portion and the selected tab page
  • auto-post-woocommerce-products/trunk/admin/class-auto-post-woocommerce-products-admin.php

    r2124737 r2144962  
    1515 * Created    Saturday, Jun-15-2019 at 13:33:29
    1616 */
     17
    1718if ( !function_exists( 'apwp_fs' ) ) {
    18     /**
    19      *  Create a helper function for easy SDK access.
    20      *
    21      * @since  2.0.0
    22      *
    23      * @return mixed
    24      */
     19    // Create a helper function for easy SDK access.
    2520    function apwp_fs()
    2621    {
     
    6156        return $apwp_fs;
    6257    }
    63 
    64 }
    65 apwp_fs();
    66 // Init Freemius.
    67 do_action( 'apwp_fs_loaded' );
    68 // Signal that SDK was initiated.
    69 /**
    70  * Plugin URL for Freemius
    71  *
    72  * @since  2.0.0
    73  *
    74  * @return mixed
    75  */
    76 function apwp_fs_settings_url()
    77 {
    78     return admin_url( '/admin.php?page=atwc_products_options&tab=twitter_settings' );
    79 }
    80 
    81 apwp_fs()->add_filter( 'connect_url', 'apwp_fs_settings_url' );
    82 apwp_fs()->add_filter( 'after_skip_url', 'apwp_fs_settings_url' );
    83 apwp_fs()->add_filter( 'after_connect_url', 'apwp_fs_settings_url' );
    84 apwp_fs()->add_filter( 'after_pending_connect_url', 'apwp_fs_settings_url' );
     58   
     59    // Init Freemius.
     60    apwp_fs();
     61    // Signal that SDK was initiated.
     62    do_action( 'apwp_fs_loaded' );
     63    function apwp_fs_settings_url()
     64    {
     65        return admin_url( '/admin.php?page=atwc_products_options&tab=twitter_settings' );
     66    }
     67   
     68    apwp_fs()->add_filter( 'connect_url', 'apwp_fs_settings_url' );
     69    apwp_fs()->add_filter( 'after_skip_url', 'apwp_fs_settings_url' );
     70    apwp_fs()->add_filter( 'after_connect_url', 'apwp_fs_settings_url' );
     71    apwp_fs()->add_filter( 'after_pending_connect_url', 'apwp_fs_settings_url' );
     72}
     73
    8574/**
    8675 *
  • auto-post-woocommerce-products/trunk/admin/css/apwp-styles.css

    r2134375 r2144962  
    1043710437.dash, .dash2 { font-weight: 500; text-align: center; padding: 0 5px 0 5px; font-size: 0.9em; font-style: italic; }
    1043810438
    10439 .dash2 { font-size: 1em; }
     10439.dash2 { font-size: 1em; color: #111; font-style: normal; font-weight: bold; }
    1044010440
    1044110441td.dash-apwp2-sale { color: green; font-weight: 700; }
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-add-social-icons.php

    r2122132 r2144962  
    4040    foreach ( $inventory as $product ) {
    4141       
    42         if ( (string) $product['id'] === $last_id ) {
     42        if ( $product['id'] === $last_id ) {
    4343            $prod = $product;
    4444            break;
     
    8585    $tumblr = $links['tumblr'];
    8686   
    87     if ( !apwp_check_local_host() && !is_ssl() ) {
     87    if ( !apwp_check_local_host() && is_ssl() ) {
    8888        if ( apwp_fs()->is_not_paying() ) {
    8989            $repost = '</span><table style="width: 75%; margin-left: 18%;"><tr><td>' . $twit_url . '</td><td>&nbsp;</td><td>' . $fb_url . '</td></tr><tr><td>' . $tumblr . '</td></tr></table>';
     
    110110function apwp_get_social_links( $data )
    111111{
    112     $sh_url = $data['short_url'];
     112    $sh_url = urlencode_deep( $data['short_url'] );
    113113    $url = $data['url'];
    114114    $last_id = $data['last_id'];
    115     $desc = $data['desc'];
     115    $desc = urlencode_deep( $data['desc'] );
    116116    $image = $data['image'];
    117117    $_twit_tags = $data['_twit_tags'];
     
    126126        <div id="fb-root"></div>
    127127        <script>
    128         (function(d, s, id) {
    129             var js, fjs = d.getElementsByTagName(s)[0];
    130             if (d.getElementById(id))
    131                 return;
     128            (function(d, s, id) {
     129                var js, fjs = d.getElementsByTagName(s)[0];
     130                if (d.getElementById(id))
     131                    return;
     132                js = d.createElement(s);
     133                js.id = id;
     134                js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0&appId=<?php
     135    echo  $val ;
     136    ?>&autoLogAppEvents=1';
     137                fjs.parentNode.insertBefore(js, fjs);
     138            }(document, 'script', 'facebook-jssdk'));
     139        </script>
     140        <script id="tumblr-js" async src="https://assets.tumblr.com/share-button.js"></script>
     141        <script type="text/javascript" async defer src="//assets.pinterest.com/js/pinit.js"></script>
     142        <script>
     143            window.twttr = (function(d, s, id) {
     144            var js, fjs = d.getElementsByTagName(s)[0],
     145            t = window.twttr || {};
     146            if (d.getElementById(id)) return t;
    132147            js = d.createElement(s);
    133148            js.id = id;
    134             js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0&appId=<?php
    135     echo  $val ;
    136     ?>&autoLogAppEvents=1';
     149            js.src = "https://platform.twitter.com/widgets.js";
    137150            fjs.parentNode.insertBefore(js, fjs);
    138         }(document, 'script', 'facebook-jssdk'));
     151
     152            t._e = [];
     153            t.ready = function(f) {
     154            t._e.push(f);
     155            };
     156
     157            return t;
     158        }(document, "script", "twitter-wjs"));
    139159        </script>
    140 
    141160        <?php
    142     $fb_url = '<div class="fb-share-button" data-href="' . $sh_url . '" data-layout="button" data-size="large" data-mobile-iframe="true"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . urlencode_deep( $sh_url ) . '&amp;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>';
     161    $fb_url = '<div class="fb-share-button" data-href="' . $url . '" data-layout="button" data-size="large"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . urlencode_deep( $sh_url ) . '&amp;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>';
    143162    // twitter.
    144     $twit_url = '<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-size="large" data-text="' . $desc . '" data-url="' . $sh_url . '" data-hashtags="' . $_twit_tags . '" data-show-count="false">Tweet</a>';
     163    $twit_url = "<a href='https://twitter.com/share?ref_src=twsrc%5Etfw&text={$desc}&url={$sh_url}&hashtags={$_twit_tags}' class='twitter-share-button' data-show-count='false'>Tweet</a><script async src='https://platform.twitter.com/widgets.js' charset='utf-8'></script>";
    145164    // Tumblr.
    146165    $tumblr = "<a class='tumblr-share-button' data-color='blue' data-notes='none' href='https://www.tumblr.com/widgets/share/tool?canonicalUrl={$url}&tags={$tum_hashtgs}&title={$title}&posttype=link&content={$sh_url}&caption={$caption}'></a>";
     
    160179    ];
    161180}
    162 
    163 /**
    164  * Enqueue social media scripts
    165  *
    166  * @since  1.0.0
    167  *
    168  * @return mixed
    169  */
    170 function apwp_enqueue_social_scripts()
    171 {
    172     wp_enqueue_script(
    173         'apwp-pinterest-script',
    174         'http://assets.pinterest.com/js/pinit.js#asyncload',
    175         [ 'jquery' ],
    176         APWP_VERSION,
    177         true
    178     );
    179     wp_enqueue_script(
    180         'apwp-tumblr-script',
    181         'https://assets.tumblr.com/share-button.js#asyncload',
    182         [ 'jquery' ],
    183         APWP_VERSION,
    184         true
    185     );
    186     wp_enqueue_script(
    187         'apwp-twitter-script',
    188         'https://platform.twitter.com/widgets.js#asyncload',
    189         [ 'jquery' ],
    190         APWP_VERSION,
    191         true
    192     );
    193 }
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-check-setup.php

    r2124737 r2144962  
    6767
    6868        if ( filter_input( INPUT_POST, 'reset_pr_tweet' ) ) {
    69                 apwp_set_onetime_cron( [ 'create' ] );
     69            apwp_set_products_array();
    7070        }
    7171
     
    8585                    update_option( APWP_SCHEDULE_PAGE, 'pause_schedule' );
    8686                    $apwp_current_sched = 'pause_schedule';
    87                     $cron->atwc_delete_schedule();
     87                    apwp_deactivate_apwp_cron();
    8888            }
    8989        }
     
    214214                apwp_set_onetime_cron( [ 'data' ] );
    215215            }
    216             if ( empty( get_option( 'atwc_products_post' ) ) ) {
    217                 apwp_set_onetime_cron( [ 'rebuild' ] );
    218             }
    219 
    220216                return true;
    221217        }
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-dashboard-widget.php

    r2124737 r2144962  
    227227        $cron = new Apwp_Cron_Functions();
    228228        $_sched = wp_get_schedules();
    229         $timestamp = $cron->get_next_cron_run();
     229        $timestamp = wp_next_scheduled( 'auto_post_woo_prod_cron' );
    230230        $_time_format = get_option( 'time_format' );
    231231        $_date_format = 'd-M-Y ' . $_time_format;
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-debug.php

    r2134375 r2144962  
    199199                    <?php
    200200        $this->apwp_get_reset_button();
     201        $this->apwp_display_autopost_reset();
    201202        ?>
    202203                    <a id="apwpinfo"></a>
     
    320321        global  $apwp_current_sched ;
    321322        $_schedules = wp_get_schedules();
    322        
     323        $my_schedule = 'PAUSED';
    323324        if ( 'pause_schedule' !== $apwp_current_sched ) {
    324             $my_schedule = $_schedules[$apwp_current_sched]['display'];
    325         } else {
    326             $my_schedule = 'PAUSED';
    327         }
    328        
     325            if ( in_array( $apwp_current_sched, $_schedules, true ) ) {
     326                $my_schedule = $_schedules[$apwp_current_sched]['display'];
     327            }
     328        }
    329329        $cron = new Apwp_Cron_Functions();
    330330        ?>
     
    344344                <td class="debug-label">Next Posting </td>
    345345                <td class="debug-data"><?php
    346         echo  ( $cron->get_next_cron_run() ? apwp_convert_time( $cron->get_next_cron_run() ) : 'n/a' ) ;
     346        echo  ( wp_next_scheduled( 'auto_post_woo_prod_cron' ) ? apwp_convert_time( wp_next_scheduled( 'auto_post_woo_prod_cron' ) ) : 'n/a' ) ;
    347347        ?></td>
    348348            </tr>
     
    933933        ?>
    934934            </div><br />
    935             <div>
     935            <div><span style="font-weight: bold;">
    936936            <?php
    937937        echo  $this->label->other_tabs_labels['reset-plugin-desc2'] ;
    938938        ?>
    939             </div>
     939            </span></div>
    940940        </div><br />
    941941        <div style="text-align:center;">
     
    953953   
    954954    /**
     955     * Undocumented function
     956     *
     957     * @since  1.0.0
     958     *
     959     * @return mixed
     960     */
     961    public function apwp_display_autopost_reset()
     962    {
     963        global  $apwp_theme ;
     964        $labels = new Apwp_Labels();
     965        $ttl = get_option( 'apwp_total_products_to_tweet' );
     966        $prod_to_post = 0;
     967       
     968        if ( get_option( 'atwc_products_post' ) ) {
     969            $prod_to_post = get_option( 'atwc_products_post' );
     970           
     971            if ( empty($prod_to_post) ) {
     972                $prod_to_post = 0;
     973                apwp_set_onetime_cron( [ 'create' ] );
     974            } else {
     975                $prod_to_post = count( get_option( 'atwc_products_post' ) );
     976            }
     977       
     978        }
     979       
     980        ?>
     981        </div>
     982        <div class="debug-split-container debug-instructions" style="margin-top: 5px;">
     983            <div class="qstart-heading">
     984                <?php
     985        echo  $labels->other_tabs_labels['current-post-data'] ;
     986        ?>
     987                </div>
     988            <table style="width: 100%; margin-top: 3px;">
     989                <tr>
     990                    <td style="width: 50%; text-align: center;">
     991                        <div class="other-items-clicks-green">
     992                            <span class="other-numbers2">
     993                                <?php
     994        echo  number_format_i18n( $ttl ) ;
     995        ?></span></div>
     996                        <br /><span class="dash2">
     997                            <?php
     998        echo  _n(
     999            'Product to Tweet',
     1000            'Products to Tweet',
     1001            $ttl,
     1002            'auto-post-woocommerce-products'
     1003        ) ;
     1004        ?>
     1005                            </span>
     1006                    </td>
     1007                    <td style="width: 50%; text-align: center;">
     1008                        <div class="low-items">
     1009                            <span class="other-numbers2">
     1010                                <?php
     1011        echo  number_format_i18n( $prod_to_post ) ;
     1012        ?></span></div>
     1013                        <br /><span class="dash2">
     1014                            <?php
     1015        echo  $labels->other_tabs_labels['scheduled-tweet'] ;
     1016        ?>
     1017                            </span>
     1018                    </td>
     1019                </tr>
     1020            </table>
     1021            <hr />
     1022            <div class="debug-inst">
     1023                <?php
     1024        echo  $labels->other_tabs_labels['auto-post-desc'] ;
     1025        ?>
     1026                <br /><br />
     1027                <?php
     1028        echo  $labels->other_tabs_labels['posting-info'] ;
     1029        ?>
     1030                <hr />
     1031                <div class="subtitle-apwp" style="text-align: center; padding-bottom: 10px;">
     1032                    <?php
     1033        echo  $labels->other_tabs_labels['reset-list'] ;
     1034        ?>
     1035                    </div>
     1036                <form method="post" action="admin.php?page=atwc_products_options&tab=debug" style="text-align: center;">
     1037                    <button type="submit" class="<?php
     1038        echo  $apwp_theme ;
     1039        ?> shadows-btn" value="reset_pr_tweet" id="reset_pr_tweet" name="reset_pr_tweet">
     1040                        <?php
     1041        echo  $labels->other_tabs_labels['reset-button-txt'] ;
     1042        ?></button>
     1043                </form><br/>
     1044            </div>
     1045        </div>
     1046    </div>
     1047</div>
     1048        <?php
     1049    }
     1050   
     1051    /**
    9551052     * Get for displaying UNCHECKED in the list
    9561053     *
     
    9691066     * @return self
    9701067     */
    971     public function set_unchecked( string $unchecked )
     1068    public function set_unchecked( $unchecked )
    9721069    {
    9731070        $this->get_unchecked = $unchecked;
     
    9921089     * @return self
    9931090     */
    994     public function set_checked( string $checked )
     1091    public function set_checked( $checked )
    9951092    {
    9961093        $this->get_checked = $checked;
     
    10151112     * @return self
    10161113     */
    1017     public function set_false( string $false )
     1114    public function set_false( $false )
    10181115    {
    10191116        $this->false = $false;
     
    10381135     * @return  self
    10391136     */
    1040     public function set_true( string $true )
     1137    public function set_true( $true )
    10411138    {
    10421139        $this->true = $true;
     
    10611158     * @return  self
    10621159     */
    1063     public function set_ok( string $ok )
     1160    public function set_ok( $ok )
    10641161    {
    10651162        $this->ok = $ok;
     
    10841181     * @return  self
    10851182     */
    1086     public function set_attention( string $attention )
     1183    public function set_attention( $attention )
    10871184    {
    10881185        $this->attention = $attention;
     
    11071204     * @return self
    11081205     */
    1109     public function set_error( string $error )
     1206    public function set_error( $error )
    11101207    {
    11111208        $this->error = $error;
     
    11301227     * @return self
    11311228     */
    1132     public function set_no( string $no )
     1229    public function set_no( $no )
    11331230    {
    11341231        $this->no = $no;
     
    11531250     * @return self
    11541251     */
    1155     public function set_yes( string $yes )
     1252    public function set_yes( $yes )
    11561253    {
    11571254        $this->yes = $yes;
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-inventory-update-functions.php

    r2134375 r2144962  
    112112                break;
    113113            case 'create':
    114                 delete_transient( 'apwp_create_product_array_check' );
     114                apwp_set_products_array();
    115115                break;
    116116            case 'on_sale':
     
    278278            if ( !$_enabled ) {
    279279                unset( $in_que[$value['id']], $posted[$value['id']] );
     280                array_merge( $in_que );
     281                array_merge( $posted );
    280282                continue;
    281283            }
     
    301303   
    302304    }
    303     $in_que = array_merge( $in_que );
    304305    update_option( 'apwp_auto_post_products_list', $my_array );
    305     update_option( 'atwc_products_post', $in_que );
     306    update_option( 'atwc_products_post', array_merge( $in_que ) );
    306307    update_option( 'atwc_products_posted', array_merge( $posted ) );
    307308    set_transient( 'apwp_rebuild_product_array_check', 'x', 30 * MINUTE_IN_SECONDS );
    308     return $in_que;
     309    return array_merge( $in_que );
    309310}
    310311
     
    320321{
    321322    $my_products = get_transient( 'apwp_prod_list_data' );
     323    update_option( 'atwc_products_post', [] );
     324    update_option( 'atwc_products_posted', [] );
    322325    $products_to_tweet = [];
    323326    $auto_list = [];
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-list-table-functions.php

    r2134375 r2144962  
    17941794 * If using premium plan, get recent click data
    17951795 *
    1796  * @param int    $product_id Product ID.
     1796 * @param int    $id Product ID.
    17971797 * @param string $prod_type Product type.
    17981798 *
    17991799 * @return int
    18001800 */
    1801 function apwp__get_recent_clicks( $product_id, $prod_type )
    1802 {
    1803     $data = '';
    1804     return $data;
    1805 }
    1806 
    1807 /**
    1808  * If using premium plan, get today's click data
    1809  *
    1810  * @param int    $product_id Product ID.
     1801function apwp__get_recent_clicks( $id, $prod_type )
     1802{
     1803    if ( 'variation' === $prod_type ) {
     1804        return '';
     1805    }
     1806}
     1807
     1808/**
     1809 * If using premium plan, get today's click data.
     1810 *
     1811 * @param int    $id Product ID.
    18111812 * @param string $prod_type Product type.
    18121813 *
    18131814 * @return int
    18141815 */
    1815 function apwp__get_today_clicks( $product_id, $prod_type )
    1816 {
    1817     $data = '';
    1818     return $data;
     1816function apwp__get_today_clicks( $id, $prod_type )
     1817{
     1818    if ( 'variation' === $prod_type ) {
     1819        return '';
     1820    }
    18191821}
    18201822
     
    18221824 * If using premium plan, get total click data
    18231825 *
    1824  * @param int    $product_id Product ID.
     1826 * @param int    $id Product ID.
    18251827 * @param string $prod_type Product type.
    18261828 *
    18271829 * @return int
    18281830 */
    1829 function apwp__get_clicks( $product_id, $prod_type )
    1830 {
    1831     $data = '';
    1832     return $data;
     1831function apwp__get_clicks( $id, $prod_type )
     1832{
     1833    if ( 'variation' === $prod_type ) {
     1834        return '';
     1835    }
    18331836}
    18341837
     
    18361839 * If using premium plan, get click data for last 30 days
    18371840 *
    1838  * @param int    $product_id Product ID.
     1841 * @param int    $id Product ID.
    18391842 * @param string $prod_type Product type.
    18401843 *
    18411844 * @return int
    18421845 */
    1843 function apwp__get_last30_clicks( $product_id, $prod_type )
    1844 {
    1845     $data = '';
    1846     return $data;
     1846function apwp__get_last30_clicks( $id, $prod_type )
     1847{
     1848    if ( 'variation' === $prod_type ) {
     1849        return '';
     1850    }
    18471851}
    18481852
  • auto-post-woocommerce-products/trunk/admin/includes/apwp-quick-edit.php

    r2134375 r2144962  
    245245           
    246246            if ( !$errors ) {
    247                 apwp_set_onetime_cron( [
    248                     'rebuild',
    249                     'data',
    250                     'on_sale',
    251                     'cats'
    252                 ] );
     247                apwp_set_onetime_cron( [ 'data', 'on_sale', 'cats' ] );
    253248                wp_safe_redirect( $link );
    254249                return;
  • auto-post-woocommerce-products/trunk/admin/includes/class-apwp-cron-functions.php

    r2134375 r2144962  
    2929{
    3030    /**
    31      * Get the next time cron is scheduled
    32      *
    33      * @since        1.0.0
    34      *
    35      * @return mixed Timestamp on success and DISABLED on failure.
    36      */
    37     public function get_next_cron_run()
    38     {
    39         $time_next_cron = wp_next_scheduled( 'auto_post_woo_prod_cron' );
    40         return $time_next_cron;
    41     }
    42    
    43     /**
    44      * Delete the cron events/schedules
    45      *
    46      * @since  1.0.0
    47      *
    48      * @return void
    49      */
    50     public function atwc_delete_schedule()
    51     {
    52         $timestamp = wp_next_scheduled( 'auto_post_woo_prod_cron' );
    53         wp_unschedule_event( $timestamp, 'auto_post_woo_prod_cron' );
    54         wp_clear_scheduled_hook( 'auto_post_woo_prod_cron' );
    55     }
    56    
    57     /**
    5831     * Update cron schedule when changes are made
    5932     *
     
    6841        $opt = get_option( APWP_SCHEDULE_PAGE );
    6942        $apwp_current_sched = $opt;
    70         $this->atwc_delete_schedule();
     43        \apwp_deactivate_apwp_cron();
    7144       
    7245        if ( 'pause_schedule' === $apwp_current_sched ) {
     
    7649            $next = $_sched[$apwp_current_sched]['interval'];
    7750           
    78             if ( !$this->get_next_cron_run() ) {
     51            if ( !wp_next_scheduled( 'auto_post_woo_prod_cron' ) ) {
    7952                wp_schedule_single_event( time(), 'auto_post_woo_prod_cron', array( false ) );
    8053                wp_schedule_event( time() + $next, $apwp_current_sched, 'auto_post_woo_prod_cron' );
     
    8861// Hook into WP Cron to run postings.
    8962add_filter( 'cron_schedules', 'apwp_add_schedules' );
    90 add_action( 'auto_post_woo_prod_cron', 'apwp_run_cron' );
     63add_action(
     64    'auto_post_woo_prod_cron',
     65    'apwp_run_cron',
     66    10,
     67    1
     68);
    9169/**
    9270 * For accessing and running our auto posting cron job
     
    11694    wp_unschedule_event( $timestamp, 'auto_post_woo_prod_cron' );
    11795    wp_clear_scheduled_hook( 'auto_post_woo_prod_cron' );
    118 }
    119 
    120 /**
    121  * Disable Twitter auto posting
    122  *
    123  * @since  2.0.3
    124  *
    125  * @return void
    126  */
    127 function apwp_disable_twitter_auto_post()
    128 {
    129     $cron = new Apwp_Cron_Functions();
    130     $cron->atwc_delete_schedule();
    131 }
    132 
    133 /**
    134  * Enable Twitter auto posting
    135  *
    136  * @since  2.0.3
    137  *
    138  * @return bool
    139  */
    140 function apwp_enable_twitter_auto_post()
    141 {
    142     $click_data = new Apwp_Short_Links();
    143     $click_data->set_bitly_array();
    144     return true;
    14596}
    14697
  • auto-post-woocommerce-products/trunk/admin/includes/class-apwp-labels.php

    r2134375 r2144962  
    142142    private function set_quick_start_updates_array() {
    143143        $labels = [
    144             '1' => __( 'Corrected issue for the error "Call to a member function get_category_ids() on boolean". ', 'auto-post-woocommerce-products' ),
    145             '2' => __( 'Corrected issue for Auto post list refreshing before all auto post products have been posted to Twitter. ', 'auto-post-woocommerce-products' ),
     144            '1' => __( 'Corrected Twitter auto posting issue.', 'auto-post-woocommerce-products' ),
     145            '2' => __( 'Updated to use new Bitly API v4 and corrected previous Bitly errors.', 'auto-post-woocommerce-products' ),
     146            '3' => __( 'Pinterest should now show the sale price when product is on sale.', 'auto-post-woocommerce-products' ),
     147            '4' => __( 'Fixed issue with "sharing buttons" not showing on the individual sharing page.', 'auto-post-woocommerce-products' ),
     148            '5' => __( 'Moved the RESET AUTO POST PRODUCTS box from the categories tab to the STATUS tab.', 'auto-post-woocommerce-products' ),
    146149
    147150        ];
     
    353356                esc_url(
    354357                    'https://www.cilcreations.com/apwp/knowledgebase/settings-tab/'
    355                 )
    356             ),
    357 
    358             'additional-help-curl-link'       => sprintf(
    359                 wp_kses(
    360                     /* translators: %s: url */ __(
    361                         'For additional information, <a href="%s" title="https://www.cilcreations.com/apwp/knowledgebase/enable-curl-via-the-php-ini-file/" target="_blank">see this knowledge base article</a>.',
    362                         'auto-post-woocommerce-products'
    363                     ),
    364                     [
    365                         'a' =>
    366                             [
    367                                 'href'   => [],
    368                                 'target' => [],
    369                             ],
    370                     ]
    371                 ),
    372                 esc_url(
    373                     'https://www.cilcreations.com/apwp/knowledgebase/enable-curl-via-the-php-ini-file/'
    374358                )
    375359            ),
     
    10671051            'reset-plugin'             => __( 'APWCP Reset plugin', 'auto-post-woocommerce-products' ),
    10681052            'reset-plugin-desc1'       => __( 'In the event this plugin is not functioning correctly, you may click the button below to reset certain items. The reset items will be erased and recreated, hopefully correcting your issue. Before proceeding with the reset, please clear your browser cache by pressing and holding the CTRL+SHIFT+DELETE keys on your keyboard.', 'auto-post-woocommerce-products' ),
    1069             'reset-plugin-desc2'       => __( 'The items to be reset will be: <em>product list temporary data files, auto posting, auto posting products list and product list view filters/settings.', 'auto-post-woocommerce-products' ),
     1053            'reset-plugin-desc2'       => __( 'The items to be reset will be: product list temporary data files, auto posting, auto posting products list and product list view filters/settings.', 'auto-post-woocommerce-products' ),
    10701054            'reset-plugin-sub'         => __( 'Resetting plugin', 'auto-post-woocommerce-products' ),
    10711055            'scheduled-tweet'          => __( 'Scheduled to Tweet', 'auto-post-woocommerce-products' ),
     
    15021486            'quick-start11'            => __( 'Finally, click on the Schedule tab. Scroll down the page until you see the section "Set your schedule". Select how often you would like to automatically post a product to Twitter and save. You are now setup and your CRON schedule is activated! Your first auto post to Twitter has been sent.', 'auto-post-woocommerce-products' ),
    15031487            'quick-start2'             => __( 'Simply press Ctrl Shift Delete on your keyboard, holding all three buttons down to open the browser window for erasing temporary internet files. When you have the window open, make sure the option for CACHE is checked and any others you would like the browser to delete. Refresh the page and everything should look fine.', 'auto-post-woocommerce-products' ),
    1504             'quick-start3'             => __( 'If you are seeing the above error regarding your Apache server cURL installation, please click the link in the error box for instructions on enabling this module. This is required for auto posting to function.', 'auto-post-woocommerce-products' ),
    15051488            'quick-start4'             => __( 'If this is the first time you have installed this plugin, you should be seeing the following messages on your screen:', 'auto-post-woocommerce-products' ),
    15061489            'quick-start5'             => __( 'This message is telling you to enter the Twitter and Bitly API access codes. To get your codes, click on the Settings tab, scroll to the bottom and then click on the link to create a Twitter App. If you wish to skip setting this up, you may disable the Twitter auto posting feature on the', 'auto-post-woocommerce-products' ),
  • auto-post-woocommerce-products/trunk/admin/includes/class-apwp-short-links.php

    r2134375 r2144962  
    1818 * Includes
    1919 */
    20 require_once APWP_PLUGIN_PATH . 'src/Bitly/bitly-new.php';
     20require_once APWP_PLUGIN_PATH . 'src/bitly-api.php';
    2121register_deactivation_hook( __FILE__, 'apwp_deactivate_bitly_update_data' );
    2222register_activation_hook( __FILE__, 'apwp_activate_bitly_update_data' );
     
    3434{
    3535    /**
    36      * Bitly access token.
    37      *
    38      * @since 2.1.2.0
    39      *
    40      * @var type string
    41      */
    42     protected  $bit_token = '' ;
    43     /**
    4436     * Construct
    4537     *
     
    5547            // Prevents this from executing during testing.
    5648        }
    57        
    58         $option = get_option( 'atwc_products_twitter_options_page' );
    59         $this->bit_token = $option['bitly_code'];
    60        
    61         if ( !$this->bit_token || '' === $this->bit_token ) {
    62             apwp_add_to_debug( 'BITLY token not found.', '<span style="color: red;">BITLY</span>' );
    63             return;
    64         }
    6549   
    6650    }
     
    6953     * Retrieve short url
    7054     *
    71      * @since 1.0.0
     55     * @since 2.1.4.4
    7256     * @param string $url Product url.
    7357     *
     
    7660    public function bitly_get_short_url( $url )
    7761    {
    78        
    79         if ( apwp_check_local_host() ) {
    80             return '';
    81             // Prevents this from executing during testing.
    82         }
    83        
    84         $s_url = $this->bitly_url_shorten( $url, $this->bit_token );
     62        $bitly_api = new APWP_BITLY_API();
     63        $s_url = $bitly_api->apwp_get_bitly_link( $url );
    8564        $sh_url = trim( $s_url );
    86        
    87         if ( 'empty' === $s_url ) {
    88             apwp_add_to_debug( 'BITLY DID NOT RETURN A PROPER RESPONSE.', '<span style="color: red;">BITLY</span>' );
    89             $sh_url = '';
    90             // If bitly error then use the full url.
    91         }
    92        
    93        
    94         if ( 'no_token' === $s_url ) {
    95             apwp_add_to_debug( 'BITLY token not found.', '<span style="color: red;">BITLY</span>' );
    96             $sh_url = '';
    97         }
    98        
    9965        return $sh_url;
    100     }
    101    
    102     /**
    103      * Shorten long url with Bitly.
    104      *
    105      * @since 1.0.0
    106      *
    107      * @param string $long_url Product long url.
    108      *
    109      * @return string short url Product Bitly link.
    110      */
    111     public function bitly_url_shorten( $long_url )
    112     {
    113        
    114         if ( apwp_check_local_host() ) {
    115             return;
    116             // Prevents this from executing during testing.
    117         }
    118        
    119         $result = [];
    120         $bitly = new Bitly2( null, null, $this->bit_token );
    121         // Create new Bitly API client.
    122         $result = $bitly->shorten( $long_url );
    123         if ( isset( $result['data'] ) ) {
    124             apwp_add_to_debug( $result['data'], '<span style="color: chocolate;">BITLY</span>' );
    125         }
    126        
    127         if ( isset( $result ) ) {
    128             return $result['url'];
    129         } else {
    130             return 'empty';
    131         }
    132    
    13366    }
    13467
  • auto-post-woocommerce-products/trunk/admin/includes/display-quick-start-tab.php

    r2121574 r2144962  
    1414 * Created    Tuesday, Jun-18-2019 at 02:01:12
    1515 */
    16 
     16require_once APWP_PLUGIN_PATH . 'src/bitly-api.php';
    1717/**
    1818 * Quick start tab
     
    9696                </p>
    9797            <p class="apwp-para">
    98                 <div style="text-align: center;">
    99                     <img alt="" class="apwp-setup" src="<?php echo $img_pth . 'error4.png'; ?>" />
    100                 </div>
    10198                <a id="twitter"></a>
    102                 <p class="apwp-para">
    103                     <?php
    104                     echo $label->product_list_labels['quick-start3'] . ' ';
    105                     echo $label->link_labels['additional-help-curl-link'];
    106                     ?>
    107                     </p>
    108 
    10999                <p class="apwp-quick-start-sub">>>
    110100                    <?php
  • auto-post-woocommerce-products/trunk/admin/src/Twitter/OAuth.php

    r1900832 r2144962  
    2323OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    2424THE SOFTWARE.
    25 */
     25 */
    2626
    2727/* Generic exception class
    2828 */
    29 class Twitter_OAuthException extends Exception
    30 {
     29class Twitter_OAuthException extends Exception {
    3130    // pass
    3231}
    3332
    34 class Twitter_OAuthConsumer
    35 {
     33class Twitter_OAuthConsumer {
     34    /**
     35     * @var mixed
     36     */
    3637    public $key;
     38    /**
     39     * @var mixed
     40     */
    3741    public $secret;
    3842
    39 
    40     public function __construct($key, $secret, $callback_url = null)
    41     {
    42         $this->key = $key;
    43         $this->secret = $secret;
     43    /**
     44     * @param $key
     45     * @param $secret
     46     * @param $callback_url
     47     */
     48    public function __construct( $key, $secret, $callback_url = null ) {
     49        $this->key          = $key;
     50        $this->secret       = $secret;
    4451        $this->callback_url = $callback_url;
    4552    }
    4653
    47 
    48     public function __toString()
    49     {
     54    public function __toString() {
    5055        return "OAuthConsumer[key=$this->key,secret=$this->secret]";
    5156    }
    5257}
    5358
    54 class Twitter_OAuthToken
    55 {
     59class Twitter_OAuthToken {
    5660    // access tokens and request tokens
     61    /**
     62     * @var mixed
     63     */
    5764    public $key;
     65    /**
     66     * @var mixed
     67     */
    5868    public $secret;
    59 
    6069
    6170    /**
     
    6372     * secret = the token secret
    6473     */
    65     public function __construct($key, $secret)
    66     {
    67         $this->key = $key;
     74    public function __construct( $key, $secret ) {
     75        $this->key    = $key;
    6876        $this->secret = $secret;
    6977    }
    70 
    7178
    7279    /**
     
    7481     * would respond to request_token and access_token calls with
    7582     */
    76     public function to_string()
    77     {
     83    public function to_string() {
    7884        return 'oauth_token=' .
    79                     Twitter_OAuthUtil::urlencode_rfc3986($this->key) .
    80                     '&oauth_token_secret=' .
    81                     Twitter_OAuthUtil::urlencode_rfc3986($this->secret);
    82     }
    83 
    84 
    85     public function __toString()
    86     {
     85        Twitter_OAuthUtil::urlencode_rfc3986( $this->key ) .
     86        '&oauth_token_secret=' .
     87        Twitter_OAuthUtil::urlencode_rfc3986( $this->secret );
     88    }
     89
     90    /**
     91     * @return mixed
     92     */
     93    public function __toString() {
    8794        return $this->to_string();
    8895    }
     
    93100 * See section 9 ("Signing Requests") in the spec
    94101 */
    95 abstract class Twitter_OAuthSignatureMethod
    96 {
     102abstract class Twitter_OAuthSignatureMethod {
    97103    /**
    98104     * Needs to return the name of the Signature Method (ie HMAC-SHA1)
     
    100106     */
    101107    abstract public function get_name();
    102 
    103108
    104109    /**
     
    112117     * @return string
    113118     */
    114     abstract public function build_signature($request, $consumer, $token);
    115 
     119    abstract public function build_signature( $request, $consumer, $token );
    116120
    117121    /**
     
    123127     * @return bool
    124128     */
    125     public function check_signature($request, $consumer, $token, $signature)
    126     {
    127         $built = $this->build_signature($request, $consumer, $token);
     129    public function check_signature( $request, $consumer, $token, $signature ) {
     130        $built = $this->build_signature( $request, $consumer, $token );
     131
    128132        return $built == $signature;
    129133    }
     
    137141 *   - Chapter 9.2 ("HMAC-SHA1")
    138142 */
    139 class Twitter_OAuthSignatureMethod_HMAC_SHA1 extends Twitter_OAuthSignatureMethod
    140 {
    141     public function get_name()
    142     {
     143class Twitter_OAuthSignatureMethod_HMAC_SHA1 extends Twitter_OAuthSignatureMethod {
     144    public function get_name() {
    143145        return 'HMAC-SHA1';
    144146    }
    145147
    146 
    147     public function build_signature($request, $consumer, $token)
    148     {
    149         $base_string = $request->get_signature_base_string();
     148    /**
     149     * @param $request
     150     * @param $consumer
     151     * @param $token
     152     */
     153    public function build_signature( $request, $consumer, $token ) {
     154        $base_string          = $request->get_signature_base_string();
    150155        $request->base_string = $base_string;
    151156
    152157        $key_parts = [
    153158            $consumer->secret,
    154             ($token) ? $token->secret : '',
     159            ( $token ) ? $token->secret : '',
    155160        ];
    156161
    157         $key_parts = Twitter_OAuthUtil::urlencode_rfc3986($key_parts);
    158         $key = implode('&', $key_parts);
    159 
    160         return base64_encode(hash_hmac('sha1', $base_string, $key, true));
     162        $key_parts = Twitter_OAuthUtil::urlencode_rfc3986( $key_parts );
     163        $key       = implode( '&', $key_parts );
     164
     165        return base64_encode( hash_hmac( 'sha1', $base_string, $key, true ) );
    161166    }
    162167}
     
    167172 *   - Chapter 9.4 ("PLAINTEXT")
    168173 */
    169 class Twitter_OAuthSignatureMethod_PLAINTEXT extends Twitter_OAuthSignatureMethod
    170 {
    171     public function get_name()
    172     {
     174class Twitter_OAuthSignatureMethod_PLAINTEXT extends Twitter_OAuthSignatureMethod {
     175    public function get_name() {
    173176        return 'PLAINTEXT';
    174177    }
    175 
    176178
    177179    /**
     
    184186     * OAuthRequest handles this!
    185187     */
    186     public function build_signature($request, $consumer, $token)
    187     {
     188    public function build_signature( $request, $consumer, $token ) {
    188189        $key_parts = [
    189190            $consumer->secret,
    190             ($token) ? $token->secret : '',
     191            ( $token ) ? $token->secret : '',
    191192        ];
    192193
    193         $key_parts = Twitter_OAuthUtil::urlencode_rfc3986($key_parts);
    194         $key = implode('&', $key_parts);
     194        $key_parts            = Twitter_OAuthUtil::urlencode_rfc3986( $key_parts );
     195        $key                  = implode( '&', $key_parts );
    195196        $request->base_string = $key;
    196197
     
    207208 *   - Chapter 9.3 ("RSA-SHA1")
    208209 */
    209 abstract class Twitter_OAuthSignatureMethod_RSA_SHA1 extends Twitter_OAuthSignatureMethod
    210 {
    211     public function get_name()
    212     {
     210abstract class Twitter_OAuthSignatureMethod_RSA_SHA1 extends Twitter_OAuthSignatureMethod {
     211    public function get_name() {
    213212        return 'RSA-SHA1';
    214213    }
    215 
    216214
    217215    // Up to the SP to implement this lookup of keys. Possible ideas are:
     
    221219    //
    222220    // Either way should return a string representation of the certificate
    223     abstract protected function fetch_public_cert(&$request);
    224 
     221    /**
     222     * @param $request
     223     */
     224    abstract protected function fetch_public_cert( &$request );
    225225
    226226    // Up to the SP to implement this lookup of keys. Possible ideas are:
     
    228228    //
    229229    // Either way should return a string representation of the certificate
    230     abstract protected function fetch_private_cert(&$request);
    231 
    232 
    233     public function build_signature($request, $consumer, $token)
    234     {
     230    /**
     231     * @param $request
     232     */
     233    abstract protected function fetch_private_cert( &$request );
     234
     235    /**
     236     * @param $request
     237     * @param $consumer
     238     * @param $token
     239     */
     240    public function build_signature( $request, $consumer, $token ) {
     241        $base_string          = $request->get_signature_base_string();
     242        $request->base_string = $base_string;
     243
     244        // Fetch the private key cert based on the request
     245        $cert = $this->fetch_private_cert( $request );
     246
     247        // Pull the private key ID from the certificate
     248        $privatekeyid = openssl_get_privatekey( $cert );
     249
     250        // Sign using the key
     251        $ok = openssl_sign( $base_string, $signature, $privatekeyid );
     252
     253        // Release the key resource
     254        openssl_free_key( $privatekeyid );
     255
     256        return base64_encode( $signature );
     257    }
     258
     259    /**
     260     * @param $request
     261     * @param $consumer
     262     * @param $token
     263     * @param $signature
     264     * @return mixed
     265     */
     266    public function check_signature( $request, $consumer, $token, $signature ) {
     267        $decoded_sig = base64_decode( $signature, true );
     268
    235269        $base_string = $request->get_signature_base_string();
    236         $request->base_string = $base_string;
    237 
    238         // Fetch the private key cert based on the request
    239         $cert = $this->fetch_private_cert($request);
    240 
    241         // Pull the private key ID from the certificate
    242         $privatekeyid = openssl_get_privatekey($cert);
    243 
    244         // Sign using the key
    245         $ok = openssl_sign($base_string, $signature, $privatekeyid);
     270
     271        // Fetch the public key cert based on the request
     272        $cert = $this->fetch_public_cert( $request );
     273
     274        // Pull the public key ID from the certificate
     275        $publickeyid = openssl_get_publickey( $cert );
     276
     277        // Check the computed signature against the one passed in the query
     278        $ok = openssl_verify( $base_string, $decoded_sig, $publickeyid );
    246279
    247280        // Release the key resource
    248         openssl_free_key($privatekeyid);
    249 
    250         return base64_encode($signature);
    251     }
    252 
    253 
    254     public function check_signature($request, $consumer, $token, $signature)
    255     {
    256         $decoded_sig = base64_decode($signature, true);
    257 
    258         $base_string = $request->get_signature_base_string();
    259 
    260         // Fetch the public key cert based on the request
    261         $cert = $this->fetch_public_cert($request);
    262 
    263         // Pull the public key ID from the certificate
    264         $publickeyid = openssl_get_publickey($cert);
    265 
    266         // Check the computed signature against the one passed in the query
    267         $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
    268 
    269         // Release the key resource
    270         openssl_free_key($publickeyid);
    271 
    272         return $ok == 1;
     281        openssl_free_key( $publickeyid );
     282
     283        return 1 == $ok;
    273284    }
    274285}
    275286
    276 class Twitter_OAuthRequest
    277 {
     287class Twitter_OAuthRequest {
    278288    // for debug purposes
     289    /**
     290     * @var mixed
     291     */
    279292    public $base_string;
     293    /**
     294     * @var string
     295     */
    280296    public static $version = '1.0';
     297    /**
     298     * @var string
     299     */
    281300    public static $POST_INPUT = 'php://input';
     301    /**
     302     * @var mixed
     303     */
    282304    protected $parameters;
     305    /**
     306     * @var mixed
     307     */
    283308    protected $http_method;
     309    /**
     310     * @var mixed
     311     */
    284312    protected $http_url;
    285313
    286 
    287     public function __construct($http_method, $http_url, $parameters = null)
    288     {
    289         $parameters = ($parameters) ? $parameters : [];
    290         $parameters = array_merge(Twitter_OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
    291         $this->parameters = $parameters;
     314    /**
     315     * @param $http_method
     316     * @param $http_url
     317     * @param $parameters
     318     */
     319    public function __construct( $http_method, $http_url, $parameters = null ) {
     320        $parameters        = ( $parameters ) ? $parameters : [];
     321        $parameters        = array_merge( Twitter_OAuthUtil::parse_parameters( parse_url( $http_url, PHP_URL_QUERY ) ), $parameters );
     322        $this->parameters  = $parameters;
    292323        $this->http_method = $http_method;
    293         $this->http_url = $http_url;
    294     }
    295 
     324        $this->http_url    = $http_url;
     325    }
    296326
    297327    /**
    298328     * attempt to build up a request from what was passed to the server
    299329     */
    300     public static function from_request($http_method = null, $http_url = null, $parameters = null)
    301     {
    302         $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')
    303                             ? 'http'
    304                             : 'https';
    305         $http_url = ($http_url) ? $http_url : $scheme .
    306                                                             '://' . $_SERVER['HTTP_HOST'] .
    307                                                             ':' .
    308                                                             $_SERVER['SERVER_PORT'] .
    309                                                             $_SERVER['REQUEST_URI'];
    310         $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
     330    public static function from_request( $http_method = null, $http_url = null, $parameters = null ) {
     331        $scheme = ( ! isset( $_SERVER['HTTPS'] ) || 'on' != $_SERVER['HTTPS'] )
     332        ? 'http'
     333        : 'https';
     334        $http_url = ( $http_url ) ? $http_url : $scheme .
     335            '://' . $_SERVER['HTTP_HOST'] .
     336            ':' .
     337            $_SERVER['SERVER_PORT'] .
     338            $_SERVER['REQUEST_URI'];
     339        $http_method = ( $http_method ) ? $http_method : $_SERVER['REQUEST_METHOD'];
    311340
    312341        // We weren't handed any parameters, so let's find the ones relevant to
     
    314343        // If you run XML-RPC or similar you should use this to provide your own
    315344        // parsed parameter-list
    316         if (!$parameters) {
     345        if ( ! $parameters ) {
    317346            // Find request headers
    318347            $request_headers = Twitter_OAuthUtil::get_headers();
    319348
    320349            // Parse the query-string to find GET parameters
    321             $parameters = Twitter_OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
     350            $parameters = Twitter_OAuthUtil::parse_parameters( $_SERVER['QUERY_STRING'] );
    322351
    323352            // It's a POST request of the proper content-type, so parse POST
    324353            // parameters and add those overriding any duplicates from GET
    325             if ($http_method == 'POST'
    326                     && isset($request_headers['Content-Type'])
    327                     && strstr($request_headers['Content-Type'],
    328                                         'application/x-www-form-urlencoded')
    329                     ) {
     354            if ( 'POST' == $http_method && isset( $request_headers['Content-Type'] )
     355                && strstr( $request_headers['Content-Type'],
     356                    'application/x-www-form-urlencoded' )
     357            ) {
    330358                $post_data = Twitter_OAuthUtil::parse_parameters(
    331                     file_get_contents(self::$POST_INPUT)
     359                    file_get_contents( self::$POST_INPUT )
    332360                );
    333                 $parameters = array_merge($parameters, $post_data);
     361                $parameters = array_merge( $parameters, $post_data );
    334362            }
    335363
    336364            // We have a Authorization-header with OAuth data. Parse the header
    337365            // and add those overriding any duplicates from GET or POST
    338             if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
     366            if ( isset( $request_headers['Authorization'] ) && substr( $request_headers['Authorization'], 0, 6 ) == 'OAuth ' ) {
    339367                $header_parameters = Twitter_OAuthUtil::split_header(
    340368                    $request_headers['Authorization']
    341369                );
    342                 $parameters = array_merge($parameters, $header_parameters);
    343             }
    344         }
    345 
    346         return new self($http_method, $http_url, $parameters);
    347     }
    348 
     370                $parameters = array_merge( $parameters, $header_parameters );
     371            }
     372        }
     373
     374        return new self( $http_method, $http_url, $parameters );
     375    }
    349376
    350377    /**
    351378     * pretty much a helper function to set up the request
    352379     */
    353     public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = null)
    354     {
    355         $parameters = ($parameters) ? $parameters : [];
    356         $defaults = ['oauth_version' => self::$version,
    357                                             'oauth_nonce' => self::generate_nonce(),
    358                                             'oauth_timestamp' => self::generate_timestamp(),
    359                                             'oauth_consumer_key' => $consumer->key, ];
    360         if ($token) {
     380    public static function from_consumer_and_token( $consumer, $token, $http_method, $http_url, $parameters = null ) {
     381        $parameters = ( $parameters ) ? $parameters : [];
     382        $defaults   = ['oauth_version' => self::$version,
     383            'oauth_nonce'                  => self::generate_nonce(),
     384            'oauth_timestamp'              => self::generate_timestamp(),
     385            'oauth_consumer_key'           => $consumer->key];
     386        if ( $token ) {
    361387            $defaults['oauth_token'] = $token->key;
    362388        }
    363389
    364         $parameters = array_merge($defaults, $parameters);
    365 
    366         return new self($http_method, $http_url, $parameters);
    367     }
    368 
    369 
    370     public function set_parameter($name, $value, $allow_duplicates = true)
    371     {
    372         if ($allow_duplicates && isset($this->parameters[$name])) {
     390        $parameters = array_merge( $defaults, $parameters );
     391
     392        return new self( $http_method, $http_url, $parameters );
     393    }
     394
     395    /**
     396     * @param $name
     397     * @param $value
     398     * @param $allow_duplicates
     399     */
     400    public function set_parameter( $name, $value, $allow_duplicates = true ) {
     401        if ( $allow_duplicates && isset( $this->parameters[$name] ) ) {
    373402            // We have already added parameter(s) with this name, so add to the list
    374             if (is_scalar($this->parameters[$name])) {
     403            if ( is_scalar( $this->parameters[$name] ) ) {
    375404                // This is the first duplicate, so transform scalar (string)
    376405                // into an array so we can add the duplicates
     
    384413    }
    385414
    386 
    387     public function get_parameter($name)
    388     {
    389         return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
    390     }
    391 
    392 
    393     public function get_parameters()
    394     {
     415    /**
     416     * @param $name
     417     */
     418    public function get_parameter( $name ) {
     419        return isset( $this->parameters[$name] ) ? $this->parameters[$name] : null;
     420    }
     421
     422    /**
     423     * @return mixed
     424     */
     425    public function get_parameters() {
    395426        return $this->parameters;
    396427    }
    397428
    398 
    399     public function unset_parameter($name)
    400     {
    401         unset($this->parameters[$name]);
    402     }
    403 
     429    /**
     430     * @param $name
     431     */
     432    public function unset_parameter( $name ) {
     433        unset( $this->parameters[$name] );
     434    }
    404435
    405436    /**
     
    407438     * @return string
    408439     */
    409     public function get_signable_parameters()
    410     {
     440    public function get_signable_parameters() {
    411441        // Grab all parameters
    412442        $params = $this->parameters;
     
    414444        // Remove oauth_signature if present
    415445        // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
    416         if (isset($params['oauth_signature'])) {
    417             unset($params['oauth_signature']);
    418         }
    419 
    420         return Twitter_OAuthUtil::build_http_query($params);
    421     }
    422 
     446        if ( isset( $params['oauth_signature'] ) ) {
     447            unset( $params['oauth_signature'] );
     448        }
     449
     450        return Twitter_OAuthUtil::build_http_query( $params );
     451    }
    423452
    424453    /**
     
    429458     * and the concated with &.
    430459     */
    431     public function get_signature_base_string()
    432     {
     460    public function get_signature_base_string() {
    433461        $parts = [
    434462            $this->get_normalized_http_method(),
     
    437465        ];
    438466
    439         $parts = Twitter_OAuthUtil::urlencode_rfc3986($parts);
    440 
    441         return implode('&', $parts);
    442     }
    443 
     467        $parts = Twitter_OAuthUtil::urlencode_rfc3986( $parts );
     468
     469        return implode( '&', $parts );
     470    }
    444471
    445472    /**
    446473     * just uppercases the http method
    447474     */
    448     public function get_normalized_http_method()
    449     {
    450         return strtoupper($this->http_method);
    451     }
    452 
     475    public function get_normalized_http_method() {
     476        return strtoupper( $this->http_method );
     477    }
    453478
    454479    /**
     
    456481     * scheme://host/path
    457482     */
    458     public function get_normalized_http_url()
    459     {
    460         $parts = parse_url($this->http_url);
    461 
    462         $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
    463         $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
    464         $host = (isset($parts['host'])) ? $parts['host'] : '';
    465         $path = (isset($parts['path'])) ? $parts['path'] : '';
    466 
    467         if (($scheme == 'https' && $port != '443')
    468                 || ($scheme == 'http' && $port != '80')) {
     483    public function get_normalized_http_url() {
     484        $parts = parse_url( $this->http_url );
     485
     486        $scheme = ( isset( $parts['scheme'] ) ) ? $parts['scheme'] : 'http';
     487        $port   = ( isset( $parts['port'] ) ) ? $parts['port'] : (  ( 'https' == $scheme ) ? '443' : '80' );
     488        $host   = ( isset( $parts['host'] ) ) ? $parts['host'] : '';
     489        $path   = ( isset( $parts['path'] ) ) ? $parts['path'] : '';
     490
     491        if (  ( 'https' == $scheme && '443' != $port )
     492            || ( 'http' == $scheme && '80' != $port ) ) {
    469493            $host = "$host:$port";
    470494        }
     495
    471496        return "$scheme://$host$path";
    472497    }
    473498
    474 
    475499    /**
    476500     * builds a url usable for a GET request
    477501     */
    478     public function to_url()
    479     {
     502    public function to_url() {
    480503        $post_data = $this->to_postdata();
    481         $out = $this->get_normalized_http_url();
    482         if ($post_data) {
     504        $out       = $this->get_normalized_http_url();
     505        if ( $post_data ) {
    483506            $out .= '?' . $post_data;
    484507        }
     508
    485509        return $out;
    486510    }
    487511
    488 
    489512    /**
    490513     * builds the data one would send in a POST request
    491514     */
    492     public function to_postdata()
    493     {
    494         return Twitter_OAuthUtil::build_http_query($this->parameters);
    495     }
    496 
     515    public function to_postdata() {
     516        return Twitter_OAuthUtil::build_http_query( $this->parameters );
     517    }
    497518
    498519    /**
    499520     * builds the Authorization: header
    500521     */
    501     public function to_header($realm = null)
    502     {
     522    public function to_header( $realm = null ) {
    503523        $first = true;
    504         if ($realm) {
    505             $out = 'Authorization: OAuth realm="' . Twitter_OAuthUtil::urlencode_rfc3986($realm) . '"';
     524        if ( $realm ) {
     525            $out   = 'Authorization: OAuth realm="' . Twitter_OAuthUtil::urlencode_rfc3986( $realm ) . '"';
    506526            $first = false;
    507527        } else {
     
    510530
    511531        $total = [];
    512         foreach ($this->parameters as $k => $v) {
    513             if (substr($k, 0, 5) != 'oauth') {
     532        foreach ( $this->parameters as $k => $v ) {
     533            if ( substr( $k, 0, 5 ) != 'oauth' ) {
    514534                continue;
    515535            }
    516             if (is_array($v)) {
    517                 throw new Twitter_OAuthException('Arrays not supported in headers');
    518             }
    519             $out .= ($first) ? ' ' : ',';
    520             $out .= Twitter_OAuthUtil::urlencode_rfc3986($k) .
    521                             '="' .
    522                             Twitter_OAuthUtil::urlencode_rfc3986($v) .
    523                             '"';
     536            if ( is_array( $v ) ) {
     537                throw new Twitter_OAuthException( 'Arrays not supported in headers' );
     538            }
     539            $out .= ( $first ) ? ' ' : ',';
     540            $out .= Twitter_OAuthUtil::urlencode_rfc3986( $k ) .
     541            '="' .
     542            Twitter_OAuthUtil::urlencode_rfc3986( $v ) .
     543                '"';
    524544            $first = false;
    525545        }
     546
    526547        return $out;
    527548    }
    528549
    529 
    530     public function __toString()
    531     {
     550    /**
     551     * @return mixed
     552     */
     553    public function __toString() {
    532554        return $this->to_url();
    533555    }
    534556
    535 
    536     public function sign_request($signature_method, $consumer, $token)
    537     {
     557    /**
     558     * @param $signature_method
     559     * @param $consumer
     560     * @param $token
     561     */
     562    public function sign_request( $signature_method, $consumer, $token ) {
    538563        $this->set_parameter(
    539564            'oauth_signature_method',
     
    541566            false
    542567        );
    543         $signature = $this->build_signature($signature_method, $consumer, $token);
    544         $this->set_parameter('oauth_signature', $signature, false);
    545     }
    546 
    547 
    548     public function build_signature($signature_method, $consumer, $token)
    549     {
    550         $signature = $signature_method->build_signature($this, $consumer, $token);
     568        $signature = $this->build_signature( $signature_method, $consumer, $token );
     569        $this->set_parameter( 'oauth_signature', $signature, false );
     570    }
     571
     572    /**
     573     * @param $signature_method
     574     * @param $consumer
     575     * @param $token
     576     * @return mixed
     577     */
     578    public function build_signature( $signature_method, $consumer, $token ) {
     579        $signature = $signature_method->build_signature( $this, $consumer, $token );
     580
    551581        return $signature;
    552582    }
    553583
    554 
    555584    /**
    556585     * util function: current timestamp
    557586     */
    558     private static function generate_timestamp()
    559     {
     587    private static function generate_timestamp() {
    560588        return time();
    561589    }
    562590
    563 
    564591    /**
    565592     * util function: current nonce
    566593     */
    567     private static function generate_nonce()
    568     {
    569         $mt = microtime();
     594    private static function generate_nonce() {
     595        $mt   = microtime();
    570596        $rand = mt_rand();
    571597
    572         return md5($mt . $rand); // md5s look nicer than numbers
     598        return md5( $mt . $rand ); // md5s look nicer than numbers
    573599    }
    574600}
    575601
    576 class Twitter_OAuthServer
    577 {
     602class Twitter_OAuthServer {
     603    /**
     604     * @var int
     605     */
    578606    protected $timestamp_threshold = 300; // in seconds, five minutes
    579     protected $version = '1.0';             // hi blaine
     607    /**
     608     * @var string
     609     */
     610    protected $version = '1.0'; // hi blaine
     611    /**
     612     * @var array
     613     */
    580614    protected $signature_methods = [];
    581615
     616    /**
     617     * @var mixed
     618     */
    582619    protected $data_store;
    583620
    584 
    585     public function __construct($data_store)
    586     {
     621    /**
     622     * @param $data_store
     623     */
     624    public function __construct( $data_store ) {
    587625        $this->data_store = $data_store;
    588626    }
    589627
    590 
    591     public function add_signature_method($signature_method)
    592     {
     628    /**
     629     * @param $signature_method
     630     */
     631    public function add_signature_method( $signature_method ) {
    593632        $this->signature_methods[$signature_method->get_name()] =
    594633            $signature_method;
    595634    }
    596635
    597 
    598636    // high level functions
    599 
    600637
    601638    /**
     
    603640     * returns the request token on success
    604641     */
    605     public function fetch_request_token(&$request)
    606     {
    607         $this->get_version($request);
    608 
    609         $consumer = $this->get_consumer($request);
     642    public function fetch_request_token( &$request ) {
     643        $this->get_version( $request );
     644
     645        $consumer = $this->get_consumer( $request );
    610646
    611647        // no token required for the initial token request
    612648        $token = null;
    613649
    614         $this->check_signature($request, $consumer, $token);
     650        $this->check_signature( $request, $consumer, $token );
    615651
    616652        // Rev A change
    617         $callback = $request->get_parameter('oauth_callback');
    618         $new_token = $this->data_store->new_request_token($consumer, $callback);
     653        $callback  = $request->get_parameter( 'oauth_callback' );
     654        $new_token = $this->data_store->new_request_token( $consumer, $callback );
    619655
    620656        return $new_token;
    621657    }
    622 
    623658
    624659    /**
     
    626661     * returns the access token on success
    627662     */
    628     public function fetch_access_token(&$request)
    629     {
    630         $this->get_version($request);
    631 
    632         $consumer = $this->get_consumer($request);
     663    public function fetch_access_token( &$request ) {
     664        $this->get_version( $request );
     665
     666        $consumer = $this->get_consumer( $request );
    633667
    634668        // requires authorized request token
    635         $token = $this->get_token($request, $consumer, 'request');
    636 
    637         $this->check_signature($request, $consumer, $token);
     669        $token = $this->get_token( $request, $consumer, 'request' );
     670
     671        $this->check_signature( $request, $consumer, $token );
    638672
    639673        // Rev A change
    640         $verifier = $request->get_parameter('oauth_verifier');
    641         $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
     674        $verifier  = $request->get_parameter( 'oauth_verifier' );
     675        $new_token = $this->data_store->new_access_token( $token, $consumer, $verifier );
    642676
    643677        return $new_token;
    644678    }
    645679
    646 
    647680    /**
    648681     * verify an api call, checks all the parameters
    649682     */
    650     public function verify_request(&$request)
    651     {
    652         $this->get_version($request);
    653         $consumer = $this->get_consumer($request);
    654         $token = $this->get_token($request, $consumer, 'access');
    655         $this->check_signature($request, $consumer, $token);
     683    public function verify_request( &$request ) {
     684        $this->get_version( $request );
     685        $consumer = $this->get_consumer( $request );
     686        $token    = $this->get_token( $request, $consumer, 'access' );
     687        $this->check_signature( $request, $consumer, $token );
     688
    656689        return [$consumer, $token];
    657690    }
    658691
    659 
    660692    // Internals from here
    661    
    662693
    663694/**
    664      * version 1
    665      */
    666     private function get_version(&$request)
    667     {
    668         $version = $request->get_parameter('oauth_version');
    669         if (!$version) {
     695 * version 1
     696 */
     697    private function get_version( &$request ) {
     698        $version = $request->get_parameter( 'oauth_version' );
     699        if ( ! $version ) {
    670700            // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
    671701            // Chapter 7.0 ("Accessing Protected Ressources")
    672702            $version = '1.0';
    673703        }
    674         if ($version !== $this->version) {
    675             throw new Twitter_OAuthException("OAuth version '$version' not supported");
    676         }
     704        if ( $version !== $this->version ) {
     705            throw new Twitter_OAuthException( "OAuth version '$version' not supported" );
     706        }
     707
    677708        return $version;
    678709    }
    679710
    680 
    681711    /**
    682712     * figure out the signature with some defaults
    683713     */
    684     private function get_signature_method($request)
    685     {
     714    private function get_signature_method( $request ) {
    686715        $signature_method = $request instanceof Twitter_OAuthRequest
    687                 ? $request->get_parameter('oauth_signature_method')
    688                 : null;
    689 
    690         if (!$signature_method) {
     716        ? $request->get_parameter( 'oauth_signature_method' )
     717        : null;
     718
     719        if ( ! $signature_method ) {
    691720            // According to chapter 7 ("Accessing Protected Ressources") the signature-method
    692721            // parameter is required, and we can't just fallback to PLAINTEXT
    693             throw new Twitter_OAuthException('No signature method parameter. This parameter is required');
    694         }
    695 
    696         if (!in_array($signature_method,
    697                                     array_keys($this->signature_methods), true)) {
     722            throw new Twitter_OAuthException( 'No signature method parameter. This parameter is required' );
     723        }
     724
     725        if ( ! in_array( $signature_method,
     726            array_keys( $this->signature_methods ), true ) ) {
    698727            throw new Twitter_OAuthException(
    699728                "Signature method '$signature_method' not supported " .
    700729                'try one of the following: ' .
    701                 implode(', ', array_keys($this->signature_methods))
     730                implode( ', ', array_keys( $this->signature_methods ) )
    702731            );
    703732        }
     733
    704734        return $this->signature_methods[$signature_method];
    705735    }
    706736
    707 
    708737    /**
    709738     * try to find the consumer for the provided request's consumer key
    710739     */
    711     private function get_consumer($request)
    712     {
     740    private function get_consumer( $request ) {
    713741        $consumer_key = $request instanceof Twitter_OAuthRequest
    714                 ? $request->get_parameter('oauth_consumer_key')
    715                 : null;
    716 
    717         if (!$consumer_key) {
    718             throw new Twitter_OAuthException('Invalid consumer key');
    719         }
    720 
    721         $consumer = $this->data_store->lookup_consumer($consumer_key);
    722         if (!$consumer) {
    723             throw new Twitter_OAuthException('Invalid consumer');
     742        ? $request->get_parameter( 'oauth_consumer_key' )
     743        : null;
     744
     745        if ( ! $consumer_key ) {
     746            throw new Twitter_OAuthException( 'Invalid consumer key' );
     747        }
     748
     749        $consumer = $this->data_store->lookup_consumer( $consumer_key );
     750        if ( ! $consumer ) {
     751            throw new Twitter_OAuthException( 'Invalid consumer' );
    724752        }
    725753
     
    727755    }
    728756
    729 
    730757    /**
    731758     * try to find the token for the provided request's token key
    732759     */
    733     private function get_token($request, $consumer, $token_type = 'access')
    734     {
     760    private function get_token( $request, $consumer, $token_type = 'access' ) {
    735761        $token_field = $request instanceof Twitter_OAuthRequest
    736                 ? $request->get_parameter('oauth_token')
    737                 : null;
     762        ? $request->get_parameter( 'oauth_token' )
     763        : null;
    738764
    739765        $token = $this->data_store->lookup_token(
    740766            $consumer, $token_type, $token_field
    741767        );
    742         if (!$token) {
    743             throw new Twitter_OAuthException("Invalid $token_type token: $token_field");
    744         }
     768        if ( ! $token ) {
     769            throw new Twitter_OAuthException( "Invalid $token_type token: $token_field" );
     770        }
     771
    745772        return $token;
    746773    }
    747 
    748774
    749775    /**
     
    751777     * should guess the signature method appropriately
    752778     */
    753     private function check_signature($request, $consumer, $token)
    754     {
     779    private function check_signature( $request, $consumer, $token ) {
    755780        // this should probably be in a different method
    756781        $timestamp = $request instanceof Twitter_OAuthRequest
    757                 ? $request->get_parameter('oauth_timestamp')
    758                 : null;
     782        ? $request->get_parameter( 'oauth_timestamp' )
     783        : null;
    759784        $nonce = $request instanceof Twitter_OAuthRequest
    760                 ? $request->get_parameter('oauth_nonce')
    761                 : null;
    762 
    763         $this->check_timestamp($timestamp);
    764         $this->check_nonce($consumer, $token, $nonce, $timestamp);
    765 
    766         $signature_method = $this->get_signature_method($request);
    767 
    768         $signature = $request->get_parameter('oauth_signature');
     785        ? $request->get_parameter( 'oauth_nonce' )
     786        : null;
     787
     788        $this->check_timestamp( $timestamp );
     789        $this->check_nonce( $consumer, $token, $nonce, $timestamp );
     790
     791        $signature_method = $this->get_signature_method( $request );
     792
     793        $signature = $request->get_parameter( 'oauth_signature' );
    769794        $valid_sig = $signature_method->check_signature(
    770795            $request,
     
    774799        );
    775800
    776         if (!$valid_sig) {
    777             throw new Twitter_OAuthException('Invalid signature');
    778         }
    779     }
    780 
     801        if ( ! $valid_sig ) {
     802            throw new Twitter_OAuthException( 'Invalid signature' );
     803        }
     804    }
    781805
    782806    /**
    783807     * check that the timestamp is new enough
    784808     */
    785     private function check_timestamp($timestamp)
    786     {
    787         if (!$timestamp) {
     809    private function check_timestamp( $timestamp ) {
     810        if ( ! $timestamp ) {
    788811            throw new Twitter_OAuthException(
    789812                'Missing timestamp parameter. The parameter is required'
     
    793816        // verify that timestamp is recentish
    794817        $now = time();
    795         if (abs($now - $timestamp) > $this->timestamp_threshold) {
     818        if ( abs( $now - $timestamp ) > $this->timestamp_threshold ) {
    796819            throw new Twitter_OAuthException(
    797820                "Expired timestamp, yours $timestamp, ours $now"
     
    800823    }
    801824
    802 
    803825    /**
    804826     * check that the nonce is not repeated
    805827     */
    806     private function check_nonce($consumer, $token, $nonce, $timestamp)
    807     {
    808         if (!$nonce) {
     828    private function check_nonce( $consumer, $token, $nonce, $timestamp ) {
     829        if ( ! $nonce ) {
    809830            throw new Twitter_OAuthException(
    810831                'Missing nonce parameter. The parameter is required'
     
    819840            $timestamp
    820841        );
    821         if ($found) {
    822             throw new Twitter_OAuthException("Nonce already used: $nonce");
     842        if ( $found ) {
     843            throw new Twitter_OAuthException( "Nonce already used: $nonce" );
    823844        }
    824845    }
    825846}
    826847
    827 class Twitter_OAuthDataStore
    828 {
    829     public function lookup_consumer($consumer_key)
    830     {
     848class Twitter_OAuthDataStore {
     849    /**
     850     * @param $consumer_key
     851     */
     852    public function lookup_consumer( $consumer_key ) {
    831853        // implement me
    832854    }
    833855
    834 
    835     public function lookup_token($consumer, $token_type, $token)
    836     {
     856    /**
     857     * @param $consumer
     858     * @param $token_type
     859     * @param $token
     860     */
     861    public function lookup_token( $consumer, $token_type, $token ) {
    837862        // implement me
    838863    }
    839864
    840 
    841     public function lookup_nonce($consumer, $token, $nonce, $timestamp)
    842     {
     865    /**
     866     * @param $consumer
     867     * @param $token
     868     * @param $nonce
     869     * @param $timestamp
     870     */
     871    public function lookup_nonce( $consumer, $token, $nonce, $timestamp ) {
    843872        // implement me
    844873    }
    845874
    846 
    847     public function new_request_token($consumer, $callback = null)
    848     {
     875    /**
     876     * @param $consumer
     877     * @param $callback
     878     */
     879    public function new_request_token( $consumer, $callback = null ) {
    849880        // return a new token attached to this consumer
    850881    }
    851882
    852 
    853     public function new_access_token($token, $consumer, $verifier = null)
    854     {
     883    /**
     884     * @param $token
     885     * @param $consumer
     886     * @param $verifier
     887     */
     888    public function new_access_token( $token, $consumer, $verifier = null ) {
    855889        // return a new access token attached to this consumer
    856890        // for the user associated with this token if the request token
     
    860894}
    861895
    862 class Twitter_OAuthUtil
    863 {
    864     public static function urlencode_rfc3986($input)
    865     {
    866         if (is_array($input)) {
    867             return array_map(['Twitter_OAuthUtil', 'urlencode_rfc3986'], $input);
     896class Twitter_OAuthUtil {
     897    /**
     898     * @param $input
     899     */
     900    public static function urlencode_rfc3986( $input ) {
     901        if ( is_array( $input ) ) {
     902            return array_map( ['Twitter_OAuthUtil', 'urlencode_rfc3986'], $input );
    868903        } else {
    869             if (is_scalar($input)) {
     904            if ( is_scalar( $input ) ) {
    870905                return str_replace(
    871                 '+',
    872                 ' ',
    873                 str_replace('%7E', '~', rawurlencode($input))
    874             );
     906                    '+',
     907                    ' ',
     908                    str_replace( '%7E', '~', rawurlencode( $input ) )
     909                );
    875910            } else {
    876911                return '';
     
    878913        }
    879914    }
    880 
    881915
    882916    // This decode function isn't taking into consideration the above
    883917    // modifications to the encoding process. However, this method doesn't
    884918    // seem to be used anywhere so leaving it as is.
    885     public static function urldecode_rfc3986($string)
    886     {
    887         return urldecode($string);
    888     }
    889 
     919    /**
     920     * @param $string
     921     */
     922    public static function urldecode_rfc3986( $string ) {
     923        return urldecode( $string );
     924    }
    890925
    891926    // Utility function for turning the Authorization: header into
     
    894929    // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
    895930    //                  see http://code.google.com/p/oauth/issues/detail?id=163
    896     public static function split_header($header, $only_allow_oauth_parameters = true)
    897     {
     931    /**
     932     * @param $header
     933     * @param $only_allow_oauth_parameters
     934     * @return mixed
     935     */
     936    public static function split_header( $header, $only_allow_oauth_parameters = true ) {
    898937        $params = [];
    899         if (preg_match_all('/(' . ($only_allow_oauth_parameters ? 'oauth_' : '') . '[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
    900             foreach ($matches[1] as $i => $h) {
    901                 $params[$h] = self::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
    902             }
    903             if (isset($params['realm'])) {
    904                 unset($params['realm']);
    905             }
    906         }
     938        if ( preg_match_all( '/(' . ( $only_allow_oauth_parameters ? 'oauth_' : '' ) . '[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches ) ) {
     939            foreach ( $matches[1] as $i => $h ) {
     940                $params[$h] = self::urldecode_rfc3986( empty( $matches[3][$i] ) ? $matches[4][$i] : $matches[3][$i] );
     941            }
     942            if ( isset( $params['realm'] ) ) {
     943                unset( $params['realm'] );
     944            }
     945        }
     946
    907947        return $params;
    908948    }
    909949
    910 
    911950    // helper to try to sort out headers for people who aren't running apache
    912     public static function get_headers()
    913     {
    914         if (function_exists('apache_request_headers')) {
     951    /**
     952     * @return mixed
     953     */
     954    public static function get_headers() {
     955        if ( function_exists( 'apache_request_headers' ) ) {
    915956            // we need this to get the actual Authorization: header
    916957            // because apache tends to tell us it doesn't exist
     
    922963            // request
    923964            $out = [];
    924             foreach ($headers as $key => $value) {
     965            foreach ( $headers as $key => $value ) {
    925966                $key = str_replace(
    926                         ' ',
    927                         '-',
    928                         ucwords(strtolower(str_replace('-', ' ', $key)))
    929                     );
     967                    ' ',
     968                    '-',
     969                    ucwords( strtolower( str_replace( '-', ' ', $key ) ) )
     970                );
    930971                $out[$key] = $value;
    931972            }
     
    934975            // that $_SERVER actually contains what we need
    935976            $out = [];
    936             if (isset($_SERVER['CONTENT_TYPE'])) {
     977            if ( isset( $_SERVER['CONTENT_TYPE'] ) ) {
    937978                $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
    938979            }
    939             if (isset($_ENV['CONTENT_TYPE'])) {
     980            if ( isset( $_ENV['CONTENT_TYPE'] ) ) {
    940981                $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
    941982            }
    942983
    943             foreach ($_SERVER as $key => $value) {
    944                 if (substr($key, 0, 5) == 'HTTP_') {
     984            foreach ( $_SERVER as $key => $value ) {
     985                if ( substr( $key, 0, 5 ) == 'HTTP_' ) {
    945986                    // this is chaos, basically it is just there to capitalize the first
    946987                    // letter of every word that is not an initial HTTP and strip HTTP
     
    949990                        ' ',
    950991                        '-',
    951                         ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))
     992                        ucwords( strtolower( str_replace( '_', ' ', substr( $key, 5 ) ) ) )
    952993                    );
    953994                    $out[$key] = $value;
     
    955996            }
    956997        }
     998
    957999        return $out;
    9581000    }
    959 
    9601001
    9611002    // This function takes a input like a=b&a=c&d=e and returns the parsed
    9621003    // parameters like this
    9631004    // ['a' => array('b','c'), 'd' => 'e']
    964     public static function parse_parameters($input)
    965     {
    966         if (!isset($input) || !$input) {
     1005    /**
     1006     * @param $input
     1007     * @return mixed
     1008     */
     1009    public static function parse_parameters( $input ) {
     1010        if ( ! isset( $input ) || ! $input ) {
    9671011            return [];
    9681012        }
    9691013
    970         $pairs = explode('&', $input);
     1014        $pairs = explode( '&', $input );
    9711015
    9721016        $parsed_parameters = [];
    973         foreach ($pairs as $pair) {
    974             $split = explode('=', $pair, 2);
    975             $parameter = self::urldecode_rfc3986($split[0]);
    976             $value = isset($split[1]) ? self::urldecode_rfc3986($split[1]) : '';
    977 
    978             if (isset($parsed_parameters[$parameter])) {
     1017        foreach ( $pairs as $pair ) {
     1018            $split     = explode( '=', $pair, 2 );
     1019            $parameter = self::urldecode_rfc3986( $split[0] );
     1020            $value     = isset( $split[1] ) ? self::urldecode_rfc3986( $split[1] ) : '';
     1021
     1022            if ( isset( $parsed_parameters[$parameter] ) ) {
    9791023                // We have already recieved parameter(s) with this name, so add to the list
    9801024                // of parameters with this name
    9811025
    982                 if (is_scalar($parsed_parameters[$parameter])) {
     1026                if ( is_scalar( $parsed_parameters[$parameter] ) ) {
    9831027                    // This is the first duplicate, so transform scalar (string) into an array
    9841028                    // so we can add the duplicates
     
    9911035            }
    9921036        }
     1037
    9931038        return $parsed_parameters;
    9941039    }
    9951040
    996 
    997     public static function build_http_query($params)
    998     {
    999         if (!$params) {
     1041    /**
     1042     * @param $params
     1043     */
     1044    public static function build_http_query( $params ) {
     1045        if ( ! $params ) {
    10001046            return '';
    10011047        }
    10021048
    10031049        // Urlencode both keys and values
    1004         $keys = self::urlencode_rfc3986(array_keys($params));
    1005         $values = self::urlencode_rfc3986(array_values($params));
    1006         $params = array_combine($keys, $values);
     1050        $keys   = self::urlencode_rfc3986( array_keys( $params ) );
     1051        $values = self::urlencode_rfc3986( array_values( $params ) );
     1052        $params = array_combine( $keys, $values );
    10071053
    10081054        // Parameters are sorted by name, using lexicographical byte value ordering.
    10091055        // Ref: Spec: 9.1.1 (1)
    1010         uksort($params, 'strcmp');
     1056        uksort( $params, 'strcmp' );
    10111057
    10121058        $pairs = [];
    1013         foreach ($params as $parameter => $value) {
    1014             if (is_array($value)) {
     1059        foreach ( $params as $parameter => $value ) {
     1060            if ( is_array( $value ) ) {
    10151061                // If two or more parameters share the same name, they are sorted by their value
    10161062                // Ref: Spec: 9.1.1 (1)
    10171063                // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
    1018                 sort($value, SORT_STRING);
    1019                 foreach ($value as $duplicate_value) {
     1064                sort( $value, SORT_STRING );
     1065                foreach ( $value as $duplicate_value ) {
    10201066                    $pairs[] = $parameter . '=' . $duplicate_value;
    10211067                }
     
    10261072        // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
    10271073        // Each name-value pair is separated by an '&' character (ASCII code 38)
    1028         return implode('&', $pairs);
     1074
     1075        return implode( '&', $pairs );
    10291076    }
    10301077}
  • auto-post-woocommerce-products/trunk/admin/src/Twitter/Twitter.php

    r1910091 r2144962  
    2525    const RETWEETS = 128; // include retweets
    2626
    27    
     27
    2828    /*     * #@- */
    2929
     
    5454     * @param  string  app secret
    5555     * @param  string  optional access token
    56      * @param  string  optinal access token secret
     56     * @param  string  optional access token secret
    5757     * @throws TwitterException when CURL extension is not loaded
    5858     */
     
    123123     * @param string $id The id# of the post to retweet
    124124     * @param string $message The retweet @
    125      * 
     125     *
    126126     * @return
    127127     */
     
    474474class TwitterException extends Exception
    475475    {
    476    
    477     }
     476
     477    }
  • auto-post-woocommerce-products/trunk/auto-post-woocommerce-products.php

    r2134375 r2144962  
    1111 * Description: APWCP is a powerful tool to assist you in managing your WooCommerce inventory and advertising your products on social media.
    1212 * Tested up to: 5.2.2
    13  * Version: 2.1.4.3
     13 * Version: 2.1.4.4
    1414 * Author: Carl Lockett III, CIL Creations
    1515 * Author URI: http://www.cilcreations.com/apwp
    1616 * WC requires at least: 3.3.0
    17  * WC tested up to: 3.6.5
     17 * WC tested up to: 3.7
    1818 * License: GPL-3.0+
    1919 * License URI: http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3232
    3333require plugin_dir_path( __FILE__ ) . 'includes/class-auto-post-woocommerce-products.php';
    34 define( 'APWP_VERSION', '2.1.4.3' );
     34define( 'APWP_VERSION', '2.1.4.4' );
     35update_option( 'apwp_is_beta_version', false );
    3536register_activation_hook( __FILE__, 'apwp_activate' );
    3637register_deactivation_hook( __FILE__, 'apwp_deactivate' );
  • auto-post-woocommerce-products/trunk/includes/class-auto-post-woocommerce-products-activator.php

    r2121574 r2144962  
    3434        delete_transient( 'apwp_prod_list_search_id' );
    3535        delete_transient( 'apwp_prod_list_search' );
    36         apwp_reset_plugin();
    3736        apwp_set_onetime_cron( [ 'trash', 'cats' ] ); // Update product data.
    3837    }
Note: See TracChangeset for help on using the changeset viewer.