From 4f5e553cffa801a29b5aa4b3b2f367f221a148ff Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Mon, 21 Apr 2008 21:35:27 +0200 Subject: [PATCH] First round of style changes to php5 just to make it stop crashing. --- php5/attribute-empty.php | 2 +- php5/attribute.php | 2 +- php5/attribute2.php | 2 +- php5/attribute3.php | 2 +- php5/attribute4.php | 2 +- php5/clone.php | 2 +- php5/include.php | 2 +- php5/namespace.php | 2 +- php5/namespace2.php | 2 +- php5/passthru.php | 2 +- php5/simple.php | 2 +- php5/structure.php | 2 +- php5/xml-template.php | 83 ++++++++++++++++++++-------------------- 13 files changed, 54 insertions(+), 53 deletions(-) diff --git a/php5/attribute-empty.php b/php5/attribute-empty.php index d461140..3818141 100644 --- a/php5/attribute-empty.php +++ b/php5/attribute-empty.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( 'color' => 'blue', '#things' => array(NULL) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/attribute.php b/php5/attribute.php index 626812e..df0f5f5 100644 --- a/php5/attribute.php +++ b/php5/attribute.php @@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens', 'li/class' => 'even' ) ) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/attribute2.php b/php5/attribute2.php index 186828f..f58b4ad 100644 --- a/php5/attribute2.php +++ b/php5/attribute2.php @@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ), ), array('odd', 'even')) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/attribute3.php b/php5/attribute3.php index f4fa718..0fbfba7 100644 --- a/php5/attribute3.php +++ b/php5/attribute3.php @@ -11,5 +11,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ), ), array('odd', 'even')) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/attribute4.php b/php5/attribute4.php index b2c39f9..1251aa3 100644 --- a/php5/attribute4.php +++ b/php5/attribute4.php @@ -4,5 +4,5 @@ require('xml-template.php'); $doc = XML_Template_process_file('../xml/attribute4.xml', array( '#foo/value' => 'bar', )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/clone.php b/php5/clone.php index 2bbd266..28b4442 100644 --- a/php5/clone.php +++ b/php5/clone.php @@ -10,5 +10,5 @@ $doc = XML_Template_process_file('../xml/clone.xml', array( array( 'li' => 'Warm, woolen mittens' ) ) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/include.php b/php5/include.php index 8819ef7..79b15c3 100644 --- a/php5/include.php +++ b/php5/include.php @@ -9,5 +9,5 @@ $master = XML_Template_process_file('../xml/master.xml', array( 'h1' => 'Nice heading here', 'contents' => $doc )); -print $master->dump_mem(); +print $master->saveXML(); ?> diff --git a/php5/namespace.php b/php5/namespace.php index 35bb707..0236711 100644 --- a/php5/namespace.php +++ b/php5/namespace.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/namespace.xml', array( 'tagname' => 'foo', '#moretest' => 'bar' )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/namespace2.php b/php5/namespace2.php index 6ff09fd..57c2778 100644 --- a/php5/namespace2.php +++ b/php5/namespace2.php @@ -5,5 +5,5 @@ $doc = XML_Template_process_file('../xml/namespace2.xml', array( 'title' => 'Namespace tests', '#hello' => 'Replaced.', )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/passthru.php b/php5/passthru.php index 95dd1be..49e1b61 100644 --- a/php5/passthru.php +++ b/php5/passthru.php @@ -2,5 +2,5 @@ require('xml-template.php'); $doc = XML_Template_process_file('../xml/passthru.xml', array()); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/simple.php b/php5/simple.php index 10e73f1..afcdc34 100644 --- a/php5/simple.php +++ b/php5/simple.php @@ -5,5 +5,5 @@ $doc = XML_Template_process_file('../xml/simple.xml', array( 'title' => 'A very basic example', '#hello' => 'Hello world!' )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/structure.php b/php5/structure.php index adb153e..ebf7235 100644 --- a/php5/structure.php +++ b/php5/structure.php @@ -8,5 +8,5 @@ $doc = XML_Template_process_file('../xml/structure.xml', array( array( '#inner' => 'Three' ), ) )); -print $doc->dump_mem(); +print $doc->saveXML(); ?> diff --git a/php5/xml-template.php b/php5/xml-template.php index 6fbf4bf..911a641 100644 --- a/php5/xml-template.php +++ b/php5/xml-template.php @@ -2,7 +2,8 @@ function XML_Template_process_file($filename, $obj, $clean = 1) { - $doc = domxml_open_file($filename); + $doc = new DOMDocument; + $doc->load($filename); XML_Template_process($doc, $obj, $clean); return $doc; } @@ -10,39 +11,39 @@ function XML_Template_process_file($filename, $obj, $clean = 1) function XML_Template_process($node, $obj, $clean = 1) { if (is_a($obj, 'domnode')) { # overwrite - foreach ($node->child_nodes() as $child) { - $node->remove_child($child); + foreach ($node->childNodes as $child) { + $node->removeChild($child); } if (is_a($obj, 'domdocument')) { $obj = $obj->document_element(); } - $newobj = own_clone_node($obj, $node->owner_document()); + $newobj = own_clone_node($obj, $node->ownerDocument); $node->append_child($newobj); XML_Template_process($newobj, array(), $clean); } else if (!is_array($obj)) { # overwrite - foreach ($node->child_nodes() as $child) { - $node->remove_child($child); + foreach ($node->childNodes as $child) { + $node->removeChild($child); } - $doc = $node->owner_document(); - $node->add_child($doc->create_text_node($obj)); + $doc = $node->ownerDocument; + $node->appendChild($doc->createTextNode($obj)); } else if (is_associative_array($obj)) { # substitute - foreach ($node->child_nodes() as $child) { + foreach ($node->childNodes as $child) { $processed = false; - if ($child->node_type() == XML_ELEMENT_NODE) { + if ($child->nodeType == XML_ELEMENT_NODE) { unset($id); - $tag = $child->node_name(); - $attrs = $child->attributes(); + $tag = $child->nodeName; + $attrs = $child->attributes; if (isset($attrs)) { - foreach ($child->attributes() as $attr) { - if ($attr->namespace_uri() == 'http://template.sesse.net/' && $attr->name() == 'id') { - $id = $attr->value(); + foreach ($child->attributes as $attr) { + if ($attr->namespaceURI == 'http://template.sesse.net/' && $attr->name == 'id') { + $id = $attr->value; if ($clean) { - $attr->unlink_node(); + # $attr->unlinkNode(); } } } @@ -72,12 +73,12 @@ function XML_Template_process($node, $obj, $clean = 1) } } } else { # repeat - $doc = $node->owner_document(); - $frag = $doc->create_element("temporary-fragment"); # ugh + $doc = $node->ownerDocument; + $frag = $doc->createElement("temporary-fragment"); # ugh - foreach ($node->child_nodes() as $child) { + foreach ($node->childNodes as $child) { $frag->append_child($child); - $node->remove_child($child); + $node->removeChild($child); } foreach ($obj as $instance) { @@ -85,7 +86,7 @@ function XML_Template_process($node, $obj, $clean = 1) continue; } - $newnode = own_clone_node($frag, $frag->owner_document()); + $newnode = own_clone_node($frag, $frag->ownerDocument); $node->append_child($newnode); XML_Template_process($newnode, $instance, $clean); if ($clean) { @@ -95,14 +96,14 @@ function XML_Template_process($node, $obj, $clean = 1) # remove all the tags - foreach ($node->child_nodes() as $child) { - if ($child->name() != 'temporary-fragment') { + foreach ($node->childNodes as $child) { + if ($child->name != 'temporary-fragment') { continue; } - foreach ($child->child_nodes() as $child2) { + foreach ($child->childNodes as $child2) { $node->append_child($child2); } - $node->remove_child($child); + $node->removeChild($child); } } @@ -113,20 +114,20 @@ function XML_Template_process($node, $obj, $clean = 1) function XML_Template_clean($node) { - if ($node->node_type() == XML_ELEMENT_NODE) { - if ($node->namespace_uri() != 'http://template.sesse.net/') { + if ($node->nodeType == XML_ELEMENT_NODE) { + if ($node->namespaceURI != 'http://template.sesse.net/') { return; } # as this is a dummy node, we want to remove it and move everything further up # after we've done any required replacements - $doc = $node->owner_document(); + $doc = $node->ownerDocument; $parent = $node->parent_node(); - foreach ($node->child_nodes() as $child) { - $node->remove_child($child); + foreach ($node->childNodes as $child) { + $node->removeChild($child); $node->insert_before($child, $node); } - $parent->remove_child($node); + $parent->removeChild($node); } } @@ -150,26 +151,26 @@ function XML_Template_alternate($tag, $array, $elems) function own_clone_node($node, $doc) { // we only need these two - if ($node->node_type() == XML_ELEMENT_NODE) { - $nsuri = $node->namespace_uri(); + if ($node->nodeType == XML_ELEMENT_NODE) { + $nsuri = $node->namespaceURI; if (isset($nsuri)) { - $newnode = $doc->create_element_ns($node->namespace_uri(), $node->node_name(), $node->prefix()); + $newnode = $doc->createElementNS($node->namespaceURI, $node->nodeName, $node->prefix()); } else { - $newnode = $doc->create_element($node->node_name()); + $newnode = $doc->createElement($node->nodeName); } - $attrs = $node->attributes(); + $attrs = $node->attributes; if (isset($attrs)) { - foreach ($node->attributes() as $attr) { - $attr2 = $doc->create_attribute($attr->name(), $attr->value()); - $nsuri = $attr->namespace_uri(); + foreach ($node->attributes as $attr) { + $attr2 = $doc->createAttribute($attr->name, $attr->value); + $nsuri = $attr->namespaceURI; if (isset($nsuri)) { - $attr2->set_namespace($nsuri, $attr->prefix()); + $attr2->set_namespace($nsuri, $attr->prefix); } $newnode->append_child($attr2); } } - foreach ($node->child_nodes() as $child) { + foreach ($node->childNodes as $child) { $newnode->append_child(own_clone_node($child, $doc)); } return $newnode; -- 2.39.2