Emoticons filter fixes.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Jul 2010 06:58:36 +0000 (00:58 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Jul 2010 07:04:14 +0000 (01:04 -0600)
Fix image generation with new Horde_Themes code.
Remove Core dependency from Emoticons filter by moving image generation
code to a Core library.

framework/Core/lib/Horde/Core/Text/Filter/Emoticons.php [new file with mode: 0644]
framework/Core/package.xml
framework/Text_Filter/lib/Horde/Text/Filter/Emoticons.php
framework/Text_Filter/package.xml
imp/lib/Mime/Viewer/Html.php
imp/lib/Mime/Viewer/Plain.php

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 (file)
index 0000000..ab2e429
--- /dev/null
@@ -0,0 +1,30 @@
+<?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));
+    }
+
+}
index e821ada..fd648aa 100644 (file)
@@ -146,6 +146,11 @@ Application Framework.</description>
        </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">
@@ -255,6 +260,10 @@ Application Framework.</description>
     <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>
@@ -267,7 +276,7 @@ Application Framework.</description>
     <channel>pear.horde.org</channel>
    </package>
    <package>
-    <name>Form</name>
+    <name>Text_Filter</name>
     <channel>pear.horde.org</channel>
    </package>
   </optional>
@@ -344,6 +353,7 @@ Application Framework.</description>
    <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" />
index ad6d54a..b525e91 100644 (file)
  * 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
 {
@@ -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);
     }
 
 }
index e911331..89584c7 100644 (file)
@@ -37,7 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Html2text converter now uses XML parser to generate output.
+ <notes>* 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).
index 6fb6aec..1995194 100644 (file)
@@ -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(
index f9be002..87501b0 100644 (file)
@@ -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.