26
26
function hook_chatwoot_output ($ vars )
27
27
{
28
28
29
- $ isenabled = Capsule::table ('tbladdonmodules ' )->select ('value ' )->where ('module ' , '= ' , 'chatwoot ' )->where ('setting ' , '= ' , 'chatwoot_enable ' )->where ('value ' , 'on ' )->count ();
30
- $ chatwoot_jscode = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_jscode ' )->value ('value ' );
31
- $ verification_hash = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_verhash ' )->value ('value ' );
32
- $ chatwoot_position = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_position ' )->value ('value ' );
33
- $ chatwoot_bubble = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_bubble ' )->value ('value ' );
34
- $ chatwoot_lang_setting = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_lang ' )->value ('value ' );
35
- $ chatwoot_admin = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_enableonadmin ' )->value ('value ' );
36
- $ signing_hash = Capsule::table ('mod_chatwoot ' )->where ('setting ' , 'signing_hash ' )->value ('value ' );
29
+ $ isenabled = Capsule::table ('tbladdonmodules ' )->select ('value ' )->where ('module ' , '= ' , 'chatwoot ' )->where ('setting ' , '= ' , 'chatwoot_enable ' )->where ('value ' , 'on ' )->count ();
30
+ $ chatwoot_url = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_url ' )->value ('value ' );
31
+ $ chatwoot_token = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_token ' )->value ('value ' );
32
+ $ verification_hash = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_verhash ' )->value ('value ' );
33
+ $ chatwoot_position = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_position ' )->value ('value ' );
34
+ $ chatwoot_bubble = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_bubble ' )->value ('value ' );
35
+ $ chatwoot_launcherTitle = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_launcherTitle ' )->value ('value ' );
36
+ $ chatwoot_dark = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_dark ' )->value ('value ' );
37
+ $ chatwoot_lang_setting = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_lang ' )->value ('value ' );
37
38
38
39
$ chatwoot_setlabel = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_setlabel ' )->value ('value ' );
39
40
$ chatwoot_setlabelloggedin = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_setlabelloggedin ' )->value ('value ' );
40
41
42
+ $ chatwoot_admin = Capsule::table ('tbladdonmodules ' )->where ('module ' , 'chatwoot ' )->where ('setting ' , 'chatwoot_enableonadmin ' )->value ('value ' );
41
43
42
44
# ignore if admin
43
45
if (empty ($ chatwoot_admin ) && isset ($ _SESSION ['adminid ' ])) {
@@ -56,6 +58,11 @@ function hook_chatwoot_output($vars)
56
58
$ chatwoot_bubble = 'expanded_bubble ' ;
57
59
}
58
60
61
+ # dark mode
62
+ if ($ chatwoot_dark == 'on ' ) {
63
+ $ chatwoot_dark = 'auto ' ;
64
+ }
65
+
59
66
# widget lang
60
67
if ($ chatwoot_lang_setting ) {
61
68
$ chatwoot_lang = cw_langCode (ucfirst ($ vars ['language ' ]));
@@ -65,11 +72,7 @@ function hook_chatwoot_output($vars)
65
72
$ currentUser = new CurrentUser ;
66
73
$ client = $ currentUser ->client ();
67
74
$ user = $ currentUser ->user ();
68
- $ ipaddress = $ _SERVER ['REMOTE_ADDR ' ];
69
- $ ip = gethostbyaddr ($ ipaddress );
70
75
$ currentpage = (isset ($ _SERVER ['HTTPS ' ]) && $ _SERVER ['HTTPS ' ] === 'on ' ? "https " : "http " ) . ":// $ _SERVER [HTTP_HOST ]$ _SERVER [REQUEST_URI ]" ;
71
- $ user_os = getOS ();
72
- $ user_browser = getBrowser ();
73
76
74
77
# Fetch labels
75
78
if (!is_null ($ user )) {
@@ -79,7 +82,7 @@ function hook_chatwoot_output($vars)
79
82
}
80
83
81
84
# Get client ID and set contact ID
82
- if ($ user && $ client && $ user ->isOwner ( $ client )) {
85
+ if ($ user && $ client && $ user ->isOwner ($ client )) {
83
86
$ ClientID = $ client ->id ;
84
87
} elseif ($ user ) {
85
88
//$ownedClients = $user->ownedClients()->all();
@@ -88,8 +91,8 @@ function hook_chatwoot_output($vars)
88
91
}
89
92
90
93
if (!is_null ($ user )) {
91
- $ ClientChatID = hash_hmac ("sha256 " , $ ClientID , $ signing_hash );
92
- $ identifier_hash = hash_hmac ("sha256 " , $ ClientChatID , $ verification_hash );
94
+ $ clientChatID = hash_hmac ("sha256 " , $ ClientID , $ verification_hash );
95
+ $ identifier_hash = hash_hmac ("sha256 " , $ clientChatID , $ verification_hash );
93
96
}
94
97
95
98
# build contact info
@@ -135,28 +138,49 @@ function hook_chatwoot_output($vars)
135
138
}
136
139
}
137
140
138
- # Now let's prepare our code for the final output
141
+ # prepare widget code
142
+ $ chatwoot_jscode = "
143
+ <script>
144
+ window.chatwootSettings = {'position':' $ chatwoot_position','type':' $ chatwoot_bubble','launcherTitle':' $ chatwoot_launcherTitle','darkMode': ' $ chatwoot_dark'};
145
+ (function(d,t) {
146
+ var BASE_URL=' $ chatwoot_url';
147
+ var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
148
+ g.src=BASE_URL+'/packs/js/sdk.js';
149
+ g.defer = true;
150
+ g.async = true;
151
+ s.parentNode.insertBefore(g,s);
152
+ g.onload=function(){
153
+ window.chatwootSDK.run({
154
+ websiteToken: ' $ chatwoot_token',
155
+ baseUrl: BASE_URL
156
+ })
157
+ }
158
+ })(document,'script');
159
+ </script>
160
+ " ;
161
+
162
+ # Now let's set the final output
139
163
140
164
if (!is_null ($ user )) {
141
165
142
166
$ chatwoot_output =
143
167
"$ chatwoot_jscode
144
168
<script>
145
169
window.addEventListener('chatwoot:ready', function () {
146
- window. \$chatwoot.setUser(' $ ClientChatID ', {
170
+ window. \$chatwoot.setUser(' $ clientChatID ', {
147
171
email: ' $ clientemail',
148
172
name: ' $ clientname',
149
173
identifier_hash: ' $ identifier_hash',
150
174
company_name: ' $ clientcompany',
151
175
});
152
176
window. \$chatwoot.setCustomAttributes({
153
- ID : ' $ ClientID',
154
- Phone: ' $ clientphone',
155
- Language: ' $ clientlang',
156
- City: ' $ clientcity',
157
- State: ' $ clientstate',
177
+ 'ID' : ' $ ClientID',
178
+ ' Phone' : ' $ clientphone',
179
+ ' Language' : ' $ clientlang',
180
+ ' City' : ' $ clientcity',
181
+ ' State' : ' $ clientstate',
158
182
'Post Code': ' $ clientpostcode',
159
- Country: ' $ clientcountry',
183
+ ' Country' : ' $ clientcountry',
160
184
'Active Tickets': ' $ clienttickets',
161
185
'Credit Balance': ' $ clientcredit',
162
186
'Revenue': ' $ clientrevenue',
@@ -166,37 +190,23 @@ function hook_chatwoot_output($vars)
166
190
'Account Overdue': ' $ clientoverduetotal',
167
191
'Email Status': ' $ clientemailver',
168
192
'Is Affiliate': ' $ clientaffiliate',
169
- 'IP Address': ' $ ip',
170
193
'Current Page': ' $ currentpage',
171
- 'User Browser': ' $ user_browser',
172
- 'User System': ' $ user_os',
173
194
});
174
- window. \$chatwoot.deleteCustomAttribute('Test Attribute')
175
- window. \$chatwoot.setLabel(' $ chatwoot_setlabelloggedin')
195
+ window. \$chatwoot.deleteCustomAttribute('Test Attribute');
196
+ window. \$chatwoot.setLabel(' $ chatwoot_setlabelloggedin');
176
197
window. \$chatwoot.removeLabel(' $ chatwoot_setlabel');
177
- window. \$chatwoot.setLocale(' $ chatwoot_lang')
178
- window.chatwootSettings = {
179
- position: ' $ chatwoot_position',
180
- type: ' $ chatwoot_bubble',
181
- }
198
+ window. \$chatwoot.setLocale(' $ chatwoot_lang');
182
199
});
183
200
</script> " ;
184
201
} else {
185
202
$ chatwoot_output = "
186
203
$ chatwoot_jscode
187
204
<script>
188
205
window.addEventListener('chatwoot:ready', function () {
189
- window. \$chatwoot.setLabel(' $ chatwoot_label')
190
- window. \$chatwoot.setLocale(' $ chatwoot_lang')
191
- window.chatwootSettings = {
192
- position: ' $ chatwoot_position',
193
- type: ' $ chatwoot_bubble',
194
- };
206
+ window. \$chatwoot.setLabel(' $ chatwoot_label');
207
+ window. \$chatwoot.setLocale(' $ chatwoot_lang');
195
208
window. \$chatwoot.setCustomAttributes({
196
- 'IP Address': ' $ ip',
197
209
'Current Page': ' $ currentpage',
198
- 'User Browser': ' $ user_browser',
199
- 'User System': ' $ user_os',
200
210
});
201
211
});
202
212
</script> " ;
@@ -242,17 +252,17 @@ function hook_chatwoot_logout_output($vars)
242
252
$ LogoutHook = ($ whmcsver > 7 ) ? 'UserLogout ' : 'ClientLogout ' ;
243
253
244
254
function ViewClientSwitchAccount ($ vars ) {
245
-
246
- $ url = "https:// $ _SERVER [HTTP_HOST ]$ _SERVER [REQUEST_URI ]" ;
247
255
248
- if (str_contains ($ url , '/user/accounts ' )) {
256
+ $ url = "https:// $ _SERVER [HTTP_HOST ]$ _SERVER [REQUEST_URI ]" ;
257
+
258
+ if (str_contains ($ url , '/user/accounts ' ) || str_contains ($ url , '/login ' )) {
249
259
250
260
$ output .= <<<HTML
251
261
<!-- Chatwoot Logout Code -->
252
262
<script>
253
- document.addEventListener('readystatechange', event => {
254
- window. \$chatwoot.reset()
255
- });
263
+ document.addEventListener('readystatechange', event => {
264
+ window. \$chatwoot.reset()
265
+ });
256
266
</script>
257
267
<!-- Chatwoot End Logout Code -->
258
268
HTML ;
@@ -271,69 +281,6 @@ function cwoot_whmcs_version() {
271
281
return substr ($ whmcsversion , 0 , 1 );
272
282
}
273
283
274
- function getOS ()
275
- {
276
-
277
- $ user_agent = $ _SERVER ['HTTP_USER_AGENT ' ];
278
- $ os_platform = "Unknown OS Platform " ;
279
- $ os_array = array (
280
- '/windows nt 6.3/i ' => 'Windows 8.1 ' ,
281
- '/windows nt 6.2/i ' => 'Windows 8 ' ,
282
- '/windows nt 6.1/i ' => 'Windows 7 ' ,
283
- '/windows nt 6.0/i ' => 'Windows Vista ' ,
284
- '/windows nt 5.2/i ' => 'Windows Server 2003/XP x64 ' ,
285
- '/windows nt 5.1/i ' => 'Windows XP ' ,
286
- '/windows xp/i ' => 'Windows XP ' ,
287
- '/windows nt 5.0/i ' => 'Windows 2000 ' ,
288
- '/windows me/i ' => 'Windows ME ' ,
289
- '/win98/i ' => 'Windows 98 ' ,
290
- '/win95/i ' => 'Windows 95 ' ,
291
- '/win16/i ' => 'Windows 3.11 ' ,
292
- '/macintosh|mac os x/i ' => 'Mac OS X ' ,
293
- '/mac_powerpc/i ' => 'Mac OS 9 ' ,
294
- '/linux/i ' => 'Linux ' ,
295
- '/ubuntu/i ' => 'Ubuntu ' ,
296
- '/iphone/i ' => 'iPhone ' ,
297
- '/ipod/i ' => 'iPod ' ,
298
- '/ipad/i ' => 'iPad ' ,
299
- '/android/i ' => 'Android ' ,
300
- '/blackberry/i ' => 'BlackBerry ' ,
301
- '/webos/i ' => 'Mobile ' ,
302
- );
303
-
304
- foreach ($ os_array as $ regex => $ value ) {
305
- if (preg_match ($ regex , $ user_agent )) {
306
- $ os_platform = $ value ;
307
- }
308
- }
309
- return $ os_platform ;
310
- }
311
-
312
- function getBrowser ()
313
- {
314
-
315
- $ user_agent = $ _SERVER ['HTTP_USER_AGENT ' ];
316
- $ browser = "Unknown Browser " ;
317
- $ browser_array = array (
318
- '/msie/i ' => 'Internet Explorer ' ,
319
- '/firefox/i ' => 'Firefox ' ,
320
- '/safari/i ' => 'Safari ' ,
321
- '/chrome/i ' => 'Chrome ' ,
322
- '/opera/i ' => 'Opera ' ,
323
- '/netscape/i ' => 'Netscape ' ,
324
- '/maxthon/i ' => 'Maxthon ' ,
325
- '/konqueror/i ' => 'Konqueror ' ,
326
- '/mobile/i ' => 'Handheld Browser ' ,
327
- );
328
-
329
- foreach ($ browser_array as $ regex => $ value ) {
330
- if (preg_match ($ regex , $ user_agent )) {
331
- $ browser = $ value ;
332
- }
333
- }
334
- return $ browser ;
335
- }
336
-
337
284
# to deal with langs
338
285
function cw_langCode ($ name )
339
286
{
0 commit comments