Changeset 2011966
- Timestamp:
- 01/14/2019 11:35:39 AM (6 years ago)
- Location:
- tidio-live-chat/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tidio-live-chat/trunk/readme.txt
r1987129 r2011966 11 11 12 12 == Description == 13 13 14 14 Tidio Live Chat is a live chat service which allows you to communicate with your customers easily, also with the help of chatbots. It is designed specifically for the WordPress community. Once you install the plugin, you will be ready to take full advantage of the benefits our service provides. **A free plan is available!** 15 15 … … 103 103 104 104 = Can I install TidioChat on my plain html site? = 105 Yes you can 105 Yes you can 106 106 107 107 = Is it possible to initiate a conversation before the visitor does? = … … 122 122 == Changelog == 123 123 124 = 3.4.0 = 125 * Add asynchronous loading of chat widget option 126 * Code cleanup 127 124 128 = 3.3.2 = 125 129 * Change of the widget script placement in Wordpress themes to improve the rendering performance. 126 130 * Use admin email as a default email for a Tidio account. 127 131 132 = 3.3.2 = 133 * Change of the widget script placement in Wordpress themes to improve the rendering performance. 134 * Use admin email as a default email for a Tidio account. 135 128 136 = 3.3.1 = 129 137 * Refreshed texts within the plugin to be more intuitive. … … 142 150 * Cleanup with changes after last modifications. 143 151 144 = 3.0.1 = 152 = 3.0.1 = 145 153 * (added) curl support 146 154 147 = 3.0 = 155 = 3.0 = 148 156 * (added) new design 149 157 * (added) integration with tidio chat account 150 158 151 = 2.1.2 = 159 = 2.1.2 = 152 160 * (added) compatibility with other tidio plugins 153 161 154 = 2.1 = 162 = 2.1 = 155 163 * (added) compatibility with tidio one api 156 164 157 = 2.0.5 = 165 = 2.0.5 = 158 166 * (added) compatibility with tidio one 159 167 160 168 = 2.0.2 = 161 * (added) support to sites with disabled allow_url_fopen flag 169 * (added) support to sites with disabled allow_url_fopen flag 162 170 163 171 = 2.0.1 = -
tidio-live-chat/trunk/tidio-elements.php
r1929077 r2011966 5 5 * Plugin URI: http://www.tidiochat.com 6 6 * Description: Tidio Live Chat - Live chat for your website. No logging in, no signing up - integrates with your website in less than 20 seconds. 7 * Version: 3. 3.37 * Version: 3.4.0 8 8 * Author: Tidio Ltd. 9 9 * Author URI: http://www.tidiochat.com 10 10 * License: GPL2 11 11 */ 12 define('TIDIOCHAT_VERSION', '3.3.3'); 13 14 class TidioLiveChat { 15 16 private $scriptUrl = '//code.tidio.co/'; 17 private static $apiUrl = 'https://api-v2.tidio.co'; 18 private static $chatUrl = 'https://www.tidiochat.com'; 19 20 public function __construct() { 21 12 define('TIDIOCHAT_VERSION', '3.4.0'); 13 14 class TidioLiveChat 15 { 16 const SCRIPT_URL = '//code.tidio.co/'; 17 const API_URL = 'https://api-v2.tidio.co'; 18 const CHAT_URL = 'https://www.tidiochat.com'; 19 const PUBLIC_KEY_OPTION = 'tidio-one-public-key'; 20 const PRIVATE_KEY_OPTION = 'tidio-one-private-key'; 21 const ASYNC_LOAD_OPTION = 'tidio-async-load'; 22 const CLEAR_ACCOUNT_DATA_ACTION = 'tidio-chat-reset'; 23 const TIDIO_PLUGIN_NAME = 'tidio-live-chat'; 24 const TOGGLE_ASYNC_ACTION = 'tidio-chat-toggle-async'; 25 26 public function __construct() 27 { 22 28 if (!empty($_GET['tidio_chat_version'])) { 23 29 echo TIDIOCHAT_VERSION; … … 26 32 27 33 /* Before add link to menu - check is user trying to unninstal */ 28 if (is_admin() && !empty($_GET['tidio_one_clear_cache'])) { 29 delete_option('tidio-one-public-key'); 30 delete_option('tidio-one-private-key'); 31 } 32 33 add_action('admin_menu', array($this, 'addAdminMenuLink')); 34 35 if(get_option('tidio-one-public-key')){ 34 if (is_admin() && current_user_can('activate_plugins') && !empty($_GET['tidio_one_clear_cache'])) { 35 delete_option(TidioLiveChat::PUBLIC_KEY_OPTION); 36 delete_option(TidioLiveChat::PRIVATE_KEY_OPTION); 37 } 38 39 if (get_option(TidioLiveChat::PUBLIC_KEY_OPTION)) { 36 40 add_action('admin_footer', array($this, 'adminJS')); 37 41 } 38 42 39 43 if (!is_admin()) { 40 add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'), 1000); 41 }else{ 44 if (get_option(TidioLiveChat::ASYNC_LOAD_OPTION)) { 45 add_action('wp_footer', array($this, 'enqueueScriptsAsync'), PHP_INT_MAX); 46 } else { 47 add_action('wp_enqueue_scripts', array($this, 'enqueueScriptsSync'), 1000); 48 } 49 } else if (current_user_can('activate_plugins')) { 50 add_action('admin_menu', array($this, 'addAdminMenuLink')); 42 51 add_action('admin_enqueue_scripts', array($this, 'enqueueAdminScripts')); 43 } 44 45 add_action('wp_ajax_tidio_chat_save_keys', array($this, 'ajaxTidioChatSaveKeys')); 46 47 /* Ajax functions to set up existing tidio account */ 48 add_action('wp_ajax_get_project_keys', array($this, 'ajaxGetProjectKeys')); 49 add_action('wp_ajax_get_private_key', array($this, 'ajaxGetPrivateKey')); 50 51 add_filter('plugin_action_links', array($this, 'pluginActionLinks'), 10, 2); 52 add_action('admin_post_tidio-chat-reset', array($this, 'uninstall')); 53 } 54 55 public function pluginActionLinks($links, $file) { 56 if (strpos($file, 'tidio-elements.php') !== false && get_option('tidio-one-private-key')) { 57 $links[] = '<a href="'.admin_url('admin-post.php').'?action=tidio-chat-reset">'.esc_html__( 'Clear Account Data' , 'tidio-live-chat').'</a>'; 58 } 59 60 return $links; 61 } 62 63 public function ajaxGetProjectKeys(){ 64 update_option('tidio-one-public-key', $_POST['public_key']); 65 update_option('tidio-one-private-key', $_POST['private_key']); 66 echo self::getRedirectUrl($_POST['private_key']); 52 53 add_action('wp_ajax_tidio_chat_save_keys', array($this, 'ajaxTidioChatSaveKeys')); 54 add_action('wp_ajax_get_project_keys', array($this, 'ajaxGetProjectKeys')); 55 add_action('wp_ajax_get_private_key', array($this, 'ajaxGetPrivateKey')); 56 57 add_action('admin_post_' . TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION . '', array($this, 'uninstall')); 58 add_action('admin_post_' . TidioLiveChat::TOGGLE_ASYNC_ACTION . '', array($this, 'toggleAsync')); 59 60 add_filter('plugin_action_links', array($this, 'pluginActionLinks'), 10, 2); 61 } 62 } 63 64 public static function activate() 65 { 66 update_option(TidioLiveChat::ASYNC_LOAD_OPTION, true); 67 } 68 69 public static function ajaxGetPrivateKey() 70 { 71 $privateKey = TidioLiveChat::getPrivateKey(); 72 if (!$privateKey || $privateKey == 'false') { 73 echo 'error'; 74 exit(); 75 } 76 echo TidioLiveChat::getRedirectUrl($privateKey); 67 77 exit(); 68 78 } 69 79 70 // Ajax - Create an new project 71 72 public function ajaxTidioChatSaveKeys() { 73 74 if (!is_admin()) { 75 exit; 76 } 77 78 if (empty($_POST['private_key']) || empty($_POST['public_key'])) { 79 exit; 80 } 81 82 update_option('tidio-one-public-key', $_POST['public_key']); 83 update_option('tidio-one-private-key', $_POST['private_key']); 84 85 echo '1'; 86 exit; 87 } 88 89 // Front End Scripts 90 public function enqueueScripts() { 91 wp_enqueue_script('tidio-chat', $this->scriptUrl . self::getPublicKey() . '.js', array(), TIDIOCHAT_VERSION, true); 92 } 93 94 // Admin scripts and style enquee 95 public function enqueueAdminScripts(){ 96 wp_enqueue_script('tidio-chat-admin', plugins_url('media/js/options.js', __FILE__), array(), TIDIOCHAT_VERSION, true); 97 wp_enqueue_style('tidio-chat-admin-style', plugins_url('media/css/options.css', __FILE__), array(), TIDIOCHAT_VERSION); 98 } 99 100 // Admin JavaScript 101 public function adminJS() { 102 $privateKey = self::getPrivateKey(); 103 $redirectUrl = ''; 104 105 if ($privateKey && $privateKey != 'false') { 106 $redirectUrl = self::getRedirectUrl($privateKey); 107 } else { 108 $redirectUrl = admin_url('admin-ajax.php?action=tidio_chat_redirect'); 109 } 110 111 echo "<script>jQuery('a[href=\"admin.php?page=tidio-chat\"]').attr('href', '" . $redirectUrl . "').attr('target', '_blank') </script>"; 112 } 113 114 // Menu Pages 115 116 public function addAdminMenuLink() { 117 $optionPage = add_menu_page( 118 'Tidio Chat', 'Tidio Chat', 'manage_options', 'tidio-chat', array($this, 'addAdminPage'), content_url() . '/plugins/tidio-live-chat/media/img/icon.png' 119 ); 120 } 121 122 public function addAdminPage() { 123 // Set class property 124 $dir = plugin_dir_path(__FILE__); 125 include $dir . 'options.php'; 126 } 127 128 // Uninstall 129 130 public function uninstall() { 131 delete_option('tidio-one-public-key'); 132 delete_option('tidio-one-private-key'); 133 wp_redirect( admin_url('plugins.php') ); 134 die(); 135 } 136 137 // Get Private Key 138 139 public static function getPrivateKey() { 140 self::syncPrivateKey(); 141 142 $privateKey = get_option('tidio-one-private-key'); 80 public static function getPrivateKey() 81 { 82 TidioLiveChat::syncPrivateKey(); 83 84 $privateKey = get_option(TidioLiveChat::PRIVATE_KEY_OPTION); 143 85 144 86 if ($privateKey) { … … 147 89 148 90 try { 149 $data = self::getContent(self::getAccessUrl());150 } catch (Exception $e){91 $data = TidioLiveChat::getContent(TidioLiveChat::getAccessUrl()); 92 } catch (Exception $e) { 151 93 $data = null; 152 94 } 153 95 // 154 96 if (!$data) { 155 update_option( 'tidio-one-private-key', 'false');97 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, 'false'); 156 98 return false; 157 99 } … … 159 101 @$data = json_decode($data, true); 160 102 if (!$data || !$data['status']) { 161 update_option( 'tidio-one-private-key', 'false');103 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, 'false'); 162 104 return false; 163 105 } 164 106 165 update_option('tidio-one-private-key', $data['value']['private_key']); 166 update_option('tidio-one-public-key', $data['value']['public_key']); 107 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $data['value']['private_key']); 108 update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $data['value']['public_key']); 109 update_option(TidioLiveChat::ASYNC_LOAD_OPTION, true); 167 110 168 111 return $data['value']['private_key']; 169 112 } 170 113 171 public static function getContent($url){ 172 173 if(function_exists('curl_version')){ // load trought curl 114 public static function syncPrivateKey() 115 { 116 if (get_option(TidioLiveChat::PUBLIC_KEY_OPTION)) { 117 return false; 118 } 119 120 $publicKey = get_option('tidio-chat-external-public-key'); 121 $privateKey = get_option('tidio-chat-external-private-key'); 122 123 if (!$publicKey || !$privateKey) { 124 return false; 125 } 126 127 // sync old variables with new one 128 129 update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $publicKey); 130 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $privateKey); 131 132 return true; 133 } 134 135 public static function getContent($url) 136 { 137 138 if (function_exists('curl_version')) { // load trought curl 174 139 $ch = curl_init(); 175 140 … … 185 150 return file_get_contents($url); 186 151 } 187 188 } 189 190 // Sync private key with old version 191 192 public static function syncPrivateKey() { 193 if (get_option('tidio-one-public-key')) { 194 return false; 195 } 196 197 $publicKey = get_option('tidio-chat-external-public-key'); 198 $privateKey = get_option('tidio-chat-external-private-key'); 199 200 if (!$publicKey || !$privateKey) { 201 return false; 202 } 203 204 // sync old variables with new one 205 206 update_option('tidio-one-public-key', $publicKey); 207 update_option('tidio-one-private-key', $privateKey); 208 209 return true; 210 } 211 212 // Get Access Url 213 214 public static function getAccessUrl() { 215 return self::$apiUrl . '/access/external/create?url=' . urlencode(site_url()) . '&platform=wordpress&email=' . urlencode(get_option('admin_email')) . '&_ip=' . $_SERVER['REMOTE_ADDR']; 216 } 217 218 public static function getRedirectUrl($privateKey) { 219 return self::$chatUrl . '/access?' . http_build_query( 152 } 153 154 public static function getAccessUrl() 155 { 156 return TidioLiveChat::API_URL . '/access/external/create?url=' . urlencode(site_url()) . '&platform=wordpress&email=' . urlencode(get_option('admin_email')) . '&_ip=' . $_SERVER['REMOTE_ADDR']; 157 } 158 159 public static function getRedirectUrl($privateKey) 160 { 161 return TidioLiveChat::CHAT_URL . '/access?' . http_build_query( 220 162 array( 221 163 'privateKey' => $privateKey, … … 227 169 } 228 170 229 public static function ajaxGetPrivateKey(){ 230 $privateKey = self::getPrivateKey(); 231 if(!$privateKey || $privateKey=='false'){ 232 echo 'error'; 233 exit(); 234 } 235 echo self::getRedirectUrl($privateKey); 171 public function pluginActionLinks($links, $file) 172 { 173 if (strpos($file, basename(__FILE__)) !== false) { 174 if (get_option(TidioLiveChat::PRIVATE_KEY_OPTION)) { 175 $links[] = '<a href="' . admin_url('admin-post.php') . '?action=' . TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION . '">' . esc_html__('Clear Account Data', 176 TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>'; 177 if (get_option(TidioLiveChat::ASYNC_LOAD_OPTION)) { 178 $toggleAsyncLabel = '✓'; 179 $onclickPart = 'onclick="return confirm(\'Disabling asynchronous loading of the chat widget may affect the page loading time of your website. Are you sure you want to disable the asynchronous loading?\');"'; 180 } else { 181 $toggleAsyncLabel = '✘'; 182 $onclickPart = ''; 183 } 184 $links[] = '<a href="' . admin_url('admin-post.php') . '?action=' . TidioLiveChat::TOGGLE_ASYNC_ACTION . '" ' . $onclickPart . '>' . esc_html__($toggleAsyncLabel . ' Asynchronous loading', 185 TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>'; 186 } 187 } 188 189 return $links; 190 } 191 192 public function toggleAsync() 193 { 194 update_option(TidioLiveChat::ASYNC_LOAD_OPTION, !get_option(TidioLiveChat::ASYNC_LOAD_OPTION)); 195 wp_redirect(admin_url('plugins.php')); 196 die(); 197 } 198 199 public function ajaxGetProjectKeys() 200 { 201 update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $_POST['public_key']); 202 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $_POST['private_key']); 203 echo TidioLiveChat::getRedirectUrl($_POST['private_key']); 236 204 exit(); 237 205 } 238 206 239 // Get Public Key 240 241 public static function getPublicKey() { 242 $publicKey = get_option('tidio-one-public-key'); 207 public function ajaxTidioChatSaveKeys() 208 { 209 if (!is_admin()) { 210 exit; 211 } 212 213 if (empty($_POST['private_key']) || empty($_POST['public_key'])) { 214 exit; 215 } 216 217 update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $_POST['public_key']); 218 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $_POST['private_key']); 219 220 echo '1'; 221 exit; 222 } 223 224 public function enqueueScriptsAsync() 225 { 226 $publicKey = TidioLiveChat::getPublicKey(); 227 $widgetUrl = TidioLiveChat::SCRIPT_URL . $publicKey . '.js'; 228 $asyncScript = <<<SRC 229 <script type='text/javascript'> 230 document.tidioChatCode = "$publicKey"; 231 (function() { 232 function asyncLoad() { 233 var tidioScript = document.createElement("script"); 234 tidioScript.type = "text/javascript"; 235 tidioScript.async = true; 236 tidioScript.src = "{$widgetUrl}"; 237 document.body.appendChild(tidioScript); 238 } 239 if (window.attachEvent) { 240 window.attachEvent("onload", asyncLoad); 241 } else { 242 window.addEventListener("load", asyncLoad, false); 243 } 244 })(); 245 </script> 246 SRC; 247 echo $asyncScript; 248 } 249 250 public static function getPublicKey() 251 { 252 $publicKey = get_option(TidioLiveChat::PUBLIC_KEY_OPTION); 243 253 244 254 if ($publicKey) { … … 246 256 } 247 257 248 self::getPrivateKey(); 249 250 return get_option('tidio-one-public-key'); 251 } 252 258 TidioLiveChat::getPrivateKey(); 259 260 return get_option(TidioLiveChat::PUBLIC_KEY_OPTION); 261 } 262 263 public function enqueueScriptsSync() 264 { 265 wp_enqueue_script('tidio-chat', TidioLiveChat::SCRIPT_URL . TidioLiveChat::getPublicKey() . '.js', array(), 266 TIDIOCHAT_VERSION, 267 true); 268 wp_add_inline_script('tidio-chat', 'document.tidioChatCode = "' . TidioLiveChat::getPublicKey() . '";', 269 'before'); 270 } 271 272 public function enqueueAdminScripts() 273 { 274 wp_enqueue_script('tidio-chat-admin', plugins_url('media/js/options.js', __FILE__), array(), TIDIOCHAT_VERSION, 275 true); 276 wp_enqueue_style('tidio-chat-admin-style', plugins_url('media/css/options.css', __FILE__), array(), 277 TIDIOCHAT_VERSION); 278 } 279 280 public function adminJS() 281 { 282 $privateKey = TidioLiveChat::getPrivateKey(); 283 $redirectUrl = ''; 284 285 if ($privateKey && $privateKey != 'false') { 286 $redirectUrl = TidioLiveChat::getRedirectUrl($privateKey); 287 } else { 288 $redirectUrl = admin_url('admin-ajax.php?action=tidio_chat_redirect'); 289 } 290 291 echo "<script>jQuery('a[href=\"admin.php?page=tidio-chat\"]').attr('href', '" . $redirectUrl . "').attr('target', '_blank') </script>"; 292 } 293 294 public function addAdminMenuLink() 295 { 296 add_menu_page( 297 'Tidio Chat', 'Tidio Chat', 'manage_options', 'tidio-chat', array($this, 'addAdminPage'), 298 content_url() . '/plugins/' . TidioLiveChat::TIDIO_PLUGIN_NAME . '/media/img/icon.png' 299 ); 300 } 301 302 public function addAdminPage() 303 { 304 // Set class property 305 $dir = plugin_dir_path(__FILE__); 306 include $dir . 'options.php'; 307 } 308 309 public function uninstall() 310 { 311 delete_option(TidioLiveChat::PUBLIC_KEY_OPTION); 312 delete_option(TidioLiveChat::PRIVATE_KEY_OPTION); 313 delete_option(TidioLiveChat::ASYNC_LOAD_OPTION); 314 wp_redirect(admin_url('plugins.php')); 315 die(); 316 } 253 317 } 254 318 255 $tidioLiveChat = new TidioLiveChat(); 256 319 add_action('init', 'initialize_tidio'); 320 321 function initialize_tidio() 322 { 323 $tidioLiveChat = new TidioLiveChat(); 324 } 325 326 register_activation_hook(__FILE__, array('TidioLiveChat', 'activate'));
Note: See TracChangeset
for help on using the changeset viewer.