mailin
Last commit date
css
3 years ago
form
4 years ago
img
2 years ago
inc
2 years ago
js
2 years ago
lang
3 years ago
model
3 years ago
page
2 years ago
widget
4 years ago
index.php
11 years ago
readme.txt
2 years ago
screenshot-1.png
2 years ago
screenshot-2.png
2 years ago
screenshot-3.png
2 years ago
screenshot-4.png
2 years ago
screenshot-5.png
2 years ago
sendinblue.php
2 years ago
sendinblue.php
1644 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: Newsletter, SMTP, Email marketing and Subscribe forms by Brevo |
| 4 | * Plugin URI: https://www.brevo.com/?r=wporg |
| 5 | * Description: Manage your contact lists, subscription forms and all email and marketing-related topics from your wp panel, within one single plugin |
| 6 | * Version: 3.1.72 |
| 7 | * Author: Brevo |
| 8 | * Author URI: https://www.brevo.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 | if ( ! class_exists( 'SendinblueApiClient' ) ) { |
| 35 | require_once( 'inc/SendinblueApiClient.php' ); |
| 36 | } |
| 37 | if ( ! class_exists( 'SendinblueAccount' ) ) { |
| 38 | require_once( 'inc/SendinblueAccount.php' ); |
| 39 | } |
| 40 | // For marketing automation. |
| 41 | if ( ! class_exists( 'Sendinblue' ) ) { |
| 42 | require_once( 'inc/sendinblue.php' ); |
| 43 | } |
| 44 | |
| 45 | if ( ! class_exists( 'SIB_Manager' ) ) { |
| 46 | register_deactivation_hook( __FILE__, array( 'SIB_Manager', 'deactivate' ) ); |
| 47 | register_activation_hook( __FILE__, array( 'SIB_Manager', 'install' ) ); |
| 48 | register_uninstall_hook( __FILE__, array( 'SIB_Manager', 'uninstall' ) ); |
| 49 | |
| 50 | require_once( 'page/page-home.php' ); |
| 51 | require_once( 'page/page-form.php' ); |
| 52 | require_once( 'page/page-statistics.php' ); |
| 53 | require_once( 'page/page-scenarios.php' ); |
| 54 | require_once( 'widget/widget_form.php' ); |
| 55 | require_once( 'inc/table-forms.php' ); |
| 56 | require_once( 'inc/sib-api-manager.php' ); |
| 57 | require_once( 'inc/sib-sms-code.php' ); |
| 58 | require_once( 'model/model-forms.php' ); |
| 59 | require_once( 'model/model-users.php' ); |
| 60 | require_once( 'model/model-lang.php' ); |
| 61 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 62 | require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
| 63 | /** |
| 64 | * Class SIB_Manager |
| 65 | */ |
| 66 | class SIB_Manager { |
| 67 | |
| 68 | /** Main setting option name */ |
| 69 | const MAIN_OPTION_NAME = 'sib_main_option'; |
| 70 | |
| 71 | /** Home setting option name */ |
| 72 | const HOME_OPTION_NAME = 'sib_home_option'; |
| 73 | |
| 74 | /** Access token option name */ |
| 75 | const ACCESS_TOKEN_OPTION_NAME = 'sib_token_store'; |
| 76 | |
| 77 | /** Plugin language notice option name */ |
| 78 | const LANGUAGE_OPTION_NAME = 'sib_language_notice_option'; |
| 79 | |
| 80 | /** Form preview option name */ |
| 81 | const PREVIEW_OPTION_NAME = 'sib_preview_form'; |
| 82 | |
| 83 | const API_KEY_V3_OPTION_NAME = 'sib_api_key_v3'; |
| 84 | |
| 85 | const RECAPTCHA_API_TEMPLATE = 'https://www.google.com/recaptcha/api/siteverify?%s'; |
| 86 | |
| 87 | /** Installation id option name */ |
| 88 | const INSTALLATION_ID = 'sib_installation_id'; |
| 89 | |
| 90 | /*Pushowl Url */ |
| 91 | const PUSHOWL_STAGING_URL = "https://cdn-staging.pushowl.com/latest/sdks/service-worker.js"; |
| 92 | const PUSHOWL_PRODUCTION_URL = "https://cdn.pushowl.com/latest/sdks/service-worker.js"; |
| 93 | const URL_CHECK_STAGING = "staging"; |
| 94 | const SERVICE_WORKER_FILE_URL = "/js/service-worker.js"; |
| 95 | |
| 96 | const SIB_ATTRIBUTE = array( |
| 97 | 'input' => array( |
| 98 | 'type' => true, |
| 99 | 'name' => true, |
| 100 | 'value' => true, |
| 101 | 'class' => true, |
| 102 | 'id' => true, |
| 103 | 'size' => true, |
| 104 | 'min' => true, |
| 105 | 'max' => true, |
| 106 | 'pattern' => true, |
| 107 | 'title' => true, |
| 108 | 'placeholder' => true, |
| 109 | 'required' => true, |
| 110 | ), |
| 111 | 'p' => array( |
| 112 | 'align' => true, |
| 113 | 'id' => true, |
| 114 | 'class' => true, |
| 115 | 'dir' => true, |
| 116 | 'lang' => true, |
| 117 | 'style' => true, |
| 118 | 'xml:lang' => true, |
| 119 | ), |
| 120 | 'iframe' => array( |
| 121 | 'name' => true, |
| 122 | 'id' => true, |
| 123 | 'class' => true, |
| 124 | 'src' => true, |
| 125 | 'width' => true, |
| 126 | 'height' => true, |
| 127 | 'style' => true, |
| 128 | 'loading' => true, |
| 129 | 'allow' => true, |
| 130 | 'allowfullscreen' => true, |
| 131 | ), |
| 132 | 'div' => array( |
| 133 | 'id' => true, |
| 134 | 'class' => true, |
| 135 | 'dir' => true, |
| 136 | 'lang' => true, |
| 137 | 'style' => true, |
| 138 | 'xml:lang' => true, |
| 139 | 'data-require' => true, |
| 140 | 'data-sitekey' => true, |
| 141 | ), |
| 142 | 'a' => array( |
| 143 | 'href' => true, |
| 144 | 'id' => true, |
| 145 | 'class' => true, |
| 146 | 'rel' => true, |
| 147 | 'rev' => true, |
| 148 | 'name' => true, |
| 149 | 'target' => true, |
| 150 | ), |
| 151 | 'style' => array(), |
| 152 | 'script' => array( |
| 153 | 'src' => true, |
| 154 | ), |
| 155 | 'link' => array( |
| 156 | 'rel' => true, |
| 157 | 'href' => true, |
| 158 | 'type' => true, |
| 159 | ), |
| 160 | 'select' => array( |
| 161 | 'name' => true, |
| 162 | 'class' => true, |
| 163 | 'id' => true, |
| 164 | 'style' => true, |
| 165 | 'required' => true, |
| 166 | ), |
| 167 | 'option' => array( |
| 168 | 'value' => true, |
| 169 | ), |
| 170 | 'ul' => array( |
| 171 | 'class' => true, |
| 172 | 'style' => true, |
| 173 | ), |
| 174 | 'center' => array(), |
| 175 | 'download' => array( |
| 176 | 'valueless' => 'y', |
| 177 | ) |
| 178 | ); |
| 179 | |
| 180 | /** |
| 181 | * API key |
| 182 | * |
| 183 | * @var $access_key |
| 184 | */ |
| 185 | public static $access_key; |
| 186 | |
| 187 | /** |
| 188 | * Store instance |
| 189 | * |
| 190 | * @var $instance |
| 191 | */ |
| 192 | public static $instance; |
| 193 | |
| 194 | /** |
| 195 | * Plugin directory path value. set in constructor |
| 196 | * |
| 197 | * @var $plugin_dir |
| 198 | */ |
| 199 | public static $plugin_dir; |
| 200 | |
| 201 | /** |
| 202 | * Plugin url. set in constructor |
| 203 | * |
| 204 | * @var $plugin_url |
| 205 | */ |
| 206 | public static $plugin_url; |
| 207 | |
| 208 | /** |
| 209 | * Plugin name. set in constructor |
| 210 | * |
| 211 | * @var $plugin_name |
| 212 | */ |
| 213 | public static $plugin_name; |
| 214 | |
| 215 | /** |
| 216 | * Check if wp_mail is declared |
| 217 | * |
| 218 | * @var $wp_mail_conflict |
| 219 | */ |
| 220 | static $wp_mail_conflict; |
| 221 | |
| 222 | /** |
| 223 | * Class constructor |
| 224 | * Sets plugin url and directory and adds hooks to <i>init</i>. <i>admin_menu</i> |
| 225 | */ |
| 226 | function __construct() { |
| 227 | // get basic info. |
| 228 | self::$plugin_dir = plugin_dir_path( __FILE__ ); |
| 229 | self::$plugin_url = plugins_url( '', __FILE__ ); |
| 230 | self::$plugin_name = plugin_basename( __FILE__ ); |
| 231 | |
| 232 | self::$wp_mail_conflict = false; |
| 233 | |
| 234 | // api key for sendinblue. |
| 235 | $general_settings = get_option( self::MAIN_OPTION_NAME, array() ); |
| 236 | self::$access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : ''; |
| 237 | |
| 238 | self::$instance = $this; |
| 239 | add_action( 'upgrader_process_complete', array( &$this, 'my_upgrade_function' ), 10, 2); |
| 240 | add_action( 'admin_init', array( &$this, 'admin_init' ), 9999 ); |
| 241 | add_action( 'admin_menu', array( &$this, 'admin_menu' ), 9999 ); |
| 242 | |
| 243 | add_action( 'wp_print_scripts', array( &$this, 'frontend_register_scripts' ), 9999 ); |
| 244 | add_action( 'wp_enqueue_scripts', array( &$this, 'wp_head_ac' ), 999 ); |
| 245 | |
| 246 | // create custom url for form preview. |
| 247 | add_filter( 'query_vars', array( &$this, 'sib_query_vars' ) ); |
| 248 | add_action( 'parse_request', array( &$this, 'sib_parse_request' ) ); |
| 249 | |
| 250 | add_action( 'wp_ajax_sib_validate_process', array( 'SIB_Page_Home', 'ajax_validation_process' ) ); |
| 251 | add_action( 'wp_ajax_sib_validate_ma', array( 'SIB_Page_Home', 'ajax_validate_ma' ) ); |
| 252 | add_action( 'wp_ajax_sib_activate_email_change', array( 'SIB_Page_Home', 'ajax_activate_email_change' ) ); |
| 253 | add_action( 'wp_ajax_sib_sender_change', array( 'SIB_Page_Home', 'ajax_sender_change' ) ); |
| 254 | add_action( 'wp_ajax_sib_send_email', array( 'SIB_Page_Home', 'ajax_send_email' ) ); |
| 255 | add_action( 'wp_ajax_sib_remove_cache', array( 'SIB_Page_Home', 'ajax_remove_cache' ) ); |
| 256 | add_action( 'wp_ajax_sib_sync_users', array( 'SIB_Page_Home', 'ajax_sync_users' ) ); |
| 257 | |
| 258 | add_action( 'wp_ajax_sib_change_template', array( 'SIB_Page_Form', 'ajax_change_template' ) ); |
| 259 | add_action( 'wp_ajax_sib_get_lists', array( 'SIB_Page_Form', 'ajax_get_lists' ) ); |
| 260 | add_action( 'wp_ajax_sib_get_templates', array( 'SIB_Page_Form', 'ajax_get_templates' ) ); |
| 261 | add_action( 'wp_ajax_sib_get_attributes', array( 'SIB_Page_Form', 'ajax_get_attributes' ) ); |
| 262 | add_action( 'wp_ajax_sib_update_form_html', array( 'SIB_Page_Form', 'ajax_update_html' ) ); |
| 263 | add_action( 'wp_ajax_sib_copy_origin_form', array( 'SIB_Page_Form', 'ajax_copy_origin_form' ) ); |
| 264 | |
| 265 | add_action( 'wp_ajax_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) ); |
| 266 | add_action( 'wp_ajax_nopriv_sib_get_country_prefix', array( $this, 'ajax_get_country_prefix' ) ); |
| 267 | |
| 268 | add_action( 'init', array( &$this, 'init' ) ); |
| 269 | |
| 270 | add_action( 'wp_login', array( &$this, 'sib_wp_login_identify' ), 10, 2 ); |
| 271 | |
| 272 | // change sib tables name on prior(2.6.9) versions. |
| 273 | SIB_Model_Users::add_prefix(); |
| 274 | SIB_Forms::add_prefix(); |
| 275 | SIB_Forms::modify_datatype(); |
| 276 | |
| 277 | if ( self::is_api_key_set() ) { |
| 278 | add_shortcode( 'sibwp_form', array( &$this, 'sibwp_form_shortcode' ) ); |
| 279 | // register widget. |
| 280 | add_action( 'widgets_init', array( &$this, 'sib_create_widget' ) ); |
| 281 | |
| 282 | // create forms tables and create default form. |
| 283 | SIB_Forms::createTable(); |
| 284 | // create users table. |
| 285 | SIB_Model_Users::createTable(); |
| 286 | // add columns for old versions |
| 287 | SIB_Forms::alterTable(); |
| 288 | SIB_Model_Users::add_user_added_date_column(); |
| 289 | } |
| 290 | |
| 291 | $use_api_version = get_option( 'sib_use_apiv2', '0' ); |
| 292 | if ( '0' === $use_api_version ) { |
| 293 | self::uninstall(); |
| 294 | update_option( 'sib_use_apiv2', '1' ); |
| 295 | } |
| 296 | |
| 297 | // Wpml plugin part. |
| 298 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) : |
| 299 | require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 300 | endif; |
| 301 | 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' ) ) { |
| 302 | SIB_Forms_Lang::createTable(); |
| 303 | add_action( 'sib_language_sidebar', array( $this, 'sib_create_language_sidebar' ) ); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Hook wp_mail to send transactional emails |
| 308 | */ |
| 309 | |
| 310 | // check if wp_mail function is already declared by others. |
| 311 | if ( function_exists( 'wp_mail' ) ) { |
| 312 | self::$wp_mail_conflict = true; |
| 313 | } |
| 314 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() ); |
| 315 | |
| 316 | if( 'yes' === $home_settings['activate_email'] ) |
| 317 | { |
| 318 | if ( false === self::$wp_mail_conflict ) { |
| 319 | /** |
| 320 | * Declare wp_mail function for Sendinblue SMTP module |
| 321 | * |
| 322 | * @param string $to - receiption email. |
| 323 | * @param string $subject - subject of email. |
| 324 | * @param string $message - message content. |
| 325 | * @param string $headers - header of email. |
| 326 | * @param array $attachments - attachments. |
| 327 | * @return bool |
| 328 | */ |
| 329 | function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 330 | $message = str_replace( 'NF_SIB', '', $message ); |
| 331 | $message = str_replace( 'WC_SIB', '', $message ); |
| 332 | try { |
| 333 | $sent = SIB_Manager::sib_email( $to, $subject, $message, $headers, $attachments ); |
| 334 | if ( is_wp_error( $sent ) || ! isset( $sent['code'] ) || 'success' !== $sent['code'] ) { |
| 335 | try{ |
| 336 | return true; |
| 337 | }catch( Exception $e ){ |
| 338 | return false; |
| 339 | } |
| 340 | } |
| 341 | return true; |
| 342 | } catch ( Exception $e ) { |
| 343 | return false; |
| 344 | } |
| 345 | } |
| 346 | } else { |
| 347 | add_action( 'admin_notices', array( &$this, 'wpMailNotices' ) ); |
| 348 | return; |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Add identify tag for login users |
| 355 | * |
| 356 | * @param string $user_login - user login name. |
| 357 | * @param array $user - user. |
| 358 | */ |
| 359 | function sib_wp_login_identify( $user_login, $user ) { |
| 360 | |
| 361 | $userEmail = $user->user_email; |
| 362 | $data = array( |
| 363 | 'email_id' => $userEmail, |
| 364 | 'name' => $user_login, |
| 365 | ); |
| 366 | SIB_API_Manager::identify_user( $data ); |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Initialize method. called on <i>init</i> action |
| 371 | */ |
| 372 | function init() { |
| 373 | // Sign up process. |
| 374 | if ( isset( $_POST['sib_form_action'] ) && ( 'subscribe_form_submit' == sanitize_text_field($_POST['sib_form_action']) ) ) { |
| 375 | $this->signup_process(); |
| 376 | } |
| 377 | // Subscribe. |
| 378 | if ( isset( $_GET['sib_action'] ) && ( 'subscribe' == sanitize_text_field($_GET['sib_action']) ) ) { |
| 379 | $code = isset( $_GET['code'] ) ? sanitize_text_field( $_GET['code'] ) : ''; |
| 380 | $contact_info = SIB_Model_Users::get_data_by_code( $code ); |
| 381 | $user_added_date = $contact_info['user_added_date']; |
| 382 | $current_date = gmdate( 'Y-m-d H:i:s' ); |
| 383 | $date_diff = strtotime( $current_date ) - strtotime( $user_added_date ); |
| 384 | if ( $date_diff > 5 ) { |
| 385 | SIB_API_Manager::subscribe( $contact_info ); |
| 386 | } else { |
| 387 | $type = 'Bot Event'; |
| 388 | SIB_API_Manager::template_subscribe( $type ); |
| 389 | } |
| 390 | exit; |
| 391 | } |
| 392 | // Dismiss language notice. |
| 393 | if ( isset( $_GET['dismiss_admin_lang_notice'] ) && '1' == sanitize_text_field($_GET['dismiss_admin_lang_notice']) ) { |
| 394 | update_option( SIB_Manager::LANGUAGE_OPTION_NAME, true ); |
| 395 | wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 396 | exit(); |
| 397 | } |
| 398 | |
| 399 | add_action( 'wp_head', array( &$this, 'install_ma_script' ) ); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Hook admin_init |
| 404 | */ |
| 405 | function admin_init() { |
| 406 | add_action( 'admin_action_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) ); |
| 407 | add_action( 'admin_action_nopriv_sib_setting_subscription', array( 'SIB_Page_Form', 'save_setting_subscription' ) ); |
| 408 | SIB_Manager::LoadTextDomain(); |
| 409 | $this->register_scripts(); |
| 410 | $this->register_styles(); |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Hook admin_menu |
| 415 | */ |
| 416 | function admin_menu() { |
| 417 | SIB_Manager::LoadTextDomain(); |
| 418 | new SIB_Page_Home(); |
| 419 | new SIB_Page_Form(); |
| 420 | new SIB_Page_Statistics(); |
| 421 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME ); |
| 422 | if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) { |
| 423 | new SIB_Page_Scenarios(); |
| 424 | } |
| 425 | |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Register script for admin page |
| 430 | */ |
| 431 | function register_scripts() { |
| 432 | wp_register_script( 'sib-bootstrap-js', self::$plugin_url . '/js/bootstrap/js/bootstrap.bundle.min.js', array( 'jquery' ), false ); |
| 433 | wp_register_script( 'sib-admin-js', self::$plugin_url . '/js/admin.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/admin.js' ) ); |
| 434 | wp_register_script( 'sib-chosen-js', self::$plugin_url . '/js/chosen.jquery.min.js', array( 'jquery' ), false ); |
| 435 | wp_enqueue_script('jquery-ui-datepicker'); |
| 436 | wp_enqueue_script('jquery-ui-spinner'); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Register stylesheet for admin page |
| 441 | */ |
| 442 | function register_styles() { |
| 443 | wp_register_style( 'sib-bootstrap-css', self::$plugin_url . '/js/bootstrap/css/bootstrap.css', array(), false, 'all' ); |
| 444 | wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), false, 'all' ); |
| 445 | wp_register_style( 'sib-chosen-css', self::$plugin_url . '/css/chosen.min.css' ); |
| 446 | wp_register_style( 'sib-admin-css', self::$plugin_url . '/css/admin.css', array(), filemtime( self::$plugin_dir . '/css/admin.css' ), 'all' ); |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Registers scripts for frontend |
| 451 | */ |
| 452 | function frontend_register_scripts() { |
| 453 | |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Enqueue script on front page |
| 458 | */ |
| 459 | function wp_head_ac() { |
| 460 | wp_enqueue_script( 'sib-front-js', self::$plugin_url . '/js/mailin-front.js', array( 'jquery' ), filemtime( self::$plugin_dir . '/js/mailin-front.js' ), false ); |
| 461 | wp_enqueue_style( 'sib-front-css', self::$plugin_url.'/css/mailin-front.css', array(), array(), 'all'); |
| 462 | wp_localize_script( |
| 463 | 'sib-front-js', 'sibErrMsg', array( |
| 464 | 'invalidMail' => __( 'Please fill out valid email address', 'mailin' ), |
| 465 | 'requiredField' => __( 'Please fill out required fields', 'mailin' ), |
| 466 | 'invalidDateFormat' => __( 'Please fill out valid date format', 'mailin' ), |
| 467 | 'invalidSMSFormat' => __( 'Please fill out valid phone number', 'mailin' ), |
| 468 | ) |
| 469 | ); |
| 470 | wp_localize_script( |
| 471 | 'sib-front-js', 'ajax_sib_front_object', |
| 472 | array( |
| 473 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 474 | 'ajax_nonce' => wp_create_nonce( 'sib_front_ajax_nonce' ), |
| 475 | 'flag_url' => plugins_url('img/flags/', __FILE__ ), |
| 476 | ) |
| 477 | ); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Install method is called once install this plugin. |
| 482 | * create tables, default option ... |
| 483 | */ |
| 484 | static function install() { |
| 485 | $general_settings = get_option( self::MAIN_OPTION_NAME, array() ); |
| 486 | $access_key = isset( $general_settings['access_key'] ) ? $general_settings['access_key'] : ''; |
| 487 | if ( '' === $access_key ) { |
| 488 | // Default option when activate. |
| 489 | $home_settings = array( |
| 490 | 'activate_email' => 'no', |
| 491 | 'activate_ma' => 'no', |
| 492 | ); |
| 493 | update_option( self::HOME_OPTION_NAME, $home_settings ); |
| 494 | } |
| 495 | |
| 496 | self::activate_brevo_connection(); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Uninstall method is called once uninstall this plugin |
| 501 | * delete tables, options that used in plugin |
| 502 | */ |
| 503 | static function uninstall() { |
| 504 | $setting = array(); |
| 505 | update_option( SIB_Manager::MAIN_OPTION_NAME, $setting ); |
| 506 | |
| 507 | $home_settings = array( |
| 508 | 'activate_email' => 'no', |
| 509 | 'activate_ma' => 'no', |
| 510 | ); |
| 511 | update_option( SIB_Manager::HOME_OPTION_NAME, $home_settings ); |
| 512 | |
| 513 | // Delete access_token. |
| 514 | $token_settings = array(); |
| 515 | update_option( SIB_Manager::ACCESS_TOKEN_OPTION_NAME, $token_settings ); |
| 516 | |
| 517 | //Deactivate the connection on Brevo |
| 518 | self::deactivate_brevo_connection(); |
| 519 | |
| 520 | //Then delete the api key in our plugin |
| 521 | delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME); |
| 522 | // Empty tables. |
| 523 | SIB_Model_Users::removeTable(); |
| 524 | SIB_Forms::removeTable(); |
| 525 | SIB_Forms_Lang::removeTable(); |
| 526 | |
| 527 | // Remove all transient. |
| 528 | SIB_API_Manager::remove_transients(); |
| 529 | } |
| 530 | |
| 531 | static function deactivate_brevo_connection() |
| 532 | { |
| 533 | $installationId = get_option( SIB_Manager::INSTALLATION_ID ); |
| 534 | if(!empty($installationId)) |
| 535 | { |
| 536 | $apiClient = new SendinblueApiClient(); |
| 537 | $params["active"] = false; |
| 538 | $params["deactivated_at"] = gmdate("Y-m-d\TH:i:s\Z"); |
| 539 | $apiClient->updateInstallationInfo($installationId, $params); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static function activate_brevo_connection() |
| 544 | { |
| 545 | $installationId = get_option( SIB_Manager::INSTALLATION_ID ); |
| 546 | if(!empty($installationId)) |
| 547 | { |
| 548 | $apiClient = new SendinblueApiClient(); |
| 549 | $params["active"] = true; |
| 550 | $params["activated_at"] = gmdate("Y-m-d\TH:i:s\Z"); |
| 551 | $apiClient->updateInstallationInfo($installationId, $params); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Deactivate method is called once deactivate this plugin |
| 557 | */ |
| 558 | static function deactivate() { |
| 559 | update_option( SIB_Manager::LANGUAGE_OPTION_NAME, false ); |
| 560 | // Remove service worker file. |
| 561 | self::uninstall_service_worker_script(); |
| 562 | // Remove sync users option. |
| 563 | delete_option( 'sib_sync_users' ); |
| 564 | // Remove all transient. |
| 565 | SIB_API_Manager::remove_transients(); |
| 566 | |
| 567 | //Also deactivate the connection on Brevo |
| 568 | self::deactivate_brevo_connection(); |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Check if plugin is logged in. |
| 573 | * |
| 574 | * @param bool $redirect |
| 575 | * @return bool |
| 576 | */ |
| 577 | static function is_done_validation($redirect = true) { |
| 578 | if (self::is_api_key_set()) { |
| 579 | $apiClient = new SendinblueApiClient(); |
| 580 | $apiClient->getAccount(); |
| 581 | if ( SendinblueApiClient::RESPONSE_CODE_OK === $apiClient->getLastResponseCode() ) { |
| 582 | //This is only for those users who have an active connection but no installation id could be |
| 583 | //saved on their shop |
| 584 | $installationId = get_option( SIB_Manager::INSTALLATION_ID ); |
| 585 | if(empty($installationId)) |
| 586 | { |
| 587 | self::fetch_and_save_installation_id(); |
| 588 | } |
| 589 | return true; |
| 590 | } elseif (SendinblueApiClient::RESPONSE_CODE_UNAUTHORIZED === $apiClient->getLastResponseCode()) { |
| 591 | delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if ($redirect) { |
| 596 | self::redirect_to_sib_plugin_homepage(); |
| 597 | } |
| 598 | |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | static function redirect_to_sib_plugin_homepage() { |
| 603 | wp_safe_redirect(add_query_arg('page', SIB_Page_Home::PAGE_ID, admin_url('admin.php'))); |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * @return bool |
| 608 | */ |
| 609 | static function is_api_key_set() { |
| 610 | $api_key = get_option(SIB_Manager::API_KEY_V3_OPTION_NAME); |
| 611 | return !empty($api_key); |
| 612 | } |
| 613 | |
| 614 | static function fetch_and_save_installation_id() |
| 615 | { |
| 616 | $apiClient = new SendinblueApiClient(); |
| 617 | |
| 618 | $params["partnerName"] = "WORDPRESS"; |
| 619 | $params["plugin_version"] = SendinblueApiClient::PLUGIN_VERSION; |
| 620 | $params["shop_url"] = get_home_url(); |
| 621 | $params["active"] = true; |
| 622 | $response = $apiClient->createInstallationInfo($params); |
| 623 | if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_CREATED ) |
| 624 | { |
| 625 | if(!empty($response["id"])) |
| 626 | { |
| 627 | update_option(SIB_Manager::INSTALLATION_ID, $response["id"]); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Install service-worker script in plugin for push notifications |
| 634 | * @return void |
| 635 | */ |
| 636 | static function install_service_worker_script($service_worker) |
| 637 | { |
| 638 | try { |
| 639 | $site_url = get_site_url(); |
| 640 | $service_worker_file = str_contains($site_url, self::URL_CHECK_STAGING) |
| 641 | ? self::PUSHOWL_STAGING_URL |
| 642 | : self::PUSHOWL_PRODUCTION_URL; |
| 643 | $js_content = "importScripts('" . $service_worker_file . "');"; |
| 644 | $service_worker_script = fopen($service_worker, "wb"); |
| 645 | fwrite($service_worker_script, $js_content); |
| 646 | fclose($service_worker_script); |
| 647 | } catch (\Throwable $th) { |
| 648 | update_option('sib_service_worker_install_exception', $th->getMessage()); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Uninstall service-worker script from plugin |
| 654 | * @return void |
| 655 | */ |
| 656 | static function uninstall_service_worker_script() |
| 657 | { |
| 658 | try { |
| 659 | $service_worker_file = __DIR__ . self::SERVICE_WORKER_FILE_URL; |
| 660 | if (file_exists($service_worker_file)) { |
| 661 | wp_delete_file($service_worker_file); |
| 662 | } |
| 663 | update_option('sib_service_worker_install_exception', ''); |
| 664 | } catch (\Throwable $th) { |
| 665 | update_option('sib_service_worker_uninstall_exception', $th->getMessage()); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Install marketing automation script in header |
| 671 | */ |
| 672 | function install_ma_script() { |
| 673 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME, array() ); |
| 674 | if ( isset( $home_settings['activate_ma'] ) && 'yes' == $home_settings['activate_ma'] ) { |
| 675 | $general_settings = get_option( SIB_Manager::MAIN_OPTION_NAME, array() ); |
| 676 | $service_worker = __DIR__ . self::SERVICE_WORKER_FILE_URL; |
| 677 | if ( ! file_exists($service_worker)) { |
| 678 | self::install_service_worker_script($service_worker); |
| 679 | } |
| 680 | $ma_email = ''; |
| 681 | $current_user = wp_get_current_user(); |
| 682 | if ( $current_user instanceof WP_User ) { |
| 683 | $ma_email = $current_user->user_email; |
| 684 | } |
| 685 | $ma_key = sanitize_text_field($general_settings['ma_key']); |
| 686 | $output = '<script type="text/javascript"> |
| 687 | (function() { |
| 688 | window.sib ={equeue:[],client_key:"'. $ma_key .'"};/* OPTIONAL: email for identify request*/ |
| 689 | window.sib.email_id = "'. sanitize_email($ma_email) .'"; |
| 690 | 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?plugin=wordpress&key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();})(); |
| 691 | </script>'; |
| 692 | echo html_entity_decode($output); |
| 693 | } else { |
| 694 | self::uninstall_service_worker_script(); |
| 695 | } |
| 696 | |
| 697 | } |
| 698 | |
| 699 | /** |
| 700 | * Register widget |
| 701 | */ |
| 702 | function sib_create_widget() { |
| 703 | register_widget( 'SIB_Widget_Subscribe' ); |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Display form on front page |
| 708 | * |
| 709 | * @param string $frmID - form ID. |
| 710 | * @param string $lang - form language. |
| 711 | */ |
| 712 | function generate_form_box( $frmID = '-1', $lang = '' ) { |
| 713 | if ( 'oldForm' == $frmID ) { |
| 714 | $frmID = get_option( 'sib_old_form_id' ); |
| 715 | } elseif ( '' != $lang ) { |
| 716 | $trans_id = SIB_Forms_Lang::get_form_ID( $frmID, $lang ); |
| 717 | if ( null != $trans_id ) { |
| 718 | $frmID = $trans_id; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | $formData = SIB_Forms::getForm( $frmID ); |
| 723 | |
| 724 | if ( empty( $formData ) ) { |
| 725 | return; |
| 726 | } |
| 727 | // Add Google recaptcha |
| 728 | if( '0' != $formData['gCaptcha'] ) { |
| 729 | if( '1' == $formData['gCaptcha'] ) { // For old forms. |
| 730 | $formData['html'] = preg_replace( '/([\s\S]*?)<div class="g-recaptcha"[\s\S]*?data-size="invisible"><\/div>/', '$1', $formData['html'] ); |
| 731 | } |
| 732 | if ( '3' == $formData['gCaptcha'] ) // The case of using google recaptcha. |
| 733 | { |
| 734 | ?> |
| 735 | <script type="text/javascript"> |
| 736 | var onloadSibCallback = function () { |
| 737 | jQuery('.g-recaptcha').each(function (index, el) { |
| 738 | grecaptcha.render(el, { |
| 739 | 'sitekey': jQuery(el).attr('data-sitekey') |
| 740 | }); |
| 741 | }); |
| 742 | }; |
| 743 | </script> |
| 744 | <?php |
| 745 | } else { // The case of using google invisible recaptcha. |
| 746 | $formData['html'] = str_contains( $formData['html'], 'sib-default-btn' ) ? str_replace( |
| 747 | 'type="submit"', |
| 748 | 'type="submit" id="invisible"', |
| 749 | $formData['html'] |
| 750 | ) : $formData['html']; |
| 751 | ?> |
| 752 | <script type="text/javascript"> |
| 753 | var gCaptchaSibWidget; |
| 754 | var onloadSibCallbackInvisible = function () { |
| 755 | |
| 756 | var element = document.getElementsByClassName('sib-default-btn'); |
| 757 | var countInvisible = 0; |
| 758 | var indexArray = []; |
| 759 | jQuery('.sib-default-btn').each(function (index, el) { |
| 760 | if ((jQuery(el).attr('id') == "invisible")) { |
| 761 | indexArray[countInvisible] = index; |
| 762 | countInvisible++ |
| 763 | } |
| 764 | }); |
| 765 | |
| 766 | jQuery('.invi-recaptcha').each(function (index, el) { |
| 767 | grecaptcha.render(element[indexArray[index]], { |
| 768 | 'sitekey': jQuery(el).attr('data-sitekey'), |
| 769 | 'callback': sibVerifyCallback, |
| 770 | }); |
| 771 | }); |
| 772 | }; |
| 773 | </script> |
| 774 | <?php |
| 775 | } |
| 776 | ?> |
| 777 | <script src="https://www.google.com/recaptcha/api.js?onload=<?php |
| 778 | echo esc_attr( |
| 779 | $formData['gCaptcha'] == '2' ? 'onloadSibCallbackInvisible' : 'onloadSibCallback' |
| 780 | ) ?>&render=explicit" async defer></script> |
| 781 | <?php |
| 782 | } |
| 783 | |
| 784 | ?> |
| 785 | <form id="sib_signup_form_<?php echo esc_attr( $frmID ); ?>" method="post" class="sib_signup_form"> |
| 786 | <div class="sib_loader" style="display:none;"><img |
| 787 | src="<?php echo esc_url( includes_url() ); ?>images/spinner.gif" alt="loader"></div> |
| 788 | <input type="hidden" name="sib_form_action" value="subscribe_form_submit"> |
| 789 | <input type="hidden" name="sib_form_id" value="<?php echo esc_attr( $frmID ); ?>"> |
| 790 | <input type="hidden" name="sib_form_alert_notice" value="<?php echo esc_attr($formData['requiredMsg']); ?>"> |
| 791 | <input type="hidden" name="sib_form_invalid_email_notice" value="<?php echo esc_attr($formData['invalidMsg']); ?>"> |
| 792 | <input type="hidden" name="sib_security" value="<?php echo esc_attr( wp_create_nonce( 'sib_front_ajax_nonce' ) ); ?>"> |
| 793 | <div class="sib_signup_box_inside_<?php echo esc_attr( $frmID ); ?>"> |
| 794 | <div style="/*display:none*/" class="sib_msg_disp"> |
| 795 | </div> |
| 796 | <?php |
| 797 | if (($formData['gCaptcha'] == '2') && false === strpos( |
| 798 | $formData['html'], |
| 799 | 'id="sib_captcha_invisible"' |
| 800 | )) { ?> |
| 801 | <div id="sib_captcha_invisible" class="invi-recaptcha" data-sitekey="<?php |
| 802 | echo esc_attr($formData['gCaptcha_site']); ?>"></div> |
| 803 | <?php |
| 804 | } ?> |
| 805 | <?php |
| 806 | // phpcs:ignore |
| 807 | |
| 808 | if (false === strpos($formData['html'], 'class="g-recaptcha"')) { |
| 809 | $formData['html'] = str_replace( |
| 810 | 'id="sib_captcha"', |
| 811 | 'id="sib_captcha" class="g-recaptcha" data-sitekey="' . $formData['gCaptcha_site'] . '"', |
| 812 | $formData['html'] |
| 813 | ); |
| 814 | } |
| 815 | |
| 816 | echo wp_kses($formData['html'], SIB_Manager::wordpress_allowed_attributes()); |
| 817 | ?> |
| 818 | </div> |
| 819 | </form> |
| 820 | <style> |
| 821 | <?php |
| 822 | |
| 823 | if ( ! $formData['dependTheme'] ) { |
| 824 | // Custom css. |
| 825 | $formData['css'] = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, $formData['css'] ); |
| 826 | echo esc_html($formData['css']); |
| 827 | } |
| 828 | $msgCss = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, SIB_Forms::getDefaultMessageCss() ); |
| 829 | echo esc_html($msgCss); |
| 830 | ?> |
| 831 | </style> |
| 832 | <?php |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * Shortcode for sign up form |
| 837 | * |
| 838 | * @param array $atts - shortcode parameter. |
| 839 | * @return string |
| 840 | */ |
| 841 | function sibwp_form_shortcode( $atts ) { |
| 842 | $pull_atts = shortcode_atts( |
| 843 | array( |
| 844 | 'id' => 'oldForm', // We will return 'oldForm' for shortcode of old form. |
| 845 | ), $atts |
| 846 | ); |
| 847 | $frmID = $pull_atts['id']; |
| 848 | $lang = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : ''; |
| 849 | |
| 850 | ob_start(); |
| 851 | $this->generate_form_box( $frmID, $lang ); |
| 852 | |
| 853 | $output_string = ob_get_contents(); |
| 854 | ob_end_clean(); |
| 855 | return $output_string; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Sign up process |
| 860 | */ |
| 861 | function signup_process() { |
| 862 | //Handling of backslash added by WP because magic quotes are enabled by default |
| 863 | array_walk_recursive( $_POST, function(&$value) { |
| 864 | $value = stripslashes($value); |
| 865 | }); |
| 866 | |
| 867 | if ( empty( $_POST['sib_security'] ) ) { |
| 868 | wp_send_json( |
| 869 | array( |
| 870 | 'status' => 'sib_security', |
| 871 | 'msg' => 'Token not found.', |
| 872 | ) |
| 873 | ); |
| 874 | } |
| 875 | $formID = isset( $_POST['sib_form_id'] ) ? sanitize_text_field( $_POST['sib_form_id'] ) : 1; |
| 876 | if ( 'oldForm' == $formID ) { |
| 877 | $formID = get_option( 'sib_old_form_id' ); |
| 878 | } |
| 879 | $formData = SIB_Forms::getForm( $formID ); |
| 880 | |
| 881 | if (!SIB_Manager::is_done_validation(false) || 0 == count($formData)) { |
| 882 | wp_send_json( |
| 883 | array( |
| 884 | 'status' => 'failure', |
| 885 | 'msg' => array("errorMsg" => "Something wrong occurred"), |
| 886 | ) |
| 887 | ); |
| 888 | } |
| 889 | |
| 890 | if ( '0' != $formData['gCaptcha'] ) { |
| 891 | if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) { |
| 892 | wp_send_json( |
| 893 | array( |
| 894 | 'status' => 'gcaptchaEmpty', |
| 895 | 'msg' => 'Please click on the reCAPTCHA box.', |
| 896 | ) |
| 897 | ); |
| 898 | } |
| 899 | $secret = $formData['gCaptcha_secret']; |
| 900 | |
| 901 | $data = array( |
| 902 | 'secret' => $secret, |
| 903 | 'response' => sanitize_text_field( $_POST['g-recaptcha-response'] ), |
| 904 | ); |
| 905 | |
| 906 | $args = [ |
| 907 | 'method' => 'POST', |
| 908 | ]; |
| 909 | |
| 910 | try { |
| 911 | $data = wp_remote_retrieve_body(wp_remote_request(sprintf(self::RECAPTCHA_API_TEMPLATE, http_build_query($data)), $args)); |
| 912 | $responseData = json_decode($data); |
| 913 | if ( ! $responseData->success ) { |
| 914 | wp_send_json( |
| 915 | array( |
| 916 | 'status' => 'gcaptchaFail', |
| 917 | 'msg' => 'Robot verification failed, please try again.', |
| 918 | ) |
| 919 | ); |
| 920 | } |
| 921 | } catch (Exception $exception) { |
| 922 | wp_send_json( |
| 923 | array( |
| 924 | 'status' => 'gcaptchaFail', |
| 925 | 'msg' => $exception->getMessage(), |
| 926 | ) |
| 927 | ); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | $listID = $formData['listID']; |
| 932 | if (empty($listID)) { |
| 933 | $listID = array(); |
| 934 | } |
| 935 | $interestingLists = isset( $_POST['interestingLists']) ? array_map( 'sanitize_text_field', $_POST['interestingLists'] ) : array(); |
| 936 | $expectedLists = isset( $_POST['listIDs'] ) ? array_map( 'sanitize_text_field', $_POST['listIDs'] ) : array(); |
| 937 | if ( empty($interestingLists) ) |
| 938 | { |
| 939 | $unlinkedLists = []; |
| 940 | } |
| 941 | else{ |
| 942 | $unwantedLists = array_diff( $interestingLists, $expectedLists ); |
| 943 | $unlinkedLists = array_diff( $unwantedLists, $listID); |
| 944 | $listID = array_unique(array_merge( $listID, $expectedLists )); |
| 945 | } |
| 946 | |
| 947 | $email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : ''; |
| 948 | if ( ! is_email( $email ) ) { |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | $isDoubleOptin = $formData['isDopt']; |
| 953 | $isOptin = $formData['isOpt']; |
| 954 | $redirectUrlInEmail = $formData['redirectInEmail']; |
| 955 | $redirectUrlInForm = $formData['redirectInForm']; |
| 956 | |
| 957 | $info = array(); |
| 958 | $attributes = explode( ',', $formData['attributes'] ); // String to array. |
| 959 | if ( isset( $attributes ) && is_array( $attributes ) ) { |
| 960 | foreach ( $_POST as $postAttribute => $postAttributeValue ) { |
| 961 | $correspondingSibAttribute = $this->getCorrespondingSibAttribute($postAttribute, $attributes); |
| 962 | if (!empty($correspondingSibAttribute)) { |
| 963 | $info[ $correspondingSibAttribute ] = sanitize_text_field( $postAttributeValue ); |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | $templateID = $formData['templateID']; |
| 968 | |
| 969 | if ( $isDoubleOptin ) { |
| 970 | /* |
| 971 | * Double optin process |
| 972 | * 1. add record to db |
| 973 | * 2. send confirmation email with activate code |
| 974 | */ |
| 975 | $result = "success"; |
| 976 | // Send a double optin confirm email. |
| 977 | if ( 'success' == $result ) { |
| 978 | // Add a recode with activate code in db. |
| 979 | $activateCode = $this->create_activate_code( $email, $info, $formID, $listID, $redirectUrlInEmail, $unlinkedLists ); |
| 980 | SIB_API_Manager::send_comfirm_email( $email, 'double-optin', $templateID, $info, $activateCode ); |
| 981 | } |
| 982 | } elseif ( $isOptin ) { |
| 983 | $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'confirm', $unlinkedLists ); |
| 984 | if ( 'success' == $result ) { |
| 985 | // Send a confirm email. |
| 986 | SIB_API_Manager::send_comfirm_email( $email, 'confirm', $templateID, $info ); |
| 987 | } |
| 988 | } else { |
| 989 | $result = SIB_API_Manager::create_subscriber( $email, $listID, $info, 'simple', $unlinkedLists ); |
| 990 | } |
| 991 | $msg = array( |
| 992 | 'successMsg' => $formData['successMsg'], |
| 993 | 'errorMsg' => $formData['errorMsg'], |
| 994 | 'existMsg' => $formData['existMsg'], |
| 995 | 'invalidMsg' => $formData['invalidMsg'], |
| 996 | ); |
| 997 | |
| 998 | wp_send_json( |
| 999 | array( |
| 1000 | 'status' => $result, |
| 1001 | 'msg' => $msg, |
| 1002 | 'redirect' => $redirectUrlInForm, |
| 1003 | ) |
| 1004 | ); |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * Create activate code for Double optin |
| 1009 | * |
| 1010 | * @param string $email - user email. |
| 1011 | * @param array $info - info. |
| 1012 | * @param string $formID - form ID. |
| 1013 | * @param array $listIDs - lists. |
| 1014 | * @param string $redirectUrl - redirect url. |
| 1015 | * @return string - activate code. |
| 1016 | */ |
| 1017 | function create_activate_code( $email, $info, $formID, $listIDs, $redirectUrl, $unlinkedLists = null ) { |
| 1018 | $data = SIB_Model_Users::get_data_by_email( $email, $formID ); |
| 1019 | $date = gmdate( 'Y-m-d H:i:s' ); |
| 1020 | if ( $unlinkedLists != null ) |
| 1021 | { |
| 1022 | $info['unlinkedLists'] = $unlinkedLists; |
| 1023 | } |
| 1024 | if ( false == $data ) { |
| 1025 | $uniqid = uniqid(); |
| 1026 | $data = array( |
| 1027 | 'email' => $email, |
| 1028 | 'code' => $uniqid, |
| 1029 | 'info' => maybe_serialize( $info ), |
| 1030 | 'frmid' => $formID, |
| 1031 | 'listIDs' => maybe_serialize( $listIDs ), |
| 1032 | 'redirectUrl' => $redirectUrl, |
| 1033 | 'user_added_date' => $date, |
| 1034 | ); |
| 1035 | SIB_Model_Users::add_record( $data ); |
| 1036 | } else { |
| 1037 | $update_data = array( |
| 1038 | 'id' => $data['id'], |
| 1039 | 'email' => $email, |
| 1040 | 'info' => maybe_serialize( $info ), |
| 1041 | ); |
| 1042 | SIB_Model_Users::update_element( $update_data ); |
| 1043 | $uniqid = $data['code']; |
| 1044 | } |
| 1045 | return $uniqid; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * Use Sendinblue SMTP to send all emails |
| 1050 | * |
| 1051 | * @param string $to - reception email. |
| 1052 | * @param string $subject - subject of email. |
| 1053 | * @param string $message - message of email. |
| 1054 | * @param string $headers - header of email. |
| 1055 | * @param array $attachments - attachments. |
| 1056 | */ |
| 1057 | static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 1058 | $result = require self::$plugin_dir . '/inc/function.wp_mail.php'; |
| 1059 | return $result; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * To send the transactional email via Sendinblue |
| 1064 | * hook wp_mail |
| 1065 | * |
| 1066 | * @param string $to - reception email. |
| 1067 | * @param string $subject - subject of email. |
| 1068 | * @param string $message - message of email. |
| 1069 | * @param string $headers - header of email. |
| 1070 | * @param array $attachments - attachments |
| 1071 | * @param array $tags - tag. |
| 1072 | * @param string $from_name - sender name. |
| 1073 | * @param string $from_email - sender email. |
| 1074 | * @return mixed|WP_Error |
| 1075 | */ |
| 1076 | static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) { |
| 1077 | $data = []; |
| 1078 | // Compact the input, apply the filters, and extract them back out. |
| 1079 | extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); |
| 1080 | |
| 1081 | if ( !empty( $attachments ) && ! is_array( $attachments ) ) { |
| 1082 | $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
| 1083 | } |
| 1084 | |
| 1085 | // From email and name. |
| 1086 | $home_settings = get_option( SIB_Manager::HOME_OPTION_NAME ); |
| 1087 | if ( isset( $home_settings['sender'] ) ) { |
| 1088 | $from_name = $home_settings['from_name']; |
| 1089 | $from_email = $home_settings['from_email']; |
| 1090 | } else { |
| 1091 | $from_email = trim( get_bloginfo( 'admin_email' ) ); |
| 1092 | $from_name = trim( get_bloginfo( 'name' ) ); |
| 1093 | } |
| 1094 | |
| 1095 | //Set additional address fields as empty |
| 1096 | $bcc = array(); |
| 1097 | $cc = array(); |
| 1098 | $reply_to = array(); |
| 1099 | if ( ! is_array( $to ) ) { |
| 1100 | $to = explode( ',', $to ); |
| 1101 | } |
| 1102 | |
| 1103 | $from_email = apply_filters( 'wp_mail_from', $from_email ); |
| 1104 | $from_name = apply_filters( 'wp_mail_from_name', $from_name ); |
| 1105 | |
| 1106 | if ( !empty( $headers ) ) { |
| 1107 | if( is_array( $headers ) ){ |
| 1108 | foreach ($headers as $key => $val) { |
| 1109 | if( stripos($val, "Content-Type: text/html") !== false ) { |
| 1110 | unset( $headers[$key] ); |
| 1111 | } |
| 1112 | } |
| 1113 | $headers = array_values( $headers ); |
| 1114 | if( count( $headers ) == 1 && $headers[0] == '' ) { |
| 1115 | unset( $headers[0] ); |
| 1116 | } |
| 1117 | } |
| 1118 | if( is_string( $headers ) ){ |
| 1119 | $headers = str_replace("Content-Type: text/html", "", $headers); |
| 1120 | } |
| 1121 | if( !empty( $headers ) ){ |
| 1122 | $data['headers'] = $headers; |
| 1123 | } |
| 1124 | if ( ! is_array( $headers ) ) { |
| 1125 | // Explode the headers out, so this function can take both. |
| 1126 | // string headers and an array of headers. |
| 1127 | $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
| 1128 | } else { |
| 1129 | $tempheaders = $headers; |
| 1130 | } |
| 1131 | $headers = array(); |
| 1132 | // If it's actually got contents. |
| 1133 | if ( ! empty( $tempheaders ) ) { |
| 1134 | // Iterate through the raw headers. |
| 1135 | foreach ( (array) $tempheaders as $header ) { |
| 1136 | if ( strpos( $header, ':' ) === false ) { |
| 1137 | if ( false !== stripos( $header, 'boundary=' ) ) { |
| 1138 | $parts = preg_split( '/boundary=/i', trim( $header ) ); |
| 1139 | $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
| 1140 | } |
| 1141 | continue; |
| 1142 | } |
| 1143 | // Explode them out. |
| 1144 | list($name, $content) = explode( ':', trim( $header ), 2 ); |
| 1145 | |
| 1146 | // Cleanup crew. |
| 1147 | $name = trim( $name ); |
| 1148 | $content = trim( $content ); |
| 1149 | |
| 1150 | switch ( strtolower( $name ) ) { |
| 1151 | case 'content-type': |
| 1152 | $headers[ trim( $name ) ] = trim( $content ); |
| 1153 | break; |
| 1154 | case 'x-mailin-tag': |
| 1155 | $headers[ trim( $name ) ] = trim( $content ); |
| 1156 | break; |
| 1157 | case 'from': |
| 1158 | if ( strpos( $content, '<' ) !== false ) { |
| 1159 | // So... making my life hard again? |
| 1160 | $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); |
| 1161 | $from_name = str_replace( '"', '', $from_name ); |
| 1162 | $from_name = trim( $from_name ); |
| 1163 | |
| 1164 | $from_email = substr( $content, strpos( $content, '<' ) + 1 ); |
| 1165 | $from_email = str_replace( '>', '', $from_email ); |
| 1166 | $from_email = trim( $from_email ); |
| 1167 | } else { |
| 1168 | $from_name = ''; |
| 1169 | $from_email = trim( $content ); |
| 1170 | } |
| 1171 | break; |
| 1172 | |
| 1173 | case 'cc': |
| 1174 | $cc = array_merge( (array) $cc, explode( ',', $content ) ); |
| 1175 | break; |
| 1176 | |
| 1177 | case 'bcc': |
| 1178 | $bcc = array_merge( (array) $bcc, explode( ',', $content ) ); |
| 1179 | break; |
| 1180 | |
| 1181 | case 'reply-to': |
| 1182 | $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) ); |
| 1183 | break; |
| 1184 | default: |
| 1185 | break; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | // Set destination addresses, using appropriate methods for handling addresses. |
| 1192 | $address_headers = compact('to', 'cc', 'bcc', 'reply_to'); |
| 1193 | $processed_address_fields = self::processAddressFields($address_headers); |
| 1194 | $data = array_merge($data, $processed_address_fields); |
| 1195 | // Attachments. |
| 1196 | $attachment_content = array(); |
| 1197 | if ( ! empty( $attachments ) ) { |
| 1198 | foreach ( $attachments as $attachment ) { |
| 1199 | if ( !empty( $attachment ) ) { |
| 1200 | $content = self::getAttachmentStruct( $attachment ); |
| 1201 | if ( ! is_wp_error( $content ) ) { |
| 1202 | array_push( $attachment_content, $content ); |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | if ( !empty( $attachment_content ) ) { |
| 1207 | $data["attachment"] = $attachment_content; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | // Common transformations for the HTML part. |
| 1212 | // If it is text/plain, New line break found. |
| 1213 | if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) { |
| 1214 | if ( strpos( $message, "\n" ) !== false ) { |
| 1215 | if ( is_array( $message ) ) { |
| 1216 | foreach ( $message as &$value ) { |
| 1217 | $value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] ); |
| 1218 | $value['content'] = nl2br( $value['content'] ); |
| 1219 | } |
| 1220 | } else { |
| 1221 | $message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message ); |
| 1222 | $message = nl2br( $message ); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | // Sending... |
| 1227 | $data['sender'] = ['email' => $from_email, 'name' => $from_name ]; |
| 1228 | $data['subject'] = $subject; |
| 1229 | $data['htmlContent'] = $message; |
| 1230 | |
| 1231 | try { |
| 1232 | $sent = SIB_API_Manager::send_email( $data ); |
| 1233 | return $sent; |
| 1234 | } catch ( Exception $e ) { |
| 1235 | return new WP_Error( $e->getMessage() ); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * @param array $address_fields |
| 1241 | * @return array |
| 1242 | */ |
| 1243 | private static function processAddressFields($address_fields) |
| 1244 | { |
| 1245 | $data = [ |
| 1246 | 'to' => [], |
| 1247 | 'cc' => [], |
| 1248 | 'bcc' => [], |
| 1249 | 'replyTo' => [], |
| 1250 | ]; |
| 1251 | |
| 1252 | $address_fields['reply_to'] = is_array($address_fields['reply_to']) |
| 1253 | && count($address_fields['reply_to']) > 1 ? $address_fields['reply_to'][0] : $address_fields['reply_to']; |
| 1254 | foreach ($address_fields as $address_header => $addresses) { |
| 1255 | if (empty($addresses)) { |
| 1256 | continue; |
| 1257 | } |
| 1258 | |
| 1259 | foreach ((array) $addresses as $address) { |
| 1260 | // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>". |
| 1261 | if (preg_match('/(.*)<(.+)>/', $address, $matches)) { |
| 1262 | if (count($matches) == 3) { |
| 1263 | $address = preg_replace('/\s+/', '', $matches[2]); //strip whitespaces |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | switch ($address_header) { |
| 1268 | case 'to': |
| 1269 | $data['to'][] = ['email' => $address]; |
| 1270 | break; |
| 1271 | case 'cc': |
| 1272 | $data['cc'][] = ['email' => $address]; |
| 1273 | break; |
| 1274 | case 'bcc': |
| 1275 | $data['bcc'][] = ['email' => $address]; |
| 1276 | break; |
| 1277 | case 'reply_to': |
| 1278 | $data['replyTo']['email'] = $address; |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | return $data; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * @param string $path - attachment file path |
| 1288 | * @return array|WP_Error |
| 1289 | */ |
| 1290 | static function getAttachmentStruct( $path ) { |
| 1291 | |
| 1292 | $struct = array(); |
| 1293 | |
| 1294 | try { |
| 1295 | |
| 1296 | if ( ! @is_file( $path ) ) { |
| 1297 | throw new Exception( $path . ' is not a valid file.' ); |
| 1298 | } |
| 1299 | |
| 1300 | $filename = basename( $path ); |
| 1301 | |
| 1302 | if ( ! function_exists( 'get_magic_quotes' ) ) { |
| 1303 | /** |
| 1304 | * @return bool |
| 1305 | */ |
| 1306 | function get_magic_quotes() { |
| 1307 | return false; |
| 1308 | } |
| 1309 | } |
| 1310 | if ( ! function_exists( 'set_magic_quotes' ) ) { |
| 1311 | /** |
| 1312 | * @param $value |
| 1313 | * @return bool |
| 1314 | */ |
| 1315 | function set_magic_quotes( $value ) { |
| 1316 | return true; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | $isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' ) |
| 1321 | && function_exists( 'get_magic_quotes_runtime' ) |
| 1322 | && function_exists( 'set_magic_quotes_runtime' ); |
| 1323 | |
| 1324 | if ( $isMagicQuotesSupported ) { |
| 1325 | // Escape linters check. |
| 1326 | $getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime'; |
| 1327 | $setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime'; |
| 1328 | |
| 1329 | // Save magic quotes value. |
| 1330 | $magicQuotes = $getMagicQuotesRuntimeFunc(); |
| 1331 | $setMagicQuotesRuntimeFunc (0); |
| 1332 | } |
| 1333 | |
| 1334 | $file_buffer = file_get_contents( $path ); |
| 1335 | $file_buffer = base64_encode($file_buffer); |
| 1336 | |
| 1337 | if ( $isMagicQuotesSupported ) { |
| 1338 | // Restore magic quotes value. |
| 1339 | $setMagicQuotesRuntimeFunc($magicQuotes); |
| 1340 | } |
| 1341 | |
| 1342 | $struct["name"] = $filename; |
| 1343 | $struct["content"] = $file_buffer; |
| 1344 | |
| 1345 | } catch ( Exception $e ) { |
| 1346 | return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() ); |
| 1347 | } |
| 1348 | |
| 1349 | return $struct; |
| 1350 | } |
| 1351 | |
| 1352 | /** |
| 1353 | * Create custom page for form preview |
| 1354 | * |
| 1355 | * @param array $query_vars - query. |
| 1356 | * @return array |
| 1357 | */ |
| 1358 | function sib_query_vars( $query_vars ) { |
| 1359 | $query_vars[] = 'sib_form'; |
| 1360 | return $query_vars; |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Parse request |
| 1365 | * |
| 1366 | * @param mixed $wp - object. |
| 1367 | */ |
| 1368 | function sib_parse_request( &$wp ) { |
| 1369 | if ( array_key_exists( 'sib_form', $wp->query_vars ) ) { |
| 1370 | include 'inc/sib-form-preview.php'; |
| 1371 | exit(); |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | /** |
| 1376 | * Load Text domain. |
| 1377 | */ |
| 1378 | static function LoadTextDomain() { |
| 1379 | // Load lang file. |
| 1380 | $i18n_file_name = 'mailin'; |
| 1381 | $locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name ); |
| 1382 | // $locale = 'fr_FR'; |
| 1383 | $filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo'; |
| 1384 | load_textdomain( 'mailin', $filename ); |
| 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * Notice the language is difference than site's language |
| 1389 | */ |
| 1390 | static function language_admin_notice() { |
| 1391 | if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) { |
| 1392 | $lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 ); |
| 1393 | $lang = self::getLanguageName( $lang_prefix ); |
| 1394 | $class = 'error'; |
| 1395 | $message = sprintf( 'Please note that your Brevo account is in %s, but Brevo WordPress plugin is only available in English / French for now. Sorry for inconvenience.', $lang ); |
| 1396 | if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) { |
| 1397 | // phpcs:ignore |
| 1398 | 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>" ); |
| 1399 | } |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * Notice wp_mail is not possible |
| 1405 | */ |
| 1406 | static function wpMailNotices() { |
| 1407 | if ( self::$wp_mail_conflict ) { |
| 1408 | echo ( '<div class="error"><p>' . __( 'You cannot use Brevo SMTP now because wp_mail has been declared by another process or plugin. ', 'mailin' ) . '</p></div>' ); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | /** |
| 1413 | * Names of languages. |
| 1414 | * |
| 1415 | * @param string $prefix - language. |
| 1416 | * @return mixed |
| 1417 | */ |
| 1418 | public static function getLanguageName( $prefix = 'en' ) { |
| 1419 | $lang = array(); |
| 1420 | $lang['de'] = 'Deutsch'; |
| 1421 | $lang['en'] = 'English'; |
| 1422 | $lang['zh'] = '中文'; |
| 1423 | $lang['ru'] = 'Русский'; |
| 1424 | $lang['fi'] = 'suomi'; |
| 1425 | $lang['fr'] = 'Français'; |
| 1426 | $lang['nl'] = 'Nederlands'; |
| 1427 | $lang['sv'] = 'Svenska'; |
| 1428 | $lang['it'] = 'Italiano'; |
| 1429 | $lang['ro'] = 'Română'; |
| 1430 | $lang['hu'] = 'Magyar'; |
| 1431 | $lang['ja'] = '日本語'; |
| 1432 | $lang['es'] = 'Español'; |
| 1433 | $lang['vi'] = 'Tiếng Việt'; |
| 1434 | $lang['ar'] = 'العربية'; |
| 1435 | $lang['pt'] = 'Português'; |
| 1436 | $lang['pb'] = 'Português do Brasil'; |
| 1437 | $lang['pl'] = 'Polski'; |
| 1438 | $lang['gl'] = 'galego'; |
| 1439 | $lang['tr'] = 'Turkish'; |
| 1440 | $lang['et'] = 'Eesti'; |
| 1441 | $lang['hr'] = 'Hrvatski'; |
| 1442 | $lang['eu'] = 'Euskera'; |
| 1443 | $lang['el'] = 'Ελληνικά'; |
| 1444 | $lang['ua'] = 'Українська'; |
| 1445 | $lang['ko'] = '한국어'; |
| 1446 | |
| 1447 | return $lang[ $prefix ]; |
| 1448 | } |
| 1449 | |
| 1450 | /** |
| 1451 | * Create language sidebar for wpml plugin. |
| 1452 | */ |
| 1453 | public function sib_create_language_sidebar() { |
| 1454 | $languages = apply_filters( 'wpml_active_languages', array() ); |
| 1455 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 1456 | $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 1457 | $frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : ''; |
| 1458 | $pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : ''; |
| 1459 | $parent = true; |
| 1460 | if ( '' !== $frmID && '' !== $pID ) { |
| 1461 | $lang = SIB_Forms_Lang::get_lang( $frmID, $pID ); |
| 1462 | $parent = false; |
| 1463 | } else { |
| 1464 | $lang = ICL_LANGUAGE_CODE; |
| 1465 | if ( '' !== $frmID && '' === $pID ) { |
| 1466 | $pID = $frmID; |
| 1467 | |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | if ( 'sib_page_form' === $page && 'edit' === $action ) { |
| 1472 | ?> |
| 1473 | <div class="panel panel-default text-left box-border-box sib-small-content"> |
| 1474 | <div class="panel-heading"><strong><?php esc_attr_e( 'About Brevo', 'mailin' ); ?></strong></div> |
| 1475 | <div class="panel-body"> |
| 1476 | <p> |
| 1477 | <label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'mailin' ); ?> </label> |
| 1478 | <select id="sib_form_lang" name="sib_form_lang" data-selected=""> |
| 1479 | <?php |
| 1480 | foreach ( $languages as $language ) { |
| 1481 | $selected = (isset($language['code']) && ($language['code'] == $lang)) ? 'selected' : ''; |
| 1482 | if ( isset($language['code']) && $language['code'] == $lang && true === $parent ) { |
| 1483 | $option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>'; |
| 1484 | } else { |
| 1485 | $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1486 | |
| 1487 | if ( null === $exist ) { |
| 1488 | continue; |
| 1489 | } else { |
| 1490 | $option_text = ( 'selected' === $selected ) ? |
| 1491 | sprintf( '<option value="" selected>%s</option>', esc_html( $language['native_name'] ) ) : |
| 1492 | sprintf( '<option value="%s" %s>%s</option>', |
| 1493 | esc_url( add_query_arg( array( |
| 1494 | 'page' => sanitize_text_field( $_REQUEST['page'] ), |
| 1495 | 'action' => 'edit', |
| 1496 | 'pid' => absint( $pID ), |
| 1497 | 'lang' => sanitize_text_field( $language['language_code'] ) |
| 1498 | ) ) ), |
| 1499 | $selected, |
| 1500 | esc_html( $language['native_name'] ) |
| 1501 | ); |
| 1502 | } |
| 1503 | } |
| 1504 | echo $option_text ; |
| 1505 | } |
| 1506 | ?> |
| 1507 | </select> |
| 1508 | </p> |
| 1509 | <div class="sib_form_translate"> |
| 1510 | <p> |
| 1511 | <label><?php esc_attr_e( 'Translate this form', 'mailin' ); ?></label> |
| 1512 | </p> |
| 1513 | <table aria-describedby="wpml-language-table" class="sib_form_trans_table" style="border: 1px solid #8cceea;"> |
| 1514 | <tr> |
| 1515 | <?php |
| 1516 | foreach ( $languages as $language ) { |
| 1517 | if ( isset($language['code']) && $language['code'] == $lang ) { |
| 1518 | continue; |
| 1519 | } |
| 1520 | ?> |
| 1521 | <th style="text-align: center;"><img |
| 1522 | src="<?php echo esc_url( $language['country_flag_url'] ); ?>" alt="Flag of <?php echo esc_attr( $language['translated_name'] ); ?>"></th> |
| 1523 | <?php |
| 1524 | } |
| 1525 | ?> |
| 1526 | </tr> |
| 1527 | <tr style="background-color: #EFF8FC;"> |
| 1528 | <?php |
| 1529 | foreach ( $languages as $language ) { |
| 1530 | if ( isset($language['code']) && $language['code'] == $lang ) { |
| 1531 | continue; |
| 1532 | } |
| 1533 | if ( '' === $pID ) { |
| 1534 | $img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ ); |
| 1535 | $td = '<img src="' . $img_src . '" style="margin:2px;">'; |
| 1536 | } else { |
| 1537 | $exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1538 | |
| 1539 | if ( null === $exist ) { |
| 1540 | $img_src = plugins_url( 'img/add_translation.png', __FILE__ ); |
| 1541 | |
| 1542 | $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'] ); |
| 1543 | $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1544 | } else { |
| 1545 | $img_src = plugins_url( 'img/edit_translation.png', __FILE__ ); |
| 1546 | $href = sprintf( '<a class="sib-form-redirect" href="%s" style="width: 20px; text-align: center;padding: 2px 1px;">', esc_url( add_query_arg( array( |
| 1547 | 'page' => sanitize_text_field( $_REQUEST['page'] ), |
| 1548 | 'action' => 'edit', |
| 1549 | 'id' => absint( $exist ), |
| 1550 | 'pid' => absint( $pID ), |
| 1551 | 'lang' => sanitize_text_field( $language['language_code'] ) |
| 1552 | ) ) ) ); |
| 1553 | $td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1554 | } |
| 1555 | } |
| 1556 | ?> |
| 1557 | <td style="text-align: center;"><?php echo wp_kses($td, wp_kses_allowed_html('post')); ?></td> |
| 1558 | <?php |
| 1559 | } |
| 1560 | ?> |
| 1561 | </tr> |
| 1562 | </table> |
| 1563 | </div> |
| 1564 | <?php if ( isset( $_GET['pid'] ) ) { ?> |
| 1565 | <div class="sib-form-duplicate"> |
| 1566 | <button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'mailin' ); ?></button> |
| 1567 | <span class="sib-spin"><i |
| 1568 | class="fa fa-circle-o-notch fa-spin fa-lg"></i> </span> |
| 1569 | <i title="<?php echo esc_attr_e( 'Copy content from origin form', 'mailin' ); ?>" |
| 1570 | data-container="body" data-toggle="popover" data-placement="left" |
| 1571 | data-content="<?php echo esc_attr_e( 'You can copy contents from origin form. You need to translate the contents by this language.', 'mailin' ); ?>" |
| 1572 | data-html="true" class="fa fa-question-circle popover-help-form"></i> |
| 1573 | </div> |
| 1574 | <?php } ?> |
| 1575 | </div> |
| 1576 | </div> |
| 1577 | <?php |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | public function ajax_get_country_prefix() { |
| 1582 | check_ajax_referer( 'sib_front_ajax_nonce', 'security' ); |
| 1583 | $sms_manager = new SIB_SMS_Code(); |
| 1584 | $country_list = $sms_manager->get_sms_code_list(); |
| 1585 | $country_list_html = ''; |
| 1586 | foreach ( $country_list as $item => $value ) { |
| 1587 | $flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png'; |
| 1588 | $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>'; |
| 1589 | $country_list_html .= $item_html; |
| 1590 | } |
| 1591 | wp_send_json($country_list_html); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * @param string $postAttribute |
| 1596 | * @param array $sibAttributes |
| 1597 | * @return null|string the corresponding sib attribute or null if not found |
| 1598 | */ |
| 1599 | private function getCorrespondingSibAttribute($postAttribute, $sibAttributes) |
| 1600 | { |
| 1601 | $normalizedPostAttribute = strtoupper(sanitize_text_field($postAttribute)); |
| 1602 | foreach ($sibAttributes as $sibAttribute) { |
| 1603 | if ($normalizedPostAttribute == strtoupper($sibAttribute)) { |
| 1604 | return $sibAttribute; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | return null; |
| 1609 | } |
| 1610 | |
| 1611 | public function my_upgrade_function() { |
| 1612 | $current_plugin_path_name = plugin_basename( __FILE__ ); |
| 1613 | activate_plugin( $current_plugin_path_name ); |
| 1614 | } |
| 1615 | |
| 1616 | public static function wordpress_allowed_attributes() |
| 1617 | { |
| 1618 | global $allowedposttags, $allowedtags, $allowedentitynames; |
| 1619 | $attributes = [$allowedposttags, $allowedtags, $allowedentitynames, self::SIB_ATTRIBUTE]; |
| 1620 | $attributes = call_user_func_array("array_merge", $attributes); |
| 1621 | |
| 1622 | add_filter( 'safe_style_css', function($css_attr) { |
| 1623 | array_push($css_attr, 'display'); |
| 1624 | return $css_attr; |
| 1625 | }); |
| 1626 | |
| 1627 | return $attributes; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | add_action( 'sendinblue_init', 'sendinblue_init' ); |
| 1632 | add_filter( 'widget_text', 'do_shortcode' ); |
| 1633 | |
| 1634 | /** |
| 1635 | * Plugin entry point Process. |
| 1636 | */ |
| 1637 | function sendinblue_init() { |
| 1638 | SIB_Manager::LoadTextDomain(); |
| 1639 | new SIB_Manager(); |
| 1640 | } |
| 1641 | |
| 1642 | do_action( 'sendinblue_init' ); |
| 1643 | } |
| 1644 |