|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kuras Smarty n00b
Joined: 02 Nov 2007 Posts: 1
|
Posted: Fri Nov 02, 2007 11:22 am Post subject: protect email - output filter plugin |
|
|
nothing realy new... but I hope it will help someone.
There is one simple email protection filter as an example here:
(see smarty documentation Chapter 16. Extending Smarty With Plugins. Output Filters)
And here is my approach.
Code: | <?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: outputfilter.protect_email_hex.php
* Type: outputfilter
* Name: protect_email_hex
* Purpose: Email protection against spambots
* Date : 2007-11-01
* Written by: kuras
* -------------------------------------------------------------
*/
function encode_email($matches)
{
$address = $matches[1];
$address_encode = '';
for ($x=0; $x < strlen($address); $x++)
{
if(preg_match('!\w!',$address[$x])) {
$address_encode .= '%' . bin2hex($address[$x]);
} else {
$address_encode .= $address[$x];
}
}
// REMOVE SPACES in $mailto variables value.
$mailto = "& #109;& #97;& #105;& #108;& #116;& #111;& #58;";
$text = $matches[2];
$text_encode = '';
for ($x=0; $x < strlen($text); $x++) {
$text_encode .= '&#x' . bin2hex($text[$x]).';';
}
return "<a href=".$mailto.$address_encode.">".$text_encode."</a>";
}
function smarty_outputfilter_protect_email_hex($tpl_output, &$tpl)
{
return preg_replace_callback("/\<a href\=\"mailto:(.*?)\"\>(.*?)\<\/a\>/i", "encode_email", $tpl_output);
}
?> |
The exact email encoding idea (function encode_email()) is also not new.
I took it from smarty {mailto} (HEX encoding type).
You can modify it or replace as you want.
And don't forget to remove SPACES from $mailto value before using...
I just can't post normal code in to this forum, because letter codes would be replaced by actual letters... :)
kurasesu
another similar topic:
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=8563 |
|
Back to top |
|
cfletcher1856 Smarty n00b
Joined: 21 Mar 2007 Posts: 4
|
Posted: Thu Oct 30, 2008 8:23 pm Post subject: |
|
|
I took yours as an example and created one using the smarty mailto.
Code: | <?php
function encode_email($matches)
{
global $smarty;
require_once $smarty->_get_plugin_filepath('function', 'mailto');
return smarty_function_mailto(array('address' => $matches[1],
'encode' => 'javascript',
'text' => $matches[2]
),
$smarty);
}
function smarty_outputfilter_email_encode($tpl_output, &$smarty)
{
return preg_replace_callback("/\<a href\=\"mailto:(.*?)\"\>(.*?)\<\/a\>/i", "encode_email", $tpl_output);
}
?> |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|