From: Michael M Slusarz Date: Wed, 25 Aug 2010 19:32:06 +0000 (-0600) Subject: Move Domhtml lib from Support to Util X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=3608e2bb39e79845c942b01cb712051546ed5b77;p=horde.git Move Domhtml lib from Support to Util --- diff --git a/framework/Support/lib/Horde/Support/Domhtml.php b/framework/Support/lib/Horde/Support/Domhtml.php deleted file mode 100644 index 060e58b9a..000000000 --- a/framework/Support/lib/Horde/Support/Domhtml.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @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('' . 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); - } - -} diff --git a/framework/Support/package.xml b/framework/Support/package.xml index 2e9fc1eb4..d10adda6b 100644 --- a/framework/Support/package.xml +++ b/framework/Support/package.xml @@ -21,8 +21,7 @@ beta BSD - * Add Horde_Support_Domhtml::. - * Add Horde_Support_Randomid::. + * Add Horde_Support_Randomid::. * Add Portuguese numerizer. @@ -41,7 +40,6 @@ - @@ -92,11 +90,6 @@ pear.horde.org - - - dom - - @@ -104,7 +97,6 @@ - diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php index 3351bc59d..47babf402 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php @@ -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("/\/i", "\n", $text)); diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php b/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php index d24e42f9f..08d274843 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php @@ -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; } diff --git a/framework/Text_Filter/package.xml b/framework/Text_Filter/package.xml index 688c546ec..a5d26df71 100644 --- a/framework/Text_Filter/package.xml +++ b/framework/Text_Filter/package.xml @@ -113,10 +113,6 @@ pear.horde.org - Support - pear.horde.org - - Util pear.horde.org diff --git a/framework/Util/lib/Horde/Domhtml.php b/framework/Util/lib/Horde/Domhtml.php new file mode 100644 index 000000000..82b4ab40e --- /dev/null +++ b/framework/Util/lib/Horde/Domhtml.php @@ -0,0 +1,86 @@ + + * @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('' . 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); + } + +} diff --git a/framework/Util/package.xml b/framework/Util/package.xml index e56a3c7f5..61a5aaf27 100644 --- a/framework/Util/package.xml +++ b/framework/Util/package.xml @@ -27,8 +27,8 @@ beta LGPL - -* Removed Horde_Util::assertDriverConfig(). + * 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 @@ + @@ -85,6 +86,9 @@ pear.horde.org + dom + + iconv @@ -98,6 +102,7 @@ + diff --git a/imp/lib/tests/mime_viewer_html.phpt b/imp/lib/tests/mime_viewer_html.phpt index 2a7a1f861..87722ea3f 100644 --- a/imp/lib/tests/mime_viewer_html.phpt +++ b/imp/lib/tests/mime_viewer_html.phpt @@ -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"; diff --git a/imp/view.php b/imp/view.php index 6557a8b37..998abc27d 100644 --- a/imp/view.php +++ b/imp/view.php @@ -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);