Skip to content

Commit 8d1a691

Browse files
authored
Merge pull request #5 from alvinjohnsonso/fix-widget-not-loading
Fix-widget-not-loading
2 parents 5609d79 + a36dc8e commit 8d1a691

File tree

2 files changed

+79
-70
lines changed

2 files changed

+79
-70
lines changed

modules/addons/tawkto/hooks.php

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,69 @@
11
<?php
22
use Illuminate\Database\Capsule\Manager as Capsule;
3+
use Illuminate\Support\Collection;
34
function tawkto_check($vars)
45
{
56

6-
$uid = $_SESSION['uid'];
7+
$uid = $_SESSION['uid'];
8+
9+
//get the code
10+
$widgetScript = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-script')->pluck('value');
11+
12+
if ($widgetScript instanceof Collection) {
13+
$widgetScript = $widgetScript->all();
14+
}
715

8-
//get the code
9-
$widgetScript = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-script')->pluck('value');
1016
if (is_array($widgetScript)) {
1117
$widgetScript = current($widgetScript);
1218
}
19+
1320
if ($widgetScript) {
1421
// $widgetScript = addslashes($widgetScript); // this breaks the widget script when displayed on client side
1522
// $widgetScript = htmlentities($widgetScript); // this displays the script as html text and prevents proper rendering of the script
1623
$widgetScript = trim($widgetScript);
1724
} else {
1825
return;
1926
}
20-
27+
2128
// get the API key, if set
2229
$apikey = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-key')->pluck('value');
30+
if ($apikey instanceof Collection) {
31+
$apikey = $apikey->all();
32+
}
2333
if (is_array($apikey)) {
2434
$apikey = current($apikey);
2535
}
2636
if ($apikey) {
2737
$apikey = trim($apikey);
2838
}
2939

30-
//no tawk-y (for now)
31-
$isenabled = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-enable')->WHERE('value' , 'on')->count();
32-
if (empty($isenabled)) {
33-
return;
34-
}
40+
//no tawk-y (for now)
41+
$isenabled = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-enable')->WHERE('value' , 'on')->count();
42+
if (empty($isenabled)) {
43+
return;
44+
}
3545

36-
//clients only
37-
$clientsonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-clientsonly')->WHERE('value' , 'on')->count();
38-
if (!empty($clientsonly)) {
39-
if (empty($uid)) {
40-
return;
41-
}
42-
}
43-
//maybe we just wanna chat with guests?
44-
$guestonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-unregonly')->WHERE('value' , 'on')->count();
45-
if (!empty($guestonly)) {
46-
if (!empty($uid)) {
47-
return;
48-
}
49-
}
46+
//clients only
47+
$clientsonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-clientsonly')->WHERE('value' , 'on')->count();
48+
if (!empty($clientsonly)) {
49+
if (empty($uid)) {
50+
return;
51+
}
52+
}
53+
//maybe we just wanna chat with guests?
54+
$guestonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-unregonly')->WHERE('value' , 'on')->count();
55+
if (!empty($guestonly)) {
56+
if (!empty($uid)) {
57+
return;
58+
}
59+
}
5060

5161
// no name is show by default
5262
$tawkname = "";
53-
if (isset($uid)) {
54-
//to name, or not to name, that is the question
55-
$showname = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-name')->WHERE('value' , 'on')->count();
56-
63+
if (isset($uid)) {
64+
//to name, or not to name, that is the question
65+
$showname = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-name')->WHERE('value' , 'on')->count();
66+
5767
if ($showname) {
5868
//now we get what we get!
5969
foreach (Capsule::table('tblclients') ->WHERE('id', $uid)->get() as $tawkclients) {
@@ -73,21 +83,20 @@ function tawkto_check($vars)
7383
name : '{$fname} {$lname}',
7484
email : '{$emailaddress}',
7585
hash : '{$hash}'
76-
};";
86+
};";
7787
} else {
7888
$tawkname = "Tawk_API.visitor = {
7989
name : '{$fname} {$lname}',
8090
email : '{$emailaddress}'
81-
};";
91+
};";
8292
}
8393
}
8494
}
85-
}
95+
}
8696

87-
//get the key
97+
//get the key
8898
$tawkreturn = "$widgetScript";
8999
$tawkreturn = str_ireplace('</script>', $tawkname.'</script>', $tawkreturn);
90100
return($tawkreturn);
91101
}
92102
add_hook("ClientAreaFooterOutput",1,"tawkto_check");
93-

