Jump to content

CMS Hex Email Address?


Recommended Posts

Hi folks,

 

Quick question: Does anyone know how to hex encode an email address within the CMS? Say if you want to use an email address in the CMS for a static page [email protected] but you want to encode it. Using smarty template you could do {mailto address="[email protected]} but not sure how it works with the CMS.

 

Should I be looking at the cms.tpl file to achieve this?

 

Thanks in advance.

Link to comment
Share on other sites

Thanks for the reply.

 

I'm not sure how to integrate it into the $cms->content from the cms template file.

 

I know I can use smarty mailto code for emails but trying to figure out how to encode emails from within the content area on the cms pages so they are hex.

Link to comment
Share on other sites

That makes things difficult. I guess you'll have to override controllers/front/CmsController.php and do a search and replace on $cms->content. For example:
<?php

class CmsController extends CmsControllerCore
{
    public function initContent()
    {
        parent::initContent();

        if (isset($this->cms->content) && strpos($this->cms->content, '{mailto}') !== false) {
            $this->cms->content = str_replace(
​                '{mailto}',
​                smarty_function_mailto(array('address' => '[email protected]', 'encode' => 'hex')),
​                $this->cms->content
​            );
        }
    }
}

This should replace the text {mailto} in the content with the hex-generated version. I haven't tested the code, so you'll have to do that. Also, don't forget to go to Advanced Parameters > Performance and click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override.

 

Link to comment
Share on other sites

Hi,

 

Thanks a lot. I went ahead and created the overwrite for controller but for some reason the smarty_function_mailto is throwing me out an error when I use it within the str_replace. If I replace it with whatever else such as 'test' it works fine. Any ideas?

 

Thanks again!

Link to comment
Share on other sites

It's working fine on my PrestaShop v1.6.1.6 test site. I created override/controllers/front/CmsController.php with the following:

<?php

include_once('tools/smarty/plugins/function.mailto.php');

class CmsController extends CmsControllerCore
{
    public function initContent()
    {
        parent::initContent();

        if (isset($this->cms->content) && strpos($this->cms->content, '{mailto}') !== false) {
            $this->cms->content = str_replace('{mailto}', smarty_function_mailto(array('address' => '[email protected]', 'encode' => 'hex')), $this->cms->content);
        }
    }
}
  • Like 1
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...