mailin
Last commit date
css
7 years ago
img
8 years ago
inc
7 years ago
js
7 years ago
lang
7 years ago
model
7 years ago
page
7 years ago
widget
8 years ago
index.php
11 years ago
readme.txt
7 years ago
screenshot-1.png
9 years ago
screenshot-2.png
9 years ago
screenshot-3.png
9 years ago
screenshot-4.png
9 years ago
screenshot-5.png
9 years ago
screenshot-6.png
9 years ago
screenshot-7.png
9 years ago
screenshot-8.png
9 years ago
screenshot-9.png
9 years ago
sendinblue.php
7 years ago
sendinblue.php
1227 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: SendinBlue Subscribe Form And WP SMTP |
| 4 | * Plugin URI: https://www.sendinblue.com/?r=wporg |
| 5 | * Description: Easily send emails from your WordPress blog using SendinBlue SMTP and easily add a subscribe form to your site |
| 6 | * Version: 2.9.5 |
| 7 | * Author: SendinBlue |
| 8 | * Author URI: https://www.sendinblue.com/?r=wporg |
| 9 | * License: GPLv2 or later |
| 10 | * |
| 11 | * @package SIB |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | This program is free software; you can redistribute it and/or |
| 16 | modify it under the terms of the GNU General Public License |
| 17 | as published by the Free Software Foundation; either version 2 |
| 18 | of the License, or (at your option) any later version. |
| 19 | This program is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU General Public License for more details. |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Application entry point. Contains plugin startup class that loads on <i> sendinblue_init </i> action. |
| 30 | */ |
| 31 | if ( ! class_exists( 'Mailin' ) ) { |
| 32 | require_once( 'inc/mailin.php' ); |
| 33 | } |
| 34 | // For marketing automation. |
| 35 | if ( ! class_exists( 'Sendinblue' ) ) { |
| 36 | require_once( 'inc/sendinblue.php' ); |
| 37 | } |
| 38 | |
| 39 | if ( ! class_exists( 'SIB_Manager' ) ) { |
| 40 | register_deactivation_hook( __FILE__, array( 'SIB_Manager', 'deactivate' ) ); |
| 41 | register_activation_hook( __FILE__, array( 'SIB_Manager', 'install' ) ); |
| 42 | register_uninstall_hook( __FILE__, array( 'SIB_Manager', 'uninstall' ) ); |
| 43 | |
| 44 | require_once( 'page/page-home.php' ); |
| 45 | require_once( 'page/page-form.php' ); |
| 46 | require_once( 'page/page-lists.php' ); |
| 47 | require_once( 'page/page-campaigns.php' ); |
| 48 | require_once( 'page/page-statistics.php' ); |
| 49 | require_once( 'page/page-scenarios.php' ); |
| 50 | require_once( 'widget/widget_form.php' ); |
| 51 | require_once( 'inc/table-forms.php' ); |
| 52 | require_once( 'inc/sib-api-manager.php' ); |
| 53 | require_once( 'inc/sib-sms-code.php' ); |
| 54 | require_once( 'model/model-forms.php' ); |
| 55 | require_once( 'model/model-users.php' ); |
| 56 | require_once( 'model/model-lang.php' ); |
| 57 | |
| 58 | /** |
| 59 | * Class SIB_Manager |
| 60 | */ |
| 61 | class SIB_Manager { |
| 62 | |
| 63 | /** Main setting option name */ |
| 64 | const MAIN_OPTION_NAME = 'sib_main_option'; |
| 65 | |
| 66 | /** Home setting option name */ |
| 67 | const HOME_OPTION_NAME = 'sib_home_option'; |
| 68 | |
| 69 | /** Access token option name */ |
| 70 | const ACCESS_TOKEN_OPTION_NAME = 'sib_token_store'; |
| 71 | |
| 72 | /** Plugin language notice option name */ |
| 73 | const LANGUAGE_OPTION_NAME = 'sib_language_notice_option'; |
| 74 | |
| 75 | /** Temp list of Dopt option name */ |
| 76 | const TEMPLIST_OPTION_NAME = 'sib_temp_list'; |
| 77 | |
| 78 | /** Form preview option name */ |
| 79 | const PREVIEW_OPTION_NAME = 'sib_preview_form'; |
| 80 | |
| 81 | /** Request url of sendinblue api */ |
| 82 | const SENDINBLUE_API_URL = 'https://api.sendinblue.com/v2.0'; |
| 83 | |
| 84 | /** |
| 85 | * API key |
| 86 | * |
| 87 | * @var $access_key |
| 88 | */ |
| 89 | public static $access_key; |
| 90 | |
| 91 | /** |
| 92 | * Store instance |
| 93 | * |
| 94 | * @var $instance |
| 95 | */ |
| 96 | public static $instance; |
| 97 | |
| 98 | /** |
| 99 | * Plugin directory path value. set in constructor |
| 100 | * |
| 101 | * @var $plugin_dir |
| 102 | */ |
| 103 | public static $plugin_dir; |
| 104 | |
| 105 | /** |
| 106 | * Plugin url. set in constructor |
| 107 | * |
| 108 | * @var $plugin_url |
| 109 | */ |
| 110 | public static $plugin_url; |
| 111 | |
| 112 | /** |
| 113 | * Plugin name. set in constructor |
| 114 | * |
| 115 | * @var $plugin_name |
| 116 | */ |
| 117 | public static $plugin_name; |
| 118 | |
| 119 | /** |
| 120 | * Check if wp_mail is declared |
| 121 | * |
| 122 | * @var $wp_mail_conflict |
| 123 | */ |
| 124 | static $wp_mail_conflict; |
| 125 | |
| 126 | /** |
| 127 | * Class constructor |
| 128 | * Sets plugin url and directory and adds hooks to <i>init</i>. <i>admin_menu</i> |
| 129 | */ |
| 130 | function __construct() { |
| 131 | // get basic info. |
| 132 | self::$plugin_dir = plugin_dir_path( __FILE__ ); |
| 133 | self::$plugin_url = plugins_url( '', __FILE__ ); |
| 134 | self::$plugin_name = plugin_basename( __FILE__ ); |
| 135 | |
| 136 | self::$wp_mail_conflict = false; |
| 137 | |
| 138 | // api key for sendinblue. |
| 139 | $general_settings = get_option( self::MAIN_OPTION_NAME, array() ); |
| 140 | self::$access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : ''; |
| 141 | |
| 142 | self::$instance = $this; |
| 143 | |
| 144 | add_action( 'admin_init', array( &$this, 'admin_init' ), 9999 ); |
| 145 | add_action( 'admin_menu', array( &$this, 'admin_menu' ), 9999 ); |
| 146 | |
| 147 | add_action( 'wp_print_scripts', array( &$this, 'frontend_register_scripts' ), 9999 ); |
| 148 | add_action( 'wp_enqueue_scripts', array( &$this, 'wp_head_ac' ), 999 ); |
| 149 | |
| 150 | // create custom url for form preview. |
| 151 | add_filter( 'query_vars', array( &$this, 'sib_query_vars' ) ); |
| 152 | add_action( 'parse_request', array( &$this, 'sib_parse_request' ) ); |
| 153 | |
| 154 | add_action( 'wp_ajax_sib_validate_process', array( 'SIB_Page_Home', 'ajax_validation_process' ) ); |
| 155 | add_action( 'wp_ajax_sib_validate_ma', array( 'SIB_Page_Home', 'ajax_validate_ma' ) ); |
| 156 | add_action( 'wp_ajax_sib_activate_email_change', array( 'SIB_Page_Home', 'ajax_activate_email_change' ) ); |
| 157 | add_action( 'wp_ajax_sib_sender_change', array( 'SIB_Page_Home', 'ajax_sender_change' ) ); |
| 158 | add_action( 'wp_ajax_sib_send_email', array( 'SIB_Page_Home', 'ajax_send_email' ) ); |
| 159 | add_action( 'wp_ajax_sib_remove_cache', array( 'SIB_Page_Home', 'ajax_remove_cache' ) ); |
| 160 | add_action( 'wp_ajax_sib_sync_users', array( 'SIB_Page_Home', 'ajax_sync_users' ) ); |
| 161 | |
| 162 | add_action( 'wp_ajax_sib_change_template', array( 'SIB_Page_Form', 'ajax_change_template' ) ); |
| 163 | add_action( 'wp_ajax_sib_get_lists', array( 'SIB_Page_Form', 'ajax_get_lists' ) ); |
| 164 | add_action( 'wp_ajax_sib_get_templates', array( 'SIB_Page_Form', 'ajax_get_templates' ) ); |
| 165 | add_action( 'wp_ajax_sib_get_attributes', array( 'SIB_Page_Form', 'ajax_get_attributes' ) ); |
| 166 | add_action( 'wp_ajax_sib_update_form_html', array( 'SIB_Page_Form', 'ajax_update_html' ) ); |
| 167 | add_action( 'wp_ajax_sib_copy_origin_form', array( 'SIB_Page_Form', 'ajax_copy_origin_form' ) ); |
| 168 | |
| 169 | add_action( 'wp_ajax_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) ); |
| 170 | add_action( 'wp_ajax_nopriv_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) ); |
| 171 | |
| 172 | add_action( 'init', array( &$this, 'init' ) ); |
| 173 | |
| 174 | add_action( 'wp_login', array( &$this, 'sib_wp_login_identify' ), 10, 2 ); |
| 175 | |
| 176 | // change sib tables name on prior(2.6.9) versions. |
| 177 | SIB_Model_Users::add_prefix(); |
| 178 | SIB_Forms::add_prefix(); |
| 179 | |
| 180 | if ( self::is_done_validation() === true ) { |
| 181 | add_shortcode( 'sibwp_form', array( &$this, 'sibwp_form_shortcode' ) ); |
| 182 | // register widget. |
| 183 | add_action( 'widgets_init', array( &$this, 'sib_create_widget' ) ); |
| 184 | |
| 185 | // create forms tables and create default form. |
| 186 | SIB_Forms::createTable(); |
| 187 | // create users table. |
| 188 | SIB_Model_Users::createTable(); |
| 189 | // add columns for old versions |
| 190 | SIB_Forms::alterTable(); |
| 191 | } |
| 192 | |
| 193 | $use_api_version = get_option( 'sib_use_apiv2', '0' ); |
| 194 | if ( '0' === $use_api_version ) { |
| 195 | self::uninstall(); |
| 196 | update_option( 'sib_use_apiv2', '1' ); |
| 197 | } |
| 198 | |
| 199 | // Wpml plugin part. |
| 200 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) : |
| 201 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 202 | endif; |
| 203 | if ( in_array( 'sitepress-multilingual-cms/sitepress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || is_plugin_active_for_network( 'sitepress-multilingual-cms/sitepress.php' ) ) { |
| 204 | SIB_Forms_Lang::createTable(); |
| 205 | add_action( 'sib_language_sidebar', array( $this, 'sib_create_language_sidebar' ) ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Hook wp_mail to send transactional emails |
| 210 | */ |
| 211 | |
| 212 | // check if wp_mail function is already declared by others. |
| 213 | if ( function_exists( 'wp_mail' ) ) { |
| 214 | self::$wp_mail_conflict = true; |
| 215 | } |
| 216 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() ); |
| 217 | |
| 218 | if( 'yes' === $home_settings['activate_email'] ) |
| 219 | { |
| 220 | if ( false === self::$wp_mail_conflict ) { |
| 221 | /** |
| 222 | * Declare wp_mail function for SendinBlue SMTP module |
| 223 | * |
| 224 | * @param string $to - receiption email. |
| 225 | * @param string $subject - subject of email. |
| 226 | * @param string $message - message content. |
| 227 | * @param string $headers - header of email. |
| 228 | * @param array $attachments - attachments. |
| 229 | * @return bool |
| 230 | */ |
| 231 | function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 232 | $message = str_replace( 'NF_SIB', '', $message ); |
| 233 | $message = str_replace( 'WC_SIB', '', $message ); |
| 234 | try { |
| 235 | $sent = SIB_Manager::sib_email( $to, $subject, $message, $headers, $attachments ); |
| 236 | if ( is_wp_error( $sent ) || ! isset( $sent['code'] ) || 'success' !== $sent['code'] ) { |
| 237 | return SIB_Manager::wp_mail_native( $to, $subject, $message, $headers, $attachments ); |
| 238 | } |
| 239 | return true; |
| 240 | } catch ( Exception $e ) { |
| 241 | return SIB_Manager::wp_mail_native( $to, $subject, $message, $headers, $attachments ); |
| 242 | } |
| 243 | } |
| 244 | } else { |
| 245 | add_action( 'admin_notices', array( &$this, 'wpMailNotices' ) ); |
| 246 | return; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Add identify tag for login users |
| 253 | * |
| 254 | * @param string $user_login - user login name. |
| 255 | * @param array $user - user. |
| 256 | */ |
| 257 | function sib_wp_login_identify( $user_login, $user ) { |
| 258 | |
| 259 | $userEmail = $user->user_email; |
| 260 | $data = array( |
| 261 | 'email_id' => $userEmail, |
| 262 | 'name' => $user_login, |
| 263 | ); |
| 264 | SIB_API_Manager::identify_user( $data ); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Initialize method. called on <i>init</i> action |
| 269 | */ |
| 270 | function init() { |
| 271 | // Sign up process. |
| 272 | if ( isset( $_POST['sib_form_action'] ) && ( 'subscribe_form_submit' == $_POST['sib_form_action'] ) ) { |
| 273 | $this->signup_process(); |
| 274 | } |
| 275 | // Subscribe. |
| 276 | if ( isset( $_GET['sib_action'] ) && ( 'subscribe' == $_GET['sib_action'] ) ) { |
| 277 | SIB_API_Manager::subscribe(); |
| 278 | exit; |
| 279 | } |
| 280 | // Dismiss language notice. |
| 281 | if ( isset( $_GET['dismiss_admin_lang_notice'] ) && '1' == $_GET['dismiss_admin_lang_notice'] ) { |
| 282 | update_option( SIB_Manager::LANGUAGE_OPTION_NAME, true ); |
| 283 | wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 284 | exit(); |
| 285 | } |
| 286 | |
| 287 | add_action( 'wp_head', array( &$this, 'install_ma_script' ) ); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Hook admin_init |
| 292 | */ |
| 293 | function admin_init() { |
| 294 | add_action( 'admin_action_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) ); |
| 295 | add_action( 'admin_action_nopriv_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) ); |
| 296 | SIB_Manager::LoadTextDomain(); |
| 297 | $this->register_scripts(); |
| 298 | $this->register_styles(); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Hook admin_menu |
| 303 | */ |
| 304 | function admin_menu() { |
| 305 | SIB_Manager::LoadTextDomain(); |
| 306 | new SIB_Page_Home(); |
| 307 | new SIB_Page_Form(); |
| 308 | new SIB_Page_Lists(); |
| 309 | new SIB_Page_Campaigns(); |
| 310 | new SIB_Page_Statistics(); |
| 311 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME ); |
| 312 | if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) { |
| 313 | new SIB_Page_Scenarios(); |
| 314 | } |
| 315 | |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Register script for admin page |
| 320 | */ |
| 321 | function register_scripts() { |
| 322 | wp_register_script( 'sib-bootstrap-js', self::$plugin_url . '/js/bootstrap/js/bootstrap.min.js', array( 'jquery' ), null ); |
| 323 | wp_register_script( 'sib-admin-js', self::$plugin_url . '/js/admin.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/admin.js' ) ); |
| 324 | wp_register_script( 'sib-chosen-js', self::$plugin_url . '/js/chosen.jquery.min.js', array( 'jquery' ), null ); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Register stylesheet for admin page |
| 329 | */ |
| 330 | function register_styles() { |
| 331 | wp_register_style( 'sib-bootstrap-css', self::$plugin_url . '/js/bootstrap/css/bootstrap.css', array(), null, 'all' ); |
| 332 | wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), null, 'all' ); |
| 333 | wp_register_style( 'sib-chosen-css', self::$plugin_url . '/css/chosen.min.css' ); |
| 334 | wp_register_style( 'sib-admin-css', self::$plugin_url . '/css/admin.css', array(), filemtime( self::$plugin_dir . '/css/admin.css' ), 'all' ); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Registers scripts for frontend |
| 339 | */ |
| 340 | function frontend_register_scripts() { |
| 341 | |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Enqueue script on front page |
| 346 | */ |
| 347 | function wp_head_ac() { |
| 348 | wp_enqueue_script( 'sib-front-js', self::$plugin_url . '/js/mailin-front.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/mailin-front.js' ), false ); |
| 349 | wp_enqueue_style( 'sib-front-css', self::$plugin_url.'/css/mailin-front.css', array(), array(), 'all'); |
| 350 | wp_localize_script( |
| 351 | 'sib-front-js', 'sibErrMsg', array( |
| 352 | 'invalidMail' => __( 'Please fill out valid email address', 'sib_lang' ), |
| 353 | 'requiredField' => __( 'Please fill out required fields', 'sib_lang' ), |
| 354 | 'invalidDateFormat' => __( 'Please fill out valid date format', 'sib_lang' ), |
| 355 | 'invalidSMSFormat' => __( 'Please fill out valid phone number', 'sib_lang' ), |
| 356 | ) |
| 357 | ); |
| 358 | wp_localize_script( |
| 359 | 'sib-front-js', 'ajax_sib_front_object', |
| 360 | array( |
| 361 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 362 | 'ajax_nonce' => wp_create_nonce( 'sib_front_ajax_nonce' ), |
| 363 | 'flag_url' => plugins_url('img/flags/', __FILE__ ), |
| 364 | ) |
| 365 | ); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Install method is called once install this plugin. |
| 370 | * create tables, default option ... |
| 371 | */ |
| 372 | static function install() { |
| 373 | $general_settings = get_option( self::MAIN_OPTION_NAME, array() ); |
| 374 | $access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : ''; |
| 375 | if ( '' === $access_key ) { |
| 376 | // Default option when activate. |
| 377 | $home_settings = array( |
| 378 | 'activate_email' => 'no', |
| 379 | 'activate_ma' => 'no', |
| 380 | ); |
| 381 | update_option( self::HOME_OPTION_NAME, $home_settings ); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Uninstall method is called once uninstall this plugin |
| 387 | * delete tables, options that used in plugin |
| 388 | */ |
| 389 | static function uninstall() { |
| 390 | $setting = array(); |
| 391 | update_option( SIB_Manager::MAIN_OPTION_NAME, $setting ); |
| 392 | |
| 393 | $home_settings = array( |
| 394 | 'activate_email' => 'no', |
| 395 | 'activate_ma' => 'no', |
| 396 | ); |
| 397 | update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings ); |
| 398 | |
| 399 | // Delete access_token. |
| 400 | $token_settings = array(); |
| 401 | update_option( SIB_Manager::ACCESS_TOKEN_OPTION_NAME, $token_settings ); |
| 402 | |
| 403 | // Empty tables. |
| 404 | SIB_Model_Users::removeTable(); |
| 405 | SIB_Forms::removeTable(); |
| 406 | SIB_Forms_Lang::removeTable(); |
| 407 | |
| 408 | // Remove all transient. |
| 409 | SIB_API_Manager::remove_transients(); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Deactivate method is called once deactivate this plugin |
| 414 | */ |
| 415 | static function deactivate() { |
| 416 | update_option( SIB_Manager::LANGUAGE_OPTION_NAME, false ); |
| 417 | // Remove sync users option. |
| 418 | delete_option( 'sib_sync_users' ); |
| 419 | // Remove all transient. |
| 420 | SIB_API_Manager::remove_transients(); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Check that have done validation process already. |
| 425 | */ |
| 426 | static function is_done_validation() { |
| 427 | $general_settings = get_option( self::MAIN_OPTION_NAME, array() ); |
| 428 | $access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : ''; |
| 429 | if ( '' !== $access_key ) { |
| 430 | return true; |
| 431 | } else { |
| 432 | return false; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Install marketing automation script in header |
| 438 | */ |
| 439 | function install_ma_script() { |
| 440 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() ); |
| 441 | if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) { |
| 442 | $general_settings = get_option( SIB_Manager::MAIN_OPTION_NAME, array() ); |
| 443 | $ma_key = $general_settings['ma_key']; |
| 444 | $output = '<script type="text/javascript"> |
| 445 | (function() {window.sib ={equeue:[],client_key:"'. $ma_key .'"};/* OPTIONAL: email for identify request*/window.sendinblue = {}; for (var j = [\'track\', \'identify\', \'trackLink\', \'page\'], i = 0; i < j.length; i++) { (function(k) { window.sendinblue[k] = function() { var arg = Array.prototype.slice.call(arguments); (window.sib[k] || function() { var t = {}; t[k] = arg; window.sib.equeue.push(t);})(arg[0], arg[1], arg[2]);};})(j[i]);}var n = document.createElement("script"),i = document.getElementsByTagName("script")[0]; n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();})(); |
| 446 | </script>'; |
| 447 | echo $output; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Register widget |
| 453 | */ |
| 454 | function sib_create_widget() { |
| 455 | register_widget( 'SIB_Widget_Subscribe' ); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Display form on front page |
| 460 | * |
| 461 | * @param string $frmID - form ID. |
| 462 | * @param string $lang - form language. |
| 463 | */ |
| 464 | function generate_form_box( $frmID = '-1', $lang = '' ) { |
| 465 | if ( 'oldForm' == $frmID ) { |
| 466 | $frmID = get_option( 'sib_old_form_id' ); |
| 467 | } elseif ( '' != $lang ) { |
| 468 | $trans_id = SIB_Forms_Lang::get_form_ID( $frmID, $lang ); |
| 469 | if ( null != $trans_id ) { |
| 470 | $frmID = $trans_id; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | $formData = SIB_Forms::getForm( $frmID ); |
| 475 | |
| 476 | if ( empty( $formData ) ) { |
| 477 | return; |
| 478 | } |
| 479 | // Add Google recaptcha |
| 480 | if( '0' != $formData['gCaptcha'] ) { |
| 481 | if( '1' == $formData['gCaptcha'] ) { // For old forms. |
| 482 | $formData['html'] = preg_replace( '/([\s\S]*?)<div class="g-recaptcha"[\s\S]*?data-size="invisible"><\/div>/', '$1', $formData['html'] ); |
| 483 | } |
| 484 | if ( '3' == $formData['gCaptcha'] ) // The case of using google recaptcha. |
| 485 | { |
| 486 | ?> |
| 487 | <script type="text/javascript"> |
| 488 | var gCaptchaSibWidget; |
| 489 | var onloadSibCallback = function() { |
| 490 | gCaptchaSibWidget = grecaptcha.render('sib_captcha',{ |
| 491 | 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>' |
| 492 | }); |
| 493 | }; |
| 494 | </script> |
| 495 | <?php |
| 496 | } |
| 497 | else { // The case of using google invisible recaptcha. |
| 498 | ?> |
| 499 | <script type="text/javascript"> |
| 500 | var gCaptchaSibWidget; |
| 501 | var onloadSibCallback = function() { |
| 502 | var element = document.getElementsByClassName('sib-default-btn'); |
| 503 | gCaptchaSibWidget = grecaptcha.render(element[0],{ |
| 504 | 'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>', |
| 505 | 'callback' : sibVerifyCallback |
| 506 | }); |
| 507 | }; |
| 508 | </script> |
| 509 | <?php |
| 510 | } |
| 511 | ?> |
| 512 | <script src="https://www.google.com/recaptcha/api.js?onload=onloadSibCallback&render=explicit" async defer></script> |
| 513 | <?php |
| 514 | } |
| 515 | |
| 516 | ?> |
| 517 | <form id="sib_signup_form_<?php echo esc_attr( $frmID ); ?>" method="post" class="sib_signup_form"> |
| 518 | <div class="sib_loader" style="display:none;"><img |
| 519 | src="<?php echo esc_url( includes_url() ); ?>/images/spinner.gif" alt="loader"></div> |
| 520 | <input type="hidden" name="sib_form_action" value="subscribe_form_submit"> |
| 521 | <input type="hidden" name="sib_form_id" value="<?php echo esc_attr( $frmID ); ?>"> |
| 522 | <input type="hidden" name="sib_form_alert_notice" value="<?php echo esc_attr($formData['requiredMsg']); ?>"> |
| 523 | <div class="sib_signup_box_inside_<?php echo esc_attr( $frmID ); ?>"> |
| 524 | <div style="/*display:none*/" class="sib_msg_disp"> |
| 525 | </div> |
| 526 | <?php |
| 527 | echo $formData['html']; |
| 528 | ?> |
| 529 | </div> |
| 530 | </form> |
| 531 | <style> |
| 532 | <?php |
| 533 | |
| 534 | if ( ! $formData['dependTheme'] ) { |
| 535 | // Custom css. |
| 536 | $formData['css'] = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, $formData['css'] ); |
| 537 | echo $formData['css']; |
| 538 | } |
| 539 | $msgCss = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, SIB_Forms::getDefaultMessageCss() ); |
| 540 | echo $msgCss; |
| 541 | ?> |
| 542 | </style> |
| 543 | <?php |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Shortcode for sign up form |
| 548 | * |
| 549 | * @param array $atts - shortcode parameter. |
| 550 | * @return string |
| 551 | */ |
| 552 | function sibwp_form_shortcode( $atts ) { |
| 553 | $pull_atts = shortcode_atts( |
| 554 | array( |
| 555 | 'id' => 'oldForm', // We will return 'oldForm' for shortcode of old form. |
| 556 | ), $atts |
| 557 | ); |
| 558 | $frmID = $pull_atts['id']; |
| 559 | $lang = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : ''; |
| 560 | |
| 561 | ob_start(); |
| 562 | $this->generate_form_box( $frmID, $lang ); |
| 563 | |
| 564 | $output_string = ob_get_contents(); |
| 565 | ob_end_clean(); |
| 566 | return $output_string; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Sign up process |
| 571 | */ |
| 572 | function signup_process() { |
| 573 | check_ajax_referer( 'sib_front_ajax_nonce', 'security' ); |
| 574 | $formID = isset( $_POST['sib_form_id'] ) ? sanitize_text_field( $_POST['sib_form_id'] ) : 1; |
| 575 | if ( 'oldForm' == $formID ) { |
| 576 | $formID = get_option( 'sib_old_form_id' ); |
| 577 | } |
| 578 | $formData = SIB_Forms::getForm( $formID ); |
| 579 | |
| 580 | if ( '0' != $formData['gCaptcha'] ) { |
| 581 | if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) { |
| 582 | wp_send_json( |
| 583 | array( |
| 584 | 'status' => 'gcaptchaEmpty', |
| 585 | 'msg' => 'Please click on the reCAPTCHA box.', |
| 586 | ) |
| 587 | ); |
| 588 | } |
| 589 | $secret = $formData['gCaptcha_secret']; |
| 590 | |
| 591 | $data = array( |
| 592 | 'secret' => $secret, |
| 593 | 'response' => sanitize_text_field( $_POST['g-recaptcha-response'] ), |
| 594 | ); |
| 595 | |
| 596 | $verify = curl_init(); |
| 597 | curl_setopt( $verify, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify' ); |
| 598 | curl_setopt( $verify, CURLOPT_POST, true ); |
| 599 | curl_setopt( $verify, CURLOPT_POSTFIELDS, http_build_query( $data ) ); |
| 600 | curl_setopt( $verify, CURLOPT_SSL_VERIFYPEER, false ); |
| 601 | curl_setopt( $verify, CURLOPT_RETURNTRANSFER, true ); |
| 602 | $response = curl_exec( $verify ); |
| 603 | $responseData = json_decode( $response ); |
| 604 | if ( ! $responseData->success ) { |
| 605 | wp_send_json( |
| 606 | array( |
| 607 | 'status' => 'gcaptchaFail', |
| 608 | 'msg' => 'Robot verification failed, please try again.', |
| 609 | ) |
| 610 | ); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | $listID = $formData['listID']; |
| 615 | $interestingLists = isset( $_POST['interestingLists']) ? $_POST['interestingLists'] : array(); |
| 616 | $expectedLists = isset( $_POST['listIDs'] ) ? $_POST['listIDs'] : array(); |
| 617 | if ( empty($interestingLists) ) |
| 618 | { |
| 619 | $unlinkedLists = null; |
| 620 | } |
| 621 | else{ |
| 622 | $unwantedLists = array_diff( $interestingLists, $expectedLists ); |
| 623 | $unlinkedLists = array_diff( $unwantedLists, $listID); |
| 624 | $listID = array_unique(array_merge( $listID, $expectedLists )); |
| 625 | } |
| 626 | |
| 627 | $email = isset( $_POST['email'] ) ? sanitize_text_field( $_POST['email'] ) : ''; |
| 628 | if ( ! is_email( $email ) ) { |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | $isDoubleOptin = $formData['isDopt']; |
| 633 | $isOptin = $formData['isOpt']; |
| 634 | $redirectUrlInEmail = $formData['redirectInEmail']; |
| 635 | $redirectUrlInForm = $formData['redirectInForm']; |
| 636 | |
| 637 | $info = array(); |
| 638 | $attributes = explode( ',', $formData['attributes'] ); // String to array. |
| 639 | if ( isset( $attributes ) && is_array( $attributes ) ) { |
| 640 | foreach ( $attributes as $attribute ) { |
| 641 | $info[ $attribute ] = isset( $_POST[ $attribute ] ) ? sanitize_text_field( $_POST[ $attribute ] ) : '' ; |
| 642 | } |
| 643 | } |
| 644 | $templateID = $formData['templateID']; |
| 645 | |
| 646 | if ( $isDoubleOptin ) { |
| 647 | /* |
| 648 | * Double optin process |
| 649 | * 1. add/update user in SIB contacts |
| 650 | * 2. add record to db |
| 651 | * 3. send confirmation email with activate code |
| 652 | */ |
| 653 | // Create/updated subscriber. |
| 654 | $result = SIB_API_Manager::create_subscriber( 'double-optin', $email, $listID, $info, $unlinkedLists ); |
| 655 | // Send a double optin confirm email. |
| 656 | if ( 'success' == $result ) { |
| 657 | // Add a recode with activate code in db. |
| 658 | $activateCode = $this->create_activate_code( $email, $info, $formID, $listID, $redirectUrlInEmail, $unlinkedLists ); |
| 659 | SIB_API_Manager::send_comfirm_email( 'double-optin', $email, $templateID, $info, $activateCode ); |
| 660 | } |
| 661 | } elseif ( $isOptin ) { |
| 662 | $result = SIB_API_Manager::create_subscriber( 'confirm', $email, $listID, $info, $unlinkedLists ); |
| 663 | if ( 'success' == $result ) { |
| 664 | // Send a confirm email. |
| 665 | SIB_API_Manager::send_comfirm_email( 'confirm', $email, $templateID, $info ); |
| 666 | } |
| 667 | } else { |
| 668 | $result = SIB_API_Manager::create_subscriber( 'simple', $email, $listID, $info, $unlinkedLists ); |
| 669 | } |
| 670 | $msg = array( |
| 671 | 'successMsg' => $formData['successMsg'], |
| 672 | 'errorMsg' => $formData['errorMsg'], |
| 673 | 'existMsg' => $formData['existMsg'], |
| 674 | 'invalidMsg' => $formData['invalidMsg'], |
| 675 | ); |
| 676 | |
| 677 | wp_send_json( |
| 678 | array( |
| 679 | 'status' => $result, |
| 680 | 'msg' => $msg, |
| 681 | 'redirect' => $redirectUrlInForm, |
| 682 | ) |
| 683 | ); |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Create activate code for Double optin |
| 688 | * |
| 689 | * @param string $email - user email. |
| 690 | * @param array $info - info. |
| 691 | * @param string $formID - form ID. |
| 692 | * @param array $listIDs - lists. |
| 693 | * @param string $redirectUrl - redirect url. |
| 694 | * @return string - activate code. |
| 695 | */ |
| 696 | function create_activate_code( $email, $info, $formID, $listIDs, $redirectUrl, $unlinkedLists = null ) { |
| 697 | $data = SIB_Model_Users::get_data_by_email( $email, $formID ); |
| 698 | if ( $unlinkedLists != null ) |
| 699 | { |
| 700 | $info['unlinkedLists'] = $unlinkedLists; |
| 701 | } |
| 702 | if ( false == $data ) { |
| 703 | $uniqid = uniqid(); |
| 704 | $data = array( |
| 705 | 'email' => $email, |
| 706 | 'code' => $uniqid, |
| 707 | 'info' => maybe_serialize( $info ), |
| 708 | 'frmid' => $formID, |
| 709 | 'listIDs' => maybe_serialize( $listIDs ), |
| 710 | 'redirectUrl' => $redirectUrl, |
| 711 | ); |
| 712 | SIB_Model_Users::add_record( $data ); |
| 713 | } else { |
| 714 | $uniqid = $data['code']; |
| 715 | } |
| 716 | return $uniqid; |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Use SendinBlue SMTP to send all emails |
| 721 | * |
| 722 | * @param string $to - reception email. |
| 723 | * @param string $subject - subject of email. |
| 724 | * @param string $message - message of email. |
| 725 | * @param string $headers - header of email. |
| 726 | * @param array $attachments - attachments. |
| 727 | */ |
| 728 | static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 729 | require self::$plugin_dir . '/inc/function.wp_mail.php'; |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * To send the transactional email via Sendinblue |
| 734 | * hook wp_mail |
| 735 | * |
| 736 | * @param string $to - reception email. |
| 737 | * @param string $subject - subject of email. |
| 738 | * @param string $message - message of email. |
| 739 | * @param string $headers - header of email. |
| 740 | * @param array $attachments - attachments |
| 741 | * @param array $tags - tag. |
| 742 | * @param string $from_name - sender name. |
| 743 | * @param string $from_email - sender email. |
| 744 | * @return mixed|WP_Error |
| 745 | */ |
| 746 | static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) { |
| 747 | // Compact the input, apply the filters, and extract them back out. |
| 748 | extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); |
| 749 | |
| 750 | if ( ! is_array( $attachments ) ) { |
| 751 | $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
| 752 | } |
| 753 | |
| 754 | // From email and name. |
| 755 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME ); |
| 756 | if ( isset( $home_settings['sender'] ) ) { |
| 757 | $from_name = $home_settings['from_name']; |
| 758 | $from_email = $home_settings['from_email']; |
| 759 | } else { |
| 760 | $from_email = trim( get_bloginfo( 'admin_email' ) ); |
| 761 | $from_name = trim( get_bloginfo( 'name' ) ); |
| 762 | } |
| 763 | $from_email = apply_filters( 'wp_mail_from', $from_email ); |
| 764 | $from_name = apply_filters( 'wp_mail_from_name', $from_name ); |
| 765 | |
| 766 | // Headers. |
| 767 | if ( empty( $headers ) ) { |
| 768 | $headers = array(); |
| 769 | $reply = array(); |
| 770 | $bcc = array(); |
| 771 | $cc = array(); |
| 772 | } else { |
| 773 | if ( ! is_array( $headers ) ) { |
| 774 | // Explode the headers out, so this function can take both. |
| 775 | // string headers and an array of headers. |
| 776 | $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
| 777 | } else { |
| 778 | $tempheaders = $headers; |
| 779 | } |
| 780 | $headers = array(); |
| 781 | $reply = array(); |
| 782 | $bcc = array(); |
| 783 | $cc = array(); |
| 784 | // If it's actually got contents. |
| 785 | if ( ! empty( $tempheaders ) ) { |
| 786 | // Iterate through the raw headers. |
| 787 | foreach ( (array) $tempheaders as $header ) { |
| 788 | if ( strpos( $header, ':' ) === false ) { |
| 789 | if ( false !== stripos( $header, 'boundary=' ) ) { |
| 790 | $parts = preg_split( '/boundary=/i', trim( $header ) ); |
| 791 | $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
| 792 | } |
| 793 | continue; |
| 794 | } |
| 795 | // Explode them out. |
| 796 | list($name, $content) = explode( ':', trim( $header ), 2 ); |
| 797 | |
| 798 | // Cleanup crew. |
| 799 | $name = trim( $name ); |
| 800 | $content = trim( $content ); |
| 801 | |
| 802 | switch ( strtolower( $name ) ) { |
| 803 | case 'content-type': |
| 804 | $headers[ trim( $name ) ] = trim( $content ); |
| 805 | break; |
| 806 | case 'x-mailin-tag': |
| 807 | $headers[ trim( $name ) ] = trim( $content ); |
| 808 | break; |
| 809 | case 'from': |
| 810 | if ( strpos( $content, '<' ) !== false ) { |
| 811 | // So... making my life hard again? |
| 812 | $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); |
| 813 | $from_name = str_replace( '"', '', $from_name ); |
| 814 | $from_name = trim( $from_name ); |
| 815 | |
| 816 | $from_email = substr( $content, strpos( $content, '<' ) + 1 ); |
| 817 | $from_email = str_replace( '>', '', $from_email ); |
| 818 | $from_email = trim( $from_email ); |
| 819 | } else { |
| 820 | $from_name = ''; |
| 821 | $from_email = trim( $content ); |
| 822 | } |
| 823 | break; |
| 824 | |
| 825 | case 'bcc': |
| 826 | if ( strpos( $content, '<') !== false ) |
| 827 | { |
| 828 | $bcc_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 829 | $bcc_content = str_replace( '>', '', $bcc_content ); |
| 830 | $bcc[ trim( $bcc_content ) ] = ''; |
| 831 | } else { |
| 832 | $bcc[ trim( $content ) ] = ''; |
| 833 | } |
| 834 | break; |
| 835 | case 'cc': |
| 836 | if ( strpos( $content, '<') !== false ) |
| 837 | { |
| 838 | $cc_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 839 | $cc_content = str_replace( '>', '', $cc_content ); |
| 840 | $cc[ trim( $cc_content ) ] = ''; |
| 841 | } else { |
| 842 | $bcc[ trim( $content ) ] = ''; |
| 843 | } |
| 844 | break; |
| 845 | case 'reply-to': |
| 846 | if ( strpos( $content, '<') !== false ) |
| 847 | { |
| 848 | $reply_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 849 | $reply_content = str_replace( '>', '', $reply_content ); |
| 850 | $reply[] = trim( $reply_content ); |
| 851 | } else { |
| 852 | $reply[] = trim( $content ); |
| 853 | } |
| 854 | break; |
| 855 | default: |
| 856 | break; |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | // Set destination addresses. |
| 863 | if ( ! is_array( $to ) ) { |
| 864 | $to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace. |
| 865 | } |
| 866 | |
| 867 | $processed_to = array(); |
| 868 | foreach ( $to as $email ) { |
| 869 | if ( is_array( $email ) ) { |
| 870 | $processed_to[] = $email; |
| 871 | } else { |
| 872 | $processed_to[ $email ] = ''; |
| 873 | } |
| 874 | } |
| 875 | $to = $processed_to; |
| 876 | |
| 877 | // Attachments. |
| 878 | $attachment_content = array(); |
| 879 | if ( ! empty( $attachments ) ) { |
| 880 | foreach ( $attachments as $attachment ) { |
| 881 | $content = self::getAttachmentStruct( $attachment ); |
| 882 | if ( ! is_wp_error( $content ) ) { |
| 883 | $attachment_content = array_merge( $attachment_content, $content ); |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | // Common transformations for the HTML part. |
| 889 | // If it is text/plain, New line break found. |
| 890 | if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) { |
| 891 | if ( strpos( $message, "\n" ) !== false ) { |
| 892 | if ( is_array( $message ) ) { |
| 893 | foreach ( $message as &$value ) { |
| 894 | $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] ); |
| 895 | $value['content'] = nl2br( $value['content'] ); |
| 896 | } |
| 897 | } else { |
| 898 | $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message ); |
| 899 | $message = nl2br( $message ); |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | // Sending... |
| 904 | $data = array( |
| 905 | 'to' => $to, |
| 906 | 'from' => array( $from_email, $from_name ), |
| 907 | 'cc' => $cc, |
| 908 | 'bcc' => $bcc, |
| 909 | 'replyto' => $reply, |
| 910 | 'subject' => $subject, |
| 911 | 'headers' => $headers, |
| 912 | 'attachment' => $attachment_content, |
| 913 | 'html' => $message, |
| 914 | ); |
| 915 | |
| 916 | try { |
| 917 | $sent = SIB_API_Manager::send_email( $data ); |
| 918 | return $sent; |
| 919 | } catch ( Exception $e ) { |
| 920 | return new WP_Error( $e->getMessage() ); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * @param string $path - attachment file path |
| 926 | * @return array|WP_Error |
| 927 | */ |
| 928 | static function getAttachmentStruct( $path ) { |
| 929 | |
| 930 | $struct = array(); |
| 931 | |
| 932 | try { |
| 933 | |
| 934 | if ( ! @is_file( $path ) ) { |
| 935 | throw new Exception( $path . ' is not a valid file.' ); |
| 936 | } |
| 937 | |
| 938 | $filename = basename( $path ); |
| 939 | |
| 940 | if ( ! function_exists( 'get_magic_quotes' ) ) { |
| 941 | /** |
| 942 | * @return bool |
| 943 | */ |
| 944 | function get_magic_quotes() { |
| 945 | return false; |
| 946 | } |
| 947 | } |
| 948 | if ( ! function_exists( 'set_magic_quotes' ) ) { |
| 949 | /** |
| 950 | * @param $value |
| 951 | * @return bool |
| 952 | */ |
| 953 | function set_magic_quotes( $value ) { |
| 954 | return true; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' ) |
| 959 | && function_exists( 'get_magic_quotes_runtime' ) |
| 960 | && function_exists( 'set_magic_quotes_runtime' ); |
| 961 | |
| 962 | if ( $isMagicQuotesSupported ) { |
| 963 | // Escape linters check. |
| 964 | $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime'; |
| 965 | $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime'; |
| 966 | |
| 967 | // Save magic quotes value. |
| 968 | $magicQuotes = $getMagicQuotesRuntimeFunc(); |
| 969 | $setMagicQuotesRuntimeFunc (0); |
| 970 | } |
| 971 | |
| 972 | $file_buffer = file_get_contents( $path ); |
| 973 | $file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" ); |
| 974 | |
| 975 | if ( $isMagicQuotesSupported ) { |
| 976 | // Restore magic quotes value. |
| 977 | $setMagicQuotesRuntimeFunc($magicQuotes); |
| 978 | } |
| 979 | |
| 980 | $struct[ $filename ] = $file_buffer; |
| 981 | |
| 982 | } catch ( Exception $e ) { |
| 983 | return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() ); |
| 984 | } |
| 985 | |
| 986 | return $struct; |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Create custom page for form preview |
| 991 | * |
| 992 | * @param array $query_vars - query. |
| 993 | * @return array |
| 994 | */ |
| 995 | function sib_query_vars( $query_vars ) { |
| 996 | $query_vars[] = 'sib_form'; |
| 997 | return $query_vars; |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Parse request |
| 1002 | * |
| 1003 | * @param mixed $wp - object. |
| 1004 | */ |
| 1005 | function sib_parse_request( &$wp ) { |
| 1006 | if ( array_key_exists( 'sib_form', $wp->query_vars ) ) { |
| 1007 | include 'inc/sib-form-preview.php'; |
| 1008 | exit(); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Load Text domain. |
| 1014 | */ |
| 1015 | static function LoadTextDomain() { |
| 1016 | // Load lang file. |
| 1017 | $i18n_file_name = 'sib_lang'; |
| 1018 | $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name ); |
| 1019 | // $locale = 'fr_FR'; |
| 1020 | $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo'; |
| 1021 | load_textdomain( 'sib_lang', $filename ); |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Notice the language is difference than site's language |
| 1026 | */ |
| 1027 | static function language_admin_notice() { |
| 1028 | if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) { |
| 1029 | $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 ); |
| 1030 | $lang = self::getLanguageName( $lang_prefix ); |
| 1031 | $class = 'error'; |
| 1032 | $message = sprintf( 'Please note that your SendinBlue account is in %s, but SendinBlue WordPress plugin is only available in English / French for now. Sorry for inconvenience.', $lang ); |
| 1033 | if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) { |
| 1034 | echo ( "<div class=\"$class\" style='margin-left: 2px;margin-bottom: 4px;'> <p>$message<a class='' href='?dismiss_admin_lang_notice=1'> No problem...</a></p></div>" ); |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Notice wp_mail is not possible |
| 1041 | */ |
| 1042 | static function wpMailNotices() { |
| 1043 | if ( self::$wp_mail_conflict ) { |
| 1044 | echo ( '<div class="error"><p>' . __( 'You cannot use SendinBlue SMTP now because wp_mail has been declared by another process or plugin. ', 'sib_lang' ) . '</p></div>' ); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Names of languages. |
| 1050 | * |
| 1051 | * @param string $prefix - language. |
| 1052 | * @return mixed |
| 1053 | */ |
| 1054 | public static function getLanguageName( $prefix = 'en' ) { |
| 1055 | $lang = array(); |
| 1056 | $lang['de'] = 'Deutsch'; |
| 1057 | $lang['en'] = 'English'; |
| 1058 | $lang['zh'] = '中文'; |
| 1059 | $lang['ru'] = 'Русский'; |
| 1060 | $lang['fi'] = 'suomi'; |
| 1061 | $lang['fr'] = 'Français'; |
| 1062 | $lang['nl'] = 'Nederlands'; |
| 1063 | $lang['sv'] = 'Svenska'; |
| 1064 | $lang['it'] = 'Italiano'; |
| 1065 | $lang['ro'] = 'Română'; |
| 1066 | $lang['hu'] = 'Magyar'; |
| 1067 | $lang['ja'] = '日本語'; |
| 1068 | $lang['es'] = 'Español'; |
| 1069 | $lang['vi'] = 'Tiếng Việt'; |
| 1070 | $lang['ar'] = 'العربية'; |
| 1071 | $lang['pt'] = 'Português'; |
| 1072 | $lang['pb'] = 'Português do Brasil'; |
| 1073 | $lang['pl'] = 'Polski'; |
| 1074 | $lang['gl'] = 'galego'; |
| 1075 | $lang['tr'] = 'Turkish'; |
| 1076 | $lang['et'] = 'Eesti'; |
| 1077 | $lang['hr'] = 'Hrvatski'; |
| 1078 | $lang['eu'] = 'Euskera'; |
| 1079 | $lang['el'] = 'Ελληνικά'; |
| 1080 | $lang['ua'] = 'Українська'; |
| 1081 | $lang['ko'] = '한국어'; |
| 1082 | |
| 1083 | return $lang[ $prefix ]; |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * Create language sidebar for wpml plugin. |
| 1088 | */ |
| 1089 | public function sib_create_language_sidebar() { |
| 1090 | $languages = apply_filters( 'wpml_active_languages', array() ); |
| 1091 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 1092 | $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 1093 | $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : ''; |
| 1094 | $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : ''; |
| 1095 | $parent = true; |
| 1096 | if ( '' !== $frmID && '' !== $pID ) { |
| 1097 | $lang = SIB_Forms_Lang::get_lang( $frmID, $pID ); |
| 1098 | $parent = false; |
| 1099 | } else { |
| 1100 | $lang = ICL_LANGUAGE_CODE; |
| 1101 | if ( '' !== $frmID && '' === $pID ) { |
| 1102 | $pID = $frmID; |
| 1103 | |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | if ( 'sib_page_form' === $page && 'edit' === $action ) { |
| 1108 | ?> |
| 1109 | <div class="panel panel-default text-left box-border-box small-content"> |
| 1110 | <div class="panel-heading"><strong><?php esc_attr_e( 'About SendinBlue', 'sib_lang' ); ?></strong></div> |
| 1111 | <div class="panel-body"> |
| 1112 | <p> |
| 1113 | <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'sib_lang' ); ?> </label> |
| 1114 | <select id="sib_form_lang" name="sib_form_lang" data-selected=""> |
| 1115 | <?php |
| 1116 | foreach ( $languages as $language ) { |
| 1117 | $selected = ($language['code'] == $lang) ? 'selected' : ''; |
| 1118 | if ( $language['code'] == $lang && true === $parent ) { |
| 1119 | $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>'; |
| 1120 | } else { |
| 1121 | $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1122 | |
| 1123 | if ( null === $exist ) { |
| 1124 | continue; |
| 1125 | } else { |
| 1126 | $option_text = ( 'selected' === $selected ) ? sprintf( '<option value="" selected>%s</option>', $language['native_name'] ) : sprintf( '<option value="?page=%s&action=%s&pid=%s&lang=%s" %s >%s</option>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $pID ), $language['language_code'], $selected, $language['native_name'] ); |
| 1127 | } |
| 1128 | } |
| 1129 | echo $option_text ; |
| 1130 | } |
| 1131 | ?> |
| 1132 | </select> |
| 1133 | </p> |
| 1134 | <div class="sib_form_translate"> |
| 1135 | <p> |
| 1136 | <label><?php esc_attr_e( 'Translate this form', 'sib_lang' ); ?></label> |
| 1137 | </p> |
| 1138 | <table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;"> |
| 1139 | <tr> |
| 1140 | <?php |
| 1141 | foreach ( $languages as $language ) { |
| 1142 | if ( $language['code'] == $lang ) { |
| 1143 | continue; |
| 1144 | } |
| 1145 | ?> |
| 1146 | <th style="text-align: center;"><img |
| 1147 | src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th> |
| 1148 | <?php |
| 1149 | } |
| 1150 | ?> |
| 1151 | </tr> |
| 1152 | <tr style="background-color: #EFF8FC;"> |
| 1153 | <?php |
| 1154 | foreach ( $languages as $language ) { |
| 1155 | if ( $language['code'] == $lang ) { |
| 1156 | continue; |
| 1157 | } |
| 1158 | if ( '' === $pID ) { |
| 1159 | $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ ); |
| 1160 | $td = '<img src="' . $img_src . '" style="margin:2px;">'; |
| 1161 | } else { |
| 1162 | $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1163 | |
| 1164 | if ( null === $exist ) { |
| 1165 | $img_src = plugins_url( 'img/add_translation.png', __FILE__ ); |
| 1166 | |
| 1167 | $href = sprintf( '<a class="sib-form-redirect" href="?page=%s&action=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', esc_attr( $_REQUEST['page'] ), 'edit', absint( $pID ), $language['language_code'] ); |
| 1168 | $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1169 | } else { |
| 1170 | $img_src = plugins_url( 'img/edit_translation.png', __FILE__ ); |
| 1171 | $href = sprintf( '<a class="sib-form-redirect" href="?page=%s&action=%s&id=%s&pid=%s&lang=%s" style="width: 20px; text-align: center;padding: 2px 1px;">', esc_attr( $_REQUEST['page'] ), 'edit', absint( $exist ), absint( $pID ), $language['language_code'] ); |
| 1172 | $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1173 | } |
| 1174 | } |
| 1175 | ?> |
| 1176 | <td style="text-align: center;"><?php echo $td; ?></td> |
| 1177 | <?php |
| 1178 | } |
| 1179 | ?> |
| 1180 | </tr> |
| 1181 | </table> |
| 1182 | </div> |
| 1183 | <?php if ( isset( $_GET['pid'] ) ) { ?> |
| 1184 | <div class="sib-form-duplicate"> |
| 1185 | <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'sib_lang' ); ?></button> |
| 1186 | <span class="sib-spin"><i |
| 1187 | class="fa fa-circle-o-notch fa-spin fa-lg"></i> </span> |
| 1188 | <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'sib_lang' ); ?>" |
| 1189 | data-container="body" data-toggle="popover" data-placement="left" |
| 1190 | data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'sib_lang' ); ?>" |
| 1191 | data-html="true" class="fa fa-question-circle popover-help-form"></i> |
| 1192 | </div> |
| 1193 | <?php } ?> |
| 1194 | </div> |
| 1195 | </div> |
| 1196 | <?php |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | public function ajax_get_country_prefix() { |
| 1201 | check_ajax_referer( 'sib_front_ajax_nonce', 'security' ); |
| 1202 | $sms_manager = new SIB_SMS_Code(); |
| 1203 | $country_list = $sms_manager->get_sms_code_list(); |
| 1204 | $country_list_html = ''; |
| 1205 | foreach ( $country_list as $item => $value ) { |
| 1206 | $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png'; |
| 1207 | $item_html = '<li class="sib-country-prefix" data-country-code="'.$item.'" data-dial-code="'.$value["code"].'"><div class="sib-flag-box"><div class="sib-flag '.$item.'" style="background-image: url('.$flg_url.')"></div><span>'.$value['name'].'</span><span class="sib-dial-code">+'.$value['code'].'</span></div></li>'; |
| 1208 | $country_list_html .= $item_html; |
| 1209 | } |
| 1210 | wp_send_json($country_list_html); |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | add_action( 'sendinblue_init', 'sendinblue_init' ); |
| 1215 | add_filter( 'widget_text', 'do_shortcode' ); |
| 1216 | |
| 1217 | /** |
| 1218 | * Plugin entry point Process. |
| 1219 | */ |
| 1220 | function sendinblue_init() { |
| 1221 | SIB_Manager::LoadTextDomain(); |
| 1222 | new SIB_Manager(); |
| 1223 | } |
| 1224 | |
| 1225 | do_action( 'sendinblue_init' ); |
| 1226 | } |
| 1227 |