Jump to content

{SOLVED} Prestashop 1.7 smarty modifier sur {url entity} (obfuscation de lien pour le SEO)


Recommended Posts

Bonjour, je cherche a faire de l'obfuscation de lien via javascript, j'utilise donc un modifier smarty base64_encode

 <span data-o="{$link->getProductLink($product.id,null,$product.id_category,null,$language.id_lang)|base64_encode}" class="l-obf dropdown-item" data-iso-code="{$language.iso_code}">{$language.name_simple}</span>

J'utilise le tuto de webbax: 

Bon par contre mon projet n'utilise pas Jquery (librairie trop lourde et d'aucune utilité depuis bootstrap 5), j' utilise donc du pure JS

// Link obfuscation
var obf = document.querySelectorAll(".l-obf");
for(var i =0; i < obf.length; i++){
  obf[i].addEventListener('click', function(){
    var link = atob(this.dataset.o);
      window.location.href =link;
});
}
<span class="l-obf" data-o="{$urls.pages.contact|base64_encode}">
 {l s='Contact Us' d='Shop.Theme.Monsupertheme'}
</span>

Ma question est la suivante:

Sur certains liens je ne peux pas utiliser la classe link,  avec la nouvelle facon d'ecrire les liens avec {url} comment puis je injecter un modifier smarty base64_encode ?

merci a ceux qui pourront m'aiguiller,

cdt

Edited by Alexandre Carette (see edit history)
Link to comment
Share on other sites

bon en réfléchissant un peu j'ai trouvé haha:

....
{elseif $page.page_name =='index'}
  {assign var=linkHome value={url entity='index' controller='index' id_lang=$language.id_lang id_shop=1}}
 <span data-o="{$linkHome|base64_encode}" class="l-obf dropdown-item" data-iso-code="{$language.iso_code}">{$language.name_simple}</span>

suffit de faire un assign...

 

Edited by Alexandre Carette (see edit history)
Link to comment
Share on other sites

  • Baba deCode changed the title to {SOLVED} Prestashop 1.7 smarty modifier sur {url entity} (obfuscation de lien pour le SEO)

petite update du JS pour les url UTF8 avec accents encodés en Base64 

// Link obfuscation
var obf = document.querySelectorAll(".l-obf");
for(var i =0; i < obf.length; i++){
  obf[i].addEventListener('click', function(){
    var link = escape(atob(this.dataset.o));
      window.location.href = decodeURIComponent(link);
});
}

 

Edited by Alexandre Carette (see edit history)
Link to comment
Share on other sites

  • 1 year later...
On 5/4/2021 at 9:34 PM, Alexandre Carette said:

petite update du JS pour les url UTF8 avec accents encodés en Base64 

// Link obfuscation
var obf = document.querySelectorAll(".l-obf");
for(var i =0; i < obf.length; i++){
  obf[i].addEventListener('click', function(){
    var link = escape(atob(this.dataset.o));
      window.location.href = decodeURIComponent(link);
});
}

 

Bonjour Alexandre,

peux-tu m'en dire plus sur la facon que tu as effectué l'obfuscation?

Je suis intéressé pour le faire dans mon mégamenu qui a des liens <a>.

Merci

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...