/** Get all guests by pagenum, per_page*/
 public static function get_all($orderby = 'email', $order = 'asc', $pagenum = 1, $per_page = 15)
 {
     global $wpdb;
     $limit = ($pagenum - 1) * $per_page;
     $query = 'SELECT * FROM ' . self::table_name . ' ';
     $query .= 'ORDER BY ' . $orderby . ' ' . $order . ' ';
     $query .= 'LIMIT ' . $limit . ',' . $per_page . ';';
     $results = $wpdb->get_results($query, ARRAY_A);
     self::$found_count = self::get_count_element();
     if (!is_array($results)) {
         $results = array();
         return $results;
     }
     return $results;
 }
Exemple #2
0
        /**
         * Subscribe process
         */
        function subscribe()
        {
            $site_domain = str_replace('https://', '', home_url());
            $site_domain = str_replace('http://', '', $site_domain);
            $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key);
            $code = esc_attr($_GET['code']);
            $list_id = intval($_GET['li']);
            $contact_info = SIB_Model_Contact::get_data_by_code($code);
            if ($contact_info != false) {
                $email = $contact_info['email'];
                $response = $mailin->get_user($email);
                if ($response['code'] == 'success') {
                    $listid = $response['data']['listid'];
                } else {
                    $listid = array();
                }
                if (SIB_Manager::$is_confirm_email == 'yes' && in_array($list_id, $listid) == false) {
                    $this->send_email('confirm', $email, $code, $list_id);
                }
                array_push($listid, $list_id);
                $attribues = maybe_unserialize($contact_info['info']);
                $mailin->create_update_user($email, $attribues, 0, $listid, null);
            }
            if (SIB_Manager::$redirect_url != '') {
                wp_redirect(SIB_Manager::$redirect_url);
                exit;
            }
            ?>
            <body style="margin:0; padding:0;">
            <table style="background-color:#ffffff" cellpadding="0" cellspacing="0" border="0" width="100%">
                <tbody>
                <tr style="border-collapse:collapse;">
                    <td style="border-collapse:collapse;" align="center">
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20"></td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20">
                                    <div style="font-family:arial,sans-serif; color:#61a6f3; font-size:20px; font-weight:bold; line-height:28px;">
                                        <?php 
            _e('Thank you for subscribing', 'sib_lang');
            ?>
</div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20"></td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td align="left">

                                    <div style="font-family:arial,sans-serif; font-size:14px; margin:0; line-height:24px; color:#555555;">
                                        <br>
                                        <?php 
            echo __('You have just subscribed to the newsletter of ', 'sib_lang') . $site_domain . ' .';
            ?>
<br><br>
                                        <?php 
            _e('-SendinBlue', 'sib_lang');
            ?>
