-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dainis Tillers
committed
Nov 22, 2014
0 parents
commit 438d675
Showing
6 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @author Tawk.to | ||
* @copyright Copyright (c) Tawk.to 2014 | ||
* @license http://www.whmcs.com/license/ WHMCS Eula | ||
* @link https://tawk.to | ||
*/ | ||
|
||
if (!defined("WHMCS")) | ||
die("This file cannot be accessed directly"); | ||
|
||
function tawk_to_widget_retrieve_widget() { | ||
$result = select_query('tawk_to_widget_settings', 'page_id, widget_id', array('id' => 1)); | ||
$data = mysql_fetch_array($result); | ||
|
||
if(!$data || !isset($data['page_id']) || !isset($data['widget_id'])) { | ||
return array('page_id' => '', 'widget_id' => ''); | ||
} | ||
|
||
return $data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* @author Tawk.to | ||
* @copyright Copyright (c) Tawk.to 2014 | ||
* @license http://www.whmcs.com/license/ WHMCS Eula | ||
* @link https://tawk.to | ||
*/ | ||
|
||
if (!defined("WHMCS")) | ||
die("This file cannot be accessed directly"); | ||
|
||
require_once dirname(__FILE__) . '/functions.php'; | ||
|
||
function tawk_to_widget_embed_code_output($vars) { | ||
$widget = tawk_to_widget_retrieve_widget(); | ||
|
||
if($widget['page_id'] === '' || $widget['widget_id'] === '') { | ||
return; | ||
} | ||
|
||
return '<!--Start of Tawk.to Script--> | ||
<script type="text/javascript"> | ||
var $_Tawk_API={},$_Tawk_LoadStart=new Date(); | ||
(function(){ | ||
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0]; | ||
s1.async=true; | ||
s1.src="https://embed.tawk.to/'.$widget['page_id'].'/'.$page['widget_id'].'"; | ||
s1.charset="UTF-8"; | ||
s1.setAttribute("crossorigin","*"); | ||
s0.parentNode.insertBefore(s1,s0); | ||
})(); | ||
</script> | ||
<!--End of Tawk.to Script-->'; | ||
} | ||
|
||
add_hook("ClientAreaFooterOutput", 1, "tawk_to_widget_embed_code_output"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* @author Tawk.to | ||
* @copyright Copyright (c) Tawk.to 2014 | ||
* @license http://www.whmcs.com/license/ WHMCS Eula | ||
* @link https://tawk.to | ||
*/ | ||
|
||
if (!defined("WHMCS")) | ||
die("This file cannot be accessed directly"); | ||
|
||
require_once dirname(__FILE__) . '/functions.php'; | ||
|
||
define('TAWK_TO_WIDGET_PLUGINS_BASE_URL', 'https://plugins.tawk.to'); | ||
|
||
function tawk_to_widget_config() { | ||
return array( | ||
"name" => "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'; | ||
} |
82 changes: 82 additions & 0 deletions
82
modules/addons/tawk_to_widget/templates/widget_choose_iframe.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* @author Tawk.to | ||
* @copyright Copyright (c) Tawk.to 2014 | ||
* @license http://www.whmcs.com/license/ WHMCS Eula | ||
* @link https://tawk.to | ||
*/ | ||
|
||
if (!defined("WHMCS")) | ||
die("This file cannot be accessed directly"); | ||
?> | ||
|
||
<iframe | ||
id="tawkIframe" | ||
src="" | ||
style="min-height: 400px; width : 100%; border: none; margin-top: 20px"> | ||
</iframe> | ||
|
||
<script type="text/javascript"> | ||
var currentHost = window.location.protocol + "//" + window.location.host, | ||
url = "<?php echo $iframe_url?>&parentDomain=" + currentHost, | ||
baseUrl = '<?php echo $base_url ?>', | ||
current_id_tab = '{$tab_id}', | ||
controller = '<?php echo $ajax_link ?>'; | ||
|
||
jQuery('#tawkIframe').attr('src', url); | ||
|
||
var iframe = jQuery('#tawk_widget_customization')[0]; | ||
|
||
window.addEventListener('message', function(e) { | ||
|
||
if(e.origin === baseUrl) { | ||
|
||
if(e.data.action === 'setWidget') { | ||
setWidget(e); | ||
} | ||
|
||
if(e.data.action === 'removeWidget') { | ||
removeWidget(e); | ||
} | ||
} | ||
}); | ||
|
||
function setWidget(e) { | ||
|
||
$.ajax({ | ||
type : 'POST', | ||
url : controller, | ||
dataType : 'json', | ||
data : { | ||
action : 'set', | ||
page_id : e.data.pageId, | ||
widget_id : e.data.widgetId | ||
}, | ||
success : function(r) { | ||
if(r.success) { | ||
e.source.postMessage({action: 'setDone'} , baseUrl); | ||
} else { | ||
e.source.postMessage({action: 'setFail'} , baseUrl); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function removeWidget(e) { | ||
$.ajax({ | ||
type : 'POST', | ||
url : controller, | ||
dataType : 'json', | ||
data : { | ||
action : 'remove', | ||
}, | ||
success : function(r) { | ||
if(r.success) { | ||
e.source.postMessage({action: 'removeDone'} , baseUrl); | ||
} else { | ||
e.source.postMessage({action: 'removeFail'} , baseUrl); | ||
} | ||
} | ||
}); | ||
} | ||
</script> |