Bring back Html::mailto and Html::email from L3
This commit is contained in:
1 parent
a120936148
commit
00ad50157f
1 file changed
+63
-1
+63
-1
@@ -127,7 +127,7 @@ class HtmlBuilder {
|
||||
|
||||
return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a HTTPS HTML link.
|
||||
*
|
||||
@@ -198,6 +198,68 @@ class HtmlBuilder {
|
||||
return $this->link($this->url->action($action, $parameters), $title, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a HTML link to a mailto
|
||||
* @param string $email
|
||||
* @param string $title
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public function mailto($email, $title = null, $attributes = array())
|
||||
{
|
||||
$email = static::email($email);
|
||||
|
||||
$title = $title ?: $email;
|
||||
|
||||
$email = static::obfuscate('mailto:') . $email;
|
||||
|
||||
return '<a href="'.$email.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Obfuscate an e-mail address to prevent spam-bots from sniffing it.
|
||||
*
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
public static function email($email)
|
||||
{
|
||||
return str_replace('@', '@', static::obfuscate($email));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obfuscate a string to prevent spam-bots from sniffing it.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected static function obfuscate($value)
|
||||
{
|
||||
$safe = '';
|
||||
|
||||
foreach (str_split($value) as $letter)
|
||||
{
|
||||
// To properly obfuscate the value, we will randomly convert each
|
||||
// letter to its entity or hexadecimal representation, keeping a
|
||||
// bot from sniffing the randomly obfuscated letters.
|
||||
switch (rand(1, 3))
|
||||
{
|
||||
case 1:
|
||||
$safe .= '&#'.ord($letter).';';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$safe .= '&#x'.dechex(ord($letter)).';';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$safe .= $letter;
|
||||
}
|
||||
}
|
||||
|
||||
return $safe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an ordered list of items.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user