Move Domhtml lib from Support to Util
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 19:32:06 +0000 (13:32 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 19:36:46 +0000 (13:36 -0600)
framework/Support/lib/Horde/Support/Domhtml.php [deleted file]
framework/Support/package.xml
framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php
framework/Text_Filter/lib/Horde/Text/Filter/Xss.php
framework/Text_Filter/package.xml
framework/Util/lib/Horde/Domhtml.php [new file with mode: 0644]
framework/Util/package.xml
imp/lib/tests/mime_viewer_html.phpt
imp/view.php

diff --git a/framework/Support/lib/Horde/Support/Domhtml.php b/framework/Support/lib/Horde/Support/Domhtml.php
deleted file mode 100644 (file)
index 060e58b..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-/**
- * @category   Horde
- * @package    Support
- * @copyright  2010 The Horde Project (http://www.horde.org/)
- * @license    http://opensource.org/licenses/bsd-license.php
- */
-
-/**
- * Utility class to help in loading DOM data from HTML strings.
- *
- * @author     Michael Slusarz <slusarz@horde.org>
- * @category   Horde
- * @package    Support
- * @copyright  2010 The Horde Project (http://www.horde.org/)
- * @license    http://opensource.org/licenses/bsd-license.php
- */
-class Horde_Support_Domhtml
-{
-    /**
-     * DOM object.
-     *
-     * @var DOMDocument
-     */
-    public $dom;
-
-    /**
-     * Charset/encoding used in object.
-     *
-     * @var string
-     */
-    public $encoding;
-
-    /**
-     * Original charset of data.
-     *
-     * @var string
-     */
-    protected $_origCharset;
-
-    /**
-     * @param string $text
-     * @param string $charset
-     *
-     * @throws Exception
-     */
-    public function __construct($text, $charset = null)
-    {
-        if (!extension_loaded('dom')) {
-            throw new Exception('DOM extension is not available.');
-        }
-
-        $this->_origCharset = $charset;
-
-        $old_error = libxml_use_internal_errors(true);
-        $doc = new DOMDocument();
-        $doc->loadHTML($text);
-        $this->encoding = $doc->encoding;
-
-        if (!is_null($charset)) {
-            if (!$doc->encoding) {
-                $doc->loadHTML('<?xml encoding="UTF-8">' . Horde_String::convertCharset($text, $charset, 'UTF-8'));
-                $this->encoding = 'UTF-8';
-            } elseif ($doc->encoding != $charset) {
-                /* If libxml can't auto-detect encoding, convert to what it
-                 * *thinks* the encoding should be. */
-                $doc->loadHTML(Horde_String::convertCharset($text, $charset, $doc->encoding));
-            }
-        }
-
-        if ($old_error) {
-            libxml_use_internal_errors(false);
-        }
-
-        $this->dom = $doc;
-    }
-
-    /**
-     * @return string
-     */
-    public function returnHtml()
-    {
-        return Horde_String::convertCharset($this->dom->saveHTML(), $this->encoding, $this->_origCharset);
-    }
-
-}
index 2e9fc1e..d10adda 100644 (file)
@@ -21,8 +21,7 @@
   <api>beta</api>
  </stability>
  <license uri="http://opensource.org/licenses/bsd-license.php">BSD</license>
- <notes>* Add Horde_Support_Domhtml::.
- * Add Horde_Support_Randomid::.
+ <notes>* Add Horde_Support_Randomid::.
  * Add Portuguese numerizer.
  </notes>
  <contents>
@@ -41,7 +40,6 @@
       <file name="Backtrace.php" role="php" />
       <file name="CombineStream.php" role="php" />
       <file name="ConsistentHash.php" role="php" />
-      <file name="Domhtml.php" role="php" />
       <file name="Guid.php" role="php" />
       <file name="Inflector.php" role="php" />
       <file name="Numerizer.php" role="php" />
     <channel>pear.horde.org</channel>
    </package>
   </required>
-  <optional>
-   <extension>
-    <name>dom</name>
-   </extension>
-  </optional>
  </dependencies>
  <phprelease>
   <filelist>
    <install as="Horde/Support/Backtrace.php" name="lib/Horde/Support/Backtrace.php" />
    <install as="Horde/Support/CombineStream.php" name="lib/Horde/Support/CombineStream.php" />
    <install as="Horde/Support/ConsistentHash.php" name="lib/Horde/Support/ConsistentHash.php" />
-   <install as="Horde/Support/Domhtml.php" name="lib/Horde/Support/Domhtml.php" />
    <install as="Horde/Support/Guid.php" name="lib/Horde/Support/Guid.php" />
    <install as="Horde/Support/Inflector.php" name="lib/Horde/Support/Inflector.php" />
    <install as="Horde/Support/Numerizer.php" name="lib/Horde/Support/Numerizer.php" />
index 3351bc5..47babf4 100644 (file)
@@ -107,7 +107,7 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base
     public function postProcess($text)
     {
         try {
-            $dom = new Horde_Support_Domhtml($text, $this->_params['charset']);
+            $dom = new Horde_Domhtml($text, $this->_params['charset']);
             $text = Horde_String::convertCharset($this->_node($dom->dom, $dom->dom), null, $this->_params['charset']);
         } catch (Exception $e) {
             $text = strip_tags(preg_replace("/\<br\s*\/?\>/i", "\n", $text));
index d24e42f..08d2748 100644 (file)
@@ -15,8 +15,8 @@
  *                     the document.
  *                     DEFAULT: false (returns the contents contained inside
  *                              the BODY tag)
- * 'return_dom' - (boolean) If true, return a Horde_Support_Domhtml object
- *                instead of HTML text (overrides return_document).
+ * 'return_dom' - (boolean) If true, return a Horde_Domhtml object instead of
+ *                HTML text (overrides return_document).
  *                DEFAULT: false
  * 'strip_styles' - (boolean) Strip style tags?
  *                  DEFAULT: true
@@ -94,14 +94,13 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base
      *
      * @param string $text  The text after the filtering.
      *
-     * @return string|Horde_Support_Domhtml  The modified text or a Domhtml
-     *                                       object if the 'return_dom'
-     *                                       parameter is set.
+     * @return string|Horde_Domhtml  The modified text or a Domhtml object if
+     *                               the 'return_dom' parameter is set.
      */
     public function postProcess($text)
     {
         try {
-            $dom = new Horde_Support_Domhtml($text, $this->_params['charset']);
+            $dom = new Horde_Domhtml($text, $this->_params['charset']);
         } catch (Exception $e) {
             return $text;
         }
index 688c546..a5d26df 100644 (file)
     <channel>pear.horde.org</channel>
    </package>
    <package>
-    <name>Support</name>
-    <channel>pear.horde.org</channel>
-   </package>
-   <package>
     <name>Util</name>
     <channel>pear.horde.org</channel>
    </package>
diff --git a/framework/Util/lib/Horde/Domhtml.php b/framework/Util/lib/Horde/Domhtml.php
new file mode 100644 (file)
index 0000000..82b4ab4
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Util
+ * @copyright  2010 The Horde Project (http://www.horde.org/)
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ */
+
+/**
+ * Utility class to help in loading DOM data from HTML strings.
+ *
+ * @author     Michael Slusarz <slusarz@horde.org>
+ * @category   Horde
+ * @package    Util
+ * @copyright  2010 The Horde Project (http://www.horde.org/)
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ */
+class Horde_Domhtml
+{
+    /**
+     * DOM object.
+     *
+     * @var DOMDocument
+     */
+    public $dom;
+
+    /**
+     * Charset/encoding used in object.
+     *
+     * @var string
+     */
+    public $encoding;
+
+    /**
+     * Original charset of data.
+     *
+     * @var string
+     */
+    protected $_origCharset;
+
+    /**
+     * @param string $text
+     * @param string $charset
+     *
+     * @throws Exception
+     */
+    public function __construct($text, $charset = null)
+    {
+        if (!extension_loaded('dom')) {
+            throw new Exception('DOM extension is not available.');
+        }
+
+        $this->_origCharset = $charset;
+
+        $old_error = libxml_use_internal_errors(true);
+        $doc = new DOMDocument();
+        $doc->loadHTML($text);
+        $this->encoding = $doc->encoding;
+
+        if (!is_null($charset)) {
+            if (!$doc->encoding) {
+                $doc->loadHTML('<?xml encoding="UTF-8">' . Horde_String::convertCharset($text, $charset, 'UTF-8'));
+                $this->encoding = 'UTF-8';
+            } elseif ($doc->encoding != $charset) {
+                /* If libxml can't auto-detect encoding, convert to what it
+                 * *thinks* the encoding should be. */
+                $doc->loadHTML(Horde_String::convertCharset($text, $charset, $doc->encoding));
+            }
+        }
+
+        if ($old_error) {
+            libxml_use_internal_errors(false);
+        }
+
+        $this->dom = $doc;
+    }
+
+    /**
+     * @return string
+     */
+    public function returnHtml()
+    {
+        return Horde_String::convertCharset($this->dom->saveHTML(), $this->encoding, $this->_origCharset);
+    }
+
+}
index e56a3c7..61a5aaf 100644 (file)
@@ -27,8 +27,8 @@
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
-* Removed Horde_Util::assertDriverConfig().
+ <notes>* Added Horde_Domhtml::.
+ * Removed Horde_Util::assertDriverConfig().
  * Removed Horde_Util::bufferOutput().
  * Removed Horde_Util::uriB64Encode() and Horde_Util::uriB64Decode().
  * Removed Horde_Util::strftime2date() and Horde_Util::date2strftime().
@@ -48,6 +48,7 @@
       </dir> <!-- /lib/Horde/Array/Sort -->
      </dir> <!-- /lib/Horde/Array -->
      <file name="Array.php" role="php" />
+     <file name="Domhtml.php" role="php" />
      <file name="String.php" role="php" />
      <file name="Util.php" role="php" />
      <file name="Variables.php" role="php" />
@@ -85,6 +86,9 @@
     <channel>pear.horde.org</channel>
    </package>
    <extension>
+    <name>dom</name>
+   </extension>
+   <extension>
     <name>iconv</name>
    </extension>
    <extension>
  <phprelease>
   <filelist>
    <install as="Horde/Array.php" name="lib/Horde/Array.php" />
+   <install as="Horde/Domhtml.php" name="lib/Horde/Domhtml.php" />
    <install as="Horde/String.php" name="lib/Horde/String.php" />
    <install as="Horde/Util.php" name="lib/Horde/Util.php" />
    <install as="Horde/Variables.php" name="lib/Horde/Variables.php" />
index 2a7a1f8..87722ea 100644 (file)
@@ -22,7 +22,7 @@ class IMP_Html_Viewer_Test extends IMP_Horde_Mime_Viewer_Html
             'target' => '_blank'
         );
 
-        $dom = new Horde_Support_Domhtml($html);
+        $dom = new Horde_Domhtml($html);
         $this->_node($dom->dom, $dom->dom);
 
         return $dom->dom->saveXML($dom->dom->getElementsByTagName('body')->item(0)->firstChild) . "\n";
index 6557a8b..998abc2 100644 (file)
@@ -291,7 +291,7 @@ case 'print_attach':
                 if ($browser->isBrowser('mozilla')) {
                     $pstring = Horde_Mime::decodeParam('content-type', $render[$key]['type']);
 
-                    $doc = new Horde_Support_Domhtml($render[$key]['data'], $pstring['params']['charset']);
+                    $doc = new Horde_Domhtml($render[$key]['data'], $pstring['params']['charset']);
 
                     $bodyelt = $doc->dom->getElementsByTagName('body')->item(0);
                     $bodyelt->insertBefore($doc->dom->importNode($div, true), $bodyelt->firstChild);