Plugin Directory

Changeset 3264867


Ignore:
Timestamp:
04/01/2025 06:29:07 AM (12 months ago)
Author:
lemonink
Message:

Tagging version 0.8.0

Location:
lemonink
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • lemonink/tags/0.8.0/includes/class-wc-lemonink-download-handler.php

    r2476246 r3264867  
    3030            return true;
    3131        }
    32        
     32
    3333        public function download_product( $user_email, $order_key, $product_id, $user_id, $download_id, $order_id ) {
    3434            if ( $this->is_lemoninkable_download( $download_id ) ) {
    3535                $meta_prefix = "_li_product_{$product_id}_";
    3636
    37                 $transaction_id = get_post_meta( $order_id, $meta_prefix . 'transaction_id', true );
    38                 $transaction = $this->settings->get_api_client()->find( 'transaction', $transaction_id );
    39                
     37                $transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $order_id, $meta_prefix );
     38                if (!$transaction_data || !$transaction_data['id']) {
     39                    return;
     40                }
     41
     42                $transaction = $this->settings->get_api_client()->find( 'transaction', $transaction_data['id'] );
     43
    4044                $product = wc_get_product( $product_id );
    4145                $files = get_downloads( $product );
    4246
    4347                $format = strtolower($files[$download_id]['name']);
    44                
     48
    4549                WC_Download_Handler::download( $transaction->getUrl($format), $product_id );
    4650                exit;
     
    5559            $product = wc_get_product( $product_id );
    5660            $files = get_downloads( $product );
    57            
     61
    5862            foreach ($files as $download_id => $file) {
    5963                if ( $this->is_lemoninkable_download( $download_id ) ) {
  • lemonink/tags/0.8.0/includes/class-wc-lemonink-integration.php

    r3106535 r3264867  
    6666            } else {
    6767                $this->settings['api_key'] = $this->get_field_value( 'api_key', $fields['api_key'], $post_data );
    68             }       
    69        
     68            }
     69
    7070            $option_key = $this->get_option_key();
    7171            do_action( 'woocommerce_update_option', array( 'id' => $option_key ) );
    7272            $result = update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
    73    
     73
    7474            // Fetch API key from settings and reload form fields to reflect changes
    7575            $this->forget_api_key();
    7676            $this->get_settings();
    7777            $this->init_form_fields();
    78    
     78
    7979            return $result;
    8080        }
  • lemonink/tags/0.8.0/includes/class-wc-lemonink-order.php

    r3173483 r3264867  
    2525        public function create_transaction( $download_data ) {
    2626            $meta_prefix = "_li_product_{$download_data['product_id']}_";
    27             $transaction_exists = get_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', 'yes' );
     27            $transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $download_data['order_id'], $meta_prefix );
     28            $transaction_exists = !!$transaction_data;
    2829
    2930            $product = wc_get_product( $download_data['product_id'] );
     
    4041                if ( $parent_id ) {
    4142                    $parent_meta_prefix = "_li_product_{$parent_id}_";
    42                     $transaction_id = get_post_meta( $download_data['order_id'], $parent_meta_prefix . 'transaction_id', 'yes' );
    43                     $transaction_token = get_post_meta( $download_data['order_id'], $parent_meta_prefix . 'transaction_token', 'yes' );
     43                    $parent_transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $download_data['order_id'], $parent_meta_prefix );
    4444
    45                     if ( $transaction_id ) {
    46                         add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', $transaction_id, true );
    47                         add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_token', $transaction_token, true );
     45                    if ( $parent_transaction_data ) {
     46                        WC_LemonInk_Order_Metadata::set_transaction_data(
     47                            $download_data['order_id'],
     48                            $meta_prefix,
     49                            $parent_transaction_data['id'],
     50                            $parent_transaction_data['token']
     51                        );
    4852                        $transaction_exists = true;
    4953                    }
     
    6670                        $transaction->setWatermarkParams( $this->watermark_params( $user->getWatermarkParams(), $order ) );
    6771                    } else {
    68                         $watermark_value = get_post_meta( $download_data['order_id'], '_li_watermark_value', 'yes' );
     72                        $watermark_value = WC_LemonInk_Order_Metadata::get_watermark_value( $download_data['order_id'] );
    6973                        if ( !isset($watermark_value) ) {
    7074                            $watermark_value = $this->watermark_value( $download_data['order_id'], $download_data['user_email'] );
     
    7579                    $this->settings->get_api_client()->save($transaction);
    7680
    77                     add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', $transaction->getId(), true );
    78                     add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_token', $transaction->getToken(), true );
     81                    WC_LemonInk_Order_Metadata::set_transaction_data(
     82                        $download_data['order_id'],
     83                        $meta_prefix,
     84                        $transaction->getId(),
     85                        $transaction->getToken()
     86                    );
    7987                }
    8088            }
  • lemonink/tags/0.8.0/includes/class-wc-lemonink-product.php

    r2763015 r3264867  
    9595
    9696        }
    97        
     97
    9898        public function save_product( $product_id ) {
    9999            $post = get_post( $product_id );
     
    114114                '_li_master_id'    => trim( $_POST['variable_li_master_id'][ $i ] )
    115115            );
    116            
     116
    117117            $this->_save_product( $product_id, $params );
    118118        }
     
    140140
    141141                $files = array();
    142                
     142
    143143                if ( $master ) {
    144144                    foreach ( $master->getFormats() as $format ) {
     
    168168            if ( !$exists_on_disk ) {
    169169                $master_id = preg_replace( '/\.([^.]+)$/', '', $file_url);
    170                
     170
    171171                return !!preg_match( '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $master_id );
    172172            } else {
     
    178178            if ( !$exists_on_disk ) {
    179179                $master_id = preg_replace( '/\.([^.]+)$/', '', $file_url);
    180                
     180
    181181                $master = $this->settings->get_api_client()->find( 'master', $master_id );
    182182
  • lemonink/tags/0.8.0/lemonink.php

    r3173483 r3264867  
    55 * Plugin URI: https://www.lemonink.co/
    66 * Description: Watermark EPUB, MOBI and PDF files in your WooCommerce store using the LemonInk service.
    7  * Version: 0.7.2
     7 * Version: 0.8.0
    88 * Author: LemonInk
    99 * Author URI: https://www.lemonink.co/
    1010 * Requires at least: 4.4
    11  * Tested up to: 6.6.2
     11 * Tested up to: 6.8
    1212 *
    1313 * Text Domain: lemonink
     
    7979
    8080            include_once plugin_dir_path( __FILE__ ) . "vendor/autoload.php";
     81            require_once( dirname( __FILE__ ) . '/includes/class-wc-lemonink-order-metadata.php' );
    8182
    8283            include_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-lemonink-product.php';
     
    8889            include_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-lemonink-download-handler.php';
    8990            new WC_LemonInk_Download_Handler( $this->settings );
     91
    9092        }
    9193
  • lemonink/tags/0.8.0/readme.txt

    r3173483 r3264867  
    33Tags: lemonink, ecommerce, e-commerce, downloadable, downloads, ebooks, drm, watermark, watermarking, epub, mobi, pdf, Kindle, woocommerce
    44Requires at least: 4.4
    5 Tested up to: 6.6.2
    6 Stable tag: 0.7.2
     5Tested up to: 6.8
     6Stable tag: 0.8.0
    77License: MIT
    88
  • lemonink/trunk/includes/class-wc-lemonink-download-handler.php

    r2476246 r3264867  
    3030            return true;
    3131        }
    32        
     32
    3333        public function download_product( $user_email, $order_key, $product_id, $user_id, $download_id, $order_id ) {
    3434            if ( $this->is_lemoninkable_download( $download_id ) ) {
    3535                $meta_prefix = "_li_product_{$product_id}_";
    3636
    37                 $transaction_id = get_post_meta( $order_id, $meta_prefix . 'transaction_id', true );
    38                 $transaction = $this->settings->get_api_client()->find( 'transaction', $transaction_id );
    39                
     37                $transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $order_id, $meta_prefix );
     38                if (!$transaction_data || !$transaction_data['id']) {
     39                    return;
     40                }
     41
     42                $transaction = $this->settings->get_api_client()->find( 'transaction', $transaction_data['id'] );
     43
    4044                $product = wc_get_product( $product_id );
    4145                $files = get_downloads( $product );
    4246
    4347                $format = strtolower($files[$download_id]['name']);
    44                
     48
    4549                WC_Download_Handler::download( $transaction->getUrl($format), $product_id );
    4650                exit;
     
    5559            $product = wc_get_product( $product_id );
    5660            $files = get_downloads( $product );
    57            
     61
    5862            foreach ($files as $download_id => $file) {
    5963                if ( $this->is_lemoninkable_download( $download_id ) ) {
  • lemonink/trunk/includes/class-wc-lemonink-integration.php

    r3106535 r3264867  
    6666            } else {
    6767                $this->settings['api_key'] = $this->get_field_value( 'api_key', $fields['api_key'], $post_data );
    68             }       
    69        
     68            }
     69
    7070            $option_key = $this->get_option_key();
    7171            do_action( 'woocommerce_update_option', array( 'id' => $option_key ) );
    7272            $result = update_option( $option_key, apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' );
    73    
     73
    7474            // Fetch API key from settings and reload form fields to reflect changes
    7575            $this->forget_api_key();
    7676            $this->get_settings();
    7777            $this->init_form_fields();
    78    
     78
    7979            return $result;
    8080        }
  • lemonink/trunk/includes/class-wc-lemonink-order.php

    r3173483 r3264867  
    2525        public function create_transaction( $download_data ) {
    2626            $meta_prefix = "_li_product_{$download_data['product_id']}_";
    27             $transaction_exists = get_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', 'yes' );
     27            $transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $download_data['order_id'], $meta_prefix );
     28            $transaction_exists = !!$transaction_data;
    2829
    2930            $product = wc_get_product( $download_data['product_id'] );
     
    4041                if ( $parent_id ) {
    4142                    $parent_meta_prefix = "_li_product_{$parent_id}_";
    42                     $transaction_id = get_post_meta( $download_data['order_id'], $parent_meta_prefix . 'transaction_id', 'yes' );
    43                     $transaction_token = get_post_meta( $download_data['order_id'], $parent_meta_prefix . 'transaction_token', 'yes' );
     43                    $parent_transaction_data = WC_LemonInk_Order_Metadata::get_transaction_data( $download_data['order_id'], $parent_meta_prefix );
    4444
    45                     if ( $transaction_id ) {
    46                         add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', $transaction_id, true );
    47                         add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_token', $transaction_token, true );
     45                    if ( $parent_transaction_data ) {
     46                        WC_LemonInk_Order_Metadata::set_transaction_data(
     47                            $download_data['order_id'],
     48                            $meta_prefix,
     49                            $parent_transaction_data['id'],
     50                            $parent_transaction_data['token']
     51                        );
    4852                        $transaction_exists = true;
    4953                    }
     
    6670                        $transaction->setWatermarkParams( $this->watermark_params( $user->getWatermarkParams(), $order ) );
    6771                    } else {
    68                         $watermark_value = get_post_meta( $download_data['order_id'], '_li_watermark_value', 'yes' );
     72                        $watermark_value = WC_LemonInk_Order_Metadata::get_watermark_value( $download_data['order_id'] );
    6973                        if ( !isset($watermark_value) ) {
    7074                            $watermark_value = $this->watermark_value( $download_data['order_id'], $download_data['user_email'] );
     
    7579                    $this->settings->get_api_client()->save($transaction);
    7680
    77                     add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_id', $transaction->getId(), true );
    78                     add_post_meta( $download_data['order_id'], $meta_prefix . 'transaction_token', $transaction->getToken(), true );
     81                    WC_LemonInk_Order_Metadata::set_transaction_data(
     82                        $download_data['order_id'],
     83                        $meta_prefix,
     84                        $transaction->getId(),
     85                        $transaction->getToken()
     86                    );
    7987                }
    8088            }
  • lemonink/trunk/includes/class-wc-lemonink-product.php

    r2763015 r3264867  
    9595
    9696        }
    97        
     97
    9898        public function save_product( $product_id ) {
    9999            $post = get_post( $product_id );
     
    114114                '_li_master_id'    => trim( $_POST['variable_li_master_id'][ $i ] )
    115115            );
    116            
     116
    117117            $this->_save_product( $product_id, $params );
    118118        }
     
    140140
    141141                $files = array();
    142                
     142
    143143                if ( $master ) {
    144144                    foreach ( $master->getFormats() as $format ) {
     
    168168            if ( !$exists_on_disk ) {
    169169                $master_id = preg_replace( '/\.([^.]+)$/', '', $file_url);
    170                
     170
    171171                return !!preg_match( '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $master_id );
    172172            } else {
     
    178178            if ( !$exists_on_disk ) {
    179179                $master_id = preg_replace( '/\.([^.]+)$/', '', $file_url);
    180                
     180
    181181                $master = $this->settings->get_api_client()->find( 'master', $master_id );
    182182
  • lemonink/trunk/lemonink.php

    r3173483 r3264867  
    55 * Plugin URI: https://www.lemonink.co/
    66 * Description: Watermark EPUB, MOBI and PDF files in your WooCommerce store using the LemonInk service.
    7  * Version: 0.7.2
     7 * Version: 0.8.0
    88 * Author: LemonInk
    99 * Author URI: https://www.lemonink.co/
    1010 * Requires at least: 4.4
    11  * Tested up to: 6.6.2
     11 * Tested up to: 6.8
    1212 *
    1313 * Text Domain: lemonink
     
    7979
    8080            include_once plugin_dir_path( __FILE__ ) . "vendor/autoload.php";
     81            require_once( dirname( __FILE__ ) . '/includes/class-wc-lemonink-order-metadata.php' );
    8182
    8283            include_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-lemonink-product.php';
     
    8889            include_once plugin_dir_path( __FILE__ ) . 'includes/class-wc-lemonink-download-handler.php';
    8990            new WC_LemonInk_Download_Handler( $this->settings );
     91
    9092        }
    9193
  • lemonink/trunk/readme.txt

    r3173483 r3264867  
    33Tags: lemonink, ecommerce, e-commerce, downloadable, downloads, ebooks, drm, watermark, watermarking, epub, mobi, pdf, Kindle, woocommerce
    44Requires at least: 4.4
    5 Tested up to: 6.6.2
    6 Stable tag: 0.7.2
     5Tested up to: 6.8
     6Stable tag: 0.8.0
    77License: MIT
    88
Note: See TracChangeset for help on using the changeset viewer.