Jump to content

Module addons tawkto


Recommended Posts

The addon tawkto is creating a error o WHMCS 8.0. Below is the code. If you know how to fix please let me know.

 

Thanks

 

<?php
use Illuminate\Database\Capsule\Manager as Capsule;
function tawkto_check($vars)
{

	$uid = $_SESSION['uid'];

	//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 (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;
	}

	//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 ($showname) {
            //now we get what we get!
            foreach (Capsule::table('tblclients') ->WHERE('id', $uid)->get() as $tawkclients) {
                $fname = html_entity_decode($tawkclients->firstname, ENT_QUOTES);
                $tlname = html_entity_decode($tawkclients->lastname, ENT_QUOTES);
                $fname = addslashes($fname);
                $lname = addslashes($tlname);
                $company = $tawkclients->companyname;
                $emailaddress = $tawkclients->email;
            }

            // show in secure mode if api key is set. else, show basic name/email info
            if (($fname || $lname) && $emailaddress) {
                if ($apikey && strlen($apikey) > 10) {
                    $hash = hash_hmac("sha256", $emailaddress, $apikey);
                    $tawkname = "Tawk_API.visitor = {
                        name  : '{$fname} {$lname}',
                        email : '{$emailaddress}',
                        hash : '{$hash}'
                        };";
                } else {
                    $tawkname = "Tawk_API.visitor = {
                        name  : '{$fname} {$lname}',
                        email : '{$emailaddress}'
                        };";
                }
            }
        }
	}

	//get the key
    $tawkreturn = "$widgetScript";
    $tawkreturn = str_ireplace('</script>', $tawkname.'</script>', $tawkreturn);
    return($tawkreturn);
}
function tawkto_check_invoice($vars)
{

	$uid = $_SESSION['uid'];

	//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 (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;
	}

	//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 ($showname) {
            //now we get what we get!
            foreach (Capsule::table('tblclients') ->WHERE('id', $uid)->get() as $tawkclients) {
                $fname = html_entity_decode($tawkclients->firstname, ENT_QUOTES);
                $tlname = html_entity_decode($tawkclients->lastname, ENT_QUOTES);
                $fname = addslashes($fname);
                $lname = addslashes($tlname);
                $company = $tawkclients->companyname;
                $emailaddress = $tawkclients->email;
            }

            // show in secure mode if api key is set. else, show basic name/email info
            if (($fname || $lname) && $emailaddress) {
                if ($apikey && strlen($apikey) > 10) {
                    $hash = hash_hmac("sha256", $emailaddress, $apikey);
                    $tawkname = "Tawk_API.visitor = {
                        name  : '{$fname} {$lname}',
                        email : '{$emailaddress}',
                        hash : '{$hash}'
                        };";
                } else {
                    $tawkname = "Tawk_API.visitor = {
                        name  : '{$fname} {$lname}',
                        email : '{$emailaddress}'
                        };";
                }
            }
        }
	}

	//get the key
    $tawkreturn = "$widgetScript";
    $tawkreturn = str_ireplace('</script>', $tawkname.'</script>', $tawkreturn);
    echo $tawkreturn;
}
// JUST COMMENT LINES BELOW TO FIX THE ERROR
//add_hook("ClientAreaFooterOutput",1,"tawkto_check");
//add_hook("ClientAreaPageViewInvoice",1,"tawkto_check_invoice");

 

Link to comment
Share on other sites

16 hours ago, souzadavi said:

The addon tawkto is creating a error o WHMCS 8.0.

the tawkto_check function is already used by the tawkto addon (if enabled in the addon) - so this hook causes an error because the function is getting redeclared by it.

if it were me, i'd just use the hook that comes with the addon - and because the invoice page doesn't have a footer and therefore the chat doesn't appear on that page, i'd just copy & paste the tawk script code and paste it before the closing </body> tag in the template (if you need to have the chat on the view invoice page).

Link to comment
Share on other sites

1 minute ago, souzadavi said:

@brian! this is the tawkto addon, this solution would works, but i would like to use the addon.

the hook you posted is a combination of the default hook (to show the chat on every page), and another hook to show it on the viewinvoice page - what i'm saying is that you don't need the above hook... the tawkto addon can add the script to the footer using a hook very similar to above... the only thing you need to worry about is the invoice page (if that's important to you).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated