From: Michael M Slusarz Date: Fri, 9 Jul 2010 06:58:36 +0000 (-0600) Subject: Emoticons filter fixes. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=01be634d9b7a943fb6d437db62005cf99636dc10;p=horde.git Emoticons filter fixes. Fix image generation with new Horde_Themes code. Remove Core dependency from Emoticons filter by moving image generation code to a Core library. --- diff --git a/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php b/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php new file mode 100644 index 000000000..ab2e429dd --- /dev/null +++ b/framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php @@ -0,0 +1,30 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Core_Text_Filter_Emoticons extends Horde_Text_Filter_Emoticons +{ + /** + * Return the HTML image tag needed to display an emoticon. + * + * @param string $icon The emoticon name. + * + * @return string The HTML image code. + */ + protected function _getImage($icon) + { + return Horde::img(Horde_Themes::img('emoticons/' . $this->getIcons($icon) . '.png'), $icon, array('align' => 'middle', 'title' => $icon)); + } + +} diff --git a/framework/Core/package.xml b/framework/Core/package.xml index e821adaba..fd648aa92 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -146,6 +146,11 @@ Application Framework. + + + + + @@ -255,6 +260,10 @@ Application Framework. pear.horde.org + Form + pear.horde.org + + Http pear.horde.org @@ -267,7 +276,7 @@ Application Framework. pear.horde.org - Form + Text_Filter pear.horde.org @@ -344,6 +353,7 @@ Application Framework. + diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php b/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php index ad6d54a94..b525e91d2 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php @@ -13,8 +13,10 @@ * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. * - * @author Marko Djukic - * @package Horde_Text + * @author Marko Djukic + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Text_Filter */ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base { @@ -25,16 +27,9 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base */ protected $_params = array('entities' => false); - /** - * The icon path. - * - * @var string - */ - static protected $_iconpath; - /* List complex strings before simpler ones, otherwise for example :(( * would be matched against :( before :(( is found. */ - static protected $_icons = array( + protected $_icons = array( ':/' => 'frustrated', ':-/' => 'frustrated', // ':*>' => 'blush', ':e' => 'disappointed', @@ -104,9 +99,11 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base /* Check for a smiley either immediately at the start of a line or * following a space. Use {} as the preg delimiters as this is not * found in any smiley. */ - $regexp['{' . $beg_pattern . implode('|', $patterns) . $end_pattern . '}e'] = 'Horde_Text_Filter_Emoticons::getImage(\'$2\', \'$1\', \'' . ($this->_params['entities'] ? '$3' : '') . '\')'; + $regexp = '{' . $beg_pattern . implode('|', $patterns) . $end_pattern . '}'; - return array('regexp' => $regexp); + return array('regexp_callback' => array( + $regexp => array($this, 'getImage') + )); } /** @@ -114,20 +111,26 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base * * @see self::getPatterns() * - * @param string $icon The emoticon. - * @param string $prefix A html prefix. - * @param string $postfix A html postfix. + * @param array $matches Matches from preg_replace_callback(). * * @return string HTML code with the image tag and any additional prefix * or postfix. */ - static public function getImage($icon, $prefix, $postfix) + public function getImage($matches) { - if (!isset(self::$_iconpath)) { - self::$_iconpath = Horde_Themes::img(null, 'horde') . '/emoticons'; - } + return $matches[1] . $this->_getImage($matches[2]) . (empty($matches[3]) ? '' : $matches[3]); + } - return $prefix . Horde::img(self::getIcons($icon) . '.png', $icon, array('align' => 'middle', 'title' => $icon), self::$_iconpath) . $postfix; + /** + * Return the HTML image tag needed to display an emoticon. + * + * @param string $icon The emoticon name. + * + * @return string The HTML image code. + */ + protected function _getImage($icon) + { + return ''; } /** @@ -138,11 +141,11 @@ class Horde_Text_Filter_Emoticons extends Horde_Text_Filter_Base * * @return array|string Patterns hash or icon name. */ - static public function getIcons($icon = null) + public function getIcons($icon = null) { return is_null($icon) - ? self::$_icons - : (isset(self::$_icons[$icon]) ? self::$_icons[$icon] : null); + ? $this->_icons + : (isset($this->_icons[$icon]) ? $this->_icons[$icon] : null); } } diff --git a/framework/Text_Filter/package.xml b/framework/Text_Filter/package.xml index e9113316a..89584c7c5 100644 --- a/framework/Text_Filter/package.xml +++ b/framework/Text_Filter/package.xml @@ -37,7 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Html2text converter now uses XML parser to generate output. + * Remove Horde/Core dependency in the Emoticons driver. + * Html2text converter now uses XML parser to generate output. * Add ability to define filters to use with preg_replace_callback(). * Add 'noprefetch' parameter to XSS filter (Ticket #8836). * Add XSS filtering for data URLs in A HREF parameters (Bug #8715). diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index 6fb6aecd5..19951946b 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -257,7 +257,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html } if ($GLOBALS['prefs']->getValue('emoticons')) { - $data = Horde_Text_Filter::filter($data, array('emoticons'), array(array('entities' => true))); + $data = Horde_Text_Filter::filter($data, array('Horde_Core_Text_Filter_Emoticons'), array(array('entities' => true))); } return array( diff --git a/imp/lib/Mime/Viewer/Plain.php b/imp/lib/Mime/Viewer/Plain.php index f9be002f1..87501b0b7 100644 --- a/imp/lib/Mime/Viewer/Plain.php +++ b/imp/lib/Mime/Viewer/Plain.php @@ -143,7 +143,7 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain } if ($prefs->getValue('emoticons')) { - $filters['emoticons'] = array('entities' => true); + $filters['Horde_Core_Text_Filter_Emoticons'] = array('entities' => true); } // Run filters.