chaty
Last commit date
admin
1 day ago
css
1 month ago
images
1 year ago
includes
1 day ago
js
2 months ago
languages
1 day ago
views
1 day ago
cht-icons.php
1 day ago
readme.txt
1 day ago
cht-icons.php
237 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Chaty |
| 4 | Contributors: galdub, tomeraharon |
| 5 | Description: Chat with your website visitors via their favorite channels. Show a chat icon on the bottom of your site and communicate with your website visitors. |
| 6 | Author: Premio |
| 7 | Author URI: https://premio.io/downloads/chaty/ |
| 8 | Text Domain: chaty |
| 9 | Domain Path: /languages |
| 10 | Version: 3.5.7 |
| 11 | License: GPLv3 |
| 12 | */ |
| 13 | |
| 14 | if (!defined('ABSPATH')) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | |
| 19 | define('CHT_FILE', __FILE__); // this file |
| 20 | if(!defined('CHT_OPT')) { |
| 21 | define('CHT_OPT', 'chaty'); |
| 22 | } |
| 23 | define('CHT_DIR', dirname(CHT_FILE)); // our directory |
| 24 | define('CHT_ADMIN_INC', CHT_DIR . '/admin'); |
| 25 | define('CHT_FRONT_INC', CHT_DIR . '/frontend'); |
| 26 | define('CHT_INC', CHT_DIR . '/includes'); |
| 27 | define('CHT_PRO_URL', admin_url("admin.php?page=chaty-app-upgrade")); |
| 28 | define('CHT_PLUGIN_URL', plugin_dir_url(__FILE__)); |
| 29 | define('CHT_PLUGIN_BASE', plugin_basename(CHT_FILE)); |
| 30 | define('CHT_VERSION', "3.5.7"); |
| 31 | if(!defined('CHT_DEV_MODE')) { |
| 32 | define('CHT_DEV_MODE', false); |
| 33 | } |
| 34 | if (!function_exists('wp_doing_ajax')) { |
| 35 | function wp_doing_ajax() |
| 36 | { |
| 37 | /** |
| 38 | * Filters whether the current request is a WordPress Ajax request. |
| 39 | * |
| 40 | * @since 4.7.0 |
| 41 | * |
| 42 | * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. |
| 43 | */ |
| 44 | return apply_filters('wp_doing_ajax', defined('DOING_AJAX') && DOING_AJAX); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if(!function_exists("cht_clear_all_caches")) { |
| 49 | function cht_clear_all_caches() |
| 50 | { |
| 51 | /* Clear cookies from browser */ |
| 52 | if (isset($_COOKIE['chaty_settings'])) { |
| 53 | setcookie("chaty_settings", '', time() - 3600, "/"); |
| 54 | setcookie("cta_exit_intent_shown", '', time() - 3600, "/"); |
| 55 | } |
| 56 | if(isset($_COOKIE['chatyWidget_0'])) { |
| 57 | setcookie("chatyWidget_0", '', time() - 3600, "/"); |
| 58 | } |
| 59 | for($i=1; $i<=20; $i++) { |
| 60 | if(isset($_COOKIE['chatyWidget__'.$i])) { |
| 61 | setcookie('chatyWidget__'.$i, '', time() - 3600, "/"); |
| 62 | } |
| 63 | } |
| 64 | try { |
| 65 | global $wp_fastest_cache; |
| 66 | // if W3 Total Cache is being used, clear the cache |
| 67 | if (function_exists('w3tc_flush_all')) { |
| 68 | w3tc_flush_all(); |
| 69 | |
| 70 | } |
| 71 | /* if WP Super Cache is being used, clear the cache */ |
| 72 | if (function_exists('wp_cache_clean_cache')) { |
| 73 | global $file_prefix, $supercachedir; |
| 74 | if (empty($supercachedir) && function_exists('get_supercache_dir')) { |
| 75 | $supercachedir = get_supercache_dir(); |
| 76 | } |
| 77 | wp_cache_clean_cache($file_prefix); |
| 78 | } |
| 79 | if (class_exists('WpeCommon')) { |
| 80 | //be extra careful, just in case 3rd party changes things on us |
| 81 | if (method_exists('WpeCommon', 'purge_memcached')) { |
| 82 | //WpeCommon::purge_memcached(); |
| 83 | } |
| 84 | if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { |
| 85 | //WpeCommon::clear_maxcdn_cache(); |
| 86 | } |
| 87 | if (method_exists('WpeCommon', 'purge_varnish_cache')) { |
| 88 | //WpeCommon::purge_varnish_cache(); |
| 89 | } |
| 90 | } |
| 91 | /* WP Fastest Cache Plugin */ |
| 92 | if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) { |
| 93 | $wp_fastest_cache->deleteCache(); |
| 94 | } |
| 95 | /* WP Rocket Plugin */ |
| 96 | if (function_exists('rocket_clean_domain')) { |
| 97 | rocket_clean_domain(); |
| 98 | // Preload cache. |
| 99 | if (function_exists('run_rocket_sitemap_preload')) { |
| 100 | run_rocket_sitemap_preload(); |
| 101 | } |
| 102 | } |
| 103 | /* Autoptimize Cache Plugin */ |
| 104 | if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall")) { |
| 105 | autoptimizeCache::clearall(); |
| 106 | } |
| 107 | /* LiteSpeed Plugin */ |
| 108 | if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all")) { |
| 109 | LiteSpeed_Cache_API::purge_all(); |
| 110 | } |
| 111 | /* Breeze Plugin */ |
| 112 | if (class_exists("Breeze_PurgeCache") && method_exists("Breeze_PurgeCache", "breeze_cache_flush")) { |
| 113 | Breeze_PurgeCache::breeze_cache_flush(); |
| 114 | } |
| 115 | /* Hummingbird */ |
| 116 | if (class_exists( '\Hummingbird\Core\Utils' ) ) { |
| 117 | $modules = \Hummingbird\Core\Utils::get_active_cache_modules(); |
| 118 | foreach ( $modules as $module => $name ) { |
| 119 | $mod = \Hummingbird\Core\Utils::get_module( $module ); |
| 120 | if ( $mod->is_active() ) { |
| 121 | if ( 'minify' === $module ) { |
| 122 | $mod->clear_files(); |
| 123 | } else { |
| 124 | $mod->clear_cache(); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | /* WP Total Cache */ |
| 130 | if ( function_exists( 'wp_cache_clean_cache' ) ) { |
| 131 | global $file_prefix; |
| 132 | wp_cache_clean_cache( $file_prefix, true ); |
| 133 | } |
| 134 | } catch (Exception $e) { |
| 135 | return 1; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | if(!function_exists("cht_init")) { |
| 140 | function cht_init() { |
| 141 | if(is_admin()) { |
| 142 | require_once CHT_ADMIN_INC . '/chaty-timezone.php'; |
| 143 | require_once CHT_INC . '/class-review-box.php'; |
| 144 | require_once CHT_INC . '/class-upgrade-box.php'; |
| 145 | require_once CHT_INC . '/class-email-signup.php'; |
| 146 | } |
| 147 | require_once CHT_INC . '/class-cht-icons.php'; |
| 148 | require_once CHT_INC . '/class-frontend.php'; |
| 149 | } |
| 150 | add_action( 'init' , 'cht_init' ); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | add_action('activated_plugin', 'cht_activation_redirect'); |
| 155 | |
| 156 | register_activation_hook(CHT_FILE, 'cht_install', 10); |
| 157 | |
| 158 | function cht_install() |
| 159 | { |
| 160 | $widgetSize = get_option('cht_numb_slug'); |
| 161 | $cht_devices = get_option('cht_devices'); |
| 162 | |
| 163 | if (empty($widgetSize) && empty($cht_devices)) { |
| 164 | $options = array( |
| 165 | 'mobile' => '1', |
| 166 | 'desktop' => '1', |
| 167 | ); |
| 168 | |
| 169 | update_option('cht_created_on', gmdate("Y-m-d")); |
| 170 | update_option('cht_devices', $options); |
| 171 | update_option('cht_position', 'right'); |
| 172 | update_option('cht_cta', 'Contact us'); |
| 173 | update_option('cht_numb_slug', ',Phone,Whatsapp'); |
| 174 | update_option('cht_social_whatsapp', ''); |
| 175 | update_option('cht_social_phone', ''); |
| 176 | update_option('cht_widget_size', '54'); |
| 177 | update_option('widget_icon', 'chat-base'); |
| 178 | update_option('cht_widget_img', ''); |
| 179 | update_option('cht_color', '#A886CD'); |
| 180 | } |
| 181 | |
| 182 | $popup_status = get_option("chaty_intro_popup"); |
| 183 | if($popup_status === false || empty($popup_status)) { |
| 184 | add_option("chaty_intro_popup", "show"); |
| 185 | } |
| 186 | |
| 187 | $option = get_option("Chaty_show_affiliate_box_after"); |
| 188 | if($option === false || empty($option)) { |
| 189 | $date = gmdate("Y-m-d", strtotime("+5 days")); |
| 190 | add_option("Chaty_show_affiliate_box_after", $date); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | function cht_activation_redirect($plugin) |
| 195 | { |
| 196 | if ($plugin == plugin_basename(__FILE__)) { |
| 197 | if (!defined("DOING_AJAX") && $plugin == plugin_basename(__FILE__)) { |
| 198 | delete_option("cht_redirect"); |
| 199 | add_option("cht_redirect",1); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | function chaty_plugin_check_db_table() { |
| 205 | global $wpdb, $pagenow; |
| 206 | $page = filter_input(INPUT_GET, 'page'); |
| 207 | if ($pagenow == 'plugins.php' || ($page == 'chaty-app' || $page == 'chaty-upgrade' || $page == 'widget-analytics' || $page == 'chaty-contact-form-feed')) { |
| 208 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 209 | $charset_collate = $wpdb->get_charset_collate(); |
| 210 | $chaty_table = $wpdb->prefix . 'chaty_contact_form_leads'; |
| 211 | $query = "SHOW TABLES LIKE '".esc_sql($chaty_table)."'"; |
| 212 | if ($wpdb->get_var($query) != $chaty_table) { |
| 213 | $chaty_table_settings = "CREATE TABLE {$chaty_table} ( |
| 214 | id bigint(11) NOT NULL AUTO_INCREMENT, |
| 215 | widget_id int(11) NULL, |
| 216 | name varchar(100) NULL, |
| 217 | email varchar(100) NULL, |
| 218 | phone_number varchar(100) NULL, |
| 219 | message text NULL, |
| 220 | ref_page text NULL, |
| 221 | ip_address tinytext NULL, |
| 222 | created_on datetime, |
| 223 | PRIMARY KEY (id) |
| 224 | ) $charset_collate;"; |
| 225 | dbDelta($chaty_table_settings); |
| 226 | } |
| 227 | |
| 228 | /* version 2.7.3 change added new column */ |
| 229 | $column_name = 'phone_number'; |
| 230 | $field_check = $wpdb->get_var($wpdb->prepare("SHOW COLUMNS FROM {$chaty_table} LIKE %s", $column_name)); |
| 231 | if ('phone_number' != $field_check) { |
| 232 | $wpdb->query("ALTER TABLE {$chaty_table} ADD phone_number VARCHAR(100) NULL DEFAULT NULL AFTER email"); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | add_action( 'admin_init' , 'chaty_plugin_check_db_table' ); |
| 237 |