diff --git a/libraries/Gelato/Gelato.php b/libraries/Gelato/Gelato.php index 60a2c01..c5a01a8 100644 --- a/libraries/Gelato/Gelato.php +++ b/libraries/Gelato/Gelato.php @@ -18,7 +18,7 @@ /** * The version of Gelato */ -define('GELATO_VERSION', '1.0.2'); +define('GELATO_VERSION', '1.0.3'); /** * Define __DIR__ constant for PHP 5.2.x diff --git a/libraries/Gelato/Html/Html.php b/libraries/Gelato/Html/Html.php index 351f76b..bba92bc 100644 --- a/libraries/Gelato/Html/Html.php +++ b/libraries/Gelato/Html/Html.php @@ -28,6 +28,13 @@ class Html 'accept', 'tabindex', 'accesskey', 'alt', 'title', 'class', 'style', 'selected', 'checked', 'readonly', 'disabled', ); + + /** + * The registered custom macros. + * + * @var array + */ + public static $macros = array(); /** * Protected constructor since this is a static class. @@ -279,7 +286,56 @@ class Html $attributes['alt'] = (isset($attributes['alt'])) ? $attributes['alt'] : pathinfo($file, PATHINFO_FILENAME); return ''; - } + } + + /** + * Obfuscate an e-mail address to prevent spam-bots from sniffing it. + * + * + * echo Html::email('gelato@monstra.org'); + * + * + * @param string $email + * @return string + */ + public static function email($email) + { + return str_replace('@', '@', Html::obfuscate($email)); + } + + /** + * Obfuscate a string to prevent spam-bots from sniffing it. + * + * This method obfuscate the value, randomly convert each + * letter to its entity or hexadecimal representation, keeping a + * bot from sniffing the randomly obfuscated letters. + * + * + * echo Html::obfuscate('gelato@monstra.org'); + * + * + * @param string $value + * @return string + */ + public static function obfuscate($value) + { + $safe = ''; + + foreach (str_split($value) as $letter) { + switch (rand(1, 3)) { + case 1: + $safe .= '&#'.ord($letter).';'; + break; + case 2: + $safe .= '&#x'.dechex(ord($letter)).';'; + break; + case 3: + $safe .= $letter; + } + } + + return $safe; + } /** * Convert html to plain text diff --git a/libraries/Gelato/README.md b/libraries/Gelato/README.md index 69f3f05..6d6fad1 100644 --- a/libraries/Gelato/README.md +++ b/libraries/Gelato/README.md @@ -4,6 +4,6 @@ Gelato is a PHP5 library for kickass Web Applications. ## Links - [Site](http://gelato.monstra.org) -- [Github Repository](https://github.com/Monstra/gelato) +- [Github Repository](https://github.com/MonstrLab/gelato) Copyright (C) 2013 Romanenko Sergey / Awilum [awilum@msn.com] \ No newline at end of file diff --git a/libraries/Gelato/changelog.txt b/libraries/Gelato/changelog.txt index 9a78a9c..aa40a88 100644 --- a/libraries/Gelato/changelog.txt +++ b/libraries/Gelato/changelog.txt @@ -1,3 +1,13 @@ +Gelato 1.0.3, 2013-04-03 +------------------------ +- Html Class: obfuscate() method added. +- Html Class: email() method added. +- Html Class: missing $macros var added. + +Gelato 1.0.2, 2013-03-17 +------------------------ +- Added support for PHP 5.2.3 + Gelato 1.0.1, 2013-03-05 ------------------------ - New constant GELATO_CLASS_LOADER instead of GELATO_AUTOLOADER