akonjic Posted September 3, 2016 Share Posted September 3, 2016 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 More sharing options...
rocky Posted September 4, 2016 Share Posted September 4, 2016 You could call that Smarty function directly using: smarty_function_mailto(array('address' => '[email protected]', 'encode' => 'hex')); If it says the function isn't defined, you'll need to include tools\smarty\plugins\function.mailto.php to the PHP file you want to use the function. Link to comment Share on other sites More sharing options...
akonjic Posted September 4, 2016 Author Share Posted September 4, 2016 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 More sharing options...
rocky Posted September 4, 2016 Share Posted September 4, 2016 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 More sharing options...
akonjic Posted September 4, 2016 Author Share Posted September 4, 2016 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 More sharing options...
rocky Posted September 4, 2016 Share Posted September 4, 2016 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); } } } 1 Link to comment Share on other sites More sharing options...
akonjic Posted September 4, 2016 Author Share Posted September 4, 2016 You are DA MAN! You know what it was on my end? A typo! I just couldn't see it last night and I looked and looked and finally today with some fresh eyes typo was discovered. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now