Plugin Directory

Changeset 836741


Ignore:
Timestamp:
01/11/2014 04:36:28 PM (12 years ago)
Author:
garyc40
Message:

Synced with git.

Location:
wp-e-commerce/branches/branch-3.8.13
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-e-commerce/branches/branch-3.8.13/readme.txt

    r826442 r836741  
    55Requires at least: 3.7
    66Tested up to: 3.8
    7 Stable tag: 3.8.13
     7Stable tag: 3.8.13.2
    88
    99WP e-Commerce is a free WordPress Shopping Cart Plugin that lets customers buy your products, services and digital downloads online.
     
    146146
    147147== Changelog ==
     148
     149= 3.8.13.2 =
     150* Fix: Anonymous customers should not be visible in admin UI.
     151* Fix: Cronjob to purge anonymous customers doesn't work due to memory issues.
     152* Fix: Anonymous cart items will be lost after signing in.
     153
     154= 3.8.13.1 =
     155* Security and maintenance release
    148156
    149157= 3.8.13 =
  • wp-e-commerce/branches/branch-3.8.13/wp-shopping-cart.php

    r826442 r836741  
    44  * Plugin URI: http://getshopped.org/
    55  * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
    6   * Version: 3.8.13
     6  * Version: 3.8.13.2
    77  * Author: Instinct Entertainment
    88  * Author URI: http://getshopped.org/
  • wp-e-commerce/branches/branch-3.8.13/wpsc-core/wpsc-constants.php

    r826442 r836741  
    3030
    3131    // Define Plugin version
    32     define( 'WPSC_VERSION'            , '3.8.13' );
    33     define( 'WPSC_MINOR_VERSION'      , 'e8a508c011' );
    34     define( 'WPSC_PRESENTABLE_VERSION', '3.8.13' );
     32    define( 'WPSC_VERSION'            , '3.8.13.2' );
     33    define( 'WPSC_MINOR_VERSION'      , 'b0ef2e3' );
     34    define( 'WPSC_PRESENTABLE_VERSION', '3.8.13.2' );
    3535    define( 'WPSC_DB_VERSION'         , 8 );
    3636
     
    257257        add_filter( 'the_content', 'wpsc_shopping_cart', 14 );
    258258
    259     $cart = maybe_unserialize( base64_decode( wpsc_get_customer_meta( 'cart' ) ) );
    260 
    261     if ( is_object( $cart ) && ! is_wp_error( $cart ) )
    262         $GLOBALS['wpsc_cart'] = $cart;
    263     else
    264         $GLOBALS['wpsc_cart'] = new wpsc_cart();
     259    $GLOBALS['wpsc_cart'] = wpsc_get_customer_cart();
    265260}
    266261
  • wp-e-commerce/branches/branch-3.8.13/wpsc-includes/cron.php

    r826442 r836741  
    44
    55/**
    6  * wpsc_clear_stock_claims, clears the stock claims, runs using wp-cron and when editing purchase log statuses via the dashboard
     6 * Clears the stock claims, runs on hourly WP_Cron event and when editing purchase log statuses.
     7 *
     8 * @since 3.8.9
     9 * @access public
     10 *
     11 * @return void
    712 */
    813function wpsc_clear_stock_claims() {
    914    global $wpdb;
    1015
    11     $time = (float) get_option( 'wpsc_stock_keeping_time', 1 );
     16    $time     = (float) get_option( 'wpsc_stock_keeping_time', 1 );
    1217    $interval = get_option( 'wpsc_stock_keeping_interval', 'day' );
    1318
     
    1924    );
    2025
    21     $seconds = floor( $time * $convert[$interval] );
     26    $seconds = floor( $time * $convert[ $interval ] );
    2227
    2328    $sql = $wpdb->prepare( "DELETE FROM " . WPSC_TABLE_CLAIMED_STOCK . " WHERE last_activity < UTC_TIMESTAMP() - INTERVAL %d SECOND", $seconds );
     
    2530}
    2631
     32/**
     33 * Purges customer meta that is older than WPSC_CUSTOMER_DATA_EXPIRATION on an hourly WP_Cron event.
     34 *
     35 * @since 3.8.9.2
     36 * @access public
     37 *
     38 * @return void
     39 */
    2740function _wpsc_clear_customer_meta() {
    2841    global $wpdb;
    2942
    3043    require_once( ABSPATH . 'wp-admin/includes/user.php' );
     44
     45    $purge_count = 200;
    3146
    3247    $sql = "
     
    3651        meta_key = '_wpsc_last_active'
    3752        AND meta_value < UNIX_TIMESTAMP() - " . WPSC_CUSTOMER_DATA_EXPIRATION . "
     53        LIMIT {$purge_count}
    3854    ";
    3955
    40     $ids = $wpdb->get_col( $sql );
    41     foreach ( $ids as $id ) {
    42         wp_delete_user( $id );
    43     }
     56    /* Do this in batches of 200 to avoid memory issues when there are too many anonymous users */
     57    @set_time_limit( 0 ); // no time limit
     58
     59    do {
     60        $ids = $wpdb->get_col( $sql );
     61        foreach ( $ids as $id ) {
     62            wp_delete_user( $id );
     63        }
     64    } while ( count( $ids ) == $purge_count );
    4465}
  • wp-e-commerce/branches/branch-3.8.13/wpsc-includes/customer.php

    r826442 r836741  
    55add_action( 'wpsc_before_submit_checkout', '_wpsc_action_update_customer_last_active'     );
    66add_action( 'wp_login'                   , '_wpsc_action_setup_customer'                  );
     7add_action( 'load-users.php'             , '_wpsc_action_load_users'                      );
     8add_filter( 'views_users'                , '_wpsc_filter_views_users'                     );
     9add_filter( 'editable_roles'             , '_wpsc_filter_editable_roles'                  );
    710
    811/**
     
    124127 */
    125128function _wpsc_validate_customer_cookie() {
    126     if ( is_admin() || ! isset( $_COOKIE[ WPSC_CUSTOMER_COOKIE ] ) )
    127         return;
     129
     130    if ( is_admin() || ! isset( $_COOKIE[ WPSC_CUSTOMER_COOKIE ] ) ) {
     131        return false;
     132    }
    128133
    129134    $cookie = $_COOKIE[ WPSC_CUSTOMER_COOKIE ];
     
    134139
    135140    // invalid ID
    136     if ( ! $id )
     141    if ( ! $id ) {
    137142        return false;
     143    }
    138144
    139145    $user = get_user_by( 'id', $id );
    140146
    141147    // no user found
    142     if ( $user === false )
     148    if ( $user === false ) {
    143149        return false;
     150    }
    144151
    145152    $pass_frag = substr( $user->user_pass, 8, 4 );
     
    148155
    149156    // integrity check
    150     if ( $hmac == $hash )
     157    if ( $hmac == $hash ) {
    151158        return $id;
     159    }
    152160
    153161    _wpsc_set_customer_cookie( '', time() - 3600 );
     
    193201 */
    194202function _wpsc_action_setup_customer() {
    195     // if the user is logged in and the cookie is still there, delete the cookie
    196     if ( is_user_logged_in() && isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) )
    197         _wpsc_set_customer_cookie( '', time() - 3600 );
    198 
    199203    // if the customer cookie is invalid, unset it
    200     _wpsc_validate_customer_cookie();
     204    $id = _wpsc_validate_customer_cookie();
     205
     206    // if a valid ID is present in the cookie, and the user is logged in,
     207    // it's time to merge the carts
     208    if ( isset( $_COOKIE[WPSC_CUSTOMER_COOKIE] ) && is_user_logged_in() ) {
     209        // merging cart requires the taxonomies to have been initialized
     210        if ( did_action( 'wpsc_register_taxonomies_after' ) ) {
     211            _wpsc_merge_cart();
     212        }
     213        else {
     214            add_action( 'wpsc_register_taxonomies_after', '_wpsc_merge_cart', 1 );
     215        }
     216    }
    201217
    202218    // if this request is by a bot, prevent multiple account creation
     
    210226
    211227    do_action( 'wpsc_setup_customer' );
     228}
     229
     230function _wpsc_merge_cart() {
     231    $old_id = _wpsc_validate_customer_cookie();
     232
     233    if ( ! $old_id ) {
     234        return;
     235    }
     236
     237    $new_id = get_current_user_id();
     238
     239    $old_cart = wpsc_get_customer_cart( $old_id );
     240    $items    = $old_cart->get_items();
     241
     242    $new_cart = wpsc_get_customer_cart( $new_id );
     243
     244    // first of all empty the old cart so that the claimed stock and related
     245    // hooks are released
     246    $old_cart->empty_cart();
     247
     248    // add each item to the new cart
     249    foreach ( $items as $item ) {
     250        $new_cart->set_item( $item->product_id, array(
     251            'quantity'         => $item->quantity,
     252            'variation_values' => $item->variation_values,
     253            'custom_message'   => $item->custom_message,
     254            'provided_price'   => $item->provided_price,
     255            'time_requested'   => $item->time_requested,
     256            'custom_file'      => $item->custom_file,
     257            'is_customisable'  => $item->is_customisable,
     258            'meta'             => $item->meta
     259        ) );
     260    }
     261
     262    require_once( ABSPATH . 'wp-admin/includes/user.php' );
     263    wp_delete_user( $old_id );
     264
     265    _wpsc_set_customer_cookie( '', time() - 3600 );
     266}
     267
     268function wpsc_get_customer_cart( $id = false ) {
     269    global $wpsc_cart;
     270
     271    if ( ! empty( $wpsc_cart ) && ( ! $id || $id == wpsc_get_current_customer_id() ) )
     272        return $wpsc_cart;
     273
     274    $cart = maybe_unserialize( base64_decode( wpsc_get_customer_meta( 'cart', $id ) ) );
     275    if ( empty( $cart ) || ! $cart instanceof wpsc_cart )
     276        $cart = new wpsc_cart();
     277
     278    return $cart;
     279}
     280
     281function wpsc_update_customer_cart( $cart, $id = false ) {
     282    if ( ! $id || $id == wpsc_get_current_customer_id() )
     283        return wpsc_serialize_shopping_cart();
     284
     285    return wpsc_update_customer_meta( 'cart', base64_encode( serialize( $wpsc_cart ) ), $id );
    212286}
    213287
     
    476550    return false;
    477551}
     552
     553/**
     554 * Given a users.php view's HTML code, this function returns the user count displayed
     555 * in the view.
     556 *
     557 * If `count_users()` had implented caching, we could have just called that function again
     558 * instead of using this hack.
     559 *
     560 * @access private
     561 * @since  3.8.13.2
     562 * @param  string $view
     563 * @return int
     564 */
     565function _wpsc_extract_user_count( $view ) {
     566    if ( preg_match( '/class="count">\((\d+)\)/', $view, $matches ) ) {
     567        return absint( $matches[1] );
     568    }
     569
     570    return 0;
     571}
     572
     573/**
     574 * Filter the user views so that Anonymous role is not displayed
     575 *
     576 * @since  3.8.13.2
     577 * @access private
     578 * @param  array $views
     579 * @return array
     580 */
     581function _wpsc_filter_views_users( $views ) {
     582    if ( isset( $views['wpsc_anonymous'] ) ) {
     583        // ugly hack to make the anonymous users not count towards "All"
     584        // really wish WordPress had a filter in count_users(), but in the mean time
     585        // this will do
     586        $anon_count = _wpsc_extract_user_count( $views['wpsc_anonymous'] );
     587        $all_count = _wpsc_extract_user_count( $views['all'] );
     588        $new_count = $all_count - $anon_count;
     589        $views['all'] = str_replace( "(${all_count})", "(${new_count})", $views['all'] );
     590    }
     591
     592    unset( $views['wpsc_anonymous'] );
     593    return $views;
     594}
     595
     596/**
     597 * Add the action necessary to filter out anonymous users
     598 *
     599 * @since 3.8.13.2
     600 * @access private
     601 */
     602function _wpsc_action_load_users() {
     603    add_action( 'pre_user_query', '_wpsc_action_pre_user_query', 10, 1 );
     604}
     605
     606/**
     607 * Filter out anonymous users in "All" view
     608 *
     609 * @since 3.8.13.2
     610 * @access private
     611 * @param  WP_User_Query $query
     612 */
     613function _wpsc_action_pre_user_query( $query ) {
     614    global $wpdb;
     615
     616    // only do this when we're viewing all users
     617    if ( ! empty( $query->query_vars['role'] ) )
     618        return;
     619
     620    // if the site is multisite, a JOIN is already done
     621    if ( is_multisite() ) {
     622        $query->query_where .= " AND CAST($wpdb->usermeta.meta_value AS CHAR) NOT LIKE '%" . like_escape( '"wpsc_anonymous"' ) . "%'";
     623        return;
     624    }
     625
     626    $cap_meta_query = array(
     627        array(
     628            'key'     => $wpdb->get_blog_prefix( $query->query_vars['blog_id'] ) . 'capabilities',
     629            'value'   => '"wpsc_anonymous"',
     630            'compare' => 'not like',
     631        )
     632    );
     633
     634    $meta_query = new WP_Meta_Query( $cap_meta_query );
     635    $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $query );
     636
     637    $query->query_from .= $clauses['join'];
     638    $query->query_where .= $clauses['where'];
     639}
     640
     641/**
     642 * Make sure Anonymous role not editable
     643 *
     644 * @since 3.8.13.2
     645 * @param  array $editable_roles
     646 * @return array
     647 */
     648function _wpsc_filter_editable_roles( $editable_roles ) {
     649    unset( $editable_roles['wpsc_anonymous'] );
     650    return $editable_roles;
     651}
  • wp-e-commerce/branches/branch-3.8.13/wpsc-includes/wpsc-meta-init.php

    r826442 r836741  
    123123    foreach ( $old_meta_rows as $old_meta_row ) {
    124124        $meta_data = maybe_unserialize( $old_meta_row->meta_value );
    125         add_metadata( $meta_object_type, $old_meta_row->object_id, $old_meta_row->meta_key, $meta_data, false );
     125        add_metadata( 'wpsc_' . $meta_object_type, $old_meta_row->object_id, $old_meta_row->meta_key, $meta_data, false );
    126126    }
    127127}
Note: See TracChangeset for help on using the changeset viewer.