phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] api/class.xmltool.php, 1.1.1.1.2.9


From: nomail
Subject: [Phpgroupware-cvs] api/class.xmltool.php, 1.1.1.1.2.9
Date: Thu, 20 May 2004 19:21:45 -0000

Update of /api
Modified Files:
        Branch: proposal-branch
          class.xmltool.php

date: 2004/04/16 20:59:49;  author: seek3r;  state: Exp;  lines: +153 -191

Log Message:
bringing savannah cvs back up to date with what we were doing on our private 
cvs server. We will not be doing dev from this cvs tree
=====================================================================
No syntax errors detected in -
=====================================================================
Index: api/class.xmltool.php
diff -u api/class.xmltool.php:1.1.1.1.2.8 api/class.xmltool.php:1.1.1.1.2.9
--- api/class.xmltool.php:1.1.1.1.2.8   Tue Feb 24 19:29:38 2004
+++ api/class.xmltool.php       Fri Apr 16 20:59:49 2004
@@ -24,14 +24,14 @@
        /* $Id$ */
        /* $Source$ */
 
-       function var2xml($data, $name = 'appcontent', $is_root = True)
+       function var2xml($data, $name = 'appcontent', $is_root = true)
        {
                $doc = new api_xmltool('root','','');
                if(!$is_root)
                {
-                       $this->show_xml_headers = False;
+                       $doc->show_xml_headers = false;
                }
-               $doc->import_var($name, $data, True, True);
+               $doc->import_var($name, $data, true, true);
                return $doc->export_xml();
        }
 
@@ -40,8 +40,8 @@
        function xml2var($xmldata)
        {
 //             $args = new safe_args();
-//             $args->set('xmldata', '##REQUIRED##', 'any');
-//             $args = $args->get(func_get_args(),__LINE__,__FILE__);
+//             $args->set('xmldata', REQUIRED, 'any');
+//             $args = $args->get(func_get_args());
 
                $doc = new api_xmltool('root','','');
 //             $doc->import_xml($args['xmldata']);
@@ -64,8 +64,8 @@
                var $attributes = Array();
                var $comments = Array();
 //             var $indentstring = "\t";
-               var $indentstring = "  ";
-               var $show_xml_headers = True;
+               var $indentstring = '  ';
+               var $show_xml_headers = true;
                
                /* start the class as either a root or a node */
                function api_xmltool ()
@@ -74,35 +74,31 @@
                        $args->set('node_type', 'root', 'any');
                        $args->set('name', 'anonymous', 'any');
                        $args->set('indentstring', '  ', 'any');
-                       $args = $args->get(func_get_args(),__LINE__,__FILE__);
+                       $args = $args->get(func_get_args());
 
                        $this->node_type = $args['node_type'];
                        $this->indentstring = $args['indentstring'];
                        if ($this->node_type == 'node')
                        {
-                               if($args['name'] !== '')
+                               if($args['name'] == '')
                                {
-                                       $this->name = $args['name'];
+                                       trigger_error('You must name node type 
objects',E_USER_ERROR);
                                }
-                               else
-                               {
-                                       echo 'You must name node type 
objects<br>';
-                                       exit;
-                               }
-                               $this->show_xml_headers = False;
+                               $this->name = $args['name'];
+                               $this->show_xml_headers = false;
                        }
                }
                
                function set_version ($version = '1.0')
                {
                        $this->xmlversion = $version;
-                       return True;
+                       return true;
                }
 
                function set_stylesheet ($uri)
                {
                        $this->stylesheet = $uri;
-                       return True;
+                       return true;
                }
 
                function set_doctype ($name, $uri = '')
@@ -110,12 +106,9 @@
                        if ($this->node_type == 'root')
                        {
                                $this->doctype[$name] = $uri;
-                               return True;
-                       }
-                       else
-                       {
-                               return False;
+                               return true;
                        }
+                       return false;
                }
 
                function add_node ($node_object, $name = '')
