add functions for easily adding images
[php-utility-classes.git] / include / cbsm / util / document.php-class
index 46d4293fe81d105c8aa025e4bd6e75ba9f06957f..58637850153d708b5015f58f128f0df484be1dec 100755 (executable)
@@ -46,6 +46,10 @@ class ExtendedDocument extends DOMDocument {
   //   appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
   //     returns the new child
   //
+  // function appendImage($src, [$alt_text])
+  //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
   //     returns an HTML <div> that is a child of the new child
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
   //     returns an HTML <div> that is a child of the new child
@@ -102,9 +106,16 @@ class ExtendedDocument extends DOMDocument {
   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
   //     NO return value!
   //
   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
   //     NO return value!
   //
+  // function appendCOMElement($module, $attributes)
+  //   appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // function createElementLink($target, [$value])
   //   returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
   //
   // function createElementLink($target, [$value])
   //   returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
   //
+  // function createElementImage($src, [$alt_text])
+  //   returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
+  //
   // function createElementForm($action, $method, $name)
   //   returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
   //   with the given action, method, and name
   // function createElementForm($action, $method, $name)
   //   returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
   //   with the given action, method, and name
@@ -144,6 +155,10 @@ class ExtendedDocument extends DOMDocument {
   //
   // function createElementJS($jsdata)
   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
   //
   // function createElementJS($jsdata)
   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
+  //
+  // function createCOMElement($module, $attributes)
+  //   returns an ExtendedElement that is in COM_NS namespace, with the given module as name and the
+  //     given name=>value array as attributes
 
   function __construct($version = '1.0', $encoding = 'utf-8') {
     // make sure the default DOMDocument constructor runs
 
   function __construct($version = '1.0', $encoding = 'utf-8') {
     // make sure the default DOMDocument constructor runs
@@ -164,6 +179,9 @@ class ExtendedDocument extends DOMDocument {
   function appendLink($target, $value = '') {
     return $this->appendChild($this->createElementLink($target, $value));
   }
   function appendLink($target, $value = '') {
     return $this->appendChild($this->createElementLink($target, $value));
   }
+  function appendImage($src, $alt_text = '') {
+    return $this->appendChild($this->createElementImage($src, $alt_text));
+  }
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
@@ -201,6 +219,9 @@ class ExtendedDocument extends DOMDocument {
   function appendJSElement($jsdata) {
     $this->appendChild($this->createElementJS($jsdata));
   }
   function appendJSElement($jsdata) {
     $this->appendChild($this->createElementJS($jsdata));
   }
+  function appendCOMElement($module, $attributes) {
+    $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
+  }
 
   function appendHTMLMarkup($htmldata, $parentNode = null) {
     if (is_null($parentNode)) { $parentNode =& $this; }
 
   function appendHTMLMarkup($htmldata, $parentNode = null) {
     if (is_null($parentNode)) { $parentNode =& $this; }
@@ -226,6 +247,13 @@ class ExtendedDocument extends DOMDocument {
     return $link;
   }
 
     return $link;
   }
 
+  function createElementImage($src, $alt_text = '') {
+    $link = $this->createElement('img');
+    $link->setAttribute('src', $src);
+    $link->setAttribute('alt', $alt_text);
+    return $link;
+  }
+
   function createElementForm($action, $method, $name) {
     $formelem = $this->createElement('form');
     $formelem->setAttribute('action', $action);
   function createElementForm($action, $method, $name) {
     $formelem = $this->createElement('form');
     $formelem->setAttribute('action', $action);
@@ -318,6 +346,16 @@ class ExtendedDocument extends DOMDocument {
     $jselem->appendChild($this->createCDATASection($jsdata));
     return $jselem;
   }
     $jselem->appendChild($this->createCDATASection($jsdata));
     return $jselem;
   }
+
+  function createCOMElement($module, $attributes) {
+    $com_elem = $this->createElementNS(COM_NS, $module);
+    if (is_array($attributes) && count($attributes)) {
+      foreach ($attributes as $name=>$value) {
+        $com_elem->setAttribute($name, $value);
+      }
+    }
+    return $com_elem;
+  }
 }
 
 class ExtendedElement extends DOMElement {
 }
 
 class ExtendedElement extends DOMElement {
@@ -337,6 +375,10 @@ class ExtendedElement extends DOMElement {
   //   appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
   //     returns the new child
   //
+  // function appendImage($src, [$alt_text])
+  //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
   //     returns an HTML <div> that is a child of the new child
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
   //     returns an HTML <div> that is a child of the new child
@@ -392,6 +434,10 @@ class ExtendedElement extends DOMElement {
   // function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
   //     NO return value!
   // function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
   //     NO return value!
+  //
+  // function appendCOMElement($module, $attributes)
+  //   appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
+  //     returns the new child
 
   function appendElement($name, $value = '') {
     return $this->appendChild($this->ownerDocument->createElement($name, $value));
 
   function appendElement($name, $value = '') {
     return $this->appendChild($this->ownerDocument->createElement($name, $value));
@@ -404,6 +450,9 @@ class ExtendedElement extends DOMElement {
   function appendLink($target, $value = '') {
     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
   }
   function appendLink($target, $value = '') {
     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
   }
+  function appendImage($src, $alt_text = '') {
+    return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
+  }
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
@@ -447,6 +496,9 @@ class ExtendedElement extends DOMElement {
   function appendJSElement($jsdata) {
     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
   function appendJSElement($jsdata) {
     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
+  function appendCOMElement($module, $attributes) {
+    $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
+  }
 }
 
 class ExtendedDocumentFragment extends DOMDocumentFragment {
 }
 
 class ExtendedDocumentFragment extends DOMDocumentFragment {
@@ -466,6 +518,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   //   appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
   //     returns the new child
   //
   //   appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
   //     returns the new child
   //
+  // function appendImage($src, [$alt_text])
+  //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
   //     returns an HTML <div> that is a child of the new child
   // function appendFormDiv($action, $method, $name)
   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
   //     returns an HTML <div> that is a child of the new child
@@ -521,6 +577,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   // function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
   //     NO return value!
   // function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
   //     NO return value!
+  //
+  // function appendCOMElement($module, $attributes)
+  //   appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
+  //     returns the new child
 
   function appendElement($name, $value = '') {
     return $this->appendChild($this->ownerDocument->createElement($name, $value));
 
   function appendElement($name, $value = '') {
     return $this->appendChild($this->ownerDocument->createElement($name, $value));
@@ -533,6 +593,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   function appendLink($target, $value = '') {
     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
   }
   function appendLink($target, $value = '') {
     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
   }
+  function appendImage($src, $alt_text = '') {
+    return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
+  }
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
   function appendFormDiv($action, $method, $name) {
     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
     return $formelem->appendElement('div');
@@ -576,5 +639,8 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   function appendJSElement($jsdata) {
     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
   function appendJSElement($jsdata) {
     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
+  function appendCOMElement($module, $attributes) {
+    $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
+  }
 }
 ?>
 }
 ?>