Page 2 of 2

Re: How do I execute this script?

Posted: Wed Nov 30, 2022 6:25 am
by mecinta

Re: How do I execute this script?

Posted: Thu Dec 01, 2022 1:30 pm
by Rich-Os
Omar_one wrote: Tue Nov 29, 2022 6:43 pm @Rich-Os
you can add pages to hook

Code: Select all

 var $good_pages = ['index.php', 'xxxx.php', 'xxxx.php']; // what pages do you want to load the livehelperchat script 
and called Script

Code: Select all

 $livehelperchatScript = <<<eod <script>(HERE THE SCRIPT) </script>
eod; 

Very nice of you @Omar_one
But the script is supposed to appear on all pages (by right) but this selective addition idea might come handy later, so, thank you.

I'm not sure if this script (to add pages to hook) is supposed to be a separate file for hooks or included in the first script like so below:
(note I didn't use the <<<eod as it was making browser throw HTTP ERROR 500)

Re: How do I execute this script?

Posted: Thu Dec 01, 2022 1:34 pm
by Rich-Os

Code: Select all

class hook_shop_siteWide_livehelperchat {
  var $version = '3.4.1';
   var $sitestart = null;
    var $good_pages = ['index.php', 'conditions.php', 'shipping.php']; // what pages do you want to load the livehelperchat script 
  function listen_injectSiteStart() {
    $this->sitestart .= '<!-- livehelperchat hooked -->' . PHP_EOL;
    $livehelperchatScript .= '<script>var LHC_API = LHC_API||{};
LHC_API.args = {mode:"widget",lhc_base_url:"//mysite.com/livehelperchat/lhc_web/index.php/",wheight:450,wwidth:350,pheight:520,pwidth:500,leaveamessage:true,check_messages:false};
(function() {
var po = document.createElement("script"); po.type = "text/javascript"; po.setAttribute("crossorigin","anonymous"); po.async = true;
var date = new Date();po.src = "//mysite.com/livehelperchat/lhc_web/design/defaulttheme/js/widgetv2/index.js?"+(""+date.getFullYear() + date.getMonth() + date.getDate());
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s);
})();
</script>' . PHP_EOL;

   if (in_array(basename($_SERVER['PHP_SELF']), $this->good_pages)) {	
 $this->sitestart .= $livehelperchatScript . PHP_EOL;
    return $this->sitestart;
  }

 }
}

Re: How do I execute this script?

Posted: Thu Dec 01, 2022 1:39 pm
by Rich-Os
Even apart from not using the <<<eod syntax, I'm not sure I placed the above codes right. Could you see what I did wrong? Thanks so much again.

Re: How do I execute this script?

Posted: Thu Dec 01, 2022 2:01 pm
by Rich-Os
mecinta wrote: Wed Nov 30, 2022 6:25 am Have you checked this?
https://forum.livehelperchat.com/viewtopic.php?id=1739
Yes, I have. Thank you.
I have no issue with SSL as the generated embedded codes seem to work fine. My problem is that widget will not appear on pages unless I actually type the page address fully in browser. Looks like a typical cache problem but everything I did to clear browsers cache/history, etc doesn't work.

Re: How do I execute this script?

Posted: Thu Dec 01, 2022 6:51 pm
by Omar_one
@Rich-Os the first hook I shared working well on every page (locally)

Re: How do I execute this script?

Posted: Wed Dec 07, 2022 1:45 pm
by Rich-Os
Omar_one wrote: Thu Dec 01, 2022 6:51 pm @Rich-Os the first hook I shared working well on every page (locally)
Yeah, but unfortunately, this can't be reproduced on the web with my site.