@@ -126,14 +119,12 @@
                                        if (is_object($node_object))
                                        {
                                                $this->data = $node_object;
+                                               break;
                                        }
-                                       else
-                                       {
-                                               $this->data = 
$this->import_var($name, $node_object);
-                                       }
+                                       $this->data = $this->import_var($name, 
$node_object);
                                        break;
                                case 'node':
-                                       if (! is_array($this->data))
+                                       if (!is_array($this->data))
                                        {
                                                $this->data      = array();
                                                $this->data_type = 'node';
@@ -155,9 +146,11 @@
 //                                             $this->data[$name] = 
$this->import_var($name, $node_object);
                                                $this->data[$name] = 
$this->import_var($name, $node_object);
                                        }
-                                       return True;
                                        break;
+                               default:
+                                       return false;
                        }
+                       return true;
                }
 
                function get_node ($name = '')  // what is that function doing: 
NOTHING !!!
@@ -178,7 +171,7 @@
                {
                        $this->data = $string;
                        $this->data_type = 'value';
-                       return True;
+                       return true;
                }
                
                function get_value ()
@@ -187,16 +180,13 @@
                        {
                                return $this->data;
                        }
-                       else
-                       {
-                               return False;
-                       }
+                       return false;
                }
 
                function set_attribute ($name, $value = '')
                {
                        $this->attributes[$name] = $value;
-                       return True;
+                       return true;
                }
 
                function get_attribute ($name)
@@ -212,10 +202,10 @@
                function add_comment ($comment)
                {
                        $this->comments[] = $comment;
-                       return True;
+                       return true;
                }
 
-               function import_var($name, 
$value,$is_root=False,$export_xml=False)
+               function import_var 
($name,$value,$is_root=false,$export_xml=false)
                {
                        $node = new 
api_xmltool('node',$name,$this->indentstring);
                        $node = $this->import_var_sub($name, $value, $node);
@@ -228,16 +218,10 @@
                                        $xml = $this->export_xml();
                                        return $xml;
                                }
-                               else
-                               {
-                                       return True;
-                               }
-                       }
-                       else
-                       {
-                               $this->add_node($node);
-                               //return $node;
+                               return true;
                        }
+                       $this->add_node($node);
+                       //return $node;
                }
 
                function import_var_sub($name, $value, $orignode)
@@ -251,7 +235,7 @@
                                        $orignode->set_value($value);
                                        break;
                                case 'boolean':
-                                       if($value == True)
+                                       if($value == true)
                                        {
                                                $orignode->set_value('1');
                                        }
@@ -263,7 +247,7 @@
                                case 'array':
                                        $new_index = array_key_exists(0,$value);
                                        reset($value);
-                                       foreach($value as $key=>$val)           
                
