Plugin Directory

Changeset 2835905


Ignore:
Timestamp:
12/19/2022 09:13:32 AM (3 years ago)
Author:
putler
Message:

Changes for v3.1.0

Location:
easy-digital-downloads-putler-connector/trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • easy-digital-downloads-putler-connector/trunk/classes/class-putler-connector.php

    r2820426 r2835905  
    11<?php
     2/**
     3 * Class for Putler connector.
     4 *
     5 * @package     easy-digital-downloads-putler-connector/classes/
     6 * @version     1.0.0
     7 */
     8
    29if ( ! defined( 'ABSPATH' ) ) {
    310    exit;
     
    613if ( ! class_exists( 'Putler_Connector' ) ) {
    714
     15    /**
     16     * Putler Connector class.
     17     */
    818    class Putler_Connector {
    919
     20        /**
     21         * Email address.
     22         *
     23         * @var string $email_address
     24         */
    1025        private $email_address = '';
     26
     27        /**
     28         * The API token.
     29         *
     30         * @var string $api_token
     31         */
    1132        private $api_token = '';
     33
     34        /**
     35         * The version number.
     36         *
     37         * @var float $version
     38         */
    1239        private $version;
     40
     41        /**
     42         * API URL.
     43         *
     44         * @var string $api_url
     45         */
    1346        private $api_url;
     47
     48        /**
     49         * Setting URL.
     50         *
     51         * @var string $settings_url
     52         */
    1453        public $settings_url;
    1554
     55        /**
     56         * Variable to hold instance of Putler_Connector
     57         *
     58         * @var $instance
     59         */
    1660        protected static $instance = null;
    1761
     
    5397            }
    5498
    55             // Show a message when no web tokens found
     99            // Show a message when no web tokens found.
    56100            if ( empty( $this->api_token ) && ! empty( $settings ) ) {
    57101                add_action( 'admin_notices', array( $this, 'putler_desktop_deprecated' ) );
     
    71115         */
    72116        public function get_plugin_info() {
    73 
    74             $data = array(
    75                 'epc_version' => EPC_VERSION,
    76                 'edd_version' => EDD_VERSION,
     117            wp_send_json(
     118                array(
     119                    'epc_version' => EPC_VERSION,
     120                    'edd_version' => EDD_VERSION,
     121                )
    77122            );
    78 
    79             die( json_encode( $data ) );
    80123        }
    81124
     
    84127         */
    85128        public function request_handler() {
    86             $url_path = basename( trim( parse_url( add_query_arg( array() ), PHP_URL_PATH ), '/' ) );
     129            $url_path = basename( trim( wp_parse_url( add_query_arg( array() ), PHP_URL_PATH ), '/' ) );
    87130
    88131            if ( 'ptwp-putler-connector' === $url_path ) {
    89                 $method_name = ( ! empty( $_REQUEST['action'] ) ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) : '';
     132                $method_name = ( ! empty( $_REQUEST['action'] ) ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
    90133
    91134                if ( ! empty( $method_name ) && is_callable( array( $this, $method_name ) ) ) {
     
    100143        public function putler_desktop_deprecated() {
    101144            if ( empty( $this->api_token ) || empty( $this->email_address ) ) {
    102                 echo '<div id="putler_configure_message" class="updated fade error"><p>' . sprintf( __( 'Putler Connector for Putler desktop has deprecated. Please upgrade to %s.', 'easy-digital-downloads-putler-connector' ), '<strong><a href="https://web.putler.com/" target="_blank">Putler Web</a></strong>' ) . '</p></div>';
     145                /* translators: Putler URL */
     146                echo wp_kses_post( '<div id="putler_configure_message" class="updated fade error"><p>' . sprintf( __( 'Putler Connector for Putler desktop has deprecated. Please upgrade to <strong><a href="%s" target="_blank">Putler Web</a></strong>.', 'easy-digital-downloads-putler-connector' ), 'https://web.putler.com/' ) . '</p></div>' );
    103147            }
    104148        }
     
    122166                case 'Alphanumeric':
    123167                    for ( $i = 0; $i < $str_length; $i ++ ) {
    124                         $str_random .= $str_alphanumeric[ rand( 0, strlen( $str_alphanumeric ) - 1 ) ];
     168                        $str_random .= $str_alphanumeric[ wp_rand( 0, strlen( $str_alphanumeric ) - 1 ) ];
    125169                    }
    126170                    break;
    127171                case 'Alphabets':
    128172                    for ( $i = 0; $i < $str_length; $i ++ ) {
    129                         $str_random .= $str_alphabet[ rand( 0, strlen( $str_alphabet ) - 1 ) ];
     173                        $str_random .= $str_alphabet[ wp_rand( 0, strlen( $str_alphabet ) - 1 ) ];
    130174                    }
    131175                    break;
     
    178222            }
    179223
    180             if ( ( ! empty( $_REQUEST['action'] ) && PUTLER_GATEWAY_PREFIX . '_activate' === sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) || ( empty( $this->api_token ) || empty( $this->email_address ) ) ) {
     224            if ( ( ! empty( $_REQUEST['action'] ) && PUTLER_GATEWAY_PREFIX . '_activate' === sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) ) || ( empty( $this->api_token ) || empty( $this->email_address ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
    181225                $authenticate = 1;
    182226            }
     
    185229                $display_msg = __( 'Trying to Connect to Putler...', 'easy-digital-downloads-putler-connector' );
    186230            } else {
    187                 if ( ! empty( $_REQUEST['post_activation'] ) ) { // For handling display of message post activation.
     231                if ( ! empty( sanitize_text_field( wp_unslash( $_REQUEST['post_activation'] ) ) ) ) {  // phpcs:ignore WordPress.Security.NonceVerification
    188232                    $display_msg = __( 'Your transactions are getting synced with Putler. Please check after some time.', 'easy-digital-downloads-putler-connector' );
    189233                }
    190234            }
    191235
    192             echo '<div class="wrap" id="putler_connector_settings_page" style="font-size: 1.1em;">
    193                     <h1>' . __( 'Putler Connector', 'easy-digital-downloads-putler-connector' ) . '</h1> <br/>
    194                     <div>' . wp_kses_post( $display_msg ) . '</div>
    195                   </div>';
     236            echo wp_kses_post(
     237                '<div class="wrap" id="putler_connector_settings_page" style="font-size: 1.1em;">
     238                    <h1>' . __( 'Putler Connector', 'weasy-digital-downloads-putler-connector' ) . '</h1> <br/>
     239                    <div>' . $display_msg . '</div>
     240                  </div>'
     241            );
    196242
    197243            if ( 1 === $authenticate ) {
     
    206252
    207253            $authenticate = 1;
    208             if ( ! empty( $this->api_token ) && ! empty( $this->email_address ) ) { // for existing users
     254            if ( ! empty( $this->api_token ) && ! empty( $this->email_address ) ) { // for existing users.
    209255
    210256                $result = $this->validate_api_info( $this->api_token, $this->email_address, 'validate', array( 'Site-URL' => site_url() ) );
     
    215261
    216262                    if ( ( ! empty( $result['response']['code'] ) && 200 === $result['response']['code'] ) &&
    217                          ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
     263                        ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
    218264                        $authenticate = 0;
    219265
     
    244290
    245291                        <?php
    246 
    247                         // $msg = __('Authentication Failed.', 'easy-digital-downloads-putler-connector').' <a href="">Try again</a>';
    248                         // $this->show_message($msg);
    249292                        exit;
    250293                    }
     
    262305
    263306                    <?php
    264                     // $msg = __('Authentication Failed.', 'easy-digital-downloads-putler-connector').' <a href="">Try again</a>';
    265                     // $this->show_message($msg);
    266307                    exit;
    267308                }
     
    278319                }
    279320
    280                 // getting temp token
     321                // getting temp token.
    281322                $result = $this->validate_api_info( $this->api_token, $this->email_address, 'get_temp_token', array( 'Site-URL' => site_url() ) );
    282323
     
    286327
    287328                    if ( ( ! empty( $result['response']['code'] ) && 200 === $result['response']['code'] ) &&
    288                          ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
     329                        ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
    289330
    290331                        $msg = __( 'Authenticating...', 'easy-digital-downloads-putler-connector' );
     
    315356
    316357                                            if (current_timestamp - start_timestamp >= 30000) {
    317                                                 jQuery("#putler_connector_settings_page").html('<h1><?php echo __( 'Putler Connector', 'easy-digital-downloads-putler-connector' ); ?></h1>' +
     358                                                jQuery("#putler_connector_settings_page").html('<h1><?php echo esc_html__( 'Putler Connector', 'easy-digital-downloads-putler-connector' ); ?></h1>' +
    318359                                                    '<br/>' +
    319360                                                    '<div style="background: lightyellow;border: 0.2em solid #c5c593;border-radius: 0.2em;padding: 0.75em 1em;">' +
     
    347388
    348389                        if ( empty( $existing_user ) ) {
    349                             $msg = __( 'Authentication Failed.', 'easy-digital-downloads-putler-connector' ) . '<br/> <br/> <div class="notice notice-error"> ' . __( 'Please make sure that you have added an ' . PUTLER_GATEWAY . ' account in Putler. If you do not have a Putler account, you can create one for free and enjoy trial for 14 days.', 'easy-digital-downloads-putler-connector' ) . ' <strong><i><a href="https://web.putler.com/#!/signup" target="_blank">' . __( 'Try Putler for free!', 'easy-digital-downloads-putler-connector' ) . '</a></i></strong>. <br/> <br/>' . __( 'Once the ' . PUTLER_GATEWAY . ' account has been added successfully, please click ', 'easy-digital-downloads-putler-connector' ) . '<a href="">' . __( 'here', 'easy-digital-downloads-putler-connector' ) . '.</a> </div>';
     390                            $msg = __( 'Authentication Failed.', 'easy-digital-downloads-putler-connector' ) . '<br/> <br/> <div class="notice notice-error"> ' . sprintf( /* translators: %s: Name of ecommerce gateway */ esc_html__( 'Please make sure that you have added an %s account in Putler. If you do not have a Putler account, you can create one for free and enjoy trial for 14 days.', 'easy-digital-downloads-putler-connector' ), PUTLER_GATEWAY ) . ' <strong><i><a href="https://web.putler.com/#!/signup" target="_blank">' . __( 'Try Putler for free!', 'easy-digital-downloads-putler-connector' ) . '</a></i></strong>. <br/> <br/>' . sprintf( /* translators: %s: Name of ecommerce gateway */ esc_html__( 'Once the %s account has been added successfully, please click ', 'easy-digital-downloads-putler-connector' ), PUTLER_GATEWAY ) . '<a href="">' . __( 'here', 'easy-digital-downloads-putler-connector' ) . '.</a> </div>';
    350391                        } else {
    351392                            $msg = __( 'Authentication Failed.', 'easy-digital-downloads-putler-connector' ) . ' ' . __( 'You would need to reset the account in ', 'easy-digital-downloads-putler-connector' ) . ' <strong><a href="https://web.putler.com/" target="_blank">' . __( 'Putler Web ', 'easy-digital-downloads-putler-connector' ) . '</a></strong>';
     
    379420                }
    380421            }
    381 
    382             ob_clean();
    383             echo json_encode( $response );
    384             die();
     422            wp_send_json( $response );
    385423        }
    386424
     
    418456
    419457                    if ( ! ( ( ! empty( $result['response']['code'] ) && 200 === $result['response']['code'] ) &&
    420                              ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) ) {
     458                            ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) ) {
    421459                        $msg = __( 'Authentication Failed.', 'easy-digital-downloads-putler-connector' ) . ' <a href="">Try again</a>';
    422460                        $this->show_message( $msg );
     
    434472                $this->show_message( $msg );
    435473            }
    436 
    437             ob_clean();
    438             echo json_encode( $response );
    439             die();
     474            wp_send_json( $response );
    440475        }
    441476
     
    456491                );
    457492
    458                 // save settings
     493                // save settings.
    459494                $settings = array();
    460495
    461                 $this->email_address = $settings['email_address'] = ( ! empty( $_SERVER['HTTP_X_PUTLER_EMAIL'] ) ) ? sanitize_email( wp_unslash( $_SERVER['HTTP_X_PUTLER_EMAIL'] ) ) : '';
    462                 $this->api_token     = $settings['api_token'] = ( ! empty( $_SERVER['HTTP_X_PUTLER_AUTH_TOKEN'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_PUTLER_AUTH_TOKEN'] ) ) : '';
     496                $this->email_address       = ( ! empty( $_SERVER['HTTP_X_PUTLER_EMAIL'] ) ) ? sanitize_email( wp_unslash( $_SERVER['HTTP_X_PUTLER_EMAIL'] ) ) : '';
     497                $settings['email_address'] = $this->email_address;
     498                $this->api_token           = ( ! empty( $_SERVER['HTTP_X_PUTLER_AUTH_TOKEN'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_PUTLER_AUTH_TOKEN'] ) ) : '';
     499                $settings['api_token']     = $this->api_token;
    463500
    464501                $result = $this->validate_api_info(
     
    478515
    479516                    if ( ( ! empty( $result['response']['code'] ) && 200 === $result['response']['code'] ) &&
    480                          ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
     517                        ( ! empty( $res_body['ack'] ) && 'Success' === $res_body['ack'] ) ) {
    481518
    482519                        delete_option( 'putler_connector_temp_token' );
     
    508545                $this->show_message( $msg );
    509546            }
    510 
    511             ob_clean();
    512             echo json_encode( $response );
    513             die();
     547            wp_send_json( $response );
    514548        }
    515549
     
    540574         */
    541575        private function validate_api_info( $token = '', $email = '', $action = '', $headers = array() ) {
    542             // Validate with API server
     576            // Validate with API server.
    543577            return wp_remote_post(
    544578                $this->api_url,
     
    546580                    'headers' => array_merge(
    547581                        array(
    548                             'Authorization' => 'Basic ' . base64_encode( $email . ':' . $token ),
     582                            'Authorization' => 'Basic ' . base64_encode( $email . ':' . $token ), // phpcs:ignore
    549583                            'User-Agent'    => 'Putler Connector/' . $this->version,
    550584                        ),
     
    599633         */
    600634        public function generate_valid_xml_from_array( $array = array(), $node_block = PUTLER_GATEWAY, $node_name = 'node' ) {
    601             $xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
     635            $xml  = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
    602636            $xml .= '<!--email_off--><' . $node_block . '>' . "\n";
    603637            $xml .= $this->generate_xml_from_array( $array, $node_name );
     
    618652                return false;
    619653            }
    620             $auth        = base64_decode( $code );
     654            $auth        = base64_decode( $code ); // phpcs:ignore
    621655            $credentials = array();
    622656            if ( ! empty( $auth ) ) {
     
    628662                return false;
    629663            }
    630             if ( $email != $this->email_address || $token != $this->api_token ) {
     664            if ( $email !== $this->email_address || $token !== $this->api_token ) {
    631665                return false;
    632666            }
     
    651685            }
    652686
    653             echo $this->generate_valid_xml_from_array( $response );
     687            echo $this->generate_valid_xml_from_array( $response ); // phpcs:ignore WordPress.Security.EscapeOutput
    654688            die;
    655689        }
     
    662696            /**
    663697             * Variable declaration
     698             *
    664699             * @var $edd_putler_connector Putler_EDD_Connector_JSON
    665700             */
    666             $authentication_code = ( ! empty( $_REQUEST['AUTH'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['AUTH'] ) ) : '';
     701            $authentication_code = ( ! empty( $_REQUEST['AUTH'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['AUTH'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
    667702            if ( ! $this->is_valid_request( $authentication_code ) ) {
    668703                $this->send_response(
     
    674709            }
    675710
    676             if ( empty( $_REQUEST['STARTDATE'] ) || empty( $_REQUEST['ENDDATE'] ) ) {
     711            if ( empty( sanitize_text_field( wp_unslash( $_REQUEST['STARTDATE'] ) ) ) || empty( sanitize_text_field( wp_unslash( $_REQUEST['ENDDATE'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
    677712                $this->send_response(
    678713                    array(
     
    682717                );
    683718            }
    684             update_option( 'sa_' . PUTLER_GATEWAY_PREFIX . '_last_updated', current_time( 'Y-m-d H:i:s' ) ); // updating the last synced time
    685 
    686             $offset     = ( ! empty( $_REQUEST['OFFSET'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['OFFSET'] ) ) ) : 0;
    687             $sub_offset = ( ! empty( $_REQUEST['SUBOFFSET'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['SUBOFFSET'] ) ) ) : 0;
    688             $limit      = ( ! empty( $_REQUEST['LIMIT'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['LIMIT'] ) ) ) : 100;
    689             $type       = ( ! empty( $_REQUEST['REQUESTTYPE'] ) ) ? strtolower( sanitize_text_field( wp_unslash( $_REQUEST['REQUESTTYPE'] ) ) ) : 'history';
    690 
    691             // Getting the data from ecommerce plugins
     719            update_option( 'sa_' . PUTLER_GATEWAY_PREFIX . '_last_updated', current_time( 'Y-m-d H:i:s' ) ); // updating the last synced time.
     720
     721            $offset     = ( ! empty( $_REQUEST['OFFSET'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['OFFSET'] ) ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
     722            $sub_offset = ( ! empty( $_REQUEST['SUBOFFSET'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['SUBOFFSET'] ) ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
     723            $limit      = ( ! empty( $_REQUEST['LIMIT'] ) ) ? intval( sanitize_text_field( wp_unslash( $_REQUEST['LIMIT'] ) ) ) : 100; // phpcs:ignore WordPress.Security.NonceVerification
     724            $type       = ( ! empty( $_REQUEST['REQUESTTYPE'] ) ) ? strtolower( sanitize_text_field( wp_unslash( $_REQUEST['REQUESTTYPE'] ) ) ) : 'history'; // phpcs:ignore WordPress.Security.NonceVerification
     725
     726            // Getting the data from ecommerce plugins.
    692727            $params = array(
    693                 'start_date' => sanitize_text_field( wp_unslash( $_REQUEST['STARTDATE'] ) ),
    694                 'end_date'   => sanitize_text_field( wp_unslash( $_REQUEST['ENDDATE'] ) ),
     728                'start_date' => sanitize_text_field( wp_unslash( $_REQUEST['STARTDATE'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
     729                'end_date'   => sanitize_text_field( wp_unslash( $_REQUEST['ENDDATE'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
    695730                'offset'     => $offset,
    696731                'sub_offset' => $sub_offset,
     
    720755                    'OFFSET'   => $offset,
    721756                );
    722                 update_option( 'sa_' . PUTLER_GATEWAY_PREFIX . '_last_updated', current_time( 'Y-m-d H:i:s' ) ); // updating the last synced time
     757                update_option( 'sa_' . PUTLER_GATEWAY_PREFIX . '_last_updated', current_time( 'Y-m-d H:i:s' ) ); // updating the last synced time.
    723758            } else {
    724759                $response = array(
  • easy-digital-downloads-putler-connector/trunk/classes/class-putler-edd-connector-db.php

    r2820426 r2835905  
    11<?php
     2/**
     3 * Class for handling the db updates.
     4 *
     5 * @package     easy-digital-downloads-putler-connector/classes/
     6 * @version     1.0.0
     7 */
     8
    29if ( ! defined( 'ABSPATH' ) ) {
    310    exit; // Exit if accessed directly.
     
    512
    613if ( ! class_exists( 'Putler_EDD_Connector_DB' ) ) {
     14
     15    /**
     16     * Class Putler_EDD_Connector_DB
     17     */
    718    class Putler_EDD_Connector_DB {
    819        /**
     
    1526            // For multisite table prefix.
    1627            if ( is_multisite() ) {
    17                 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
     28                $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); // WPCS: cache ok, db call ok.
    1829                foreach ( $blog_ids as $id ) {
    1930                    if ( empty( $id ) ) {
  • easy-digital-downloads-putler-connector/trunk/classes/class-putler-edd-connector-json.php

    r2820426 r2835905  
    11<?php
    22/**
    3  * Handle all JSON related stuffs here.
     3 * Class for handling the JSON API related mapping.
     4 *
     5 * @package     easy-digital-downloads-putler-connector/classes/
     6 * @version     1.0.0
    47 */
    58
     
    3740        /**
    3841         * In EDD_Payment class, it does not contain modified_date. So to solve this, we are saving the modified date
     42         *
    3943         * @var array
    4044         */
     
    4347        /**
    4448         * Class Putler_EDD_Connector_JSON constructor
    45          *
    4649         */
    4750        public function __construct() {
     
    8992            }
    9093            $current_time = time();
    91             $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}eddpc_subscription (subscription_id, modified_time) VALUES(%d, %d) ON DUPLICATE KEY UPDATE modified_time=%d", intval( $id ), $current_time, $current_time ) );
     94            $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}eddpc_subscription (subscription_id, modified_time) VALUES(%d, %d) ON DUPLICATE KEY UPDATE modified_time=%d", intval( $id ), $current_time, $current_time ) ); // WPCS: cache ok, db call ok.
    9295        }
    9396
     
    177180                }
    178181                $all_orders = array();
    179                 $start_date = date( 'Y-m-d H:i:s', $start_date_time );
    180                 $end_date   = date( 'Y-m-d H:i:s', $end_date_time );
     182                $start_date = $this->params['start_date'];
     183                $end_date   = $this->params['end_date'];
    181184                $offset     = intval( $this->params['offset'] );
    182185                $limit      = intval( $this->params['limit'] );
     
    187190                // Reason for using raw query: In EDD there are some limitations
    188191                // 1. edd_get_payments function return orders only based on created date. It does not return based on modified date. Also there is no option to do that. In our case we need only modified date.
     192                $payments = array();
    189193                if ( version_compare( '3.0', EDD_VERSION, '<' ) ) {
    190194                    if ( 'history' === $request_type ) {
    191195                        // For historical import, don't check in the notes.
    192                         $order_query = $wpdb->prepare(
    193                             "SELECT order_tbl.id as order_id,order_tbl.date_modified as order_modified,order_tbl.date_modified as note_modified FROM `{$wpdb->prefix}edd_orders` as order_tbl WHERE order_tbl.date_modified BETWEEN %s AND %s LIMIT %d OFFSET %d;",
    194                             array(
    195                                 $start_date,
    196                                 $end_date,
    197                                 $limit,
    198                                 $offset,
    199                             )
    200                         );
     196                        $payments = $wpdb->get_results(
     197                            $wpdb->prepare(
     198                                "SELECT order_tbl.id as order_id,order_tbl.date_modified as order_modified,order_tbl.date_modified as note_modified FROM `{$wpdb->prefix}edd_orders` as order_tbl WHERE order_tbl.date_modified BETWEEN %s AND %s LIMIT %d OFFSET %d;",
     199                                array(
     200                                    $start_date,
     201                                    $end_date,
     202                                    $limit,
     203                                    $offset,
     204                                )
     205                            ),
     206                            OBJECT
     207                        ); // WPCS: cache ok, db call ok.
    201208                    } else {
    202209                        // For refresh import, do check in the notes tables also.
    203                         $order_query = $wpdb->prepare(
    204                             "SELECT order_tbl.id as order_id,order_tbl.date_modified as order_modified,MAX(notes_tbl.date_modified) as note_modified FROM `{$wpdb->prefix}edd_orders` as order_tbl INNER JOIN `{$wpdb->prefix}edd_notes` notes_tbl on order_tbl.id = notes_tbl.object_id AND (order_tbl.date_modified BETWEEN %s AND %s OR notes_tbl.date_modified BETWEEN %s AND %s) GROUP BY order_id LIMIT %d OFFSET %d;",
    205                             array(
    206                                 $start_date,
    207                                 $end_date,
    208                                 $start_date,
    209                                 $end_date,
    210                                 $limit,
    211                                 $offset,
    212                             )
    213                         );
     210                        $payments = $wpdb->get_results(
     211                            $wpdb->prepare(
     212                                "SELECT order_tbl.id as order_id,order_tbl.date_modified as order_modified,MAX(notes_tbl.date_modified) as note_modified FROM `{$wpdb->prefix}edd_orders` as order_tbl INNER JOIN `{$wpdb->prefix}edd_notes` notes_tbl on order_tbl.id = notes_tbl.object_id AND (order_tbl.date_modified BETWEEN %s AND %s OR notes_tbl.date_modified BETWEEN %s AND %s) GROUP BY order_id LIMIT %d OFFSET %d;",
     213                                array(
     214                                    $start_date,
     215                                    $end_date,
     216                                    $start_date,
     217                                    $end_date,
     218                                    $limit,
     219                                    $offset,
     220                                )
     221                            ),
     222                            OBJECT
     223                        ); // WPCS: cache ok, db call ok.
    214224                    }
    215225                } else {
    216226                    if ( 'history' === $request_type ) {
    217227                        // For historical import, don't check in the comments table.
    218                         $order_query = $wpdb->prepare(
    219                             "SELECT order_tbl.id as order_id,order_tbl.post_modified_gmt as order_modified,order_tbl.post_modified_gmt as note_modified FROM `{$wpdb->prefix}posts` as order_tbl WHERE order_tbl.post_type='edd_payment' AND order_tbl.post_modified_gmt BETWEEN %s AND %s LIMIT %d OFFSET %d;",
    220                             array(
    221                                 $start_date,
    222                                 $end_date,
    223                                 $limit,
    224                                 $offset,
    225                             )
    226                         );
     228                        $payments = $wpdb->get_results(
     229                            $wpdb->prepare(
     230                                "SELECT order_tbl.id as order_id,order_tbl.post_modified_gmt as order_modified,order_tbl.post_modified_gmt as note_modified FROM `{$wpdb->prefix}posts` as order_tbl WHERE order_tbl.post_type='edd_payment' AND order_tbl.post_modified_gmt BETWEEN %s AND %s LIMIT %d OFFSET %d;",
     231                                array(
     232                                    $start_date,
     233                                    $end_date,
     234                                    $limit,
     235                                    $offset,
     236                                )
     237                            ),
     238                            OBJECT
     239                        ); // WPCS: cache ok, db call ok.
    227240                    } else {
    228241                        // For refresh import, do check in the comments tables also.
    229                         $order_query = $wpdb->prepare(
    230                             "SELECT order_tbl.ID as order_id,order_tbl.post_modified_gmt as order_modified,MAX(notes_tbl.comment_date_gmt) as note_modified FROM `{$wpdb->prefix}posts` as order_tbl INNER JOIN `{$wpdb->prefix}comments` notes_tbl on order_tbl.ID = notes_tbl.comment_post_ID AND order_tbl.post_type='edd_payment' AND (order_tbl.post_modified_gmt BETWEEN %s AND %s OR notes_tbl.comment_date_gmt BETWEEN %s AND %s) GROUP BY order_id LIMIT %d OFFSET %d;",
    231                             array(
    232                                 $start_date,
    233                                 $end_date,
    234                                 $start_date,
    235                                 $end_date,
    236                                 $limit,
    237                                 $offset,
    238                             )
    239                         );
    240                     }
    241                 }
    242                 $payments = $wpdb->get_results( $order_query, OBJECT );
     242                        $payments = $wpdb->get_results(
     243                            $wpdb->prepare(
     244                                "SELECT order_tbl.ID as order_id,order_tbl.post_modified_gmt as order_modified,MAX(notes_tbl.comment_date_gmt) as note_modified FROM `{$wpdb->prefix}posts` as order_tbl INNER JOIN `{$wpdb->prefix}comments` notes_tbl on order_tbl.ID = notes_tbl.comment_post_ID AND order_tbl.post_type='edd_payment' AND (order_tbl.post_modified_gmt BETWEEN %s AND %s OR notes_tbl.comment_date_gmt BETWEEN %s AND %s) GROUP BY order_id LIMIT %d OFFSET %d;",
     245                                array(
     246                                    $start_date,
     247                                    $end_date,
     248                                    $start_date,
     249                                    $end_date,
     250                                    $limit,
     251                                    $offset,
     252                                )
     253                            ),
     254                            OBJECT
     255                        ); // WPCS: cache ok, db call ok.
     256                    }
     257                }
    243258                if ( ! empty( $payments ) && is_array( $payments ) ) {
    244259                    foreach ( $payments as $payment ) {
     
    412427                $results = $wpdb->get_col(
    413428                    $wpdb->prepare(
    414                         "SELECT option_value FROM `{$wpdb->prefix}options` WHERE option_name LIKE '_transient_eddpc_json_deleted_%'AND SUBSTRING_INDEX( option_name, '_transient_eddpc_json_deleted_', -1 ) between %d and %d;",
     429                        "SELECT option_value FROM `{$wpdb->prefix}options` WHERE option_name LIKE %s AND SUBSTRING_INDEX( option_name, '_transient_eddpc_json_deleted_', -1 ) between %d and %d;",
    415430                        array(
     431                            $wpdb->esc_like( '_transient_eddpc_json_deleted_' ) . '%',
    416432                            $start_date_time,
    417433                            $end_date_time,
    418434                        )
    419435                    )
    420                 );
     436                ); // WPCS: cache ok, db call ok.
    421437
    422438                if ( ! empty( $results ) ) {
     
    451467                return array();
    452468            }
    453             if ( in_array( $subscription_id, self::$processed_created_subscriptions ) ) {
     469            if ( in_array( $subscription_id, self::$processed_created_subscriptions, true ) ) {
    454470                return array();
    455471            }
     
    516532                return array();
    517533            }
    518             if ( in_array( $subscription_id, self::$processed_meta_subscriptions ) ) {
     534            if ( in_array( $subscription_id, self::$processed_meta_subscriptions, true ) ) {
    519535                return array();
    520536            }
     
    792808            );
    793809
    794             if ( $is_subscription_order && 'DELETE' != $this->get_order_status( $order ) ) {
     810            if ( $is_subscription_order && 'DELETE' !== $this->get_order_status( $order ) ) {
    795811                foreach ( $subscription_orders as $subscription ) {
    796812                    $created_subscription = $this->format_subscription_created_meta_info( $subscription );
     
    865881                            return array();
    866882                        }
    867                         $modified_subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT subscription_id FROM {$wpdb->prefix}eddpc_subscription WHERE modified_time >= %d && modified_time <= %d", $start_date_time, $end_date_time ), ARRAY_A );
     883                        $modified_subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT subscription_id FROM {$wpdb->prefix}eddpc_subscription WHERE modified_time >= %d && modified_time <= %d", $start_date_time, $end_date_time ), ARRAY_A ); // WPCS: cache ok, db call ok.
    868884                        if ( empty( $modified_subscriptions ) ) {
    869885                            return array();
     
    901917            }
    902918            $used_coupons = array();
    903             if ( ! empty( $order->discounts ) && ! empty( $order->discounts ) && 'none' != $order->discounts ) {
     919            if ( ! empty( $order->discounts ) && ! empty( $order->discounts ) && 'none' !== $order->discounts ) {
    904920                $discount = $this->calculate_order_discounts( $order );
    905921                // NOTE: EDD does not provide amount of each discount code and if more than
     
    928944            }
    929945            $discount = 0;
    930             if ( ! empty( $order->discounts ) && 'none' != $order->discounts ) {
     946            if ( ! empty( $order->discounts ) && 'none' !== $order->discounts ) {
    931947                $cart_details = ( ! empty( $order->payment_meta['cart_details'] ) ) ? $order->payment_meta['cart_details'] : array();
    932948                if ( is_array( $cart_details ) ) {
     
    11401156                    }
    11411157                    if ( ! empty( $subscription_orders ) ) {
    1142                         if ( ! in_array( $product_id, $all_subscription_product_ids ) && 'meta' === $type ) {
     1158                        if ( ! in_array( $product_id, $all_subscription_product_ids, true ) && 'meta' === $type ) {
    11431159                            continue;
    11441160                        }
     
    11851201                        'handle'           => ! empty( $product->post_name ) ? $product->post_name : null,
    11861202                        'status'           => $this->get_product_status( $product ),
    1187                         'description'      => null, // $product->get_description(),
     1203                        'description'      => null,
    11881204                        'quantity'         => abs( ! empty( $line_item['quantity'] ) ? intval( $line_item['quantity'] ) : 0 ),
    11891205                        'discount'         => $this->format_price( ! empty( $line_item['discount'] ) ? floatval( $line_item['discount'] ) : 0, 0 ),
     
    13991415            $modified_date = null;
    14001416            if ( version_compare( '3.0', EDD_VERSION, '<' ) ) {
    1401                 $customer_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_customers WHERE id = %d ", $customer->id ) );
     1417                $customer_details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_customers WHERE id = %d ", $customer->id ) ); // WPCS: cache ok, db call ok.
    14021418                if ( ! empty( $customer_details->date_modified ) ) {
    14031419                    $modified_date = $this->format_date( $customer_details->date_modified, null );
     
    16741690            if ( strtotime( $date_1 ) > strtotime( $date_2 ) ) {
    16751691                return 1;
    1676             } else if ( strtotime( $date_1 ) < strtotime( $date_2 ) ) {
     1692            } elseif ( strtotime( $date_1 ) < strtotime( $date_2 ) ) {
    16771693                return - 1;
    16781694            } else {
     
    18191835                    break;
    18201836                default:
    1821                     if ( in_array( $order_status, $paid_order_statuses ) ) {
     1837                    if ( in_array( $order_status, $paid_order_statuses, true ) ) {
    18221838                        $new_order_status = 'completed';
    18231839                    } else {
     
    18351851         * @param string $date date.
    18361852         * @param string $default default value.
    1837          * @param bool   $convert_to_utc need to convert time to GMT?
     1853         * @param bool   $convert_to_utc flag to determine whether convert time to GMT or not.
    18381854         * @param string $format In which format do we need to convert.
    18391855         *
     
    18481864            }
    18491865            if ( is_numeric( $date ) ) {
    1850                 return date( $format, $date );
    1851             }
    1852 
    1853             return date( $format, strtotime( $date ) );
     1866                return date( $format, $date ); // phpcs:ignore
     1867            }
     1868
     1869            return date( $format, strtotime( $date ) ); // phpcs:ignore
    18541870        }
    18551871
  • easy-digital-downloads-putler-connector/trunk/edd-putler-connector.php

    r2820426 r2835905  
    11<?php
    22/**
    3  * Plugin Name:         Easy Digital Downloads Putler Connector
     3 * Plugin Name:         Putler Connector for Easy Digital Downloads
    44 * Plugin URI:          http://putler.com/connector/edd/
    55 * Description:         Track Easy Digital Downloads transactions data with Putler. Insightful reporting that grows your business.
     
    1111 * License:             GPL 3.0
    1212 * Copyright (c)        2016 - 2022 Putler. All rights reserved.
     13 *
     14 * @package easy-digital-downloads-putler-connector
    1315 */
    1416
     
    2123}
    2224
    23 include_once 'classes/class-putler-edd-connector-db.php';
     25require_once 'classes/class-putler-edd-connector-db.php';
    2426
    2527register_activation_hook( __FILE__, 'eddpc_activate' );
     
    5456    add_action( 'admin_notices', 'eddpc_admin_notices' );
    5557
    56     if ( ( ! in_array( 'woocommerce-putler-connector/woocommerce-putler-connector.php', $active_plugins ) && ! array_key_exists( 'woocommerce-putler-connector/woocommerce-putler-connector.php', $active_plugins ) )
    57          && ( ! in_array( 'jigoshop-putler-connector/jigoshop-putler-connector.php', $active_plugins ) && ! array_key_exists( 'jigoshop-putler-connector/jigoshop-putler-connector.php', $active_plugins ) )
    58          && ( ! in_array( 'wp-e-commerce-putler-connector/wpec-putler-connector.php', $active_plugins ) && ! array_key_exists( 'wp-e-commerce-putler-connector/wpec-putler-connector.php', $active_plugins ) ) ) {
     58    if ( ( ! in_array( 'woocommerce-putler-connector/woocommerce-putler-connector.php', $active_plugins, true ) && ! array_key_exists( 'woocommerce-putler-connector/woocommerce-putler-connector.php', $active_plugins ) )
     59        && ( ! in_array( 'jigoshop-putler-connector/jigoshop-putler-connector.php', $active_plugins, true ) && ! array_key_exists( 'jigoshop-putler-connector/jigoshop-putler-connector.php', $active_plugins ) )
     60        && ( ! in_array( 'wp-e-commerce-putler-connector/wpec-putler-connector.php', $active_plugins, true ) && ! array_key_exists( 'wp-e-commerce-putler-connector/wpec-putler-connector.php', $active_plugins ) ) ) {
    5961
    6062        $eddpc_notice_msg = '';
    6163
    62         if ( in_array( 'easy-digital-downloads/easy-digital-downloads.php', $active_plugins ) || array_key_exists( 'easy-digital-downloads/easy-digital-downloads.php', $active_plugins ) ) {
     64        if ( in_array( 'easy-digital-downloads/easy-digital-downloads.php', $active_plugins, true ) || array_key_exists( 'easy-digital-downloads/easy-digital-downloads.php', $active_plugins ) ) {
    6365
    6466            if ( ! defined( 'PUTLER_GATEWAY' ) ) {
     
    8082        } else {
    8183            $eddpc_notice_msg = '<div id="notice" class="error"><p>' .
    82                                 '<b>' . __( 'Easy Digital Downloads Putler Connector', 'putler_connector' ) . '</b> ' . __( 'add-on requires', 'putler_connector' ) . ' <a href="https://wordpress.org/plugins/easy-digital-downloads/">' . __( 'Easy Digital Downloads', 'putler_connector' ) . '</a> ' . __( 'plugin. Please install and activate it.', 'putler_connector' ) .
     84                                '<b>' . __( 'Putler Connector for Easy Digital Downloads', 'putler_connector' ) . '</b> ' . __( 'add-on requires', 'putler_connector' ) . ' <a href="https://wordpress.org/plugins/easy-digital-downloads/">' . __( 'Easy Digital Downloads', 'putler_connector' ) . '</a> ' . __( 'plugin. Please install and activate it.', 'putler_connector' ) .
    8385                                '</p></div>';
    8486        }
     
    121123            // Delete the redirect transient.
    122124            delete_option( '_eddpc_activation_redirect' );
    123             wp_redirect( admin_url( 'tools.php?page=putler_connector&action=eddpc_activate' ) );
     125            wp_safe_redirect( admin_url( 'tools.php?page=putler_connector&action=eddpc_activate' ) );
    124126            exit;
    125127        }
  • easy-digital-downloads-putler-connector/trunk/readme.txt

    r2820426 r2835905  
    1 === Easy Digital Downloads Putler Connector ===
     1=== Putler Connector for Easy Digital Downloads ===
    22Contributors: putler, storeapps
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CPTHCDC382KVA
     
    1919
    2020**Get started within minutes**
    21 Once activated, Easy Digital Downloads Putler Connector sends past orders and subscriptions to Putler using Putler's Inbound API. Once the connection is made, future orders and subscriptions are sent to Putler automatically.
     21Once activated, Putler Connector for Easy Digital Downloads sends past orders and subscriptions to Putler using Putler's Inbound API. Once the connection is made, future orders and subscriptions are sent to Putler automatically.
    2222
    2323> **Note:** Keep in mind that you need a **Putler** account (Free or Paid), and a **Easy Digital Downloads** based store to use this plugin. [**Try Putler for free!**](https://web.putler.com/#!/signup)
     
    159159== Changelog ==
    160160
     161= 3.1.0 (19.12.2022) =
     162* New: WordPress Standards compatible
     163* New: POT file
     164
    161165= 3.0.0 (18.11.2022) =
    162166* New: Easy Digital Downloads v3.1.0.2 compatible
     
    226230== Upgrade Notice ==
    227231
     232= 3.1.0 =
     233WordPress Standards compatible, POT file
     234
    228235= 3.0.0 =
    229236Easy Digital Downloads v3.1.0.2 compatible, WordPress v6.1.1 compatible, Compatibility with latest Putler API
Note: See TracChangeset for help on using the changeset viewer.