}
/* Load the DOM object. */
- include_once 'Horde/DOM.php';
- $doc = Horde_DOM_Document::factory(array('filename' => $path . '/conf.xml'));
+ $dom = new DOMDocument();
+ $dom->load($path . '/conf.xml');
/* Check if there is a CVS/Git version tag and store it. */
- $node = $doc->first_child();
+ $node = $dom->firstChild;
while (!empty($node)) {
- if (($node->type == XML_COMMENT_NODE) &&
- ($vers_tag = $this->getVersion($node->node_value()))) {
+ if (($node->nodeType == XML_COMMENT_NODE) &&
+ ($vers_tag = $this->getVersion($node->nodeValue))) {
$this->_versionTag = $vers_tag . "\n";
break;
}
- $node = $node->next_sibling();
+ $node = $node->nextSibling;
}
/* Parse the config file. */
$this->_xmlConfigTree = array();
- $root = $doc->root();
- if ($root->has_child_nodes()) {
- $this->_parseLevel($this->_xmlConfigTree, $root->child_nodes(), '');
+ $root = $dom->documentElement;
+ if ($root->hasChildNodes()) {
+ $this->_parseLevel($this->_xmlConfigTree, $root->childNodes, '');
}
return $this->_xmlConfigTree;
* Parses one level of the configuration XML tree into the associative
* array containing the traversed configuration tree.
*
- * @param array &$conf The already existing array where the processed
- * XML tree portion should be appended to.
- * @param array $children An array containing the XML nodes of the level
- * that should be parsed.
- * @param string $ctx A string representing the current position
- * (context prefix) inside the configuration XML
- * file.
+ * @param array &$conf The already existing array where the
+ * processed XML tree portion should be
+ * appended to.
+ * @param DOMNodeList $children The XML nodes of the level that should
+ * be parsed.
+ * @param string $ctx A string representing the current
+ * position (context prefix) inside the
+ * configuration XML file.
*/
protected function _parseLevel(&$conf, $children, $ctx)
{
- reset($children);
- while (list(,$node) = each($children)) {
- if ($node->type != XML_ELEMENT_NODE) {
+ foreach ($children as $node) {
+ if ($node->nodeType != XML_ELEMENT_NODE) {
continue;
}
- $name = $node->get_attribute('name');
- $desc = Horde_Text_Filter::filter($node->get_attribute('desc'), 'linkurls', array('callback' => 'Horde::externalUrl'));
- $required = !($node->get_attribute('required') == 'false');
- $quote = !($node->get_attribute('quote') == 'false');
+ $name = $node->getAttribute('name');
+ $desc = Horde_Text_Filter::filter($node->getAttribute('desc'), 'linkurls', array('callback' => 'Horde::externalUrl'));
+ $required = !($node->getAttribute('required') == 'false');
+ $quote = !($node->getAttribute('quote') == 'false');
$curctx = empty($ctx)
? $name
: $ctx . '|' . $name;
- switch ($node->tagname) {
+ switch ($node->tagName) {
case 'configdescription':
if (empty($name)) {
$name = hash('md5', uniqid(mt_rand(), true));
'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node))
);
- if ($node->get_attribute('octal') == 'true' &&
+ if ($node->getAttribute('octal') == 'true' &&
$conf[$name]['default'] != '') {
$conf[$name]['_type'] = 'octal';
$conf[$name]['default'] = sprintf('0%o', $this->_default($curctx, octdec($this->_getNodeOnlyText($node))));
break;
case 'configldap':
- $conf[$node->get_attribute('switchname')] = $this->_configLDAP($ctx, $node);
+ $conf[$node->getAttribute('switchname')] = $this->_configLDAP($ctx, $node);
break;
case 'configphp':
break;
case 'configsql':
- $conf[$node->get_attribute('switchname')] = $this->_configSQL($ctx, $node);
+ $conf[$node->getAttribute('switchname')] = $this->_configSQL($ctx, $node);
break;
case 'configvfs':
- $conf[$node->get_attribute('switchname')] = $this->_configVFS($ctx, $node);
+ $conf[$node->getAttribute('switchname')] = $this->_configVFS($ctx, $node);
break;
case 'configsection':
$conf[$name] = array();
$cur = &$conf[$name];
- if ($node->has_child_nodes()) {
- $this->_parseLevel($cur, $node->child_nodes(), $curctx);
+ if ($node->hasChildNodes()) {
+ $this->_parseLevel($cur, $node->childNodes, $curctx);
}
break;
'desc' => $desc
);
- if ($node->has_child_nodes()) {
- $this->_parseLevel($conf, $node->child_nodes(), $ctx);
+ if ($node->hasChildNodes()) {
+ $this->_parseLevel($conf, $node->childNodes, $ctx);
}
break;
default:
$conf[$name] = array();
$cur = &$conf[$name];
- if ($node->has_child_nodes()) {
- $this->_parseLevel($cur, $node->child_nodes(), $curctx);
+ if ($node->hasChildNodes()) {
+ $this->_parseLevel($cur, $node->childNodes, $curctx);
}
break;
}
'writedn' => $writedn,
'ca' => $ca
);
-
- if (isset($node) && $node->get_attribute('baseconfig') == 'true') {
+
+ if (isset($node) && $node->getAttribute('baseconfig') == 'true') {
return $custom_fields;
}
- list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->get_attribute('switchname') : $switchname), 'horde');
+ list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde');
$config = array(
'desc' => 'Driver configuration',
'default' => $default,
)
);
- if (isset($node) && $node->has_child_nodes()) {
+ if (isset($node) && $node->hasChildNodes()) {
$cur = array();
- $this->_parseLevel($cur, $node->child_nodes(), $ctx);
+ $this->_parseLevel($cur, $node->childNodes, $ctx);
$config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur);
$config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur);
}
)
);
- if (isset($node) && $node->get_attribute('baseconfig') == 'true') {
+ if (isset($node) && $node->getAttribute('baseconfig') == 'true') {
return $custom_fields;
}
- list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->get_attribute('switchname') : $switchname), 'horde');
+ list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde');
$config = array(
'desc' => 'Driver configuration',
'default' => $default,
)
);
- if (isset($node) && $node->has_child_nodes()) {
+ if (isset($node) && $node->hasChildNodes()) {
$cur = array();
- $this->_parseLevel($cur, $node->child_nodes(), $ctx);
+ $this->_parseLevel($cur, $node->childNodes, $ctx);
$config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur);
$config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur);
}
protected function _configVFS($ctx, $node)
{
$sql = $this->_configSQL($ctx . '|params');
- $default = $node->get_attribute('default');
+ $default = $node->getAttribute('default');
$default = empty($default) ? 'horde' : $default;
- list($default, $isDefault) = $this->__default($ctx . '|' . $node->get_attribute('switchname'), $default);
+ list($default, $isDefault) = $this->__default($ctx . '|' . $node->getAttribute('switchname'), $default);
$config = array(
'desc' => 'What VFS driver should we use?',
)
);
- if (isset($node) && $node->get_attribute('baseconfig') != 'true') {
+ if (isset($node) && $node->getAttribute('baseconfig') != 'true') {
$config['switch']['horde'] = array(
'desc' => 'Horde defaults',
'fields' => array()
{
$text = '';
- if (!$node->has_child_nodes()) {
- return $node->get_content();
+ if (!$node->hasChildNodes()) {
+ return $node->textContent;
}
- foreach ($node->child_nodes() as $tnode) {
- if ($tnode->type == XML_TEXT_NODE) {
- $text .= $tnode->content;
+ foreach ($node->childNodes as $tnode) {
+ if ($tnode->nodeType == XML_TEXT_NODE) {
+ $text .= $tnode->textContent;
}
}
{
$values = array();
- if (!$node->has_child_nodes()) {
+ if (!$node->hasChildNodes()) {
return $values;
}
- foreach ($node->child_nodes() as $vnode) {
- if ($vnode->type == XML_ELEMENT_NODE &&
- $vnode->tagname == 'values') {
- if (!$vnode->has_child_nodes()) {
+ foreach ($node->childNodes as $vnode) {
+ if ($vnode->nodeType == XML_ELEMENT_NODE &&
+ $vnode->tagName == 'values') {
+ if (!$vnode->hasChildNodes()) {
return array();
}
- foreach ($vnode->child_nodes() as $value) {
- if ($value->type == XML_ELEMENT_NODE) {
- if ($value->tagname == 'configspecial') {
+ foreach ($vnode->childNodes as $value) {
+ if ($value->nodeType == XML_ELEMENT_NODE) {
+ if ($value->tagName == 'configspecial') {
return $this->_handleSpecials($value);
- } elseif ($value->tagname == 'value') {
- $text = $value->get_content();
- $desc = $value->get_attribute('desc');
+ } elseif ($value->tagName == 'value') {
+ $text = $value->textContent;
+ $desc = $value->getAttribute('desc');
$values[$text] = empty($desc) ? $text : $desc;
}
}
{
$values = array();
- if (!$node->has_child_nodes()) {
+ if (!$node->hasChildNodes()) {
return $values;
}
- foreach ($node->child_nodes() as $case) {
- if ($case->type == XML_ELEMENT_NODE) {
- $name = $case->get_attribute('name');
+ foreach ($node->childNodes as $case) {
+ if ($case->nodeType == XML_ELEMENT_NODE) {
+ $name = $case->getAttribute('name');
$values[$name] = array(
- 'desc' => $case->get_attribute('desc'),
+ 'desc' => $case->getAttribute('desc'),
'fields' => array()
);
- if ($case->has_child_nodes()) {
- $this->_parseLevel($values[$name]['fields'], $case->child_nodes(), $curctx);
+ if ($case->hasChildNodes()) {
+ $this->_parseLevel($values[$name]['fields'], $case->childNodes, $curctx);
}
}
}
*/
protected function _handleSpecials($node)
{
- switch ($node->get_attribute('name')) {
+ switch ($node->getAttribute('name')) {
case 'list-horde-apps':
$apps = Horde_Array::valuesToKeys($GLOBALS['registry']->listApps(array('hidden', 'notoolbar', 'active')));
asort($apps);
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added Horde_Registry_Api:: and Horde_Registry_Application:: classes.
+ <notes>* Remove dependency on Horde_DOM package.
+ * Added Horde_Registry_Api:: and Horde_Registry_Application:: classes.
* Moved Horde_Exception to Exception package.
* Renamed Menu:: as Horde_Menu::.
* Renamed Help:: as Horde_Help::.
<channel>pear.horde.org</channel>
</package>
<package>
- <name>DOM</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Exception</name>
<channel>pear.horde.org</channel>
</package>
+++ /dev/null
-<?php
-/**
- * The Horde_DOM_Document and related classes provide a PHP 4 domxml
- * compatible wrapper around the PHP 5 dom implementation to allow scripts
- * written for PHP 4 domxml model to work under PHP 5's dom support.
- *
- * This code was derived from the Horde_Config_Dom and related classes which
- * in turn was derived from code written by Alexandre Alapetite. The only
- * changes made to the original code were to implement Horde's coding
- * standards and some minor changes to more easily fit into the framework.
- * The original code can be found at:
- * http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Horde_DOM
- */
-
-/** Validate against the DTD */
-define('HORDE_DOM_LOAD_VALIDATE', 1);
-
-/** Recover from load errors */
-define('HORDE_DOM_LOAD_RECOVER', 2);
-
-/** Remove redundant whitespace */
-define('HORDE_DOM_LOAD_REMOVE_BLANKS', 4);
-
-/** Substitute XML entities */
-define('HORDE_DOM_LOAD_SUBSTITUTE_ENTITIES', 8);
-
-class Horde_DOM_Document extends Horde_DOM_Node {
-
- /**
- * Creates an appropriate object based on the version of PHP that is
- * running and the requested xml source. This function should be passed an
- * array containing either 'filename' => $filename | 'xml' => $xmlstring
- * depending on the source of the XML document.
- *
- * You can pass an optional 'options' parameter to enable extra
- * features like DTD validation or removal of whitespaces.
- * For a list of available features see the HORDE_DOM_LOAD defines.
- * Multiple options are added by bitwise OR.
- *
- * @param array $params Array containing either 'filename' | 'xml' keys.
- * You can specify an optional 'options' key.
- *
- * @return mixed Horde_DOM_Document | PEAR_Error
- */
- function factory($params = array())
- {
- if (!isset($params['options'])) {
- $params['options'] = 0;
- }
-
- $doc = new Horde_DOM_Document($params);
- if (isset($doc->error)) {
- return $doc->error;
- }
-
- return $doc;
- }
-
- /**
- * Constructor. Determine if we are trying to load a file or xml string
- * based on the parameters.
- *
- * @param array $params Array with key 'filename' | 'xml'
- */
- function Horde_DOM_Document($params = array())
- {
- $this->node = new DOMDocument();
-
- // Load mode
- if ($params['options'] & HORDE_DOM_LOAD_VALIDATE) {
- $this->node->validateOnParse = true;
- } elseif ($params['options'] & HORDE_DOM_LOAD_RECOVER) {
- $this->node->recover = true;
- }
-
- // Load options
- if ($params['options'] & HORDE_DOM_LOAD_REMOVE_BLANKS) {
- $this->node->preserveWhiteSpace = false;
- }
- if ($params['options'] & HORDE_DOM_LOAD_SUBSTITUTE_ENTITIES) {
- $this->node->substituteEntities = true;
- }
-
- if (isset($params['xml'])) {
- $result = @$this->node->loadXML($params['xml']);
- if (!$result) {
- $this->error = PEAR::raiseError('Failed loading XML document.');
- return;
- }
- } elseif (isset($params['filename'])) {
- $this->node->load($params['filename']);
- }
- $this->document = $this;
- }
-
- /**
- * Return the root document element.
- */
- function root()
- {
- return new Horde_DOM_Element($this->node->documentElement, $this);
- }
-
- /**
- * Return the document element.
- */
- function document_element()
- {
- return $this->root();
- }
-
- /**
- * Return the node represented by the requested tagname.
- *
- * @param string $name The tagname requested.
- *
- * @return array The nodes matching the tag name
- */
- function get_elements_by_tagname($name)
- {
- $list = $this->node->getElementsByTagName($name);
- $nodes = array();
- $i = 0;
- if (isset($list)) {
- while ($node = $list->item($i)) {
- $nodes[] = $this->_newDOMElement($node, $this);
- ++$i;
- }
- return $nodes;
- }
- }
-
- /**
- * Return the document as a text string.
- *
- * @param bool $format Specifies whether the output should be
- * neatly formatted, or not
- * @param string $encoding Sets the encoding attribute in line
- * <?xml version="1.0" encoding="iso-8859-1"?>
- *
- * @return string The xml document as a string
- */
- function dump_mem($format = false, $encoding = false)
- {
- $format0 = $this->node->formatOutput;
- $this->node->formatOutput = $format;
-
- $encoding0 = $this->node->encoding;
- if ($encoding) {
- $this->node->encoding=$encoding;
- }
-
- $dump = $this->node->saveXML();
-
- $this->node->formatOutput = $format0;
-
- // UTF-8 is the default encoding for XML.
- if ($encoding) {
- $this->node->encoding = $encoding0 == '' ? 'UTF-8' : $encoding0;
- }
-
- return $dump;
- }
-
- /**
- * Create a new element for this document
- *
- * @param string $name Name of the new element
- *
- * @return Horde_DOM_Element New element
- */
- function create_element($name)
- {
- return new Horde_DOM_Element($this->node->createElement($name), $this);
- }
-
- /**
- * Create a new text node for this document
- *
- * @param string $content The content of the text element
- *
- * @return Horde_DOM_Node New node
- */
- function create_text_node($content)
- {
- return new Horde_DOM_Text($this->node->createTextNode($content), $this);
- }
-
- /**
- * Create a new attribute for this document
- *
- * @param string $name The name of the attribute
- * @param string $value The value of the attribute
- *
- * @return Horde_DOM_Attribute New attribute
- */
- function create_attribute($name, $value)
- {
- $attr = $this->node->createAttribute($name);
- $attr->value = $value;
- return new Horde_DOM_Attribute($attr, $this);
- }
-
- function xpath_new_context()
- {
- return Horde_DOM_XPath::factory($this->node);
- }
-}
-
-/**
- * @package Horde_DOM
- */
-class Horde_DOM_Node {
-
- var $node;
- var $document;
-
- /**
- * Wrap a DOMNode into the Horde_DOM_Node class.
- *
- * @param DOMNode $node The DOMXML node
- * @param Horde_DOM_Document $document The parent document
- *
- * @return Horde_DOM_Node The wrapped node
- */
- function Horde_DOM_Node($domNode, $domDocument = null)
- {
- $this->node = $domNode;
- $this->document = $domDocument;
- }
-
- function __get($name)
- {
- switch ($name) {
- case 'type':
- return $this->node->nodeType;
-
- case 'tagname':
- return $this->node->tagName;
-
- case 'content':
- return $this->node->textContent;
-
- default:
- return false;
- }
- }
-
- /**
- * Set the content of this node.
- *
- * @param string $text The new content of this node.
- *
- * @return DOMNode The modified node.
- */
- function set_content($text)
- {
- return $this->node->appendChild($this->node->ownerDocument->createTextNode($text));
- }
-
- /**
- * Return the type of this node.
- *
- * @return integer Type of this node.
- */
- function node_type()
- {
- return $this->node->nodeType;
- }
-
- function child_nodes()
- {
- $nodes = array();
-
- $nodeList = $this->node->childNodes;
- if (isset($nodeList)) {
- $i = 0;
- while ($node = $nodeList->item($i)) {
- $nodes[] = $this->_newDOMElement($node, $this->document);
- ++$i;
- }
- }
-
- return $nodes;
- }
-
- /**
- * Return the attributes of this node.
- *
- * @return array Attributes of this node.
- */
- function attributes()
- {
- $attributes = array();
-
- $attrList = $this->node->attributes;
- if (isset($attrList)) {
- $i = 0;
- while ($attribute = $attrList->item($i)) {
- $attributes[] = new Horde_DOM_Attribute($attribute, $this->document);
- ++$i;
- }
- }
-
- return $attributes;
- }
-
- function first_child()
- {
- return $this->_newDOMElement($this->node->firstChild, $this->document);
- }
-
- /**
- * Return the content of this node.
- *
- * @return string Text content of this node.
- */
- function get_content()
- {
- return $this->node->textContent;
- }
-
- function has_child_nodes()
- {
- return $this->node->hasChildNodes();
- }
-
- function next_sibling()
- {
- if ($this->node->nextSibling === null) {
- return null;
- }
-
- return $this->_newDOMElement($this->node->nextSibling, $this->document);
- }
-
- function node_value()
- {
- return $this->node->nodeValue;
- }
-
- function node_name()
- {
- if ($this->node->nodeType == XML_ELEMENT_NODE) {
- return $this->node->localName;
- } else {
- return $this->node->nodeName;
- }
- }
-
- function clone_node()
- {
- return new Horde_DOM_Node($this->node->cloneNode());
- }
-
- /**
- * Append a new node
- *
- * @param Horde_DOM_Node $newnode The child to be added
- *
- * @return Horde_DOM_Node The resulting node
- */
- function append_child($newnode)
- {
- return $this->_newDOMElement($this->node->appendChild($this->_importNode($newnode)), $this->document);
- }
-
- /**
- * Remove a child node
- *
- * @param Horde_DOM_Node $oldchild The child to be removed
- *
- * @return Horde_DOM_Node The resulting node
- */
- function remove_child($oldchild)
- {
- return $this->_newDOMElement($this->node->removeChild($oldchild->node), $this->document);
- }
-
- /**
- * Return a node of this class type.
- *
- * @param DOMNode $node The DOMXML node
- * @param Horde_DOM_Document $document The parent document
- *
- * @return Horde_DOM_Node The wrapped node
- */
- function _newDOMElement($node, $document)
- {
- if ($node == null) {
- return null;
- }
-
- switch ($node->nodeType) {
- case XML_ELEMENT_NODE:
- return new Horde_DOM_Element($node, $document);
- case XML_TEXT_NODE:
- return new Horde_DOM_Text($node, $document);
- case XML_ATTRIBUTE_NODE:
- return new Horde_DOM_Attribute($node, $document);
- // case XML_PI_NODE:
- // return new Horde_DOM_ProcessingInstruction($node, $document);
- default:
- return new Horde_DOM_Node($node, $document);
- }
- }
-
- /**
- * Private function to import DOMNode from another DOMDocument.
- *
- * @param Horde_DOM_Node $newnode The node to be imported
- *
- * @return Horde_DOM_Node The wrapped node
- */
- function _importNode($newnode)
- {
- if ($this->document === $newnode->document) {
- return $newnode->node;
- } else {
- return $this->document->node->importNode($newnode->node, true);
- }
- }
-
-}
-
-/**
- * @package Horde_DOM
- */
-class Horde_DOM_Element extends Horde_DOM_Node {
-
- /**
- * Get the value of specified attribute.
- *
- * @param string $name Name of the attribute
- *
- * @return string Indicates if the attribute was set.
- */
- function get_attribute($name)
- {
- return $this->node->getAttribute($name);
- }
-
- /**
- * Determine if an attribute of this name is present on the node.
- *
- * @param string $name Name of the attribute
- *
- * @return bool Indicates if such an attribute is present.
- */
- function has_attribute($name)
- {
- return $this->node->hasAttribute($name);
- }
-
- /**
- * Set the specified attribute on this node.
- *
- * @param string $name Name of the attribute
- * @param string $value The new value of this attribute.
- *
- * @return mixed Indicates if the attribute was set.
- */
- function set_attribute($name, $value)
- {
- return $this->node->setAttribute($name, $value);
- }
-
- /**
- * Return the node represented by the requested tagname.
- *
- * @param string $name The tagname requested.
- *
- * @return array The nodes matching the tag name
- */
- function get_elements_by_tagname($name)
- {
- $list = $this->node->getElementsByTagName($name);
- $nodes = array();
- $i = 0;
- if (isset($list)) {
- while ($node = $list->item($i)) {
- $nodes[] = $this->_newDOMElement($node, $this->document);
- $i++;
- }
- }
-
- return $nodes;
- }
-
-}
-
-/**
- * @package Horde_DOM
- */
-class Horde_DOM_Attribute extends Horde_DOM_Node {
-
- /**
- * Return a node of this class type.
- *
- * @param DOMNode $node The DOMXML node
- * @param Horde_DOM_Document $document The parent document
- *
- * @return Horde_DOM_Attribute The wrapped attribute
- */
- function _newDOMElement($node, $document)
- {
- return new Horde_DOM_Attribute($node, $document);
- }
-
-}
-
-/**
- * @package Horde_DOM
- */
-class Horde_DOM_Text extends Horde_DOM_Node {
-
- function __get($name)
- {
- if ($name == 'tagname') {
- return '#text';
- } else {
- return parent::__get($name);
- }
- }
-
- function tagname()
- {
- return '#text';
- }
-
- /**
- * Set the content of this node.
- *
- * @param string $text The new content of this node.
- */
- function set_content($text)
- {
- $this->node->nodeValue = $text;
- }
-
-}
-
-/**
- * @package Horde_DOM
- */
-class Horde_DOM_XPath {
-
- /**
- * @var DOMXPath
- */
- var $_xpath;
-
- function factory($dom)
- {
- return new Horde_DOM_XPath($dom);
- }
-
- function Horde_DOM_XPath($dom)
- {
- $this->_xpath = new DOMXPath($dom);
- }
-
- function xpath_register_ns($prefix, $uri)
- {
- $this->_xpath->registerNamespace($prefix, $uri);
- }
-
- function xpath_eval($expression, $context = null)
- {
- if (is_null($context)) {
- $nodeset = $this->_xpath->query($expression);
- } else {
- $nodeset = $this->_xpath->query($expression, $context);
- }
- $result = new stdClass();
- $result->nodeset = array();
- for ($i = 0; $i < $nodeset->length; $i++) {
- $result->nodeset[] = new Horde_DOM_Element($nodeset->item($i));
- }
- return $result;
- }
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>DOM</name>
- <channel>pear.horde.org</channel>
- <summary>Wrapper classes for PHP4 domxml compatibility using PHP5's dom functions.</summary>
- <description>These classes allow the use of code written for PHP4's domxml
-implementation to work using PHP5's dom implementation.
- </description>
- <lead>
- <name>Chuck Hagenbuch</name>
- <user>chuck</user>
- <email>chuck@horde.org</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Jan Schneider</name>
- <user>jan</user>
- <email>jan@horde.org</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Michael Rubinsky</name>
- <user>mrubinsk</user>
- <email>mrubinsk@horde.org</email>
- <active>yes</active>
- </lead>
- <date>2008-12-31</date>
- <version>
- <release>0.2.0</release>
- <api>0.2.0</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add Horde_DOM_Text class.
-* Add Horde_DOM_XPath class for XPath wrapping.
-* Return correct object types when iterating through child nodes.
-* Pass unit test with PHP 4.</notes>
- <contents>
- <dir name="/">
- <file baseinstalldir="/Horde" name="DOM.php" role="php" />
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.0.0</min>
- </php>
- <pearinstaller>
- <min>1.4.0b1</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2008-01-21</date>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Allow creation of empty documents
-* Add Horde_DOM_Document::document_element()
-* Add Horde_DOM_Node::clone_node()
-* Add configuration options (Request #5370, Thomas Jarosch <thomas.jarosch@intra2net.com>)</notes>
- </release>
- <release>
- <version>
- <release>0.0.2</release>
- <api>0.0.2</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2006-05-08</date>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Converted to package.xml 2.0 for pear.horde.org</notes>
- </release>
- <release>
- <version>
- <release>0.0.1</release>
- <api>0.0.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2006-01-30</date>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>Move out of Horde_Config and added DOM_Node::getElementsByTagName,
-and DOM_Node::Node_Name methods.
- </notes>
- </release>
- </changelog>
-</package>
+++ /dev/null
---TEST--
-Check that Horde::DOM handles load errors gracefully.
---FILE--
-<?php
-
-if (defined('E_DEPRECATED')) {
- error_reporting(E_ALL & ~E_DEPRECATED);
-}
-
-require_once dirname(__FILE__) . '/../DOM.php';
-
-// Load XML
-$xml = file_get_contents(dirname(__FILE__) . '/fixtures/load_error.xml');
-
-$params = array('xml' => $xml, 'options' => HORDE_DOM_LOAD_REMOVE_BLANKS);
-
-$dom = Horde_DOM_Document::factory($params);
-
-// Check that the xml loading elicits an error
-var_dump(is_a($dom, 'PEAR_Error'));
-
-// Load XML
-$xml = file_get_contents(dirname(__FILE__) . '/fixtures/load_ok.xml');
-
-$params = array('xml' => $xml, 'options' => HORDE_DOM_LOAD_REMOVE_BLANKS);
-
-$dom = Horde_DOM_Document::factory($params);
-
-// Check that the xml loading elicits an error
-var_dump(is_a($dom, 'PEAR_Error'));
-
---EXPECT--
-bool(true)
-bool(false)
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<event version="1.0">
- <revision>0</revision>
- <body>Abständen führen wirþedback</body>
-</event>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<event version="1.0">
- <revision>0</revision>
- <body>Abständen führen wir Feedback</body>
-</event>
} elseif ($http->getResponseCode() != 200) {
$notification->push(_("Unexpected response from server, try again later."), 'horde.error');
} else {
- $dom = Horde_DOM_Document::factory(array('xml' => $http->getResponseBody()));
- $stable = $dom->get_elements_by_tagname('stable');
- if (!count($stable) || !$stable[0]->has_child_nodes()) {
+ $dom = DOMDocument::loadXML($http->getResponseBody());
+ $stable = $dom->getElementsByTagName('stable');
+ if (!count($stable) || !$stable[0]->hasChildNodes()) {
$notification->push(_("Invalid response from server."), 'horde.error');
} else {
- for ($app = $stable[0]->first_child();
+ for ($app = $stable[0]->firstChild;
!empty($app);
- $app = $app->next_sibling()) {
- if (!is_a($app, 'domelement') &&
- !is_a($app, 'Horde_DOM_Element')) {
+ $app = $app->nextSibling) {
+ if (!($app instanceof DOMElement)) {
continue;
}
- $version = $app->get_elements_by_tagname('version');
- $url = $app->get_elements_by_tagname('url');
- $versions[$app->get_attribute('name')] = array(
- 'version' => $version[0]->get_content(),
- 'url' => $url[0]->get_content());
+ $version = $app->getElementsByTagName('version');
+ $url = $app->getElementsByTagName('url');
+ $versions[$app->getAttribute('name')] = array(
+ 'version' => $version[0]->textContent,
+ 'url' => $url[0]->textContent);
}
}
}
if (preg_match('/encoding=(["\'])([^\\1]+)\\1/', $line, $match)) {
$encoding = $match[2];
}
- $doc_en = Horde_DOM_Document::factory(array('filename' => $file_en));
- if (!is_object($doc_en)) {
+
+ if (!($doc_en = DOMDocument::load($file_en))) {
$c->message(sprintf('There was an error opening the file %s. Try running translation.php with the flag -d to see any error messages from the xml parser.', $file_en), 'cli.warning');
$c->writeln();
continue 2;
}
- $doc_loc = Horde_DOM_Document::factory(array('filename' => $file_loc));
- if (!is_object($doc_loc)) {
+
+ if (!($doc_loc = DOMDocument::load($file_loc))) {
$c->message(sprintf('There was an error opening the file %s. Try running translation.php with the flag -d to see any error messages from the xml parser.', $file_loc), 'cli.warning');
$c->writeln();
continue;
}
- $doc_new = Horde_DOM_Document::factory();
- $help_en = $doc_en->document_element();
- $help_loc = $doc_loc->document_element();
- $help_new = $help_loc->clone_node();
+ $doc_new = new DOMDocument();
+ $help_en = $doc_en->documentElement;
+ $help_loc = $doc_loc->documentElement;
+ $help_new = $help_loc->cloneNode();
$entries_loc = array();
$entries_new = array();
$count_uptodate = 0;
$count_new = 0;
$count_changed = 0;
$count_unknown = 0;
- foreach ($doc_loc->get_elements_by_tagname('entry') as $entry) {
- $entries_loc[$entry->get_attribute('id')] = $entry;
+ foreach ($doc_loc->getElementsByTagName('entry') as $entry) {
+ $entries_loc[$entry->getAttribute('id')] = $entry;
}
- foreach ($doc_en->get_elements_by_tagname('entry') as $entry) {
- $id = $entry->get_attribute('id');
+ foreach ($doc_en->getElementsByTagName('entry') as $entry) {
+ $id = $entry->getAttribute('id');
if (array_key_exists($id, $entries_loc)) {
- if ($entries_loc[$id]->has_attribute('md5') &&
- md5($entry->get_content()) != $entries_loc[$id]->get_attribute('md5')) {
+ if ($entries_loc[$id]->hasAttribute('md5') &&
+ md5($entry->textContent) != $entries_loc[$id]->getAttribute('md5')) {
$comment = $doc_loc->create_comment(" English entry:\n" . str_replace('--', '--', $doc_loc->dump_node($entry)));
- $entries_loc[$id]->append_child($comment);
- $entry_new = $entries_loc[$id]->clone_node(true);
- $entry_new->set_attribute('state', 'changed');
+ $entries_loc[$id]->appendChild($comment);
+ $entry_new = $entries_loc[$id]->cloneNode(true);
+ $entry_new->setAttribute('state', 'changed');
$count_changed++;
} else {
- if (!$entries_loc[$id]->has_attribute('state')) {
+ if (!$entries_loc[$id]->hasAttribute('state')) {
$comment = $doc_loc->create_comment(" English entry:\n" . str_replace('--', '--', $doc_loc->dump_node($entry)));
- $entries_loc[$id]->append_child($comment);
- $entry_new = $entries_loc[$id]->clone_node(true);
- $entry_new->set_attribute('state', 'unknown');
+ $entries_loc[$id]->appendChild($comment);
+ $entry_new = $entries_loc[$id]->cloneNode(true);
+ $entry_new->setAttribute('state', 'unknown');
$count_unknown++;
} else {
- $entry_new = $entries_loc[$id]->clone_node(true);
+ $entry_new = $entries_loc[$id]->cloneNode(true);
$count_uptodate++;
}
}
} else {
- $entry_new = $entry->clone_node(true);
- $entry_new->set_attribute('state', 'new');
+ $entry_new = $entry->cloneNode(true);
+ $entry_new->setAttribute('state', 'new');
$count_new++;
}
$entries_new[] = $entry_new;
}
- $doc_new->append_child($doc_new->create_comment(' $' . 'Horde$ '));
+ $doc_new->appendChild($doc_new->create_comment(' $' . 'Horde$ '));
foreach ($entries_new as $entry) {
- $help_new->append_child($entry);
+ $help_new->appendChild($entry);
}
$c->writeln(wordwrap(sprintf('Entries: %d total, %d up-to-date, %d new, %d changed, %d unknown',
$count_uptodate + $count_new + $count_changed + $count_unknown,
$count_uptodate, $count_new, $count_changed, $count_unknown)));
- $doc_new->append_child($help_new);
- $output = $doc_new->dump_mem(true, $encoding);
+ $doc_new->appendChild($help_new);
+
+ $doc_new->formatoutput = true;
+ if ($encoding) {
+ $doc_new->encoding = $encoding;
+ }
+ $output = $doc_new->savexml();
+
if ($debug || $test) {
$c->writeln(wordwrap(sprintf('Writing updated help file to %s.', $file_loc)));
}
if (preg_match('/encoding=(["\'])([^\\1]+)\\1/', $line, $match)) {
$encoding = $match[2];
}
- $doc_en = Horde_DOM_Document::factory(array('filename' => $file_en));
- if (!is_object($doc_en)) {
+
+ if (!($doc_en = DOMDocument::load($file_en))) {
$c->message(sprintf('There was an error opening the file %s. Try running translation.php with the flag -d to see any error messages from the xml parser.', $file_en), 'cli.warning');
$c->writeln();
continue 2;
}
- $doc_loc = Horde_DOM_Document::factory(array('filename' => $file_loc));
- if (!is_object($doc_loc)) {
+
+ if (!($doc_loc = DOMDocument::load($file_loc))) {
$c->message(sprintf('There was an error opening the file %s. Try running translation.php with the flag -d to see any error messages from the xml parser.', $file_loc), 'cli.warning');
$c->writeln();
continue;
}
- $help_loc = $doc_loc->document_element();
+ $help_loc = $doc_loc->documentElement;
$md5_en = array();
$count_all = 0;
$count = 0;
- foreach ($doc_en->get_elements_by_tagname('entry') as $entry) {
- $md5_en[$entry->get_attribute('id')] = md5($entry->get_content());
- }
- foreach ($doc_loc->get_elements_by_tagname('entry') as $entry) {
- foreach ($entry->child_nodes() as $child) {
- if ($child->node_type() == XML_COMMENT_NODE && strstr($child->node_value(), 'English entry')) {
- $entry->remove_child($child);
+ foreach ($doc_en->getElementsByTagName('entry') as $entry) {
+ $md5_en[$entry->getAttribute('id')] = md5($entry->textContent);
+ }
+ foreach ($doc_loc->getElementsByTagName('entry') as $entry) {
+ foreach ($entry->childNodes as $child) {
+ if ($child->nodeType == XML_COMMENT_NODE &&
+ strstr($child->nodeValue, 'English entry')) {
+ $entry->removeChild($child);
}
}
$count_all++;
- $id = $entry->get_attribute('id');
+ $id = $entry->getAttribute('id');
if (!array_key_exists($id, $md5_en)) {
$c->message(sprintf('No entry with the id "%s" exists in the original help file.', $id), 'cli.warning');
} else {
- $entry->set_attribute('md5', $md5_en[$id]);
- $entry->set_attribute('state', 'uptodate');
+ $entry->setAttribute('md5', $md5_en[$id]);
+ $entry->setAttribute('state', 'uptodate');
$count++;
}
}
- $output = $doc_loc->dump_mem(true, $encoding);
+
+ $doc_loc->formatoutput = true;
+ if ($encoding) {
+ $doc_loc->encoding = $encoding;
+ }
+ $output = $doc_loc->savexml();
+
if (!$test) {
- $fp = fopen($file_loc, 'w');
- $line = fwrite($fp, $output);
- fclose($fp);
+ file_put_contents($file_loc, $output);
}
$c->writeln(sprintf('%d of %d entries marked as up-to-date', $count, $count_all));
$c->writeln();