+                                       foreach($value as $key=>$val)
                                        {
                                                if($new_index)
                                                {
@@ -280,73 +264,69 @@
                                        
$orignode->set_value('PHP_SERIALIZED_OBJECT&:'.serialize($value));
                                        break;
                                case 'resource':
-                                       $GLOBALS['msgbox']->add('Cannot package 
PHP resource pointers into XML',__LINE__,__FILE__, 'fatal');
-                                       $this->exit;
+                                       trigger_error('Cannot package PHP 
resource pointers into XML',E_USER_ERROR);
+                                       break;
                                default:
-                                       $GLOBALS['msgbox']->add('Invalid or 
unknown data typeL',__LINE__,__FILE__, 'fatal');
-                                       exit;
+                                       trigger_error('Invalid or unknown data 
type',E_USER_ERROR);
+                                       break;
                        }
                        return $orignode;
                }
                
                function export_var()
                {
-                       if($this->node_type == 'root')
+                       if ($this->node_type == 'root')
                        {
                                return $this->data->export_var();
                        }
 
                        if ($this->data_type != 'node')
-                       {       
+                       {
                                $found_at = 
strstr($this->data,'PHP_SERIALIZED_OBJECT&:');
-                               if ($found_at != False)
+                               if ($found_at !== false)
                                {
                                        return unserialize(str_replace 
('PHP_SERIALIZED_OBJECT&:', '', $this->data));
                                }
                                return $this->data;
                        }
-                       else
-                       {
-                               $new_index = False;                             
-                               $n = count($this->data);
 
-                               for ($i=0;$i<$n;$i++)
-                               {
-                                       if (! 
isset($found_keys[$this->data[$i]->name]))
-                                       {
-                                               
$found_keys[$this->data[$i]->name] = True;
-                                       }
-                                       else
-                                       {
-                                               $new_index = True;
-                                       }
-                               }
+                       $new_index    = false;
+                       $return_array = array();
 
-                               if ($new_index)
+                       foreach($this->data as $i => $item)
+                       {
+                               if (!isset($found_keys[$item->name]))
                                {
-                                       // $n = count($this->data); // use $n 
from above
-                                       for ($i=0;$i<$n;$i++)
-                                       {
-                                               
$return_array[$this->data[$i]->name][] = $this->data[$i]->export_var();
-                                       }                               
+                                       $found_keys[$item->name] = true;
                                }
                                else
                                {
-                                       // $n = count($this->data); // use $n 
from above
-                                       for ($i=0;$i<$n;$i++)
-                                       {
-                                               
$return_array[$this->data[$i]->name] = $this->data[$i]->export_var();
-                                       }
+                                       $new_index = true;
                                }
+                       }
 
-                               // Handle attributes
-                               foreach ($this->attributes as $key => $value)
+                       if ($new_index)
+                       {
+                               foreach ($this->data as $i => $item)
                                {
-                                       $return_array['##ATTRIBUTE##' . $key] = 
$value;
+                                       $return_array[$item->name][] = 
$this->data[$i]->export_var();
                                }
+                       }
+                       else
+                       {
+                               foreach ($this->data as $i => $item)
+                               {
+                                       $return_array[$item->name] = 
$this->data[$i]->export_var();
+                               }
+                       }
 
-                               return $return_array;
+                       // Handle attributes
+                       foreach ($this->attributes as $key => $value)
+                       {
+                               $return_array['##ATTRIBUTE##' . $key] = $value;
                        }
+
+                       return $return_array;
                }
 
                function export_struct()
@@ -359,9 +339,9 @@
                        $retval['tag'] = $this->name;
                        $retval['attributes'] = $this->attributes;
                        if($this->data_type != 'node')
-                       {       
+                       {
                                $found_at = 
strstr($this->data,'PHP_SERIALIZED_OBJECT&:');
-                               if($found_at != False)
+                               if($found_at !== false)
                                {
                                        $retval['value'] = 
unserialize(str_replace ('PHP_SERIALIZED_OBJECT&:', '', $this->data));
                                }
@@ -371,15 +351,12 @@
                                }
                                return $retval;
                        }
-                       else
+
+                       foreach ($this->data as $i => $item)
                        {
-                               $n = count($this->data);
-                               for($i=0;$i<$n;$i++)
-                               {
-                                       $retval['children'][] = 
$this->data[$i]->export_struct();
-                               }                               
-                               return $retval;
+                               $retval['children'][] = 
$this->data[$i]->export_struct();
                        }
+                       return $retval;
                }
 
                function import_xml_children($data, &$i, $parent_node)
@@ -394,7 +371,7 @@
                                                $node = new 
api_xmltool('node',$data[$i]['tag'],$this->indentstring);
                                                
if(is_array($data[$i]['attributes']) && count($data[$i]['attributes']) > 0)
                                                {
-                                                       
foreach($data[$i]['attributes'] as $k=>$v)                              
+                                                       
foreach($data[$i]['attributes'] as $k=>$v)
                                                        {
                                                                
$node->set_attribute($k,$v);
                                                        }
@@ -407,7 +384,7 @@
 
                                                
if(is_array($data[$i]['attributes']) && count($data[$i]['attributes']) > 0)
                                                {
-                                                       
foreach($data[$i]['attributes'] as $k=>$v)                              
+                                                       
foreach($data[$i]['attributes'] as $k=>$v)
                                                        {
                                                                
$node->set_attribute($k,$v);
                                                        }
@@ -422,7 +399,7 @@
                        }
                }
                
-               function import_xml($xmldata) 
+               function import_xml($xmldata)
                {
                        $parser = xml_parser_create();
                        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 
0);
@@ -433,7 +410,7 @@
                        $node = new 
api_xmltool('node',$vals[0]['tag'],$this->indentstring);
                        if(isset($vals[0]['attributes']))
                        {
-                               foreach($vals[0]['attributes'] as $key=>$value) 
                        
+                               foreach($vals[0]['attributes'] as $key=>$value)
                                {
                                        $node->set_attribute($key, $value);
                                }
@@ -474,12 +451,11 @@
                                                $result .= '<?xml-stylesheet 
type="text/xsl" href="'.$this->stylesheet.'"?>'."\n";
                                        }
                                }
-                               if(count($this->comments) > 0 )
+                               if(!empty($this->comments))
                                {
-                                       $n = count($this->comments);
-                                       for($i=0;$i<$n;$i++)
+                                       foreach ($this->comments as $comment)
                                        {
-                                               $result .= "<!-- 
".$this->comments[$i]." -->\n";
+                                               $result .= '<!-- '.$comment." 
-->\n";
                                        }
                                }
                                if(is_object($this->data))
@@ -489,112 +465,98 @@
                                }
                                return $result;
                        }
-                       else /* For node objects */
+                       /* For node objects */
+                       $indentstring = str_repeat($this->indentstring,$indent);
+
+                       $result = $indentstring.'<'.$this->name;
+                       if(!empty($this->attributes))
                        {
-                               for ($i = 0; $i < $indent; $i++)
+                               foreach($this->attributes as $key=>$val)
                                {
-                                       $indentstring .= $this->indentstring;
+                                       $val = htmlentities($val);
+                                       $result .= ' '.$key.'="'.$val.'"';
                                }
+                       }
 
-                               $result = $indentstring.'<'.$this->name;
-                               if(count($this->attributes) > 0 )
-                               {
-                                       reset($this->attributes);
-                                       foreach($this->attributes as 
$key=>$val)                                
-                                       {
-                                               $val = htmlspecialchars($val);
-                                               $result .= ' 
'.$key.'="'.$val.'"';
-                                       }
-                               }
+                       $endtag_indent = $indentstring;
+                       if (empty($this->data_type))
+                       {
+                               $result .= '/>'."\n";
+                       }
+                       else
+                       {
+                               $result .= '>';
 
-                               $endtag_indent = $indentstring;
-                               if (empty($this->data_type))
-                               {
-                                       $result .= '/>'."\n";
-                               }
-                               else
+                               switch ($this->data_type)
                                {
-                                       $result .= '>';
-
-                                       switch ($this->data_type)
-                                       {
-                                               case 'value':
-                                                       
if(is_array($this->data))
-                                                       {
-                                                               $type_error = 
True;
-                                                               break;
-                                                       }
-                                                       /*if($this->data != '' 
&& !sanitize($this->data,'isxmlsafe'))   // this is unnecessary with 
htmlspecialchars($this->data)
-                                                       {
-                                                               $result .= 
'<![CDATA['.$this->data.']]>';
-                                                               $endtag_indent 
= '';            
-                                                       }
-                                                       
else*/if(strlen($this->data) > 120 && !empty($this->indentstring))
-                                                       {
-                                                               $this->data = 
htmlspecialchars($this->data);
-                                                               $result .= 
"\n".$indentstring.$this->indentstring.$this->data."\n";
-                                                               $endtag_indent 
= $indentstring;
-                                                       }
-                                                       else
-                                                       {
-                                                               $this->data = 
htmlspecialchars($this->data);
-                                                               /*
-                                                               if 
(!sanitize($this->data,'isbaseasci'))
-                                                               {
-                                                                       
$this->data = '<![CDATA['.$this->data.']]>';
-                                                               }
-                                                               */
-                                                               $result .= 
$this->data ;
-                                                               $endtag_indent 
= '';
-                                                       }
+                                       case 'value':
+                                               if(is_array($this->data))
+                                               {
+                                                       $type_error = true;
                                                        break;
-                                               case 'node':
-                                                       $result .= "\n";
-                                                       
if(!is_array($this->data))
-                                                       {
-                                                               $type_error = 
True;
-                                                               break;
-                                                       }
-                               
-                                                       $subindent = $indent+1;
+                                               }
+                                               if($this->data != 
htmlentities($this->data))    // this is unnecessary with 
htmlentities($this->data)
+                                               {
+                                                       $result .= 
'<![CDATA['.$this->data.']]>';
+                                                       $endtag_indent = '';
+                                               }
+                                               elseif(strlen($this->data) > 
120 && !empty($this->indentstring))
+                                               {
+                                                       //$this->data = 
htmlentities($this->data);
+                                                       $result .= 
"\n".$indentstring.$this->indentstring.$this->data."\n";
+                                                       $endtag_indent = 
$indentstring;
+                                               }
+                                               else
+                                               {
+                                                       //$this->data = 
htmlentities($this->data);
+                                                       $result .= $this->data ;
+                                                       $endtag_indent = '';
+                                               }
+                                               break;
+                                       case 'node':
+                                               $result .= "\n";
+                                               if(!is_array($this->data))
+                                               {
+                                                       $type_error = true;
+                                                       break;
+                                               }
 
-                                                       $n = count($this->data);
-                                                       for($i=0;$i<$n;$i++)
+                                               $subindent = $indent+1;
+                                               foreach($this->data as $i => 
$item)
+                                               {
+                                                       
if(is_object($this->data[$i]))
                                                        {
-                                                               
if(is_object($this->data[$i]))
-                                                               {
-                                                                       $result 
.= $this->data[$i]->export_xml($subindent);
-                                                               }
+                                                               $result .= 
$this->data[$i]->export_xml($subindent);
                                                        }
-                                                       break;
-                                               default:
+                                               }
+                                               break;
+                                       default:
                                                if($this->data != '')
                                                {
-                                                       
$GLOBALS['msgbox']->add('Invalid or unset data type ('.$this->data_type.'). 
This should not be possible if using the class as intended',__LINE__,__FILE__, 
'fatal');
+                                                       trigger_error('Invalid 
or unset data type ('.$this->data_type.'). This should not be possible if using 
the class as intended',E_USER_ERROR);
                                                }
-                                       }
+                               }
 
-                                       if ($type_error)
-                                       {
-                                               
$GLOBALS['msgbox']->add('Invalid data type. Tagged as '.$this->data_type.' but 
data is '.gettype($this->data),__LINE__,__FILE__, 'fatal');
-                                       }
+                               if ($type_error)
+                               {
+                                       trigger_error('Invalid data type. 
Tagged as '.$this->data_type.' but data is '.gettype($this->data),E_USER_ERROR);
+                               }
 
-                                       $result .= 
$endtag_indent.'</'.$this->name.'>';
-                                       if($indent != 0)
-                                       {
-                                               $result .= "\n";
-                                       }
+                               $result .= $endtag_indent.'</'.$this->name.'>';
+                               if ($indent != 0)
+                               {
+                                       $result .= "\n";
                                }
-                               if(count($this->comments) > 0 )
+                       }
+
+                       if(!empty($this->comments))
+                       {
+                               foreach($this->comments as $comment)
                                {
-                                       $n = count($this->comments);
-                                       for($i=0;$i<$n;$i++)
-                                       {
-                                               $result .= $endtag_indent."<!-- 
".$this->comments[$i]." -->\n";
-                                       }
+                                       $result .= $endtag_indent.'<!-- 
'.$comment." -->\n";
                                }
-                               return $result;
                        }
+                       return $result;
                }
        }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]