|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package Pure_Chat |
| 4 | + * @version 2.2 |
| 5 | + */ |
| 6 | +/* |
| 7 | +Plugin Name: Pure Chat |
| 8 | +Plugin URI: |
| 9 | +Description: Website chat, simplified. Now 100% Free for Live Chat for Three Users/Operators and Unlimited Chats for your website! Love purechat? Spread the word! <a href="https://wordpress.org/support/view/plugin-reviews/pure-chat">Click here to review the plugin!</a> |
| 10 | +Author: Pure Chat, Inc. |
| 11 | +Version: 2.2 |
| 12 | +Author URI: purechat.com |
| 13 | +*/ |
| 14 | + |
| 15 | +defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 16 | + |
| 17 | +include 'variables.php'; |
| 18 | + |
| 19 | +class Pure_Chat_Plugin { |
| 20 | + var $version = 5; |
| 21 | + |
| 22 | + public static function activate() { |
| 23 | + Pure_Chat_Plugin::clear_cache(); |
| 24 | + } |
| 25 | + |
| 26 | + public static function deactivate() { |
| 27 | + Pure_Chat_Plugin::clear_cache(); |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + function __construct() { |
| 33 | + // add_option('purechat_widget_code', '', '', 'yes'); |
| 34 | + // add_option('purechat_widget_name', '', '', 'yes'); |
| 35 | + |
| 36 | + add_action('wp_footer', array( &$this, 'pure_chat_load_snippet') ); |
| 37 | + |
| 38 | + add_action('admin_menu', array( &$this, 'pure_chat_menu' ) ); |
| 39 | + add_action('wp_ajax_pure_chat_update', array( &$this, 'pure_chat_update' ) ); |
| 40 | + |
| 41 | + $this->update_plugin(); |
| 42 | + } |
| 43 | + |
| 44 | + function update_plugin() { |
| 45 | + update_option('purechat_plugin_ver', $this->version); |
| 46 | + } |
| 47 | + |
| 48 | + function pure_chat_menu() { |
| 49 | + add_menu_page('Pure Chat', 'Pure Chat', 'manage_options', 'purechat-menu', array( &$this, 'pure_chat_generateAcctPage' ), plugins_url().'/pure-chat/favicon.ico'); |
| 50 | + } |
| 51 | + |
| 52 | + function pure_chat_update() { |
| 53 | + if($_POST['action'] == 'pure_chat_update' && strlen((string)$_POST['purechatwid']) == 36) |
| 54 | + { |
| 55 | + update_option('purechat_widget_code', $_POST['purechatwid']); |
| 56 | + update_option('purechat_widget_name', $_POST['purechatwname']); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + function pure_chat_load_snippet() { |
| 61 | + global $current_user; |
| 62 | + if(get_option('purechat_widget_code')) |
| 63 | + { |
| 64 | + echo("<script type='text/javascript' data-cfasync='false'>window.purechatApi = { l: [], t: [], on: function () { this.l.push(arguments); } }; (function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://app.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({c: '" . get_option('purechat_widget_code') . "', f: true }); done = true; } }; })();</script>"); |
| 65 | + } |
| 66 | + else |
| 67 | + { |
| 68 | + echo("<!-- Please select a widget in the wordpress plugin to activate purechat -->"); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private static function clear_cache() { |
| 73 | + if (function_exists('wp_cache_clear_cache')) { |
| 74 | + wp_cache_clear_cache(); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + function pure_chat_generateAcctPage() { |
| 79 | + global $purechatHome; |
| 80 | + ?> |
| 81 | + <head> |
| 82 | + <link rel="stylesheet" href="<?php echo plugins_url().'/pure-chat/purechatStyles.css'?>" type="text/css"> |
| 83 | + </head> |
| 84 | + <?php |
| 85 | + if (isset($_POST['purechatwid']) && isset($_POST['purechatwname'])) { |
| 86 | + pure_chat_update(); |
| 87 | + } |
| 88 | + ?> |
| 89 | + <p> |
| 90 | + <div class="purechatbuttonbox"> |
| 91 | + <img src="<?php echo plugins_url().'/pure-chat/logo.png'?>"alt="Pure Chat logo"></img> |
| 92 | + <div class = "purechatcontentdiv"> |
| 93 | + <?php |
| 94 | + if (get_option('purechat_widget_code') == '' ) { |
| 95 | + ?> |
| 96 | + <p>Pure Chat allows you to chat in real time with visitors to your WordPress site. Click the button below to get started by logging in to Pure Chat and selecting a chat widget!</p> |
| 97 | + <p>The button will open a widget selector in an external page. Keep in mind that your Pure Chat account is separate from your WordPress account.</p> |
| 98 | + <?php |
| 99 | + } else { |
| 100 | + ?> |
| 101 | + <h4>Your current chat widget is:</h4> |
| 102 | + <h1 class="purechatCurrentWidgetName"><?php echo get_option('purechat_widget_name'); ?></h1> |
| 103 | + <p>Would you like to switch widgets?</p> |
| 104 | + <?php |
| 105 | + } |
| 106 | + ?> |
| 107 | + </div> |
| 108 | + <form> |
| 109 | + <input type="button" class="purechatbutton" value="Pick a widget!" onclick="openPureChatChildWindow()"> |
| 110 | + </form> |
| 111 | + <p> |
| 112 | + </div> |
| 113 | + <script> |
| 114 | + var pureChatChildWindow; |
| 115 | + var purechatNameToPass = "<?php echo get_option('purechat_widget_name');?>"; |
| 116 | + var purechatIdToPass = "<?php echo get_option('purechat_widget_code');?>"; |
| 117 | + function openPureChatChildWindow() { |
| 118 | + pureChatChildWindow = window.open('<?php echo $purechatHome;?>/home/pagechoicewordpress?widForDisplay=' + purechatIdToPass + |
| 119 | + '&nameForDisplay=' + purechatNameToPass, 'Pure Chat'); |
| 120 | + } |
| 121 | + var url = ajaxurl; |
| 122 | + window.addEventListener('message', function(event) { |
| 123 | + var data = { |
| 124 | + 'action': 'pure_chat_update', |
| 125 | + 'purechatwid': event.data.id, |
| 126 | + 'purechatwname': event.data.name |
| 127 | + }; |
| 128 | + jQuery.post(url, data).done(function(){}) |
| 129 | + var purechatNamePassedIn = event.data.name; |
| 130 | + if(typeof purechatNamePassedIn != 'undefined') { |
| 131 | + document.getElementsByClassName('purechatcontentdiv')[0].innerHTML = '<h4>Your current chat widget is:</h4><h1 class="purechatCurrentWidgetName">' + |
| 132 | + purechatNamePassedIn + '</h1><p>Would you like to switch widgets?</p>'; |
| 133 | + purechatNameToPass = purechatNamePassedIn; |
| 134 | + purechatIdToPass = event.data.id; |
| 135 | + } |
| 136 | + }, false); |
| 137 | + </script> |
| 138 | + <div class="purechatlinkbox"> |
| 139 | + <p><a href="https://app.purechat.com/user/dashboard" target="_blank">Your Pure Chat dashboard page</a> is your place to answer chats, add more widgets, customize their appearance with images and text, manage users, and more!</p> |
| 140 | + </div> |
| 141 | + <?php |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +/*function deactivate_script(){ |
| 146 | + ?> |
| 147 | + <script type="text/javascript"> |
| 148 | +
|
| 149 | + //Popup in window |
| 150 | + jQuery(document).ready(function($){ |
| 151 | + var currentPage=''; |
| 152 | +
|
| 153 | + var deactivate_popup = [ |
| 154 | + '<div style="position: fixed; top: 80px; width: 275px; background-color: #fff; z-index: 9999; left: 0; right: 0; line-height: 20px; margin: auto; padding: 20px; box-shadow: 1px 1px 1px grey;">', |
| 155 | + '<center><img src="<?=plugin_dir_url( __FILE__ )?>/logo.png"/></center><br>', |
| 156 | + '<form action="">', |
| 157 | + '<input type="radio" name="purechat_survey" value="expensive">Didn\'t recieve enough chats</input><br><br>', |
| 158 | + '<input type="radio" name="purechat_survey" value="nowork">Too expensive</input><br><br>', |
| 159 | + '<input type="radio" name="purechat_survey" value="testing">Don\'t have the time</input><br><br>', |
| 160 | + '<input type="radio" name="purechat_survey" value="troubleshooting">Missing Key Feautres</input><br><br>', |
| 161 | + '<input type="radio" name="purechat_survey" value="option">Switched to a different chat provider</input><br><br>', |
| 162 | + '<input type="radio" name="purechat_survey" value="Not">Not a right fit or doesn\'t meat your needs</input><br><br>', |
| 163 | + '<input type="radio" name="purechat_survey" value="other">Other Reason:</input><br><input style="margin-top: 5px; width: 100%;"></input><br><br>', |
| 164 | + '</form>', |
| 165 | + '<center><button style="border-radius: 3px; cursor: pointer; font-size: 14px; white-space: nowrap; padding: 10px 60px; background-color: #289AA0; color: #ffffff; transition: 0.7s; border: 0;" id="pure-chat-send-survey">Send and Deactivate</button></center>', |
| 166 | + '</div>'].join(""); |
| 167 | +
|
| 168 | + $('#pure-chat-test').find('.deactivate a').click(function(e){ |
| 169 | + currentPage = $(this).attr('href'); |
| 170 | +
|
| 171 | + e.preventDefault(); |
| 172 | +
|
| 173 | + $('body').append(deactivate_popup); |
| 174 | + }); |
| 175 | +
|
| 176 | + $(document).on('click', '#pure-chat-send-survey', function(){ |
| 177 | +
|
| 178 | +
|
| 179 | + window.location.href=currentPage; |
| 180 | + }); |
| 181 | +
|
| 182 | + }); |
| 183 | + </script> |
| 184 | + <?php |
| 185 | +}*/ |
| 186 | + |
| 187 | +register_activation_hook(__FILE__, array('Pure_Chat_Plugin', 'activate')); |
| 188 | +register_deactivation_hook(__FILE__, array('Pure_Chat_Plugin', 'deactivate')); |
| 189 | + |
| 190 | +new Pure_Chat_Plugin(); |
| 191 | +?> |
0 commit comments