Plugin Directory

Changeset 2718672


Ignore:
Timestamp:
05/05/2022 02:40:33 PM (4 years ago)
Author:
grilabs
Message:

GriSMS provider updated for new API

Location:
wp-sms-functions/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-sms-functions/trunk/inc/providers/Gri_Provider.php

    r2676477 r2718672  
    22
    33if (!class_exists('ProviderBase')) {
    4     require_once 'ProviderBase.php';
     4    require_once 'ProviderBase.php';
    55}
    66
    77class Gri_Provider extends ProviderBase
    88{
    9     public function __construct()
    10     {
     9    public function __construct()
     10    {
    1111
    12         $this->slug = 'Gri';
    13         $this->name = 'Gri SMS';
    14         $this->api_base_url = 'https://sms-api2.gri.net';
     12        $this->slug = 'Gri';
     13        $this->name = 'Gri SMS';
     14        $this->api_base_url = 'https://sms-api3.gri.net';
    1515
    16         add_filter('Smsfunctions_providers', function ($prov) {
    17             $prov[$this->slug] = $this->name;
     16        add_filter('Smsfunctions_providers', function ($prov) {
     17            $prov[$this->slug] = $this->name;
    1818
    19             return $prov;
    20         });
     19            return $prov;
     20        });
    2121
    22         add_action('Smsfunctions_provider_settings', array($this, 'settings'));
    23         add_filter('Smsfunctions_fields', function ($fields) {
    24             return array_merge($fields, $this->fields());
    25         });
     22        add_action('Smsfunctions_provider_settings', array($this, 'settings'));
     23        add_filter('Smsfunctions_fields', function ($fields) {
     24            return array_merge($fields, $this->fields());
     25        });
    2626
    27     }
     27    }
    2828
    29     public function fields()
    30     {
    31         return array(
    32             'gri_api_key',
    33             'gri_secret_key',
    34             'gri_msg_header'
    35         );
    36     }
     29    public function fields()
     30    {
     31        return array(
     32            'gri_api_key',
     33            'gri_secret_key',
     34            'gri_msg_header'
     35        );
     36    }
    3737
    38     public function get_options()
    39     {
    40         $vals = array();
    41         $fields = $this->fields();
    42         foreach ($fields as $field) {
    43             $vals[$field] = get_option($field, '');
    44         }
     38    public function get_options()
     39    {
     40        $vals = array();
     41        $fields = $this->fields();
     42        foreach ($fields as $field) {
     43            $vals[$field] = get_option($field, '');
     44        }
    4545
    46         return $vals;
    47     }
     46        return $vals;
     47    }
    4848
    49     public function getAuthentication()
    50     {
    51         $options = $this->get_options();
    52         $api_key = $options['gri_api_key'];
    53         $secret_key = $options['gri_secret_key'];
    54         return array(
    55             'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $secret_key),
    56             'Content-Type' => 'application/json'
    57         );
    58     }
     49    public function getAuthentication()
     50    {
     51        $options = $this->get_options();
     52        $api_key = $options['gri_api_key'];
     53        $secret_key = $options['gri_secret_key'];
     54        return array(
     55            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $secret_key),
     56            'Content-Type' => 'application/json'
     57        );
     58    }
    5959
    60     public function send_sms($gsmNo = '', $message = '')
    61     {
    62         $options = $this->get_options();
    63         $header = $options['gri_msg_header'];
     60    public function send_sms($gsmNo = '', $message = '')
     61    {
     62        $options = $this->get_options();
     63        $header = $options['gri_msg_header'];
    6464
    65         $message = str_replace('\"', '"', $message); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     65        $message = str_replace('\"', '"', $message); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    6666
    67         $post_fields = json_encode(array(
    68             'header' => $header,
    69             'message' => $message,
    70             'phone' => $gsmNo
    71         ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
     67        $post_fields = json_encode(array(
     68            'header' => $header,
     69            'message' => $message,
     70            'phone' => $gsmNo
     71        ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    7272
    73         $authentication = $this->getAuthentication();
     73        $authentication = $this->getAuthentication();
    7474
    75         try {
    76             $request = parent::wpPost($this->api_base_url . '/SendSms', $post_fields, $authentication);
    77             $response = json_decode($request);
     75        $request = parent::wpPost($this->api_base_url . '/SendSms', $post_fields, $authentication);
     76        $response = json_decode($request);
    7877
    79             $errors = array();
    80             if (isset($response->errors)) {
    81                 foreach ($response->errors as $error)
    82                 {
    83                     $errors[] = implode(" - " , $error);
    84                 }
    85                 throw new Exception( count( $errors ) ? implode("\n", $errors) : 'An error occurred!' );
    86             }
    87         } catch (Exception $ex) {
    88             throw $ex;
    89         }
     78        if(isset($response->Result))
     79            $response=$response->Result;
    9080
    91         return true;
    92     }
     81        if( isset($response->status) && !$response->status && isset($response->message) )
     82            throw new \Exception($response->message);
    9383
    94     public function settings($selected_provider)
    95     {
    96         $options = $this->get_options();
    97         $selected_provider = strtolower($selected_provider);
    98         $is_tokens = !empty($options['gri_api_key']) && !empty($options['gri_secret_key']);
    99         if ($selected_provider === 'gri') {
    100             $request = parent::wpGet($this->api_base_url . '/Headers', array(), $this->getAuthentication());
    101             $response_for_sms_headers = json_decode($request);
     84        $errors = array();
     85        if (isset($response->errors)) {
     86            foreach ($response->errors as $error)
     87            {
     88                $errors[] = implode(" - " , $error);
     89            }
     90            throw new Exception( count( $errors ) ? implode("\n", $errors) : 'An error occurred!' );
     91        }
    10292
    103             if (!is_array($response_for_sms_headers) && isset($response_for_sms_headers->message)) {
    104                 echo "<strong style='color:red'>" .
    105                     $response_for_sms_headers->message .
    106                     "</strong>";
    107             }
    108         }
    109         ?>
     93        return true;
     94    }
     95
     96    public function settings($selected_provider)
     97    {
     98        $options = $this->get_options();
     99        $selected_provider = strtolower($selected_provider);
     100        $is_tokens = !empty($options['gri_api_key']) && !empty($options['gri_secret_key']);
     101        if ($selected_provider === 'gri') {
     102            $request = parent::wpGet($this->api_base_url . '/Headers', array(), $this->getAuthentication());
     103            $response_for_sms_headers = json_decode($request);
     104
     105            if(is_object($response_for_sms_headers) && isset($response_for_sms_headers->Result))
     106                $response_for_sms_headers = $response_for_sms_headers->Result;
     107
     108            if ( isset($response_for_sms_headers->status) && !($response_for_sms_headers->status) && isset($response_for_sms_headers->message)) {
     109                echo "<strong style='color:red'>" .
     110                     $response_for_sms_headers->message .
     111                     "</strong>";
     112            }
     113        }
     114        ?>
    110115        <table id="gri" class="form-table provider_tab"
    111116               style="display: <?php echo esc_html((($selected_provider == 'gri') ? 'block' : 'none')); ?>">
     
    122127                    /></td>
    123128            </tr>
    124             <?php if (is_array($response_for_sms_headers) && count($response_for_sms_headers)): ?>
     129            <?php if (is_array($response_for_sms_headers) && count($response_for_sms_headers)): ?>
    125130                <tr>
    126131                    <th><?php esc_html_e('SMS Header', 'wp-sms-functions') ?></th>
    127132                    <td>
    128                         <?php
    129                         if (!$is_tokens) {
    130                             esc_html_e('You must save api key and secret key to select the message header.', 'wp-sms-functions');
    131                         } else {
    132                             ?>
     133                        <?php
     134                        if (!$is_tokens) {
     135                            esc_html_e('You must save api key and secret key to select the message header.', 'wp-sms-functions');
     136                        } else {
     137                            ?>
    133138                            <select name="gri_msg_header">
    134139                                <option value=""><?php esc_html_e('Select', 'wp-sms-functions'); ?></option>
    135                                 <?php
    136                                 foreach ($response_for_sms_headers as $header) {
    137                                     $selected = ($options['gri_msg_header'] == $header) ? 'selected' : '';
     140                                <?php
     141                                foreach ($response_for_sms_headers as $header) {
     142                                    $selected = ($options['gri_msg_header'] == $header) ? 'selected' : '';
    138143
    139                                     echo "<option {$selected} value='{$header}'>{$header}</option>";
    140                                 }
     144                                    echo "<option {$selected} value='{$header}'>{$header}</option>";
     145                                }
    141146
    142                                 ?>
     147                                ?>
    143148                            </select>
    144                         <?php } ?>
     149                        <?php } ?>
    145150                    </td>
    146151                </tr>
    147152                <tr>
    148                     <th><?php esc_html_e('Last Balance', 'wp-sms-functions') ?></th>
     153                    <th><?php esc_html_e('Balance Remaining', 'wp-sms-functions') ?></th>
    149154                    <td>
    150                         <?php
    151                         if (!$is_tokens) {
    152                             esc_html_e('You must save api key and secret key to view the balance.', 'wp-sms-functions');
    153                         } else {
    154                             $request = parent::wpGet($this->api_base_url . '/Balance', array(), $this->getAuthentication());
    155                             $response_for_balance = json_decode($request);
    156                             if ($response_for_balance->Balance) {
    157                                 esc_html_e($response_for_balance->Balance);
    158                             } else {
    159                                 esc_html_e('There is no balance defined for you. Please contact us!', 'wp-sms-functions');
    160                             }
    161                         }
    162                         ?>
     155                        <?php
     156                        if (!$is_tokens) {
     157                            esc_html_e('You must save api key and secret key to view the balance.', 'wp-sms-functions');
     158                        } else {
     159                            $request = parent::wpGet($this->api_base_url . '/Balance', array(), $this->getAuthentication());
     160                            $response_for_balance = json_decode($request);
     161
     162                            if (isset($response_for_balance->Data) && $response_for_balance->Data) {
     163                                esc_html_e($response_for_balance->Data);
     164                            } else {
     165                                esc_html_e('There is no balance defined for you. Please contact us!', 'wp-sms-functions');
     166                            }
     167                        }
     168                        ?>
    163169                    </td>
    164170                </tr>
    165             <?php endif; ?>
     171            <?php endif; ?>
    166172        </table>
    167         <?php
    168     }
     173        <?php
     174    }
    169175
    170176}
  • wp-sms-functions/trunk/lang/wp-sms-functions-tr_TR.po

    r2640749 r2718672  
    55"Project-Id-Version: SMS Provider 1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-sms-functions\n"
    7 "POT-Creation-Date: 2021-12-07 18:16+0300\n"
    8 "PO-Revision-Date: 2021-12-07 18:17+0300\n"
     7"POT-Creation-Date: 2022-05-05 17:39+0300\n"
     8"PO-Revision-Date: 2022-05-05 17:39+0300\n"
    99"Last-Translator: \n"
    1010"Language-Team: \n"
     
    105105msgstr "API Gizli Kodu(Secret)"
    106106
    107 #: inc/providers/Gri_Provider.php:107 inc/providers/PandaSMS_Provider.php:143
     107#: inc/providers/Gri_Provider.php:118 inc/providers/PandaSMS_Provider.php:143
    108108msgid "API Key"
    109109msgstr "API Anahtarı"
    110110
    111 #: inc/providers/Gri_Provider.php:113
     111#: inc/providers/Gri_Provider.php:124
    112112msgid "Secret Key"
    113113msgstr "API Gizli Kodu(Secret)"
    114114
    115 #: inc/providers/Gri_Provider.php:120
     115#: inc/providers/Gri_Provider.php:131
    116116msgid "SMS Header"
    117117msgstr "SMS Başlığı"
    118118
    119 #: inc/providers/Gri_Provider.php:124
     119#: inc/providers/Gri_Provider.php:135
    120120msgid "You must save api key and secret key to select the message header."
    121121msgstr "Mesaj başlıklarının görüntülenebilmesi için API bilgilerinizi giriniz."
    122122
    123 #: inc/providers/Gri_Provider.php:128
     123#: inc/providers/Gri_Provider.php:139
    124124msgid "Select"
    125125msgstr "Seçiniz"
    126126
    127 #: inc/providers/Gri_Provider.php:142
    128 msgid "Last Balance"
     127#: inc/providers/Gri_Provider.php:153
     128msgid "Balance Remaining"
    129129msgstr "Kalan Bakiye"
    130130
    131 #: inc/providers/Gri_Provider.php:146
     131#: inc/providers/Gri_Provider.php:157
    132132msgid "You must save api key and secret key to view the balance."
    133133msgstr "Kalan bakiye bilgisi için ilk olarak API bilgilerinizi kaydediniz."
    134134
    135 #: inc/providers/Gri_Provider.php:153
     135#: inc/providers/Gri_Provider.php:165
    136136msgid "There is no balance defined for you. Please contact us!"
    137137msgstr "Tanımlı bakiyeniz bulunamadı. Lütfen iletişime geçiniz. info@gri.net"
     
    226226msgstr "https://www.gri.net"
    227227
     228#~ msgid "Last Balance"
     229#~ msgstr "Kalan Bakiye"
     230
    228231#~ msgid "You do not have sufficient permissions to access this page."
    229232#~ msgstr "Bu sayfaya erişmek için yetkiniz yok."
  • wp-sms-functions/trunk/lang/wp-sms-functions.pot

    r2640749 r2718672  
    1 # Copyright (C) 2021 WP SMS Functions
     1# Copyright (C) 2022 WP SMS Functions
    22# This file is distributed under the same license as the WP SMS Functions package.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: WP SMS Functions 1.2.4\n"
     5"Project-Id-Version: WP SMS Functions 1.2.6\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-sms-functions\n"
    7 "POT-Creation-Date: 2021-12-07 15:15:26+00:00\n"
     7"POT-Creation-Date: 2022-05-05 14:39:34+00:00\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=UTF-8\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "PO-Revision-Date: 2021-MO-DA HO:MI+ZONE\n"
     11"PO-Revision-Date: 2022-MO-DA HO:MI+ZONE\n"
    1212"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1313"Language-Team: LANGUAGE <LL@li.org>\n"
     
    102102msgstr ""
    103103
    104 #: inc/providers/Gri_Provider.php:107 inc/providers/PandaSMS_Provider.php:143
     104#: inc/providers/Gri_Provider.php:118 inc/providers/PandaSMS_Provider.php:143
    105105msgid "API Key"
    106106msgstr ""
    107107
    108 #: inc/providers/Gri_Provider.php:113
     108#: inc/providers/Gri_Provider.php:124
    109109msgid "Secret Key"
    110110msgstr ""
    111111
    112 #: inc/providers/Gri_Provider.php:120
     112#: inc/providers/Gri_Provider.php:131
    113113msgid "SMS Header"
    114114msgstr ""
    115115
    116 #: inc/providers/Gri_Provider.php:124
     116#: inc/providers/Gri_Provider.php:135
    117117msgid "You must save api key and secret key to select the message header."
    118118msgstr ""
    119119
    120 #: inc/providers/Gri_Provider.php:128
     120#: inc/providers/Gri_Provider.php:139
    121121msgid "Select"
    122122msgstr ""
    123123
    124 #: inc/providers/Gri_Provider.php:142
    125 msgid "Last Balance"
    126 msgstr ""
    127 
    128 #: inc/providers/Gri_Provider.php:146
     124#: inc/providers/Gri_Provider.php:153
     125msgid "Balance Remaining"
     126msgstr ""
     127
     128#: inc/providers/Gri_Provider.php:157
    129129msgid "You must save api key and secret key to view the balance."
    130130msgstr ""
    131131
    132 #: inc/providers/Gri_Provider.php:153
     132#: inc/providers/Gri_Provider.php:165
    133133msgid "There is no balance defined for you. Please contact us!"
    134134msgstr ""
  • wp-sms-functions/trunk/readme.txt

    r2676477 r2718672  
    4646== Changelog ==
    4747
     48= 1.2.6 =
     49* Gri SMS provider updated.
     50
    4851= 1.2.5 =
    4952* Gri SMS provider updated.
  • wp-sms-functions/trunk/wp-sms-functions.php

    r2676477 r2718672  
    66 * Author URI: https://www.gri.net
    77 * Text Domain: wp-sms-functions
    8  * Version: 1.2.5
     8 * Version: 1.2.6
    99 * Domain Path: /lang
    1010 * Requires at least: 4.9
Note: See TracChangeset for help on using the changeset viewer.