]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
standardized xml.php and fixed output of booleans in xml view
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 3 Nov 2009 00:19:09 +0000 (00:19 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 3 Nov 2009 00:19:09 +0000 (00:19 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3616 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/opendd.php
engine/lib/plugins.php
engine/lib/xml-rpc.php
engine/lib/xml.php

index 16d5b4671de1b621163ad6cebacd7e8f6bad1639..c582e6f771a8cf58cb92757cb6ca498b204185b2 100644 (file)
@@ -344,7 +344,7 @@ function ODD_factory(XmlElement $element) {
  */
 function ODD_Import($xml) {
        // Parse XML to an array
-       $elements = xml_2_object($xml);
+       $elements = xml_to_object($xml);
 
        // Sanity check 1, was this actually XML?
        if ((!$elements) || (!$elements->children)) {
index daa543365ad0beb082ad28f9db5733bf2083e69c..be604606ed70a89dbe9da8ca9ae62291666c9977 100644 (file)
@@ -312,7 +312,7 @@ function get_plugin_name($mainfilename = false) {
 function load_plugin_manifest($plugin) {
        global $CONFIG;
 
-       $xml = xml_2_object(file_get_contents($CONFIG->pluginspath . $plugin. "/manifest.xml"));
+       $xml = xml_to_object(file_get_contents($CONFIG->pluginspath . $plugin. "/manifest.xml"));
 
        if ($xml) {
                $elements = array();
index 1e2167507a7437c7569bb65ea753becc26512b65..9c59b1deb3d69366ef2095961d8636c37d757db1 100644 (file)
@@ -57,7 +57,7 @@
                 */
                private function parse($xml)
                {
-                       $xml = xml_2_object($xml);
+                       $xml = xml_to_object($xml);
                        
                        // sanity check
                        if ((isset($xml->name)) && (strcasecmp($xml->name, "methodCall")!=0))
index e0bb0b17a047f3d38627ce60ee4b846d12c3fcdd..cbc93655566681c0278595be8172270894cbb25e 100644 (file)
                
                $output = "";
                
-               if (($n==0) || ( is_object($data) && !($data instanceof stdClass))) $output = "<$classname>";
-
-               foreach ($vars as $key => $value)
-               {
+               if (($n==0) || ( is_object($data) && !($data instanceof stdClass))) {
+                       $output = "<$classname>";
+               }
+               
+               foreach ($vars as $key => $value) {
                        $output .= "<$key type=\"".gettype($value)."\">";
                        
-                       if (is_object($value))
+                       if (is_object($value)) {
                                $output .= serialise_object_to_xml($value, $key, $n+1);
-                       else if (is_array($value))
+                       } else if (is_array($value)) {
                                $output .= serialise_array_to_xml($value, $n+1);
-                       else
+                       } else if (gettype($value) == "boolean") {
+                               $output .= $value ? "true" : "false";
+                       } else {
                                $output .= htmlentities($value);
+                       }
                        
                        $output .= "</$key>\n";
                }
                
-               if (($n==0) || ( is_object($data) && !($data instanceof stdClass))) $output .= "</$classname>\n";
+               if (($n==0) || ( is_object($data) && !($data instanceof stdClass))) {
+                       $output .= "</$classname>\n";
+               }
                
                return $output;
        }
        {
                $output = "";
                
-               if ($n==0) $output = "<array>\n";
+               if ($n==0) {
+                       $output = "<array>\n";
+               }
                
-               foreach ($data as $key => $value)
-               {
+               foreach ($data as $key => $value) {
                        $item = "array_item";
                        
-                       if (is_numeric($key))
+                       if (is_numeric($key)) {
                                $output .= "<$item name=\"$key\" type=\"".gettype($value)."\">";
-                       else
-                       {
+                       } else {
                                $item = $key;
                                $output .= "<$item type=\"".gettype($value)."\">";
                        }
                        
-                       if (is_object($value))
+                       if (is_object($value)) {
                                $output .= serialise_object_to_xml($value, "", $n+1);
-                       else if (is_array($value))
+                       } else if (is_array($value)) {
                                $output .= serialise_array_to_xml($value, $n+1);
-                       else
+                       } else if (gettype($value) == "boolean") {
+                               $output .= $value ? "true" : "false";
+                       } else {
                                $output .= htmlentities($value);
+                       }
                        
                        $output .= "</$item>\n";
                }
                
-               if ($n==0) $output = "</array>\n";
+               if ($n==0) {
+                       $output = "</array>\n";
+               }
                
                return $output;
        }
         * 
         * @param string $xml The XML.
         */
-       function xml_2_object($xml)
+       function xml_to_object($xml)
        {
                $parser = xml_parser_create();
                
                xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);     
                xml_parse_into_struct($parser, $xml, $tags);
                
-               xml_parser_free($parser);
-               
-               $elements = array(); 
-               $stack = array();
-               
-               foreach ($tags as $tag)
-               {
+               xml_parser_free($parser);
+               
+               $elements = array(); 
+               $stack = array();
+               
+               foreach ($tags as $tag) {
                        $index = count($elements);
                        
-                       if ($tag['type'] == "complete" || $tag['type'] == "open") 
-                       {
-                       $elements[$index] = new XmlElement;
-                       $elements[$index]->name = $tag['tag'];
-                       $elements[$index]->attributes = $tag['attributes'];
-                       $elements[$index]->content = $tag['value'];
-                       
-                       if ($tag['type'] == "open") 
-                       { 
-                               $elements[$index]->children = array();
-                               $stack[count($stack)] = &$elements;
-                               $elements = &$elements[$index]->children;
-                       }
-               }
-               
-               if ($tag['type'] == "close") 
-               {
-                       $elements = &$stack[count($stack) - 1];
-                       unset($stack[count($stack) - 1]);
-               }
-               }
-               
-               return $elements[0];
+                       if ($tag['type'] == "complete" || $tag['type'] == "open") {
+                               $elements[$index] = new XmlElement;
+                               $elements[$index]->name = $tag['tag'];
+                               $elements[$index]->attributes = $tag['attributes'];
+                               $elements[$index]->content = $tag['value'];
+                               
+                               if ($tag['type'] == "open") { 
+                                       $elements[$index]->children = array();
+                                       $stack[count($stack)] = &$elements;
+                                       $elements = &$elements[$index]->children;
+                               }
+                       }
+                       
+                       if ($tag['type'] == "close") {
+                               $elements = &$stack[count($stack) - 1];
+                               unset($stack[count($stack) - 1]);
+                       }
+               }
+               
+               return $elements[0];
        }
-       
-?>
\ No newline at end of file