8000 Fix-widget-not-loading by alvinjohnsonso · Pull Request #5 · tawk/tawk-whmcs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix-widget-not-loading #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 41 additions & 32 deletions modules/addons/tawkto/hooks.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Support\Collection;
function tawkto_check($vars)
{

$uid = $_SESSION['uid'];
$uid = $_SESSION['uid'];

//get the code
$widgetScript = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-script')->pluck('value');

if ($widgetScript instanceof Collection) {
$widgetScript = $widgetScript->all();
}

//get the code
$widgetScript = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-script')->pluck('value');
if (is_array($widgetScript)) {
$widgetScript = current($widgetScript);
}

if ($widgetScript) {
// $widgetScript = addslashes($widgetScript); // this breaks the widget script when displayed on client side
// $widgetScript = htmlentities($widgetScript); // this displays the script as html text and prevents proper rendering of the script
$widgetScript = trim($widgetScript);
} else {
return;
}

// get the API key, if set
$apikey = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-key')->pluck('value');
if ($apikey instanceof Collection) {
$apikey = $apikey->all();
}
if (is_array($apikey)) {
$apikey = current($apikey);
}
if ($apikey) {
$apikey = trim($apikey);
}

//no tawk-y (for now)
$isenabled = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-enable')->WHERE('value' , 'on')->count();
if (empty($isenabled)) {
return;
}
//no tawk-y (for now)
$isenabled = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-enable')->WHERE('value' , 'on')->count();
if (empty($isenabled)) {
return;
}

//clients only
$clientsonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-clientsonly')->WHERE('value' , 'on')->count();
if (!empty($clientsonly)) {
if (empty($uid)) {
return;
}
}
//maybe we just wanna chat with guests?
$guestonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-unregonly')->WHERE('value' , 'on')->count();
if (!empty($guestonly)) {
if (!empty($uid)) {
return;
}
}
//clients only
$clientsonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-clientsonly')->WHERE('value' , 'on')->count();
if (!empty($clientsonly)) {
if (empty($uid)) {
return;
}
}
//maybe we just wanna chat with guests?
$guestonly = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-unregonly')->WHERE('value' , 'on')->count();
if (!empty($guestonly)) {
if (!empty($uid)) {
return;
}
}

// no name is show by default
$tawkname = "";
if (isset($uid)) {
//to name, or not to name, that is the question
$showname = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-name')->WHERE('value' , 'on')->count();
if (isset($uid)) {
//to name, or not to name, that is the question
$showname = Capsule::table('tbladdonmodules')->select('value')-> WHERE('module', '=' , 'tawkto')->WHERE('setting' , '=', 'tawkto-name')->WHERE('value' , 'on')->count();

if ($showname) {
//now we get what we get!
foreach (Capsule::table('tblclients') ->WHERE('id', $uid)->get() as $tawkclients) {
Expand All @@ -73,21 +83,20 @@ function tawkto_check($vars)
name : '{$fname} {$lname}',
email : '{$emailaddress}',
hash : '{$hash}'
};";
};";
} else {
$tawkname = "Tawk_API.visitor = {
name : '{$fname} {$lname}',
email : '{$emailaddress}'
};";
};";
}
}
}
}
}

//get the key
//get the key
$tawkreturn = "$widgetScript";
$tawkreturn = str_ireplace('</script>', $tawkname.'</script>', $tawkreturn);
return($tawkreturn);
}
add_hook("ClientAreaFooterOutput",1,"tawkto_check");

76 changes: 38 additions & 38 deletions modules/addons/tawkto/tawkto.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,54 @@
}

function tawkto_config() {
$configarray = array(
"name" => "tawk.to WHMCS Module",
"description" => "A module designed to make it easier for clients to integrate tawk.to into their websites, with no template edits",
"version" => "1.0.1",
"author" => "<a href='https://www.tawk.to/'>tawk.to</a> Team",
"language" => "english",
"fields" => array(
$configarray = array(
"name" => "tawk.to WHMCS Module",
"description" => "A module designed to make it easier for clients to integrate tawk.to into their websites, with no template edits",
"version" => "1.3.0",
"author" => "<a href='https://www.tawk.to/'>tawk.to</a> Team",
"language" => "english",
"fields" => array(
"tawkto-script" => array (
"FriendlyName" => "tawk.to Script",
"Type" => "textarea",
"FriendlyName" => "tawk.to Script",
"Type" => "textarea",
"Rows" => "10",
"Cols" => "100",
"Description" => "Enter the tawk.to widget script here",
"Default" => "",
"Cols" => "100",
"Description" => "Enter the tawk.to widget script here",
"Default" => "",
),
"tawkto-key" => array (
"FriendlyName" => "API Key",
"Type" => "text",
"Size" => "55",
"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' ",
"Default" => "",
"FriendlyName" => "API Key",
"Type" => "text",
"Size" => "55",
"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' ",
"Default" => "",
),
"tawkto-enable" => array (
"FriendlyName" => "Enable mod?",
"Type" => "yesno",
"Size" => "55",
"Description" => "A quick way to enable or disable this mod on your website ",
"Default" => "",
"FriendlyName" => "Enable mod?",
"Type" => "yesno",
"Size" => "55",
"Description" => "A quick way to enable or disable this mod on your website ",
"Default" => "",
),
"tawkto-name" => array ("FriendlyName" => "Show name if logged in?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Do you want your user's name displayed in their chat (requires WHMCS login)? ",
"Default" => "",
"tawkto-name" => array ("FriendlyName" => "Show name if logged in?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Do you want your user's name displayed in their chat (requires WHMCS login)? ",
"Default" => "",
),
"tawkto-clientsonly" => array ("FriendlyName" => "Only show to clients?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Hide from unregistered users?",
"Default" => "",
"tawkto-clientsonly" => array ("FriendlyName" => "Only show to clients?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Hide from unregistered users?",
"Default" => "",
),
"tawkto-unregonly" => array ("FriendlyName" => "Only show to unregistered?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Hide from registered users?",
"Default" => "",
"tawkto-unregonly" => array ("FriendlyName" => "Only show to unregistered?",
"Type" => "yesno",
"Size" => "55",
"Description" => "Hide from registered users?",
"Default" => "",
),
)
);
return $configarray;
return $configarray;
}
0