????
Current Path : C:/inetpub/vhost/webkt.nextform.vn/wp-content/plugins/echbay-facebook-messenger/ |
Current File : C:/inetpub/vhost/webkt.nextform.vn/wp-content/plugins/echbay-facebook-messenger/efm.php |
<?php /** * Plugin Name: EchBay Live Chat * Description: Add Facebook messenger box or another widget chat to your website (tawk.to, subiz.vn). Easily custom your style for chat box. * Plugin URI: https://www.facebook.com/groups/wordpresseb * Plugin Facebook page: https://www.facebook.com/webgiare.org * Author: Dao Quoc Dai * Author URI: https://www.facebook.com/ech.bay/ * Version: 1.2.7 * Text Domain: webgiareorg * Domain Path: /languages/ * License: GPLv2 or later */ if ( !defined( 'ABSPATH' ) ) { exit(); } define( 'EFM_DF_VERSION', '1.2.7' ); define( 'EFM_DF_DIR', dirname( __FILE__ ) . '/' ); define( 'EFM_THIS_PLUGIN_NAME', 'EchBay Live Chat' ); if ( !defined( 'EBP_GLOBAL_PLUGINS_SLUG_NAME' ) ) { define( 'EBP_GLOBAL_PLUGINS_SLUG_NAME', 'echbay-plugins-menu' ); define( 'EBP_GLOBAL_PLUGINS_MENU_NAME', 'Webgiare Plugins' ); define( 'EFM_ADD_TO_SUB_MENU', false ); } else { define( 'EFM_ADD_TO_SUB_MENU', true ); } if ( !class_exists( 'EFM_Actions_Module' ) ) { class EFM_Actions_Module { var $default_setting = array( 'license' => '', 'hide_powered' => 1, 'delay_time' => 3000, 'chat_with' => '', 'widget_width' => 250, 'header_bg' => '#0084FF', 'header_text' => '#FFFFFF', 'widget_position' => 'br', 'fb_page_id' => '', 'fb_customerchat_hello' => 'Hi! How can we help you?', 'fb_customerchat_lang' => '', 'fb_customerchat_theme_color' => '#0084FF', 'fb_customerchat_attribution' => 'setup_tool', 'fb_link' => '', 'fb_app_id' => '', 'zalo_id' => '', 'zalo_hello' => 'Rất vui khi được hỗ trợ bạn!', 'subiz_id' => '', 'subiz_v4_id' => '', 'tawk_id' => '', 'uhchat_id' => '', 'widget_title' => 'Support Online', 'widget_mobile_title' => 'Chat', 'custom_style' => '/* Custom CSS */', 'desktop_theme' => 'full', 'mobile_theme' => 'full', 'show_bubble' => 'no', 'bubble_bg_colors' => '#669900', 'bubble_colors' => '#FFFFFF', 'bubble_content' => 'Chat live with an agent now!', 'time_show' => 'box', 'time_out' => 'show', 'mon_time_am' => '', 'mon_time_am' => '', 'tue_time_am' => '', 'tue_time_pm' => '', 'wed_time_am' => '', 'wed_time_pm' => '', 'thu_time_am' => '', 'thu_time_pm' => '', 'fri_time_am' => '', 'fri_time_pm' => '', 'sat_time_am' => '', 'sat_time_pm' => '', 'sun_time_am' => '', 'sun_time_pm' => '', 'fbchat_content' => 'facebook' ); var $custom_setting = array(); var $eb_plugin_media_version = EFM_DF_VERSION; var $eb_plugin_prefix_option = '___efm___'; var $eb_plugin_root_dir = ''; var $gio_server = 0; var $eb_plugin_url = ''; var $eb_plugin_nonce = ''; var $eb_plugin_admin_dir = 'wp-admin'; var $web_link = ''; function load() { $this->eb_plugin_root_dir = basename( EFM_DF_DIR ); $this->eb_plugin_media_version = filemtime( EFM_DF_DIR . 'style.css' ); $this->eb_plugin_url = plugins_url() . '/' . $this->eb_plugin_root_dir . '/'; $this->eb_plugin_nonce = $this->eb_plugin_root_dir . EFM_DF_VERSION; $this->default_setting[ 'widget_height' ] = $this->default_setting[ 'widget_width' ]; if ( defined( 'WP_ADMIN_DIR' ) ) { $this->eb_plugin_admin_dir = WP_ADMIN_DIR; } $this->gio_server = current_time( 'timestamp' ); $this->get_op(); } function get_op() { global $wpdb; $pref = $this->eb_plugin_prefix_option; $sql = $wpdb->get_results( "SELECT option_name, option_value FROM `" . $wpdb->options . "` WHERE option_name LIKE '{$pref}%' ORDER BY option_id", OBJECT ); foreach ( $sql as $v ) { $this->custom_setting[ str_replace( $this->eb_plugin_prefix_option, '', $v->option_name ) ] = $v->option_value; } foreach ( $this->default_setting as $k => $v ) { if ( !isset( $this->custom_setting[ $k ] ) || $this->custom_setting[ $k ] == '' || $this->custom_setting[ $k ] == '0' ) { $this->custom_setting[ $k ] = $v; } } foreach ( $this->custom_setting as $k => $v ) { if ( $k == 'custom_style' ) { $v = esc_textarea( $v ); } else if ( $k == 'fb_link' ) { $v = esc_url( $v ); } else { $v = esc_html( $v ); } $this->custom_setting[ $k ] = $v; } if ( $this->custom_setting[ 'fb_link' ] == '' ) { } } function ck( $v1, $v2, $e = ' checked' ) { if ( $v1 == $v2 ) { return $e; } return ''; } function get_web_link() { if ( $this->web_link != '' ) { return $this->web_link; } $this->web_link = get_option( 'siteurl' ); $this->web_link = explode( '/', $this->web_link ); $this->web_link[ 2 ] = $_SERVER[ 'HTTP_HOST' ]; $this->web_link = implode( '/', $this->web_link ); if ( substr( $this->web_link, -1 ) == '/' ) { $this->web_link = substr( $this->web_link, 0, -1 ); } return $this->web_link; } function update() { if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' && isset( $_POST[ '_ebnonce' ] ) ) { if ( !wp_verify_nonce( $_POST[ '_ebnonce' ], $this->eb_plugin_nonce ) ) { wp_die( '404 not found!' ); } foreach ( $_POST as $k => $v ) { if ( substr( $k, 0, 5 ) == '_efm_' ) { $key = $this->eb_plugin_prefix_option . substr( $k, 5 ); if ( $k == '_efm_widget_width' || $k == '_efm_widget_height' ) { $v = ( int )$v; } else { $v = stripslashes( stripslashes( stripslashes( $v ) ) ); $v = strip_tags( $v ); $v = sanitize_text_field( $v ); } delete_option( $key ); add_option( $key, $v, '', 'no' ); } } die( '<script> try { if ( top != self && typeof top.a_lert == "function" ) { top.a_lert("Update done!"); } else { alert("Update done!"); } } catch (e) { alert("Update done!"); } </script>' ); } } function admin() { $arr_position = array( "tr" => 'Top Right', "tl" => 'Top Left', "br" => 'Bottom Right', "bl" => 'Bottom Left' ); $str_position = ''; foreach ( $arr_position as $k => $v ) { $str_position .= '<option value="' . $k . '"' . $this->ck( $this->custom_setting[ 'widget_position' ], $k, ' selected' ) . '>' . $v . '</option>'; } $this->eb_plugin_media_version = $this->gio_server; $this->get_web_link(); if ( $this->custom_setting[ 'fb_customerchat_lang' ] == '' ) { $a = get_option( 'WPLANG' ); if ( $a == 'vi' ) { $a = 'vi_VN'; } else if ( $a == '' ) { $a = 'en_US'; } $this->custom_setting[ 'fb_customerchat_lang' ] = $a; } $main = file_get_contents( EFM_DF_DIR . 'admin.html', 1 ); $main = $this->template( $main, $this->custom_setting + array( '_ebnonce' => wp_create_nonce( $this->eb_plugin_nonce ), 'str_position' => $str_position, 'wplang' => get_option( 'WPLANG' ), 'min_desktop_widget' => $this->ck( $this->custom_setting[ 'desktop_theme' ], 'min' ), 'full_desktop_widget' => $this->ck( $this->custom_setting[ 'desktop_theme' ], 'full' ), 'min_mobile_widget' => $this->ck( $this->custom_setting[ 'mobile_theme' ], 'min' ), 'full_mobile_widget' => $this->ck( $this->custom_setting[ 'mobile_theme' ], 'full' ), 'check_show_bubble' => $this->ck( $this->custom_setting[ 'show_bubble' ], 'no' ), 'box_time_show' => $this->ck( $this->custom_setting[ 'time_show' ], 'box' ), 'time_time_show' => $this->ck( $this->custom_setting[ 'time_show' ], 'time' ), 'form_time_show' => $this->ck( $this->custom_setting[ 'time_show' ], 'form' ), 'show_time_out' => $this->ck( $this->custom_setting[ 'time_out' ], 'show' ), 'hide_time_out' => $this->ck( $this->custom_setting[ 'time_out' ], 'hide' ), 'efm_plugin_url' => $this->eb_plugin_url, 'efm_plugin_version' => $this->eb_plugin_media_version, ) ); $main = $this->template( $main, $this->default_setting, 'aaa' ); echo $main; echo '<p>* Other <a href="' . $this->web_link . '/' . $this->eb_plugin_admin_dir . '/plugin-install.php?s=itvn9online&tab=search&type=author" target="_blank">WordPress Plugins</a> written by the same author. Thanks for choose us!</p>'; } function deline( $str, $reg = "/\r\n|\n\r|\n|\r|\t/i", $re = "" ) { $a = explode( "\n", $str ); $str = ''; foreach ( $a as $v ) { $v = trim( $v ); if ( $v != '' ) { if ( strstr( $v, '//' ) == true ) { $v .= "\n"; } $str .= $v; } } return $str; return preg_replace( $reg, $re, $str ); } function time_delay( $str, $script_name = '', $script_var = '' ) { echo $this->deline( trim( ' <!-- Start of ' . $script_name . ' Script (by ' . EFM_THIS_PLUGIN_NAME . ') --> <script>var EFM_time_for_delay=' . $this->custom_setting[ 'delay_time' ] . ';</script> <script src="' . $this->eb_plugin_url . $str . '.js?v=' . $this->eb_plugin_media_version . '" defer></script> <!-- End of ' . $script_name . ' Script --> ' ) ); } function guest() { if ( $this->custom_setting[ 'chat_with' ] == '' ) { if ( $this->custom_setting[ 'zalo_id' ] != '' && substr( $this->custom_setting[ 'zalo_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'zalo'; } else if ( $this->custom_setting[ 'subiz_id' ] != '' && substr( $this->custom_setting[ 'subiz_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'subiz'; } else if ( $this->custom_setting[ 'subiz_v4_id' ] != '' && substr( $this->custom_setting[ 'subiz_v4_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'subiz'; } else if ( $this->custom_setting[ 'tawk_id' ] != '' && substr( $this->custom_setting[ 'tawk_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'tawk'; } else if ( $this->custom_setting[ 'uhchat_id' ] != '' && substr( $this->custom_setting[ 'uhchat_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'uhchat'; } else if ( $this->custom_setting[ 'fb_page_id' ] != '' && substr( $this->custom_setting[ 'fb_page_id' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'customerchat'; } else if ( $this->custom_setting[ 'fb_link' ] != '' && substr( $this->custom_setting[ 'fb_link' ], 0, 1 ) != '#' ) { $this->custom_setting[ 'chat_with' ] = 'facebook'; } else { echo '<!-- ' . EFM_THIS_PLUGIN_NAME . ' has been active, but data widget is NULL (v1) -->'; return false; } } if ( $this->custom_setting[ 'chat_with' ] == 'customerchat' && $this->custom_setting[ 'fb_page_id' ] != '' ) { if ( $this->custom_setting[ 'fb_customerchat_lang' ] == '' ) { $a = get_option( 'WPLANG' ); if ( $a == 'vi' ) { $a = 'vi_VN'; } else if ( $a == '' ) { $a = 'en_US'; } $this->custom_setting[ 'fb_customerchat_lang' ] = $a; } $html = file_get_contents( __DIR__ . '/fb-customerchat-20210907.html', 1 ); $html = str_replace( '%js_code%', file_get_contents( __DIR__ . '/fb-customerchat-20210907.js', 1 ), $html ); $arr = [ 'fb_customerchat_lang' => $this->custom_setting[ 'fb_customerchat_lang' ], 'fb_page_id' => $this->custom_setting[ 'fb_page_id' ], 'fb_customerchat_theme_color' => $this->custom_setting[ 'fb_customerchat_theme_color' ], 'fb_customerchat_attribution' => $this->custom_setting[ 'fb_customerchat_attribution' ], 'fb_customerchat_hello' => $this->custom_setting[ 'fb_customerchat_hello' ], ]; foreach ( $arr as $k => $v ) { $html = str_replace( '%' . $k . '%', $v, $html ); } echo $html; return true; echo '<script>if ( document.getElementById("fb-root") == null ) document.write(\'<div id="fb-root"></div>\'); window.fbAsyncInit = function() { FB.init({ xfbml : true, version : \'v9.0\' }); }; (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "https://connect.facebook.net/' . $this->custom_setting[ 'fb_customerchat_lang' ] . '/sdk/xfbml.customerchat.js"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));</script> <div class="fb-customerchat" attribution=setup_tool page_id="' . $this->custom_setting[ 'fb_page_id' ] . '" theme_color="' . $this->custom_setting[ 'fb_customerchat_theme_color' ] . '" greeting_dialog_display="show" greeting_dialog_delay=0 logged_in_greeting="' . $this->custom_setting[ 'fb_customerchat_hello' ] . '" logged_out_greeting="' . $this->custom_setting[ 'fb_customerchat_hello' ] . '"> </div>'; return true; } else if ( $this->custom_setting[ 'chat_with' ] == 'zalo' && $this->custom_setting[ 'zalo_id' ] != '' ) { $autopopup = ceil( $this->custom_setting[ 'delay_time' ] / 1000 ); echo '<div class="zalo-chat-widget" data-oaid="' . $this->custom_setting[ 'zalo_id' ] . '" data-welcome-message="' . $this->custom_setting[ 'zalo_hello' ] . '" data-autopopup="' . $autopopup . '" data-width="' . $this->custom_setting[ 'widget_width' ] . '" data-height="' . $this->custom_setting[ 'widget_height' ] . '"></div> <script src="https://sp.zalo.me/plugins/sdk.js"></script>'; return true; } else if ( $this->custom_setting[ 'chat_with' ] == 'subiz' ) { if ( $this->custom_setting[ 'subiz_v4_id' ] != '' && substr( $this->custom_setting[ 'subiz_v4_id' ], 0, 1 ) != '#' ) { echo '<script>var EFM_subiz_v4_id="' . $this->custom_setting[ 'subiz_v4_id' ] . '";</script>'; $this->time_delay( 'js_subiz', 'SuBiz.com' ); return true; } else if ( $this->custom_setting[ 'subiz_id' ] != '' && substr( $this->custom_setting[ 'subiz_id' ], 0, 1 ) != '#' ) { echo '<script>var EFM_subiz_account_id="' . $this->custom_setting[ 'subiz_id' ] . '";</script>'; $this->time_delay( 'js_subiz', 'SuBiz.com' ); return true; } } else if ( $this->custom_setting[ 'chat_with' ] == 'tawk' && $this->custom_setting[ 'tawk_id' ] != '' ) { echo '<script>var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(), EFM_tawk_account_id="' . $this->custom_setting[ 'tawk_id' ] . '";</script>'; $this->time_delay( 'js_tawk', 'Tawk.to', '' ); return true; } else if ( $this->custom_setting[ 'chat_with' ] == 'uhchat' && $this->custom_setting[ 'uhchat_id' ] != '' ) { echo '<script src="https://uhchat.net/code.php?f=' . $this->custom_setting[ 'uhchat_id' ] . '"></script>'; return true; } else if ( $this->custom_setting[ 'chat_with' ] != 'facebook' ) { echo '<!-- ' . EFM_THIS_PLUGIN_NAME . ' has been active (' . $this->custom_setting[ 'chat_with' ] . '), but data widget is NULL -->'; return false; } $efm_custom_css = str_replace( ';}', '}', $this->deline( trim( ' #echbay_fb_ms, #echbay_fb_ms .echbay-fbchat-2title { /* max-width: ' . $this->custom_setting[ 'widget_width' ] . 'px; */ width: ' . $this->custom_setting[ 'widget_width' ] . 'px; } #echbay_fb_ms .echbay-fbchat-text-title, #echbay_fb_ms .echbay-fbchat-mobile-title { background-color: ' . $this->custom_setting[ 'header_bg' ] . '; color: ' . $this->custom_setting[ 'header_text' ] . '; } #echbay_fb_ms .eb-facebook-square, #echbay_fb_ms .eb-chat-square { color: ' . $this->custom_setting[ 'header_bg' ] . '; background-color: ' . $this->custom_setting[ 'header_text' ] . '; } #echbay_fb_ms.echbay-fbchat-active .echbay-fbchat-content { height: ' . $this->custom_setting[ 'widget_height' ] . 'px; } ' ) ) ) . trim( $this->custom_setting[ 'custom_style' ] ); $main = file_get_contents( EFM_DF_DIR . 'guest.html', 1 ); $form = file_get_contents( EFM_DF_DIR . $this->custom_setting[ 'fbchat_content' ] . '.html', 1 ); $main = $this->template( $main, array( 'html_fbchat_content' => $form, ) ); $me_link = $this->custom_setting[ 'fb_link' ]; $me_link = str_replace( '/www.facebook.com/', '/m.me/', $me_link ); $me_link = str_replace( '/facebook.com/', '/m.me/', $me_link ); echo '<script>var EFM_custom_fb_app_id="' . $this->custom_setting[ 'fb_app_id' ] . '";</script>'; echo $this->template( $main, $this->custom_setting + array( 'me_link' => $me_link, 'bloginfo_name' => get_bloginfo( 'name' ), 'efm_custom_css' => '<style type="text/css">' . $efm_custom_css . '</style>', 'efm_plugin_url' => $this->eb_plugin_url, 'efm_plugin_version' => $this->eb_plugin_media_version, ) ); } function template( $temp, $val = array(), $tmp = 'tmp' ) { foreach ( $val as $k => $v ) { $temp = str_replace( '{' . $tmp . '.' . $k . '}', $v, $temp ); } return $temp; } } } function EFM_show_setting_form_in_admin() { global $EFM_func; $EFM_func->update(); $EFM_func->admin(); } function EFM_add_menu_setting_to_admin_menu() { if ( !current_user_can( 'manage_options' ) ) { return false; } $a = EFM_THIS_PLUGIN_NAME; if ( EFM_ADD_TO_SUB_MENU == false ) { add_menu_page( $a, EBP_GLOBAL_PLUGINS_MENU_NAME, 'manage_options', EBP_GLOBAL_PLUGINS_SLUG_NAME, 'EFM_show_setting_form_in_admin', NULL, 99 ); } add_submenu_page( EBP_GLOBAL_PLUGINS_SLUG_NAME, $a, trim( str_replace( 'EchBay', '', $a ) ), 'manage_options', strtolower( str_replace( ' ', '-', $a ) ), 'EFM_show_setting_form_in_admin' ); } function EFM_show_facebook_messenger_box_in_site() { global $EFM_func; echo '<!-- ' . EFM_THIS_PLUGIN_NAME . ' -->'; $EFM_func->guest(); echo '<!-- END ' . EFM_THIS_PLUGIN_NAME . ' -->'; } function EFM_plugin_settings_link( $links ) { $settings_link = '<a href="admin.php?page=' . strtolower( str_replace( ' ', '-', EFM_THIS_PLUGIN_NAME ) ) . '">Settings</a>'; array_unshift( $links, $settings_link ); return $links; } $EFM_func = new EFM_Actions_Module(); $EFM_func->load(); if ( is_admin() ) { add_action( 'admin_menu', 'EFM_add_menu_setting_to_admin_menu' ); if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/plugins.php' ) !== false ) { $plugin = plugin_basename( __FILE__ ); add_filter( "plugin_action_links_$plugin", 'EFM_plugin_settings_link' ); } } else { add_action( 'wp_footer', 'EFM_show_facebook_messenger_box_in_site' ); }