--- /dev/null
+<?php
+/**
+ * Class that extends the base emoticons class to allow output of Horde image
+ * tags.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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 Michael Slusarz <slusarz@horde.org>
+ * @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));
+ }
+
+}
</dir> <!-- /lib/Horde/Core/Prefs/Ui -->
<file name="Ui.php" role="php" />
</dir> <!-- /lib/Horde/Core/Prefs -->
+ <dir name="Text">
+ <dir name="Filter">
+ <file name="Emoticons.php" role="php" />
+ </dir> <!-- /lib/Horde/Core/Text/Filter -->
+ </dir> <!-- /lib/Horde/Core/Text -->
<file name="Autoloader.php" role="php" />
</dir> <!-- /lib/Horde/Core -->
<dir name="Exception">
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>Form</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Http</name>
<channel>pear.horde.org</channel>
</package>
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Form</name>
+ <name>Text_Filter</name>
<channel>pear.horde.org</channel>
</package>
</optional>
<install as="Horde/Core/Perms/Ui.php" name="lib/Horde/Core/Perms/Ui.php" />
<install as="Horde/Core/Prefs/Ui.php" name="lib/Horde/Core/Prefs/Ui.php" />
<install as="Horde/Core/Prefs/Ui/Widgets.php" name="lib/Horde/Core/Prefs/Ui/Widgets.php" />
+ <install as="Horde/Core/Text/Filter/Emoticons.php" name="lib/Horde/Core/Text/Filter/Emoticons.php" />
<install as="Horde/Exception/HookNotSet.php" name="lib/Horde/Exception/HookNotSet.php" />
<install as="Horde/Registry/Api.php" name="lib/Horde/Registry/Api.php" />
<install as="Horde/Registry/Application.php" name="lib/Horde/Registry/Application.php" />
* 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 <marko@oblo.com>
- * @package Horde_Text
+ * @author Marko Djukic <marko@oblo.com>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package Text_Filter
*/
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',
/* 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')
+ ));
}
/**
*
* @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 '';
}
/**
*
* @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);
}
}