Source for file core.php

Documentation is available at core.php

  1. <?
  2.  
  3. class tree
  4. {
  5. var $children;
  6. function tree($children=array())
  7. {
  8. $this->children=$children;
  9. }
  10. function &add_child($child,$name="")
  11. {
  12. $slot=$name;
  13. if ($name=="") $slot=empty_slot($this->children);
  14. if ($child!="")
  15. {
  16. $this->children[$slot]=$child;
  17. return $this->children[$slot];
  18. }
  19. else return 0;
  20. }
  21. function remove_child($child)
  22. {
  23. $temp=array_intersect($this->children,array($child));
  24. $id=key($temp);
  25. unset($this->children[$id[0]]);
  26. }
  27. function set_child($id,$value)
  28. {
  29. $this->children[$id]=$value;
  30. }
  31. function &get_child($id)
  32. {
  33. return $this->children[$id];
  34. }
  35. function child_count()
  36. {
  37. return count($this->children);
  38. }
  39. function render()
  40. {
  41. $output="";
  42. foreach ($this->children as $child)
  43. {
  44. if (is_object($child)) $output.=$child->render();
  45. else $output.=$child;
  46. }
  47. return $output;
  48. }
  49. }
  50.  
  51. class text extends tree
  52. {
  53. var $content;
  54. function text($content)
  55. {
  56. $this->tree();
  57. $this->content=&$this->add_child($content);
  58. }
  59. }
  60.  
  61. class xml_comment extends tree
  62. {
  63. function render()
  64. {
  65. $output="";
  66. $output.="<!-- ";
  67. $output.=tree::render();
  68. $output.=" -->";
  69. return $output;
  70. }
  71. }
  72.  
  73.  
  74. class xml_element extends tree
  75. {
  76. var $attribs;
  77. var $tag;
  78. function xml_element($tag,$attribs=array())
  79. {
  80. $this->tree();
  81. $this->tag=$tag;
  82. $this->attribs=$attribs;
  83. }
  84. function set_attrib($name,$value)
  85. {
  86. $this->attribs[$name]=$value;
  87. }
  88. function add_attribs($attribs)
  89. {
  90. $this->attribs=array_merge($this->attribs,$attribs);
  91. }
  92. function render()
  93. {
  94. $output="";
  95. $tag=$this->tag;
  96. foreach($this->attribs as $name => $value)
  97. {
  98. $attr.=" $name=\"$value\"";
  99. }
  100. $temp=tree::render();
  101. if ($temp=="") $output="<$tag $attr/>\n";
  102. else $output="<$tag$attr>\n$temp\n</$tag>\n";
  103. return $output;
  104. }
  105. }
  106.  
  107. class xml_m_content extends tree
  108. {
  109. function xml_m_content($tag)
  110. {
  111. $this->tag=$tag;
  112. $this->tree();
  113. }
  114. function add_content($content)
  115. {
  116. $t=&$this->add_child(new xml_element($this->tag));
  117. $t->add_child($content);
  118. }
  119. }

Documentation generated on Tue, 24 May 2005 03:57:41 -0400 by phpDocumentor 1.3.0RC3