modules/addons/tawkto/tawkto.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,54 @@
88
}
99

1010
function tawkto_config() {
11-
$configarray = array(
12-
"name" => "tawk.to WHMCS Module",
13-
"description" => "A module designed to make it easier for clients to integrate tawk.to into their websites, with no template edits",
14-
"version" => "1.0.1",
15-
"author" => "<a href='https://www.tawk.to/'>tawk.to</a> Team",
16-
"language" => "english",
17-
"fields" => array(
11+
$configarray = array(
12+
"name" => "tawk.to WHMCS Module",
13+
"description" => "A module designed to make it easier for clients to integrate tawk.to into their websites, with no template edits",
14+
"version" => "1.3.0",
15+
"author" => "<a href='https://www.tawk.to/'>tawk.to</a> Team",
16+
"language" => "english",
17+
"fields" => array(
1818
"tawkto-script" => array (
19-
"FriendlyName" => "tawk.to Script",
20-
"Type" => "textarea",
19+
"FriendlyName" => "tawk.to Script",
20+
"Type" => "textarea",
2121
"Rows" => "10",
22-
"Cols" => "100",
23-
"Description" => "Enter the tawk.to widget script here",
24-
"Default" => "",
22+
"Cols" => "100",
23+
"Description" => "Enter the tawk.to widget script here",
24+
"Default" => "",
2525
),
2626
"tawkto-key" => array (
27-
"FriendlyName" => "API Key",
28-
"Type" => "text",
29-
"Size" => "55",
30-
"Description" => "Obtained by going to the <a href=https://dashboard.tawk.to>tawk.to dashboard</a>, clicking on the 'Admin' menu, then viewing 'Property Settings' ",
31-
"Default" => "",
27+
"FriendlyName" => "API Key",
28+
"Type" => "text",
29+
"Size" => "55",
30+
"Description" => "Obtained by going to the <a href=https://dashboard.tawk.to>tawk.to dashboard</a>, clicking on the 'Admin' menu, then viewing 'Property Settings' ",
31+
"Default" => "",
3232
),
3333
"tawkto-enable" => array (
34-
"FriendlyName" => "Enable mod?",
35-
"Type" => "yesno",
36-
"Size" => "55",
37-
"Description" => "A quick way to enable or disable this mod on your website ",
38-
"Default" => "",
34+
"FriendlyName" => "Enable mod?",
35+
"Type" => "yesno",
36+
"Size" => "55",
37+
"Description" => "A quick way to enable or disable this mod on your website ",
38+
"Default" => "",
3939
),
40-
"tawkto-name" => array ("FriendlyName" => "Show name if logged in?",
41-
"Type" => "yesno",
42-
"Size" => "55",
43-
"Description" => "Do you want your user's name displayed in their chat (requires WHMCS login)? ",
44-
"Default" => "",
40+
"tawkto-name" => array ("FriendlyName" => "Show name if logged in?",
41+
"Type" => "yesno",
42+
"Size" => "55",
43+
"Description" => "Do you want your user's name displayed in their chat (requires WHMCS login)? ",
44+
"Default" => "",
4545
),
46-
"tawkto-clientsonly" => array ("FriendlyName" => "Only show to clients?",
47-
"Type" => "yesno",
48-
"Size" => "55",
49-
"Description" => "Hide from unregistered users?",
50-
"Default" => "",
46+
"tawkto-clientsonly" => array ("FriendlyName" => "Only show to clients?",
47+
"Type" => "yesno",
48+
"Size" => "55",
49+
"Description" => "Hide from unregistered users?",
50+
"Default" => "",
5151
),
52-
"tawkto-unregonly" => array ("FriendlyName" => "Only show to unregistered?",
53-
"Type" => "yesno",
54-
"Size" => "55",
55-
"Description" => "Hide from registered users?",
56-
"Default" => "",
52+
"tawkto-unregonly" => array ("FriendlyName" => "Only show to unregistered?",
53+
"Type" => "yesno",
54+
"Size" => "55",
55+
"Description" => "Hide from registered users?",
56+
"Default" => "",
5757
),
5858
)
5959
);
60-
return $configarray;
60+
return $configarray;
6161
}

0 commit comments

Comments
 (0)