How do I execute this script?

Open to all! Ask other shopowners for help.
mecinta
Member
Posts: 5
Joined: Sun Nov 07, 2021 1:28 pm
Phoenix Version:
Has thanked: 6 times
Been thanked: 4 times

Re: How do I execute this script?

Post by mecinta »

I am from a land of Melayu, Cina and Tamil


Join The Code Co-op to get access to your library in the Code Co-op Forum
Rich-Os
Member
Posts: 21
Joined: Thu Sep 30, 2021 2:03 pm
Phoenix Version:
Has thanked: 5 times

Re: How do I execute this script?

Post 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)
Rich-Os
Member
Posts: 21
Joined: Thu Sep 30, 2021 2:03 pm
Phoenix Version:
Has thanked: 5 times

Re: How do I execute this script?

Post 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;
  }

 }
}
Rich-Os
Member
Posts: 21
Joined: Thu Sep 30, 2021 2:03 pm
Phoenix Version:
Has thanked: 5 times

Re: How do I execute this script?

Post 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.
Rich-Os
Member
Posts: 21
Joined: Thu Sep 30, 2021 2:03 pm
Phoenix Version:
Has thanked: 5 times

Re: How do I execute this script?

Post 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.
Omar_one
Senior Contributor
Posts: 679
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: How do I execute this script?

Post by Omar_one »

@Rich-Os the first hook I shared working well on every page (locally)
Rich-Os
Member
Posts: 21
Joined: Thu Sep 30, 2021 2:03 pm
Phoenix Version:
Has thanked: 5 times

Re: How do I execute this script?

Post 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.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply