diff --git a/README.md b/README.md new file mode 100644 index 0000000..85abbce --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +tawk/tawk-whmcs +================ + +# About tawk.to +tawk.to is a free live chat app that lets you monitor and chat with visitors on your website +or from a free customizable page. No catch. No spam. No wares. It's truly free and always will be. + +# Installation +Copy files modules folder to your whmcs installation folder. After that you will have to activate +it by going to Setup -> Addon modules (admin/configaddonmods.php) and finding and activating +Tawk.to widget module. Make sure that you configure access to this module so that you have access to +it. + +# Usage +Go to Addons -> Tawk.to widget and select widget you want to use on whmcs client side. + +If you don't have [tawk.to](https://tawk.to/?utm_source=whmcs&utm_medium=link&utm_campaign=signup) account, you can always [create one for free](https://tawk.to/?utm_source=whmcs&utm_medium=link&utm_campaign=signup) diff --git a/modules/addons/tawk_to_widget/functions.php b/modules/addons/tawk_to_widget/functions.php new file mode 100644 index 0000000..9b8766a --- /dev/null +++ b/modules/addons/tawk_to_widget/functions.php @@ -0,0 +1,21 @@ + 1)); + $data = mysql_fetch_array($result); + + if(!$data || !isset($data['page_id']) || !isset($data['widget_id'])) { + return array('page_id' => '', 'widget_id' => ''); + } + + return $data; +} \ No newline at end of file diff --git a/modules/addons/tawk_to_widget/hooks.php b/modules/addons/tawk_to_widget/hooks.php new file mode 100644 index 0000000..084dcd4 --- /dev/null +++ b/modules/addons/tawk_to_widget/hooks.php @@ -0,0 +1,36 @@ + + + '; +} + +add_hook("ClientAreaFooterOutput", 1, "tawk_to_widget_embed_code_output"); \ No newline at end of file diff --git a/modules/addons/tawk_to_widget/lang/english.php b/modules/addons/tawk_to_widget/lang/english.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/modules/addons/tawk_to_widget/lang/english.php @@ -0,0 +1 @@ + "Tawk to widget", + "description" => "This addon allows to change tawk.to widget which is used in your whmcs installation", + "version" => "1.0", + "author" => "Tawkto", + "language" => "english" + ); +} + +function tawk_to_widget_activate() { + + full_query("CREATE TABLE IF NOT EXISTS `tawk_to_widget_settings` ( + `id` int NOT NULL PRIMARY KEY, + `page_id` varchar(100) NOT NULL, + `widget_id` varchar(100) NOT NULL + ) DEFAULT CHARSET=utf8;"); + + return array('status'=>'success', 'description'=>'Tawk.to widget addon enabled, make sure to enable user access and then go to Addons => Tawk.to widget and choose widget you want to use'); +} + +function tawk_to_widget_deactivate() { + full_query('drop table `tawk_to_widget_settings`'); + return array('status'=>'success', 'description'=>'Tawk.to widget addon dactived. Tawk.to widget will not be displayed'); +} + +function tawk_to_widget_output($vars) { + + if(isset($_GET['ajax'])) { + header('Content-Type: application/json'); + + if(isset($_POST['action']) && $_POST['action'] === 'set' && isset($_POST['page_id']) && isset($_POST['widget_id'])) { + $page_id = mysql_real_escape_string($_POST['page_id']); + $widget_id = mysql_real_escape_string($_POST['widget_id']); + + full_query("insert into tawk_to_widget_settings + (id, page_id, widget_id) + values(1, '" . $page_id . "', '" . $widget_id . "') + on duplicate key update page_id='".$page_id."', widget_id='".$widget_id."'"); + + echo json_encode(array('success' => TRUE)); + } else if(isset($_POST['action']) && $_POST['action'] === 'remove') { + full_query('delete from `tawk_to_widget_settings` where id=1'); + echo json_encode(array('success' => TRUE)); + } else { + echo json_encode(array('success' => FALSE)); + } + + die(); + } + + $widget = tawk_to_widget_retrieve_widget(); + + $iframe_url = TAWK_TO_WIDGET_PLUGINS_BASE_URL.'/generic/widgets?currentWidgetId='.$widget['widget_id'].'¤tPageId='.$widget['page_id']; + $base_url = TAWK_TO_WIDGET_PLUGINS_BASE_URL; + $ajax_link = $vars['modulelink'] . '&ajax=1'; + + require dirname(__FILE__) . '/templates/widget_choose_iframe.php'; +} \ No newline at end of file diff --git a/modules/addons/tawk_to_widget/templates/widget_choose_iframe.php b/modules/addons/tawk_to_widget/templates/widget_choose_iframe.php new file mode 100644 index 0000000..b504d21 --- /dev/null +++ b/modules/addons/tawk_to_widget/templates/widget_choose_iframe.php @@ -0,0 +1,82 @@ + + + + + \ No newline at end of file