--- /dev/null
+<?php
+function __autoload($class_name) {
+ require_once strtolower($class_name).'.lib.php';
+}
+
+abstract class Container {
+ var $sID;
+ var $aAttributes;
+ var $aContents;
+ function __construct($id=null,$attributes=array(),$contents=array()) {
+ $this->sID = $id;
+ if (is_array($attributes)) {
+ $this->aAttributes = $attributes;
+ }
+ if (is_array($contents))
+ $this->aContents = $contents;
+ else
+ $this->add($contents);
+ }
+ function __get($nm) {
+ if (isset($this->aAttributes[$nm])) {
+ $r = $this->aAttributes[$nm];
+ return $r;
+ }
+ }
+ function __set($nm, $val) {
+ // if (isset($this->aAttributes[$nm])) {
+ $this->aAttributes[$nm] = $val;
+ // }
+ }
+ function __isset($nm) {
+ return isset($this->aAttributes[$nm]);
+ }
+ function __unset($nm) {
+ unset($this->aAttributes[$nm]);
+ }
+
+ function add($obj) { $this->aContents[] = $obj; }
+ function set($obj) { $this->aContents = array($obj); }
+ function get_id() { return $this->sID; }
+ function has_id() { return !is_null($this->sID); }
+ function has_attributes() { return count($this->aAttributes); }
+ function get_attributes() { return $this->aAttributes; }
+ function get_contents() { return $this->aContents; }
+
+ protected function paint_head() {
+ if ($this->has_id()) {
+ if ($this->has_attributes()) {
+ return sprintf("<%s %s>", strtolower($this->get_id()), $this->paint_attributes());
+ } else {
+ return sprintf("<%s>", strtolower($this->get_id()));
+ }
+ }
+ }
+ protected function paint_attributes() {
+ $r = array();
+ foreach($this->get_attributes() as $k=>$v) {
+ $k = strtolower($k);
+ if (is_string($v)) {
+ $r[] = "$k=\"$v\"";
+ } elseif (is_object($v)) {
+ $r[] = "$k=\"".$v->__toString()."\"";
+ }
+ }
+ return implode(' ',$r);
+ }
+ protected function paint_foot() {
+ if ($this->has_id())
+ return sprintf("</%s>", strtolower($this->get_id()));
+ }
+ protected function paint_contents($split='') {
+ $r = array();
+ foreach($this->get_contents() as $item) {
+ if (is_string($item) && is_callable($item)) {
+ $args = func_get_args();
+ $r[] = ''.call_user_func($item,$args);
+ } elseif (is_object($item)) {
+ $r[] = ''.$item->__toString();
+ } elseif (is_string($item)) {
+ $r[] = ''.$item;
+ }
+ }
+ return implode($split,$r);
+ }
+ function __toString() {
+ return $this->paint_head().$this->paint_contents().$this->paint_foot();
+ }
+}
+
+class Entity extends Container {}
--- /dev/null
+<?php
+require_once 'container.lib.php';
+
+class CSS extends Container {
+ protected function paint_head() {
+ if ($this->has_id())
+ return sprintf("%s {", $this->get_id());
+ }
+ protected function paint_attributes() {
+ $r = array();
+ foreach($this->get_attributes() as $k=>$v) {
+ //$k = strtolower($k);
+ $r[] = "$k: $v;";
+ }
+ return implode('',$r);
+ }
+ protected function paint_foot() {
+ if ($this->has_id())
+ return sprintf("};");
+ }
+ function __toString() {
+ return $this->paint_head().$this->paint_attributes().$this->paint_foot();
+ }
+}
--- /dev/null
+<?php
+require_once 'xml.lib.php';
+
+class RPCReply extends XML {
+ function __construct() {
+ parent::__construct('response');
+ }
+ function add_eval($data) {
+ parent::add(new CDATA('eval',array(),$data));
+ }
+ function add_update($id,$data) {
+ parent::add(new CDATA('update',array('id'=>$id),$data));
+ }
+}
+?>
--- /dev/null
+<?php
+require_once 'container.lib.php';
+
+class HTML extends Container {}
+class XHTML extends Container {}
+class XML extends Container {
+ function __toString() {
+ return "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n".parent::__toString();
+ }
+}
+class CDATA extends Container {
+ protected function paint_contents() {
+ $r1 = "\n<![CDATA[";
+ $r2 = "]]>\n";
+ return $r1.parent::paint_contents().$r2;
+ }
+ function __toString() {
+ return $this->paint_head().$this->paint_contents().$this->paint_foot();
+ }
+}