+++ /dev/null
-<?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);
- }
-
-}
<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>
<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" />
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));
* 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
*
* @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;
}
<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>
--- /dev/null
+<?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);
+ }
+
+}
<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().
</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" />
<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" />
'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";
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);