| 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.11 |
| 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_email = ''; |
| 444 |
$current_user = wp_get_current_user(); |
| 445 |
if ( $current_user instanceof WP_User ) { |
| 446 |
$ma_email = $current_user->user_email; |
| 447 |
} |
| 448 |
$ma_key = $general_settings['ma_key']; |
| 449 |
$output = '<script type="text/javascript"> |
| 450 |
(function() {window.sib ={equeue:[],client_key:"'. $ma_key .'"};/* OPTIONAL: email for identify request*/ |
| 451 |
window.sib.email_id = "'. $ma_email .'"; |
| 452 |
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();})(); |
| 453 |
</script>'; |
| 454 |
echo $output; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Register widget |
| 460 |
*/ |
| 461 |
function sib_create_widget() { |
| 462 |
register_widget( 'SIB_Widget_Subscribe' ); |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Display form on front page |
| 467 |
* |
| 468 |
* @param string $frmID - form ID. |
| 469 |
* @param string $lang - form language. |
| 470 |
*/ |
| 471 |
function generate_form_box( $frmID = '-1', $lang = '' ) { |
| 472 |
if ( 'oldForm' == $frmID ) { |
| 473 |
$frmID = get_option( 'sib_old_form_id' ); |
| 474 |
} elseif ( '' != $lang ) { |
| 475 |
$trans_id = SIB_Forms_Lang::get_form_ID( $frmID, $lang ); |
| 476 |
if ( null != $trans_id ) { |
| 477 |
$frmID = $trans_id; |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
$formData = SIB_Forms::getForm( $frmID ); |
| 482 |
|
| 483 |
if ( empty( $formData ) ) { |
| 484 |
return; |
| 485 |
} |
| 486 |
// Add Google recaptcha |
| 487 |
if( '0' != $formData['gCaptcha'] ) { |
| 488 |
if( '1' == $formData['gCaptcha'] ) { // For old forms. |
| 489 |
$formData['html'] = preg_replace( '/([\s\S]*?)<div class="g-recaptcha"[\s\S]*?data-size="invisible"><\/div>/', '$1', $formData['html'] ); |
| 490 |
} |
| 491 |
if ( '3' == $formData['gCaptcha'] ) // The case of using google recaptcha. |
| 492 |
{ |
| 493 |
?> |
| 494 |
<script type="text/javascript"> |
| 495 |
var gCaptchaSibWidget; |
| 496 |
var onloadSibCallback = function() { |
| 497 |
gCaptchaSibWidget = grecaptcha.render('sib_captcha',{ |
| 498 |
'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>' |
| 499 |
}); |
| 500 |
}; |
| 501 |
</script> |
| 502 |
<?php |
| 503 |
} |
| 504 |
else { // The case of using google invisible recaptcha. |
| 505 |
?> |
| 506 |
<script type="text/javascript"> |
| 507 |
var gCaptchaSibWidget; |
| 508 |
var onloadSibCallback = function() { |
| 509 |
var element = document.getElementsByClassName('sib-default-btn'); |
| 510 |
gCaptchaSibWidget = grecaptcha.render(element[0],{ |
| 511 |
'sitekey' : '<?php echo $formData["gCaptcha_site"] ?>', |
| 512 |
'callback' : sibVerifyCallback |
| 513 |
}); |
| 514 |
}; |
| 515 |
</script> |
| 516 |
<?php |
| 517 |
} |
| 518 |
?> |
| 519 |
<script src="https://www.google.com/recaptcha/api.js?onload=onloadSibCallback&render=explicit" async defer></script> |
| 520 |
<?php |
| 521 |
} |
| 522 |
|
| 523 |
?> |
| 524 |
<form id="sib_signup_form_<?php echo esc_attr( $frmID ); ?>" method="post" class="sib_signup_form"> |
| 525 |
<div class="sib_loader" style="display:none;"><img |
| 526 |
src="<?php echo esc_url( includes_url() ); ?>/images/spinner.gif" alt="loader"></div> |
| 527 |
<input type="hidden" name="sib_form_action" value="subscribe_form_submit"> |
| 528 |
<input type="hidden" name="sib_form_id" value="<?php echo esc_attr( $frmID ); ?>"> |
| 529 |
<input type="hidden" name="sib_form_alert_notice" value="<?php echo esc_attr($formData['requiredMsg']); ?>"> |
| 530 |
<div class="sib_signup_box_inside_<?php echo esc_attr( $frmID ); ?>"> |
| 531 |
<div style="/*display:none*/" class="sib_msg_disp"> |
| 532 |
</div> |
| 533 |
<?php |
| 534 |
echo $formData['html']; |
| 535 |
?> |
| 536 |
</div> |
| 537 |
</form> |
| 538 |
<style> |
| 539 |
<?php |
| 540 |
|
| 541 |
if ( ! $formData['dependTheme'] ) { |
| 542 |
// Custom css. |
| 543 |
$formData['css'] = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, $formData['css'] ); |
| 544 |
echo $formData['css']; |
| 545 |
} |
| 546 |
$msgCss = str_replace( '[form]', 'form#sib_signup_form_' . $frmID, SIB_Forms::getDefaultMessageCss() ); |
| 547 |
echo $msgCss; |
| 548 |
?> |
| 549 |
</style> |
| 550 |
<?php |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* Shortcode for sign up form |
| 555 |
* |
| 556 |
* @param array $atts - shortcode parameter. |
| 557 |
* @return string |
| 558 |
*/ |
| 559 |
function sibwp_form_shortcode( $atts ) { |
| 560 |
$pull_atts = shortcode_atts( |
| 561 |
array( |
| 562 |
'id' => 'oldForm', // We will return 'oldForm' for shortcode of old form. |
| 563 |
), $atts |
| 564 |
); |
| 565 |
$frmID = $pull_atts['id']; |
| 566 |
$lang = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : ''; |
| 567 |
|
| 568 |
ob_start(); |
| 569 |
$this->generate_form_box( $frmID, $lang ); |
| 570 |
|
| 571 |
$output_string = ob_get_contents(); |
| 572 |
ob_end_clean(); |
| 573 |
return $output_string; |
| 574 |
} |
| 575 |
|
| 576 |
/** |
| 577 |
* Sign up process |
| 578 |
*/ |
| 579 |
function signup_process() { |
| 580 |
check_ajax_referer( 'sib_front_ajax_nonce', 'security' ); |
| 581 |
$formID = isset( $_POST['sib_form_id'] ) ? sanitize_text_field( $_POST['sib_form_id'] ) : 1; |
| 582 |
if ( 'oldForm' == $formID ) { |
| 583 |
$formID = get_option( 'sib_old_form_id' ); |
| 584 |
} |
| 585 |
$formData = SIB_Forms::getForm( $formID ); |
| 586 |
|
| 587 |
if ( '0' != $formData['gCaptcha'] ) { |
| 588 |
if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) { |
| 589 |
wp_send_json( |
| 590 |
array( |
| 591 |
'status' => 'gcaptchaEmpty', |
| 592 |
'msg' => 'Please click on the reCAPTCHA box.', |
| 593 |
) |
| 594 |
); |
| 595 |
} |
| 596 |
$secret = $formData['gCaptcha_secret']; |
| 597 |
|
| 598 |
$data = array( |
| 599 |
'secret' => $secret, |
| 600 |
'response' => sanitize_text_field( $_POST['g-recaptcha-response'] ), |
| 601 |
); |
| 602 |
|
| 603 |
$verify = curl_init(); |
| 604 |
curl_setopt( $verify, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify' ); |
| 605 |
curl_setopt( $verify, CURLOPT_POST, true ); |
| 606 |
curl_setopt( $verify, CURLOPT_POSTFIELDS, http_build_query( $data ) ); |
| 607 |
curl_setopt( $verify, CURLOPT_SSL_VERIFYPEER, false ); |
| 608 |
curl_setopt( $verify, CURLOPT_RETURNTRANSFER, true ); |
| 609 |
$response = curl_exec( $verify ); |
| 610 |
$responseData = json_decode( $response ); |
| 611 |
if ( ! $responseData->success ) { |
| 612 |
wp_send_json( |
| 613 |
array( |
| 614 |
'status' => 'gcaptchaFail', |
| 615 |
'msg' => 'Robot verification failed, please try again.', |
| 616 |
) |
| 617 |
); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
$listID = $formData['listID']; |
| 622 |
if (empty($listID)) { |
| 623 |
$listID = array(); |
| 624 |
} |
| 625 |
$interestingLists = isset( $_POST['interestingLists']) ? $_POST['interestingLists'] : array(); |
| 626 |
$expectedLists = isset( $_POST['listIDs'] ) ? $_POST['listIDs'] : array(); |
| 627 |
if ( empty($interestingLists) ) |
| 628 |
{ |
| 629 |
$unlinkedLists = null; |
| 630 |
} |
| 631 |
else{ |
| 632 |
$unwantedLists = array_diff( $interestingLists, $expectedLists ); |
| 633 |
$unlinkedLists = array_diff( $unwantedLists, $listID); |
| 634 |
$listID = array_unique(array_merge( $listID, $expectedLists )); |
| 635 |
} |
| 636 |
|
| 637 |
$email = isset( $_POST['email'] ) ? sanitize_text_field( $_POST['email'] ) : ''; |
| 638 |
if ( ! is_email( $email ) ) { |
| 639 |
return; |
| 640 |
} |
| 641 |
|
| 642 |
$isDoubleOptin = $formData['isDopt']; |
| 643 |
$isOptin = $formData['isOpt']; |
| 644 |
$redirectUrlInEmail = $formData['redirectInEmail']; |
| 645 |
$redirectUrlInForm = $formData['redirectInForm']; |
| 646 |
|
| 647 |
$info = array(); |
| 648 |
$attributes = explode( ',', $formData['attributes'] ); // String to array. |
| 649 |
if ( isset( $attributes ) && is_array( $attributes ) ) { |
| 650 |
foreach ( $attributes as $attribute ) { |
| 651 |
$info[ $attribute ] = isset( $_POST[ $attribute ] ) ? sanitize_text_field( $_POST[ $attribute ] ) : '' ; |
| 652 |
} |
| 653 |
} |
| 654 |
$templateID = $formData['templateID']; |
| 655 |
|
| 656 |
if ( $isDoubleOptin ) { |
| 657 |
/* |
| 658 |
* Double optin process |
| 659 |
* 1. add/update user in SIB contacts |
| 660 |
* 2. add record to db |
| 661 |
* 3. send confirmation email with activate code |
| 662 |
*/ |
| 663 |
// Create/updated subscriber. |
| 664 |
$result = SIB_API_Manager::create_subscriber( 'double-optin', $email, $listID, $info, $unlinkedLists ); |
| 665 |
// Send a double optin confirm email. |
| 666 |
if ( 'success' == $result ) { |
| 667 |
// Add a recode with activate code in db. |
| 668 |
$activateCode = $this->create_activate_code( $email, $info, $formID, $listID, $redirectUrlInEmail, $unlinkedLists ); |
| 669 |
SIB_API_Manager::send_comfirm_email( 'double-optin', $email, $templateID, $info, $activateCode ); |
| 670 |
} |
| 671 |
} elseif ( $isOptin ) { |
| 672 |
$result = SIB_API_Manager::create_subscriber( 'confirm', $email, $listID, $info, $unlinkedLists ); |
| 673 |
if ( 'success' == $result ) { |
| 674 |
// Send a confirm email. |
| 675 |
SIB_API_Manager::send_comfirm_email( 'confirm', $email, $templateID, $info ); |
| 676 |
} |
| 677 |
} else { |
| 678 |
$result = SIB_API_Manager::create_subscriber( 'simple', $email, $listID, $info, $unlinkedLists ); |
| 679 |
} |
| 680 |
$msg = array( |
| 681 |
'successMsg' => $formData['successMsg'], |
| 682 |
'errorMsg' => $formData['errorMsg'], |
| 683 |
'existMsg' => $formData['existMsg'], |
| 684 |
'invalidMsg' => $formData['invalidMsg'], |
| 685 |
); |
| 686 |
|
| 687 |
wp_send_json( |
| 688 |
array( |
| 689 |
'status' => $result, |
| 690 |
'msg' => $msg, |
| 691 |
'redirect' => $redirectUrlInForm, |
| 692 |
) |
| 693 |
); |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* Create activate code for Double optin |
| 698 |
* |
| 699 |
* @param string $email - user email. |
| 700 |
* @param array $info - info. |
| 701 |
* @param string $formID - form ID. |
| 702 |
* @param array $listIDs - lists. |
| 703 |
* @param string $redirectUrl - redirect url. |
| 704 |
* @return string - activate code. |
| 705 |
*/ |
| 706 |
function create_activate_code( $email, $info, $formID, $listIDs, $redirectUrl, $unlinkedLists = null ) { |
| 707 |
$data = SIB_Model_Users::get_data_by_email( $email, $formID ); |
| 708 |
if ( $unlinkedLists != null ) |
| 709 |
{ |
| 710 |
$info['unlinkedLists'] = $unlinkedLists; |
| 711 |
} |
| 712 |
if ( false == $data ) { |
| 713 |
$uniqid = uniqid(); |
| 714 |
$data = array( |
| 715 |
'email' => $email, |
| 716 |
'code' => $uniqid, |
| 717 |
'info' => maybe_serialize( $info ), |
| 718 |
'frmid' => $formID, |
| 719 |
'listIDs' => maybe_serialize( $listIDs ), |
| 720 |
'redirectUrl' => $redirectUrl, |
| 721 |
); |
| 722 |
SIB_Model_Users::add_record( $data ); |
| 723 |
} else { |
| 724 |
$uniqid = $data['code']; |
| 725 |
} |
| 726 |
return $uniqid; |
| 727 |
} |
| 728 |
|
| 729 |
/** |
| 730 |
* Use Sendinblue SMTP to send all emails |
| 731 |
* |
| 732 |
* @param string $to - reception email. |
| 733 |
* @param string $subject - subject of email. |
| 734 |
* @param string $message - message of email. |
| 735 |
* @param string $headers - header of email. |
| 736 |
* @param array $attachments - attachments. |
| 737 |
*/ |
| 738 |
static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) { |
| 739 |
$result = require self::$plugin_dir . '/inc/function.wp_mail.php'; |
| 740 |
return $result; |
| 741 |
} |
| 742 |
|
| 743 |
/** |
| 744 |
* To send the transactional email via Sendinblue |
| 745 |
* hook wp_mail |
| 746 |
* |
| 747 |
* @param string $to - reception email. |
| 748 |
* @param string $subject - subject of email. |
| 749 |
* @param string $message - message of email. |
| 750 |
* @param string $headers - header of email. |
| 751 |
* @param array $attachments - attachments |
| 752 |
* @param array $tags - tag. |
| 753 |
* @param string $from_name - sender name. |
| 754 |
* @param string $from_email - sender email. |
| 755 |
* @return mixed|WP_Error |
| 756 |
*/ |
| 757 |
static function sib_email( $to, $subject, $message, $headers = '', $attachments = array(), $tags = array(), $from_name = '', $from_email = '' ) { |
| 758 |
// Compact the input, apply the filters, and extract them back out. |
| 759 |
extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); |
| 760 |
|
| 761 |
if ( ! is_array( $attachments ) ) { |
| 762 |
$attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) ); |
| 763 |
} |
| 764 |
|
| 765 |
// From email and name. |
| 766 |
$home_settings = get_option( SIB_Manager::HOME_OPTION_NAME ); |
| 767 |
if ( isset( $home_settings['sender'] ) ) { |
| 768 |
$from_name = $home_settings['from_name']; |
| 769 |
$from_email = $home_settings['from_email']; |
| 770 |
} else { |
| 771 |
$from_email = trim( get_bloginfo( 'admin_email' ) ); |
| 772 |
$from_name = trim( get_bloginfo( 'name' ) ); |
| 773 |
} |
| 774 |
$from_email = apply_filters( 'wp_mail_from', $from_email ); |
| 775 |
$from_name = apply_filters( 'wp_mail_from_name', $from_name ); |
| 776 |
|
| 777 |
// Headers. |
| 778 |
if ( empty( $headers ) ) { |
| 779 |
$headers = array(); |
| 780 |
$reply = array(); |
| 781 |
$bcc = array(); |
| 782 |
$cc = array(); |
| 783 |
} else { |
| 784 |
if ( ! is_array( $headers ) ) { |
| 785 |
// Explode the headers out, so this function can take both. |
| 786 |
// string headers and an array of headers. |
| 787 |
$tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); |
| 788 |
} else { |
| 789 |
$tempheaders = $headers; |
| 790 |
} |
| 791 |
$headers = array(); |
| 792 |
$reply = array(); |
| 793 |
$bcc = array(); |
| 794 |
$cc = array(); |
| 795 |
// If it's actually got contents. |
| 796 |
if ( ! empty( $tempheaders ) ) { |
| 797 |
// Iterate through the raw headers. |
| 798 |
foreach ( (array) $tempheaders as $header ) { |
| 799 |
if ( strpos( $header, ':' ) === false ) { |
| 800 |
if ( false !== stripos( $header, 'boundary=' ) ) { |
| 801 |
$parts = preg_split( '/boundary=/i', trim( $header ) ); |
| 802 |
$boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) ); |
| 803 |
} |
| 804 |
continue; |
| 805 |
} |
| 806 |
// Explode them out. |
| 807 |
list($name, $content) = explode( ':', trim( $header ), 2 ); |
| 808 |
|
| 809 |
// Cleanup crew. |
| 810 |
$name = trim( $name ); |
| 811 |
$content = trim( $content ); |
| 812 |
|
| 813 |
switch ( strtolower( $name ) ) { |
| 814 |
case 'content-type': |
| 815 |
$headers[ trim( $name ) ] = trim( $content ); |
| 816 |
break; |
| 817 |
case 'x-mailin-tag': |
| 818 |
$headers[ trim( $name ) ] = trim( $content ); |
| 819 |
break; |
| 820 |
case 'from': |
| 821 |
if ( strpos( $content, '<' ) !== false ) { |
| 822 |
// So... making my life hard again? |
| 823 |
$from_name = substr( $content, 0, strpos( $content, '<' ) - 1 ); |
| 824 |
$from_name = str_replace( '"', '', $from_name ); |
| 825 |
$from_name = trim( $from_name ); |
| 826 |
|
| 827 |
$from_email = substr( $content, strpos( $content, '<' ) + 1 ); |
| 828 |
$from_email = str_replace( '>', '', $from_email ); |
| 829 |
$from_email = trim( $from_email ); |
| 830 |
} else { |
| 831 |
$from_name = ''; |
| 832 |
$from_email = trim( $content ); |
| 833 |
} |
| 834 |
break; |
| 835 |
|
| 836 |
case 'bcc': |
| 837 |
if ( strpos( $content, '<') !== false ) |
| 838 |
{ |
| 839 |
$bcc_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 840 |
$bcc_content = str_replace( '>', '', $bcc_content ); |
| 841 |
$bcc[ trim( $bcc_content ) ] = ''; |
| 842 |
} else { |
| 843 |
$bcc[ trim( $content ) ] = ''; |
| 844 |
} |
| 845 |
break; |
| 846 |
case 'cc': |
| 847 |
if ( strpos( $content, '<') !== false ) |
| 848 |
{ |
| 849 |
$cc_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 850 |
$cc_content = str_replace( '>', '', $cc_content ); |
| 851 |
$cc[ trim( $cc_content ) ] = ''; |
| 852 |
} else { |
| 853 |
$bcc[ trim( $content ) ] = ''; |
| 854 |
} |
| 855 |
break; |
| 856 |
case 'reply-to': |
| 857 |
if ( strpos( $content, '<') !== false ) |
| 858 |
{ |
| 859 |
$reply_content = substr( $content, strpos( $content, '<' ) + 1 ); |
| 860 |
$reply_content = str_replace( '>', '', $reply_content ); |
| 861 |
$reply[] = trim( $reply_content ); |
| 862 |
} else { |
| 863 |
$reply[] = trim( $content ); |
| 864 |
} |
| 865 |
break; |
| 866 |
default: |
| 867 |
break; |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
} |
| 872 |
|
| 873 |
// Set destination addresses. |
| 874 |
if ( ! is_array( $to ) ) { |
| 875 |
$to = explode( ',', preg_replace( '/\s+/', '', $to ) ); // strip all whitespace. |
| 876 |
} |
| 877 |
|
| 878 |
$processed_to = array(); |
| 879 |
foreach ( $to as $email ) { |
| 880 |
if ( is_array( $email ) ) { |
| 881 |
$processed_to[] = $email; |
| 882 |
} else { |
| 883 |
$processed_to[ $email ] = ''; |
| 884 |
} |
| 885 |
} |
| 886 |
$to = $processed_to; |
| 887 |
|
| 888 |
// Attachments. |
| 889 |
$attachment_content = array(); |
| 890 |
if ( ! empty( $attachments ) ) { |
| 891 |
foreach ( $attachments as $attachment ) { |
| 892 |
$content = self::getAttachmentStruct( $attachment ); |
| 893 |
if ( ! is_wp_error( $content ) ) { |
| 894 |
$attachment_content = array_merge( $attachment_content, $content ); |
| 895 |
} |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
// Common transformations for the HTML part. |
| 900 |
// If it is text/plain, New line break found. |
| 901 |
if ( strpos( $message, '</table>' ) === false && strpos( $message, '</div>' ) === false ) { |
| 902 |
if ( strpos( $message, "\n" ) !== false ) { |
| 903 |
if ( is_array( $message ) ) { |
| 904 |
foreach ( $message as &$value ) { |
| 905 |
$value['content'] = preg_replace( '#<(https?://[^*]+)>#', '$1', $value['content'] ); |
| 906 |
$value['content'] = nl2br( $value['content'] ); |
| 907 |
} |
| 908 |
} else { |
| 909 |
$message = preg_replace( '#<(https?://[^*]+)>#', '$1', $message ); |
| 910 |
$message = nl2br( $message ); |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
// Sending... |
| 915 |
$data = array( |
| 916 |
'to' => $to, |
| 917 |
'from' => array( $from_email, $from_name ), |
| 918 |
'cc' => $cc, |
| 919 |
'bcc' => $bcc, |
| 920 |
'replyto' => $reply, |
| 921 |
'subject' => $subject, |
| 922 |
'headers' => $headers, |
| 923 |
'attachment' => $attachment_content, |
| 924 |
'html' => $message, |
| 925 |
); |
| 926 |
|
| 927 |
try { |
| 928 |
$sent = SIB_API_Manager::send_email( $data ); |
| 929 |
return $sent; |
| 930 |
} catch ( Exception $e ) { |
| 931 |
return new WP_Error( $e->getMessage() ); |
| 932 |
} |
| 933 |
} |
| 934 |
|
| 935 |
/** |
| 936 |
* @param string $path - attachment file path |
| 937 |
* @return array|WP_Error |
| 938 |
*/ |
| 939 |
static function getAttachmentStruct( $path ) { |
| 940 |
|
| 941 |
$struct = array(); |
| 942 |
|
| 943 |
try { |
| 944 |
|
| 945 |
if ( ! @is_file( $path ) ) { |
| 946 |
throw new Exception( $path . ' is not a valid file.' ); |
| 947 |
} |
| 948 |
|
| 949 |
$filename = basename( $path ); |
| 950 |
|
| 951 |
if ( ! function_exists( 'get_magic_quotes' ) ) { |
| 952 |
/** |
| 953 |
* @return bool |
| 954 |
*/ |
| 955 |
function get_magic_quotes() { |
| 956 |
return false; |
| 957 |
} |
| 958 |
} |
| 959 |
if ( ! function_exists( 'set_magic_quotes' ) ) { |
| 960 |
/** |
| 961 |
* @param $value |
| 962 |
* @return bool |
| 963 |
*/ |
| 964 |
function set_magic_quotes( $value ) { |
| 965 |
return true; |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 969 |
$isMagicQuotesSupported = version_compare( PHP_VERSION, '5.3.0', '<' ) |
| 970 |
&& function_exists( 'get_magic_quotes_runtime' ) |
| 971 |
&& function_exists( 'set_magic_quotes_runtime' ); |
| 972 |
|
| 973 |
if ( $isMagicQuotesSupported ) { |
| 974 |
// Escape linters check. |
| 975 |
$getMagicQuotesRuntimeFunc = 'get_magic_quotes_runtime'; |
| 976 |
$setMagicQuotesRuntimeFunc = 'set_magic_quotes_runtime'; |
| 977 |
|
| 978 |
// Save magic quotes value. |
| 979 |
$magicQuotes = $getMagicQuotesRuntimeFunc(); |
| 980 |
$setMagicQuotesRuntimeFunc (0); |
| 981 |
} |
| 982 |
|
| 983 |
$file_buffer = file_get_contents( $path ); |
| 984 |
$file_buffer = chunk_split( base64_encode( $file_buffer ), 76, "\n" ); |
| 985 |
|
| 986 |
if ( $isMagicQuotesSupported ) { |
| 987 |
// Restore magic quotes value. |
| 988 |
$setMagicQuotesRuntimeFunc($magicQuotes); |
| 989 |
} |
| 990 |
|
| 991 |
$struct[ $filename ] = $file_buffer; |
| 992 |
|
| 993 |
} catch ( Exception $e ) { |
| 994 |
return new WP_Error( 'Error creating the attachment structure: ' . $e->getMessage() ); |
| 995 |
} |
| 996 |
|
| 997 |
return $struct; |
| 998 |
} |
| 999 |
|
| 1000 |
/** |
| 1001 |
* Create custom page for form preview |
| 1002 |
* |
| 1003 |
* @param array $query_vars - query. |
| 1004 |
* @return array |
| 1005 |
*/ |
| 1006 |
function sib_query_vars( $query_vars ) { |
| 1007 |
$query_vars[] = 'sib_form'; |
| 1008 |
return $query_vars; |
| 1009 |
} |
| 1010 |
|
| 1011 |
/** |
| 1012 |
* Parse request |
| 1013 |
* |
| 1014 |
* @param mixed $wp - object. |
| 1015 |
*/ |
| 1016 |
function sib_parse_request( &$wp ) { |
| 1017 |
if ( array_key_exists( 'sib_form', $wp->query_vars ) ) { |
| 1018 |
include 'inc/sib-form-preview.php'; |
| 1019 |
exit(); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
/** |
| 1024 |
* Load Text domain. |
| 1025 |
*/ |
| 1026 |
static function LoadTextDomain() { |
| 1027 |
// Load lang file. |
| 1028 |
$i18n_file_name = 'sib_lang'; |
| 1029 |
$locale = apply_filters( 'plugin_locale', get_locale(), $i18n_file_name ); |
| 1030 |
// $locale = 'fr_FR'; |
| 1031 |
$filename = plugin_dir_path( __FILE__ ) . '/lang/' . $i18n_file_name . '-' . $locale . '.mo'; |
| 1032 |
load_textdomain( 'sib_lang', $filename ); |
| 1033 |
} |
| 1034 |
|
| 1035 |
/** |
| 1036 |
* Notice the language is difference than site's language |
| 1037 |
*/ |
| 1038 |
static function language_admin_notice() { |
| 1039 |
if ( ! get_option( SIB_Manager::LANGUAGE_OPTION_NAME ) ) { |
| 1040 |
$lang_prefix = substr( get_bloginfo( 'language' ), 0, 2 ); |
| 1041 |
$lang = self::getLanguageName( $lang_prefix ); |
| 1042 |
$class = 'error'; |
| 1043 |
$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 ); |
| 1044 |
if ( 'en' !== $lang_prefix && 'fr' !== $lang_prefix ) { |
| 1045 |
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>" ); |
| 1046 |
} |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
/** |
| 1051 |
* Notice wp_mail is not possible |
| 1052 |
*/ |
| 1053 |
static function wpMailNotices() { |
| 1054 |
if ( self::$wp_mail_conflict ) { |
| 1055 |
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>' ); |
| 1056 |
} |
| 1057 |
} |
| 1058 |
|
| 1059 |
/** |
| 1060 |
* Names of languages. |
| 1061 |
* |
| 1062 |
* @param string $prefix - language. |
| 1063 |
* @return mixed |
| 1064 |
*/ |
| 1065 |
public static function getLanguageName( $prefix = 'en' ) { |
| 1066 |
$lang = array(); |
| 1067 |
$lang['de'] = 'Deutsch'; |
| 1068 |
$lang['en'] = 'English'; |
| 1069 |
$lang['zh'] = '中文'; |
| 1070 |
$lang['ru'] = 'Русский'; |
| 1071 |
$lang['fi'] = 'suomi'; |
| 1072 |
$lang['fr'] = 'Français'; |
| 1073 |
$lang['nl'] = 'Nederlands'; |
| 1074 |
$lang['sv'] = 'Svenska'; |
| 1075 |
$lang['it'] = 'Italiano'; |
| 1076 |
$lang['ro'] = 'Română'; |
| 1077 |
$lang['hu'] = 'Magyar'; |
| 1078 |
$lang['ja'] = '日本語'; |
| 1079 |
$lang['es'] = 'Español'; |
| 1080 |
$lang['vi'] = 'Tiếng Việt'; |
| 1081 |
$lang['ar'] = 'العربية'; |
| 1082 |
$lang['pt'] = 'Português'; |
| 1083 |
$lang['pb'] = 'Português do Brasil'; |
| 1084 |
$lang['pl'] = 'Polski'; |
| 1085 |
$lang['gl'] = 'galego'; |
| 1086 |
$lang['tr'] = 'Turkish'; |
| 1087 |
$lang['et'] = 'Eesti'; |
| 1088 |
$lang['hr'] = 'Hrvatski'; |
| 1089 |
$lang['eu'] = 'Euskera'; |
| 1090 |
$lang['el'] = 'Ελληνικά'; |
| 1091 |
$lang['ua'] = 'Українська'; |
| 1092 |
$lang['ko'] = '한국어'; |
| 1093 |
|
| 1094 |
return $lang[ $prefix ]; |
| 1095 |
} |
| 1096 |
|
| 1097 |
/** |
| 1098 |
* Create language sidebar for wpml plugin. |
| 1099 |
*/ |
| 1100 |
public function sib_create_language_sidebar() { |
| 1101 |
$languages = apply_filters( 'wpml_active_languages', array() ); |
| 1102 |
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 1103 |
$action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 1104 |
$frmID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : ''; |
| 1105 |
$pID = isset( $_GET['pid'] ) ? sanitize_text_field( $_GET['pid'] ) : ''; |
| 1106 |
$parent = true; |
| 1107 |
if ( '' !== $frmID && '' !== $pID ) { |
| 1108 |
$lang = SIB_Forms_Lang::get_lang( $frmID, $pID ); |
| 1109 |
$parent = false; |
| 1110 |
} else { |
| 1111 |
$lang = ICL_LANGUAGE_CODE; |
| 1112 |
if ( '' !== $frmID && '' === $pID ) { |
| 1113 |
$pID = $frmID; |
| 1114 |
|
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1118 |
if ( 'sib_page_form' === $page && 'edit' === $action ) { |
| 1119 |
?> |
| 1120 |
<div class="panel panel-default text-left box-border-box small-content"> |
| 1121 |
<div class="panel-heading"><strong><?php esc_attr_e( 'About Sendinblue', 'sib_lang' ); ?></strong></div> |
| 1122 |
<div class="panel-body"> |
| 1123 |
<p> |
| 1124 |
<label for='sib_form_language'><?php esc_attr_e( 'Language of this form:', 'sib_lang' ); ?> </label> |
| 1125 |
<select id="sib_form_lang" name="sib_form_lang" data-selected=""> |
| 1126 |
<?php |
| 1127 |
foreach ( $languages as $language ) { |
| 1128 |
$selected = ($language['code'] == $lang) ? 'selected' : ''; |
| 1129 |
if ( $language['code'] == $lang && true === $parent ) { |
| 1130 |
$option_text = '<option value="" ' . $selected . '>' . $language['native_name'] . '</option>'; |
| 1131 |
} else { |
| 1132 |
$exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1133 |
|
| 1134 |
if ( null === $exist ) { |
| 1135 |
continue; |
| 1136 |
} else { |
| 1137 |
$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'] ); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
echo $option_text ; |
| 1141 |
} |
| 1142 |
?> |
| 1143 |
</select> |
| 1144 |
</p> |
| 1145 |
<div class="sib_form_translate"> |
| 1146 |
<p> |
| 1147 |
<label><?php esc_attr_e( 'Translate this form', 'sib_lang' ); ?></label> |
| 1148 |
</p> |
| 1149 |
<table width="100%" class="sib_form_trans_table" style="border: 1px solid #8cceea;"> |
| 1150 |
<tr> |
| 1151 |
<?php |
| 1152 |
foreach ( $languages as $language ) { |
| 1153 |
if ( $language['code'] == $lang ) { |
| 1154 |
continue; |
| 1155 |
} |
| 1156 |
?> |
| 1157 |
<th style="text-align: center;"><img |
| 1158 |
src="<?php echo esc_url( $language['country_flag_url'] ); ?>"></th> |
| 1159 |
<?php |
| 1160 |
} |
| 1161 |
?> |
| 1162 |
</tr> |
| 1163 |
<tr style="background-color: #EFF8FC;"> |
| 1164 |
<?php |
| 1165 |
foreach ( $languages as $language ) { |
| 1166 |
if ( $language['code'] == $lang ) { |
| 1167 |
continue; |
| 1168 |
} |
| 1169 |
if ( '' === $pID ) { |
| 1170 |
$img_src = plugins_url( 'img/add_translation_disabled.png', __FILE__ ); |
| 1171 |
$td = '<img src="' . $img_src . '" style="margin:2px;">'; |
| 1172 |
} else { |
| 1173 |
$exist = SIB_Forms_Lang::get_form_ID( $pID, $language['language_code'] ); |
| 1174 |
|
| 1175 |
if ( null === $exist ) { |
| 1176 |
$img_src = plugins_url( 'img/add_translation.png', __FILE__ ); |
| 1177 |
|
| 1178 |
$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'] ); |
| 1179 |
$td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1180 |
} else { |
| 1181 |
$img_src = plugins_url( 'img/edit_translation.png', __FILE__ ); |
| 1182 |
$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'] ); |
| 1183 |
$td = $href . '<img src="' . $img_src . '" style="margin:2px;"></a>'; |
| 1184 |
} |
| 1185 |
} |
| 1186 |
?> |
| 1187 |
<td style="text-align: center;"><?php echo $td; ?></td> |
| 1188 |
<?php |
| 1189 |
} |
| 1190 |
?> |
| 1191 |
</tr> |
| 1192 |
</table> |
| 1193 |
</div> |
| 1194 |
<?php if ( isset( $_GET['pid'] ) ) { ?> |
| 1195 |
<div class="sib-form-duplicate"> |
| 1196 |
<button class="btn btn-default sib-duplicate-btn"><?php esc_attr_e( 'Copy content from origin form', 'sib_lang' ); ?></button> |
| 1197 |
<span class="sib-spin"><i |
| 1198 |
class="fa fa-circle-o-notch fa-spin fa-lg"></i> </span> |
| 1199 |
<i title="<?php echo esc_attr_e( 'Copy content from origin form', 'sib_lang' ); ?>" |
| 1200 |
data-container="body" data-toggle="popover" data-placement="left" |
| 1201 |
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' ); ?>" |
| 1202 |
data-html="true" class="fa fa-question-circle popover-help-form"></i> |
| 1203 |
</div> |
| 1204 |
<?php } ?> |
| 1205 |
</div> |
| 1206 |
</div> |
| 1207 |
<?php |
| 1208 |
} |
| 1209 |
} |
| 1210 |
|
| 1211 |
public function ajax_get_country_prefix() { |
| 1212 |
check_ajax_referer( 'sib_front_ajax_nonce', 'security' ); |
| 1213 |
$sms_manager = new SIB_SMS_Code(); |
| 1214 |
$country_list = $sms_manager->get_sms_code_list(); |
| 1215 |
$country_list_html = ''; |
| 1216 |
foreach ( $country_list as $item => $value ) { |
| 1217 |
$flg_url = plugins_url( 'img/flags/', __FILE__ ).strtolower($item).'.png'; |
| 1218 |
$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>'; |
| 1219 |
$country_list_html .= $item_html; |
| 1220 |
} |
| 1221 |
wp_send_json($country_list_html); |
| 1222 |
} |
| 1223 |
} |
| 1224 |
|
| 1225 |
add_action( 'sendinblue_init', 'sendinblue_init' ); |
| 1226 |
add_filter( 'widget_text', 'do_shortcode' ); |
| 1227 |
|
| 1228 |
/** |
| 1229 |
* Plugin entry point Process. |
| 1230 |
*/ |
| 1231 |
function sendinblue_init() { |
| 1232 |
SIB_Manager::LoadTextDomain(); |
| 1233 |
new SIB_Manager(); |
| 1234 |
} |
| 1235 |
|
| 1236 |
do_action( 'sendinblue_init' ); |
| 1237 |
} |
| 1238 |
|