WordPress.org

Plugin Directory

Changeset 1578992


Ignore:
Timestamp:
01/20/17 22:18:44 (7 months ago)
Author:
dancameron
Message:

Deploy version 12.0.3

Location:
sprout-invoices
Files:
590 added
8 edited

Legend:

Unmodified
Added
Removed
  • sprout-invoices/trunk/Sprout_Invoices.class.php

    r1571585 r1578992  
    3333     * Current version. Should match sprout-invoices.php plugin version. 
    3434     */ 
    35     const SI_VERSION = '12.0.2'; 
     35    const SI_VERSION = '12.0.3'; 
    3636    /** 
    3737     * DB Version 
  • sprout-invoices/trunk/bundles/updates/edd_plugin_updater.class.php

    r1550009 r1578992  
    1414 * Allows plugins to use their own update API. 
    1515 * 
    16  * @author Pippin Williamson 
    17  * @version 1.6.3 
     16 * @author Easy Digital Downloads 
     17 * @version 1.6.9 // with "// Modification" 
    1818 */ 
    1919class EDD_SL_Plugin_Updater_SA_Mod { 
    20     private $api_url   = ''; 
    21     private $api_data  = array(); 
    22     private $name      = ''; 
    23     private $slug      = ''; 
    24     private $version   = ''; 
     20 
     21    private $api_url     = ''; 
     22    private $api_data    = array(); 
     23    private $name        = ''; 
     24    private $slug        = ''; 
     25    private $version     = ''; 
     26    private $wp_override = false; 
     27    private $cache_key   = ''; 
    2528 
    2629    /** 
     
    3841        global $edd_plugin_data; 
    3942 
    40         $this->api_url  = trailingslashit( $_api_url ); 
    41         $this->api_data = $_api_data; 
    42         $this->name     = plugin_basename( $_plugin_file ); 
    43         $this->slug     = basename( $_plugin_file, '.php' ); 
    44         $this->version  = $_api_data['version']; 
     43        $this->api_url     = trailingslashit( $_api_url ); 
     44        $this->api_data    = $_api_data; 
     45        $this->name        = plugin_basename( $_plugin_file ); 
     46        $this->slug        = basename( $_plugin_file, '.php' ); 
     47        $this->version     = $_api_data['version']; 
     48        $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false; 
     49 
     50        $this->cache_key   = md5( serialize( $this->slug . $this->api_data['license'] ) ); 
    4551 
    4652        $edd_plugin_data[ $this->slug ] = $this->api_data; 
     
    6268        add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); 
    6369        add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); 
    64         remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10, 2 ); 
     70        remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 ); 
    6571        add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); 
    6672        add_action( 'admin_init', array( $this, 'show_changelog' ) ); 
     
    9399        } 
    94100 
    95         if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { 
    96  
    97             $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); 
    98  
    99             if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { 
    100  
    101                 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { 
    102  
    103                     $_transient_data->response[ $this->name ] = $version_info; 
    104  
    105                 } 
    106  
    107                 $_transient_data->last_checked = time(); 
    108                 $_transient_data->checked[ $this->name ] = $this->version; 
    109  
    110             } 
     101        if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { 
     102            return $_transient_data; 
     103        } 
     104 
     105        $version_info = $this->get_cached_version_info(); 
     106 
     107        if ( false === $version_info ) { 
     108            $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => ! empty( $this->api_data['beta'] ) ) ); 
     109 
     110            $this->set_version_info_cache( $version_info ); 
     111 
     112        } 
     113 
     114        if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { 
     115 
     116            if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { 
     117 
     118                $_transient_data->response[ $this->name ] = $version_info; 
     119 
     120            } 
     121 
     122            $_transient_data->last_checked           = current_time( 'timestamp' ); 
     123            $_transient_data->checked[ $this->name ] = $this->version; 
     124 
    111125        } 
    112126 
     
    122136    public function show_update_notification( $file, $plugin ) { 
    123137 
     138        if ( is_network_admin() ) { 
     139            return; 
     140        } 
     141 
    124142        if ( ! current_user_can( 'update_plugins' ) ) { 
    125143            return; 
     
    143161        if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { 
    144162 
    145             $cache_key    = md5( 'edd_plugin_' . sanitize_key( $this->name ) . '_version_info' ); 
    146             $version_info = get_transient( $cache_key ); 
     163            $version_info = $this->get_cached_version_info(); 
    147164 
    148165            if ( false === $version_info ) { 
    149  
    150                 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); 
    151  
    152                 set_transient( $cache_key, $version_info, 3600 ); 
     166                $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => ! empty( $this->api_data['beta'] ) ) ); 
     167 
     168                $this->set_version_info_cache( $version_info ); 
    153169            } 
    154170 
     
    163179            } 
    164180 
    165             $update_cache->last_checked = time(); 
     181            $update_cache->last_checked = current_time( 'timestamp' ); 
    166182            $update_cache->checked[ $this->name ] = $this->version; 
    167183 
     
    181197            // build a plugin list row, with update notification 
    182198            $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); 
    183             echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; 
     199            # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> 
     200            echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">'; 
     201            echo '<td colspan="3" class="plugin-update colspanchange">'; 
     202            echo '<div class="update-message notice inline notice-warning notice-alt">'; 
    184203 
    185204            $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); 
     
    211230    } 
    212231 
    213  
    214232    /** 
    215233     * Updates information on the "View version x.x details" page with custom data. 
     
    240258            'is_ssl' => is_ssl(), 
    241259            'fields' => array( 
    242                 'banners' => false, // These will be supported soon hopefully 
     260                'banners' => array(), 
    243261                'reviews' => false, 
    244262            ), 
    245263        ); 
    246264 
    247         $api_response = $this->api_request( 'plugin_information', $to_send ); 
    248  
    249         if ( false !== $api_response ) { 
    250             $_data = $api_response; 
     265        $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] ) ); 
     266 
     267        // Get the transient where we store the api request for this plugin for 24 hours 
     268        $edd_api_request_transient = $this->get_cached_version_info( $cache_key ); 
     269 
     270        //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. 
     271        if ( empty( $edd_api_request_transient ) ) { 
     272 
     273            $api_response = $this->api_request( 'plugin_information', $to_send ); 
     274 
     275            // Expires in 3 hours 
     276            $this->set_version_info_cache( $api_response, $cache_key ); 
     277 
     278            if ( false !== $api_response ) { 
     279                $_data = $api_response; 
     280            } 
     281        } else { 
     282            $_data = $edd_api_request_transient; 
    251283        } 
    252284 
    253285        return $_data; 
    254286    } 
    255  
    256287 
    257288    /** 
     
    293324        if ( $this->api_url == trailingslashit( home_url() ) ) { 
    294325            return false; // Don't allow a plugin to ping itself 
     326        } 
     327 
     328        // Modification 
     329        if ( ! isset( $data['item_id'] ) && isset( $data['download_id'] ) ) { 
     330            $data['item_id'] = $data['download_id']; 
    295331        } 
    296332 
     
    300336            'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false, 
    301337            'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false, 
     338            'version'    => isset( $data['version'] ) ? $data['version'] : false, 
    302339            'slug'       => $data['slug'], 
    303340            'author'     => $data['author'], 
    304341            'url'        => home_url(), 
     342            'beta'       => ! empty( $data['beta'] ), 
    305343        ); 
    306344 
     
    317355        } 
    318356 
     357        if ( $request && isset( $request->banners ) ) { 
     358            $request->banners = maybe_unserialize( $request->banners ); 
     359        } 
     360 
     361        if ( ! empty( $request ) ) { 
     362            foreach ( $request->sections as $key => $section ) { 
     363                $request->$key = (array) $section; 
     364            } 
     365        } 
     366 
    319367        return $request; 
    320368    } 
     
    342390        $data         = $edd_plugin_data[ $_REQUEST['slug'] ]; 
    343391        $cache_key    = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' ); 
    344         $version_info = get_transient( $cache_key ); 
     392        $version_info = $this->get_cached_version_info( $cache_key ); 
    345393 
    346394        if ( false === $version_info ) { 
     
    353401                'author'     => $data['author'], 
    354402                'url'        => home_url(), 
     403                'beta'       => ! empty( $data['beta'] ), 
    355404            ); 
    356405 
     
    367416            } 
    368417 
    369             set_transient( $cache_key, $version_info, 3600 ); 
     418            if ( ! empty( $version_info ) ) { 
     419                foreach ( $version_info->sections as $key => $section ) { 
     420                    $version_info->$key = (array) $section; 
     421                } 
     422            } 
     423 
     424            $this->set_version_info_cache( $version_info, $cache_key ); 
    370425 
    371426        } 
     
    377432        exit; 
    378433    } 
     434 
     435    public function get_cached_version_info( $cache_key = '' ) { 
     436 
     437        if ( empty( $cache_key ) ) { 
     438            $cache_key = $this->cache_key; 
     439        } 
     440 
     441        $cache = get_option( $cache_key ); 
     442 
     443        if ( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) { 
     444            return false; // Cache is expired 
     445        } 
     446 
     447        return json_decode( $cache['value'] ); 
     448 
     449    } 
     450 
     451    public function set_version_info_cache( $value = '', $cache_key = '' ) { 
     452 
     453        if ( empty( $cache_key ) ) { 
     454            $cache_key = $this->cache_key; 
     455        } 
     456 
     457        $data = array( 
     458            'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ), 
     459            'value'   => json_encode( $value ), 
     460        ); 
     461 
     462        update_option( $cache_key, $data ); 
     463 
     464    } 
    379465} 
  • sprout-invoices/trunk/changelog.txt

    r1571585 r1578992  
    1 = 12.0.2 = 
     1= 12.0.3 = 
    22 
    33* FIX: Select2 Compat issues with themes and other plugins 
  • sprout-invoices/trunk/controllers/reporting/Reporting.php

    r1550009 r1578992  
    342342    } 
    343343 
    344     public static function total_invoice_data( $this = 'century' ) { 
     344    public static function total_invoice_data( $span = 'century' ) { 
    345345        // Return cache if present. 
    346         $cache = self::get_cache( __FUNCTION__ . $this ); 
     346        $cache = self::get_cache( __FUNCTION__ . $span ); 
    347347        if ( $cache ) { 
    348348            return $cache; 
     
    372372 
    373373        // If date filtered 
    374         if ( 'century' !== $this ) { 
    375             $args = self::_get_date_query( $this, $args ); 
    376             $expire = self::_get_date_query( $this, $args, true ); 
     374        if ( 'century' !== $span ) { 
     375            $args = self::_get_date_query( $span, $args ); 
     376            $expire = self::_get_date_query( $span, $args, true ); 
    377377        } 
    378378        $invoices = new WP_Query( $args ); 
     
    408408 
    409409        } 
    410         return self::set_cache( __FUNCTION__ . $this, $data, $expire ); 
     410        return self::set_cache( __FUNCTION__ . $span, $data, $expire ); 
    411411    } 
    412412 
     
    484484    } 
    485485 
    486     public static function total_payment_data( $this = 'century' ) { 
     486    public static function total_payment_data( $span = 'century' ) { 
    487487        // Return cache if present. 
    488         $cache = self::get_cache( __FUNCTION__.$this ); 
     488        $cache = self::get_cache( __FUNCTION__.$span ); 
    489489        if ( $cache ) { 
    490490            return $cache; 
     
    511511 
    512512        // If date filtered 
    513         if ( 'century' !== $this ) { 
    514             $args = self::_get_date_query( $this, $args ); 
    515             $expire = self::_get_date_query( $this, $args, true ); 
     513        if ( 'century' !== $span ) { 
     514            $args = self::_get_date_query( $span, $args ); 
     515            $expire = self::_get_date_query( $span, $args, true ); 
    516516        } 
    517517        $payments = new WP_Query( $args ); 
     
    544544        } 
    545545 
    546         return self::set_cache( __FUNCTION__.$this, $data, $expire ); 
    547     } 
    548  
    549     public static function _get_date_query( $this = 'century', $args = array(), $return_expiration = false ) { 
    550         switch ( $this ) { 
     546        return self::set_cache( __FUNCTION__.$span, $data, $expire ); 
     547    } 
     548 
     549    public static function _get_date_query( $span = 'century', $args = array(), $return_expiration = false ) { 
     550        switch ( $span ) { 
    551551            case 'week': 
    552552                $args['date_query'] = array( 
  • sprout-invoices/trunk/models/Estimate.php

    r1477306 r1578992  
    426426 
    427427    public function get_discount_total() { 
    428         $subtotal = $this->get_subtotal(); 
     428        $subtotal = (float) $this->get_subtotal(); 
    429429        if ( $subtotal < 0.01 ) { // In case the line items are zero but the total has a value 
    430             $subtotal = $this->get_total(); 
     430            $subtotal = (float) $this->get_total(); 
    431431        } 
    432432        if ( apply_filters( 'si_discount_after_taxes', true, $this ) ) { 
    433             $tax_total = $subtotal * ( ( $this->get_tax() ) / 100 ); 
    434             $tax2_total = $subtotal * ( ( $this->get_tax2() ) / 100 ); 
     433            $tax_total = $subtotal * ( ( (float) $this->get_tax() ) / 100 ); 
     434            $tax2_total = $subtotal * ( ( (float) $this->get_tax2() ) / 100 ); 
    435435            $subtotal = $subtotal + $tax_total + $tax2_total; 
    436436        } 
    437437 
    438         $discount = $subtotal * ( $this->get_discount() / 100 ); 
    439         return si_get_number_format( $discount ); 
     438        $discount = $subtotal * ( (float) $this->get_discount() / 100 ); 
     439        return si_get_number_format( (float) $discount ); 
    440440    } 
    441441 
     
    541541    public function get_calculated_total() { 
    542542        if ( isset( $this->calculated_total ) ) { 
    543             return $this->calculated_total; 
    544         } 
    545         $subtotal = $this->get_subtotal(); 
     543            return (float) $this->calculated_total; 
     544        } 
     545        $subtotal = (float) $this->get_subtotal(); 
    546546        if ( $subtotal < 0.01 ) { // In case the line items are zero but the total has a value 
    547             $subtotal = $this->get_total(); 
    548         } 
    549  
    550         $invoice_total = $subtotal + $this->get_tax_total() + $this->get_tax2_total(); 
    551         $total = $invoice_total - $this->get_discount_total(); 
    552  
    553         $total = $total + $this->get_fees_total(); 
    554  
    555         $this->calculated_total = $total; 
    556  
    557         return si_get_number_format( $total ); 
     547            $subtotal = (float) $this->get_total(); 
     548        } 
     549 
     550        $estimate_total = $subtotal + (float) $this->get_tax_total() + (float) $this->get_tax2_total(); 
     551        $total = $estimate_total - (float) $this->get_discount_total(); 
     552 
     553        $total = $total + (float) $this->get_fees_total(); 
     554 
     555        $this->calculated_total = (float) $total; 
     556 
     557        return si_get_number_format( (float) $total ); 
    558558    } 
    559559 
  • sprout-invoices/trunk/models/Invoice.php

    r1476062 r1578992  
    489489 
    490490    public function get_discount_total() { 
    491         $subtotal = $this->get_subtotal(); 
     491        $subtotal = (float) $this->get_subtotal(); 
    492492        if ( $subtotal < 0.01 ) { // In case the line items are zero but the total has a value 
    493             $subtotal = $this->get_total(); 
     493            $subtotal = (float) $this->get_total(); 
    494494        } 
    495495        if ( apply_filters( 'si_discount_after_taxes', true, $this ) ) { 
    496             $tax_total = $subtotal * ( ( $this->get_tax() ) / 100 ); 
    497             $tax2_total = $subtotal * ( ( $this->get_tax2() ) / 100 ); 
     496            $tax_total = $subtotal * ( ( (float) $this->get_tax() ) / 100 ); 
     497            $tax2_total = $subtotal * ( ( (float) $this->get_tax2() ) / 100 ); 
    498498            $subtotal = $subtotal + $tax_total + $tax2_total; 
    499499        } 
    500500 
    501         $discount = $subtotal * ( $this->get_discount() / 100 ); 
    502         return si_get_number_format( $discount ); 
     501        $discount = $subtotal * ( (float) $this->get_discount() / 100 ); 
     502        return si_get_number_format( (float) $discount ); 
    503503    } 
    504504 
     
    609609        } 
    610610        if ( isset( $this->calculated_total ) ) { 
    611             return $this->calculated_total; 
    612         } 
    613         $subtotal = $this->get_subtotal(); 
     611            return (float) $this->calculated_total; 
     612        } 
     613        $subtotal = (float) $this->get_subtotal(); 
    614614        if ( $subtotal < 0.01 ) { // In case the line items are zero but the total has a value 
    615             $subtotal = $this->get_total(); 
    616         } 
    617  
    618         $invoice_total = $subtotal + $this->get_tax_total() + $this->get_tax2_total(); 
    619         $total = $invoice_total - $this->get_discount_total(); 
    620  
    621         $total = $total + $this->get_fees_total(); 
    622  
    623         $this->calculated_total = $total; 
     615            $subtotal = (float) $this->get_total(); 
     616        } 
     617 
     618        $invoice_total = $subtotal + (float) $this->get_tax_total() + (float) $this->get_tax2_total(); 
     619        $total = $invoice_total - (float) $this->get_discount_total(); 
     620 
     621        $total = (float) $total + (float) $this->get_fees_total(); 
     622 
     623        $this->calculated_total = (float) $total; 
    624624 
    625625        if ( $total !== $this->get_total() ) { 
    626             $this->set_total( si_get_number_format( $total ) ); 
    627         } 
    628  
    629         return si_get_number_format( $total ); 
     626            $this->set_total( si_get_number_format( (float) $total ) ); 
     627        } 
     628 
     629        return si_get_number_format( (float) $total ); 
    630630    } 
    631631 
    632632    public function set_calculated_total() { 
    633         $total = $this->get_calculated_total(); 
     633        $total = (float) $this->get_calculated_total(); 
    634634        $this->save_post_meta( array( 
    635635            self::$meta_keys['total'] => $total, 
     
    640640    public function get_subtotal() { 
    641641        if ( isset( $this->subtotal ) ) { 
    642             return $this->subtotal; 
     642            return (float) $this->subtotal; 
    643643        } 
    644644        $subtotal = 0; 
     
    652652                    } 
    653653 
    654                     $data['rate'] = ( isset( $data['rate'] ) ) ? $data['rate'] : 0 ; 
    655                     $qty = ( isset( $data['qty'] ) ) ? $data['qty'] : 1; 
    656                     $line_total = ( $data['rate'] * $qty ); 
     654                    $data['rate'] = ( isset( $data['rate'] ) ) ? (float) $data['rate'] : 0 ; 
     655                    $qty = ( isset( $data['qty'] ) ) ? (float) $data['qty'] : 1; 
     656                    $line_total = (float) ( $data['rate'] * $qty ); 
    657657                    if ( isset( $data['tax'] ) ) { 
    658                         $tax = $line_total * ( $data['tax'] / 100 ); 
     658                        $tax = $line_total * ( (float) $data['tax'] / 100 ); 
    659659                        $line_total = $line_total - si_get_number_format( $tax ); // convert so that rounding can occur before discount is removed. 
    660660                    } 
     
    870870                continue; 
    871871            } elseif ( ! in_array( $payment->get_status(), array( SI_Payment::STATUS_VOID, SI_Payment::STATUS_RECURRING, SI_Payment::STATUS_CANCELLED ) ) ) { 
    872                 $payment_total += $payment->get_amount(); 
     872                $payment_total += (float) $payment->get_amount(); 
    873873            } 
    874874        } 
  • sprout-invoices/trunk/readme.txt

    r1571585 r1578992  
    55Requires at least: 3.8 
    66Tested up to: 4.7 
    7 Stable tag: 12.0.2 
     7Stable tag: 12.0.3 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    126126== Changelog == 
    127127 
    128 = 12.0.2 = 
     128= 12.0.3 = 
    129129 
    130130* FIX: Select2 Compat issues with themes and other plugins 
  • sprout-invoices/trunk/sprout-invoices.php

    r1571585 r1578992  
    33/** 
    44 * @package Sprout_Invoices 
    5  * @version 12.0.2 
     5 * @version 12.0.3 
    66 */ 
    77 
     
    1111 * Description: App allows for any WordPress site to accept estimates, create invoices and receive invoice payments. Learn more at <a href="https://sproutapps.co">Sprout Apps</a>. 
    1212 * Author: Sprout Apps 
    13  * Version: 12.0.2 
     13 * Version: 12.0.3 
    1414 * Author URI: https://sproutapps.co 
    1515 * Text Domain: sprout-invoices 
Note: See TracChangeset for help on using the changeset viewer.