</div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20">
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
                </tbody>
            </table>
            </body>
            <?php 
            exit;
        }
    /**
     * Subscribe process for submit on confirmation email
     */
    public static function subscribe()
    {
        $site_domain = str_replace('https://', '', home_url());
        $site_domain = str_replace('http://', '', $site_domain);
        $general_settings = get_option('ws_main_option', array());
        if (!class_exists('Mailin')) {
            require_once 'mailin.php';
        }
        $mailin = new Mailin(self::sendinblue_api_url, $general_settings['access_key']);
        $code = esc_attr($_GET['code']);
        $list_id = intval($_GET['li']);
        $contact_info = SIB_Model_Contact::get_data_by_code($code);
        if ($contact_info != false) {
            $email = $contact_info['email'];
            $data = array('email' => $email);
            $response = $mailin->get_user($data);
            if ($response['code'] == 'success') {
                $listid = $response['data']['listid'];
                if (!isset($listid) || !is_array($listid)) {
                    $listid = array();
                }
            } else {
                $listid = array();
            }
            array_push($listid, $list_id);
            $attributes = maybe_unserialize($contact_info['info']);
            $data = array();
            $attribute_key = implode('|', array_keys($attributes));
            $attribute_val = implode('|', array_values($attributes));
            $ip = self::get_the_user_ip();
            $data['attributes_name'] = $attribute_key;
            $data['attributes_value'] = $attribute_val;
            $data['category'] = '';
            $data['email'] = $email;
            $data['listid'] = $list_id;
            $data['blacklisted'] = 0;
            $data['blacklisted_sms'] = 0;
            $data['source'] = 'Wordpress Woocommerce';
            $data['ip'] = $ip;
            $ret = $mailin->updateUser($data);
        }
        ?>
        <body style="margin:0; padding:0;">
        <table style="background-color:#ffffff" cellpadding="0" cellspacing="0" border="0" width="100%">
            <tbody>
            <tr style="border-collapse:collapse;">
                <td style="border-collapse:collapse;" align="center">
                    <table cellpadding="0" cellspacing="0" border="0" width="540">
                        <tbody>
                        <tr>
                            <td style="line-height:0; font-size:0;" height="20"></td>
                        </tr>
                        </tbody>
                    </table>
                    <table cellpadding="0" cellspacing="0" border="0" width="540">
                        <tbody>
                        <tr>
                            <td style="line-height:0; font-size:0;" height="20">
                                <div
                                    style="font-family:arial,sans-serif; color:#61a6f3; font-size:20px; font-weight:bold; line-height:28px;">
                                    <?php 
        _e('Thank you for subscribing', 'wc_sendinblue');
        ?>
</div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table cellpadding="0" cellspacing="0" border="0" width="540">
                        <tbody>
                        <tr>
                            <td style="line-height:0; font-size:0;" height="20"></td>
                        </tr>
                        </tbody>
                    </table>
                    <table cellpadding="0" cellspacing="0" border="0" width="540">
                        <tbody>
                        <tr>
                            <td align="left">

                                <div
                                    style="font-family:arial,sans-serif; font-size:14px; margin:0; line-height:24px; color:#555555;">
                                    <br>
                                    <?php 
        echo __('You have just subscribed to the newsletter of ', 'wc_sendinblue') . $site_domain . ' .';
        ?>
                                    <br><br>
                                    <?php 
        _e('-SendinBlue', 'wc_sendinblue');
        ?>
</div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <table cellpadding="0" cellspacing="0" border="0" width="540">
                        <tbody>
                        <tr>
                            <td style="line-height:0; font-size:0;" height="20">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
        </body>
        <?php 
        exit;
    }
 /**
  * Install method is called once install this plugin.
  * create tables, default option ...
  */
 static function activate()
 {
     SIB_Model_Contact::create_table();
     // Get the country code data
     SIB_Model_Country::create_table();
     $file = fopen(plugin_dir_path(__FILE__) . "/model/country_code.csv", "r");
     $country_code = array();
     while (!feof($file)) {
         $code = fgetcsv($file);
         $country_code[$code[0]] = $code[1];
     }
     fclose($file);
     SIB_Model_Country::Initialize($country_code);
     // redirect option
     update_option('ws_do_activation_redirect', true);
 }
        /**
         * Subscribe process
         */
        function subscribe()
        {
            $site_domain = str_replace('https://', '', home_url());
            $site_domain = str_replace('http://', '', $site_domain);
            $mailin = new Mailin(SIB_Manager::sendinblue_api_url, SIB_Manager::$access_key);
            $code = esc_attr($_GET['code']);
            $list_id = intval($_GET['li']);
            $contact_info = SIB_Model_Contact::get_data_by_code($code);
            if ($contact_info != false) {
                $email = $contact_info['email'];
                $data = array('email' => $email);
                $response = $mailin->get_user($data);
                if ($response['code'] == 'success') {
                    $listid = $response['data']['listid'];
                    if (!isset($listid) || !is_array($listid)) {
                        $listid = array();
                    }
                } else {
                    $listid = array();
                }
                if (SIB_Manager::$is_confirm_email == 'yes' && in_array($list_id, $listid) == false) {
                    $this->send_email('confirm', $email, $code, $list_id);
                }
                array_push($listid, $list_id);
                $info = maybe_unserialize($contact_info['info']);
                $data = array();
                $attribute_key = implode('|', array_keys($info));
                $attribute_val = implode('|', array_values($info));
                $ip = $this->get_the_user_ip();
                $data['attributes_name'] = $attribute_key;
                $data['attributes_value'] = $attribute_val;
                $data['category'] = '';
                $data['email'] = $email;
                $data['listid'] = $list_id;
                $data['blacklisted'] = 0;
                $data['blacklisted_sms'] = 0;
                $data['source'] = 'Wordpress';
                $data['ip'] = $ip;
                $response = $mailin->updateUser($data);
            }
            if (SIB_Manager::$redirect_url != '') {
                wp_redirect(SIB_Manager::$redirect_url);
                exit;
            }
            ?>
            <body style="margin:0; padding:0;">
            <table style="background-color:#ffffff" cellpadding="0" cellspacing="0" border="0" width="100%">
                <tbody>
                <tr style="border-collapse:collapse;">
                    <td style="border-collapse:collapse;" align="center">
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20"></td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20">
                                    <div style="font-family:arial,sans-serif; color:#61a6f3; font-size:20px; font-weight:bold; line-height:28px;">
                                        <?php 
            _e('Thank you for subscribing', 'sib_lang');
            ?>
</div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20"></td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td align="left">

                                    <div style="font-family:arial,sans-serif; font-size:14px; margin:0; line-height:24px; color:#555555;">
                                        <br>
                                        <?php 
            echo __('You have just subscribed to the newsletter of ', 'sib_lang') . $site_domain . ' .';
            ?>
<br><br>
                                        <?php 
            _e('-SendinBlue', 'sib_lang');
            ?>
</div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <table cellpadding="0" cellspacing="0" border="0" width="540">
                            <tbody>
                            <tr>
                                <td style="line-height:0; font-size:0;" height="20">
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
                </tbody>
            </table>
            </body>
            <?php 
            exit;
        }
 /**
  * Send double optin email
  */
 public function double_optin_signup($email, $list_id, $info, $template_id = 0)
 {
     $response = $this->validation_email($email, $list_id);
     if ($response['code'] == 'already_exist') {
         return $response['code'];
     }
     // db store
     $data = SIB_Model_Contact::get_data_by_email($email);
     if ($data == false) {
         $uniqid = uniqid();
         $data = array('email' => $email, 'info' => maybe_serialize($info), 'code' => $uniqid, 'is_activate' => 0, 'extra' => 0);
         SIB_Model_Contact::add_record($data);
     } else {
         $uniqid = $data['code'];
     }
     // send double optin email
     //if($template_id == 0)
     $subject = __('Please confirm subscription', 'wc_sendinblue');
     if (!self::send_email('double-optin', $email, $subject, $uniqid, $list_id, $template_id, $info)) {
         return 'fail';
     }
     return 'success';
 }