Plugin Directory

Changeset 3171820


Ignore:
Timestamp:
10/19/2024 07:40:34 AM (16 months ago)
Author:
Persianscript
Message:

v 7.0.4

Location:
persian-woocommerce-sms
Files:
283 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • persian-woocommerce-sms/trunk/WoocommerceIR_SMS.php

    r3170258 r3171820  
    44 * Plugin URI: https://woosupport.ir
    55 * Description: افزونه کامل و حرفه ای برای اطلاع رسانی پیامکی سفارشات و رویداد های محصولات ووکامرس. تمامی حقوق این افزونه متعلق به <a href="http://woosupport.ir" target="_blank">تیم ووکامرس پارسی</a> می باشد و هر گونه کپی برداری، فروش آن غیر مجاز می باشد.
    6  * Version: 7.0.3
     6 * Version: 7.0.4
    77 * Author: ووکامرس فارسی
    88 * Author URI: https://woosupport.ir
     
    1919
    2020if ( ! defined( 'PWSMS_VERSION' ) ) {
    21     define( 'PWSMS_VERSION', '7.0.3' );
     21    define( 'PWSMS_VERSION', '7.0.4' );
    2222}
    2323
  • persian-woocommerce-sms/trunk/readme.txt

    r3170258 r3171820  
    99Tested up to: 6.6.2
    1010Requires PHP: 7.4
    11 Stable tag: 7.0.3
     11Stable tag: 7.0.4
    1212
    1313افزونه کامل و حرفه ای برای اطلاع رسانی پیامکی سفارشات و رویداد های محصولات ووکامرس
     
    122122 * Arad ITC
    123123 * SMSNegar.ir
    124  * MAX-SMS.co (IPPANEL.co)
    125  
     124 * MAX-SMS.co
     125 * IPPANEL.co
    126126
    127127== Installation ==
     
    147147
    148148== Changelog ==
     149= 7.0.3 =
     150* افزوده شدن وبسرویس IPPANEL.COM
    149151= 7.0.3 =
    150152* رفع چند باگ گزارش شده
     
    374376
    375377== Upgrade Notice ==
    376 = 7.0.3 =
    377 * بروزرسانی چند وبسرویس جدید و رفع چند باگ
     378= 7.0.4 =
     379* افزوده شدن وبسرویس IPPANEL.COM
  • persian-woocommerce-sms/trunk/src/Gateways/MaxSMS.php

    r3170258 r3171820  
    1313
    1414    public static function id() {
    15         return 'maxsms-normal';
     15        return 'maxsms';
    1616    }
    1717
     
    2121
    2222    public function send() {
    23         $single_api_url = $this->api_url . '/sms/send/webservice/single';
    24         $api_key        = ! empty( $this->username ) ? $this->username : $this->password;
    25         $message        = $this->message;
    26         $from           = $this->senderNumber;
    27         $recipients     = $this->mobile;
     23        $recipients      = $this->mobile;
     24        $api_key         = ! empty( $this->username ) ? trim( $this->username ) : trim( $this->password );
     25        $from            = trim( $this->senderNumber );
     26        $message_content = $this->message;
     27
     28        // Default sender number if not provided
    2829        if ( empty( $from ) ) {
    2930            $from = '+983000505';
    3031        }
    3132
    32 
    33         if ( empty( $api_key ) || empty( $message ) || empty( $recipients ) ) {
     33        // Replace "pcode" with "patterncode" in the message
     34        $message_content = str_replace( 'pcode', 'patterncode', $message_content );
     35
     36        // Determine if it's a pattern-based message
     37        if ( substr( $message_content, 0, 11 ) === "patterncode" ) {
     38            // Handle pattern-based message
     39            return $this->send_pattern_sms( $recipients, $from, $message_content, $api_key );
     40        } else {
     41            // Handle simple SMS
     42            return $this->send_simple_sms( $recipients, $from, $message_content, $api_key );
     43        }
     44    }
     45
     46    private function send_pattern_sms( array $recipients, string $from, string $message_content, string $api_key ) {
     47        $pattern_api_url = $this->api_url . '/sms/pattern/normal/send';
     48
     49        // Replace "pcode" with "patterncode" in the message
     50        $message_content = str_replace( 'pcode', 'patterncode', $message_content );
     51
     52        // Replace new lines with semicolons and split
     53        $message_content = str_replace( [ "\r\n", "\n" ], ';', $message_content );
     54        $message_parts   = explode( ';', $message_content );
     55        $pattern_code    = explode( ':', $message_parts[0] )[1];
     56        unset( $message_parts[0] ); // Remove the first element containing the pattern code
     57
     58        // Initialize the pattern data array
     59        $pattern_data = [];
     60        foreach ( $message_parts as $parameter ) {
     61            $split_parameter = explode( ':', $parameter, 2 ); // Split only on the first occurrence
     62            if ( count( $split_parameter ) === 2 ) { // Ensure both key and value exist
     63                $pattern_data[ trim( $split_parameter[0] ) ] = trim( $split_parameter[1] );
     64            }
     65        }
     66
     67        // Check for required fields
     68        if ( empty( $api_key ) || empty( $pattern_code ) || empty( $recipients ) ) {
    3469            return 'اطلاعات پنل، یا پیامک به درستی وارد نشده.';
    3570        }
    36 
    37         $date_time_now = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
    38         $date_time_now->modify( '+30 seconds' );
    39         $date_time = $date_time_now->format( 'Y-m-d\TH:i:s.v\Z' );
    40 
    41 
    42         $data = [
    43             'recipient' => $recipients,
    44             'sender'    => $from,
    45             'message'   => $message,
    46             'time'      => $date_time
    47         ];
    4871
    4972        $headers = [
     
    5376        ];
    5477
     78        $failed_numbers = [];
     79
     80        foreach ( $recipients as $recipient ) {
     81            $data = [
     82                'code'      => trim( $pattern_code ),
     83                'sender'    => $from,
     84                'recipient' => $recipient,
     85                'variable'  => $pattern_data,
     86            ];
     87
     88            $remote = wp_remote_post( $pattern_api_url, [
     89                'headers' => $headers,
     90                'body'    => wp_json_encode( $data ),
     91            ] );
     92
     93            if ( is_wp_error( $remote ) ) {
     94                $failed_numbers[ $recipient ] = $remote->get_error_message();
     95            }
     96
     97            $response_message = wp_remote_retrieve_response_message( $remote );
     98            $response_code    = wp_remote_retrieve_response_code( $remote );
     99
     100            if ( empty( $response_code ) || 200 != $response_code ) {
     101                $failed_numbers[ $recipient ] = $response_code . ' -> ' . $response_message;
     102                continue;
     103            }
     104
     105            $response = wp_remote_retrieve_body( $remote );
     106
     107            if ( empty( $response ) ) {
     108                $failed_numbers[ $recipient ] = 'بدون پاسخ دریافتی از سمت وب سرویس.';
     109                continue;
     110            }
     111
     112            $response_data = json_decode( $response, true );
     113            if ( ! empty( json_last_error() ) ) {
     114                $failed_numbers[ $recipient ] = 'فرمت نامعتبر پاسخ از سمت وب سرویس.';
     115                continue;
     116            }
     117
     118            if ( isset( $response_data['status'] ) && strtolower( $response_data['status'] ) == 'ok' ) {
     119                continue;
     120            }
     121        }
     122
     123        // Handle failed numbers and format response
     124        return $this->formatFailedNumbers( $failed_numbers );
     125    }
     126
     127    private function formatFailedNumbers( array $failed_numbers ) {
     128        // Handle failed numbers and format response
     129        if ( ! empty( $failed_numbers ) ) {
     130            $grouped = [];
     131            foreach ( $failed_numbers as $number => $message ) {
     132                if ( ! isset( $grouped[ $message ] ) ) {
     133                    $grouped[ $message ] = [];
     134                }
     135                $grouped[ $message ][] = $number;
     136            }
     137
     138            $result = implode( ', ', array_map(
     139                function ( string $message, array $numbers ) {
     140                    return implode( ',', $numbers ) . ': ' . $message;
     141                },
     142                array_keys( $grouped ),
     143                $grouped
     144            ) );
     145
     146            return $result;
     147        }
     148
     149        return true;
     150    }
     151
     152    private function send_simple_sms( array $recipients, string $from, string $message_content, string $api_key ) {
     153        $single_api_url = $this->api_url . '/sms/send/webservice/single';
     154
     155        // Check for required fields
     156        if ( empty( $api_key ) || empty( $message_content ) || empty( $recipients ) ) {
     157            return 'اطلاعات پنل، یا پیامک به درستی وارد نشده.';
     158        }
     159
     160        $date_time_now = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
     161        $date_time_now->modify( '+30 seconds' );
     162        $date_time = $date_time_now->format( 'Y-m-d\TH:i:s.v\Z' );
     163
     164        $data = [
     165            'recipient' => $recipients,
     166            'sender'    => $from,
     167            'message'   => $message_content,
     168            'time'      => $date_time
     169        ];
     170
     171        $headers = [
     172            'Content-Type' => 'application/json',
     173            'Accept'       => 'application/json',
     174            'apikey'       => $api_key,
     175        ];
     176
    55177        $remote = wp_remote_post( $single_api_url, [
    56178            'headers' => $headers,
     
    85207        }
    86208
    87 
    88209        return $response;
    89210    }
  • persian-woocommerce-sms/trunk/src/Product/Events.php

    r3170258 r3171820  
    8989                $parent_product->save();
    9090
    91                 /// TODO : justify return type by exact usage of function
    9291                return true;
    9392            }
     
    108107            return true;
    109108        }
     109        return false;
    110110    }
    111111
  • persian-woocommerce-sms/trunk/src/SMS/ListTable.php

    r3170258 r3171820  
    100100    }
    101101
    102     /*TODO : Convert these types to function or constants*/
     102
    103103    public function column_type( $item ) {
    104104
Note: See TracChangeset for help on using the changeset viewer.