ACC SHELL
<?php
class TF_Html
{
protected $_tag = null;
protected $_singleTag = false;
protected $_attributes = array();
protected $_children = array();
protected $_isXhtml = true;
protected $_stripSpaces = false;
const INDENT = " ";
function __construct ($tag, $firstChild = null, $attributes = array(), $singleTag = false, $isXhtml = true)
{
$this->_singleTag = $singleTag;
$this->_tag = $tag;
$this->setAttributes($attributes, true);
$this->_isXhtml = $isXhtml;
$this->addChild($firstChild);
}
function __toString ()
{
$attr = array();
foreach ($this->_attributes as $attribute => $value) {
$attr[] = $attribute . '="' . $value . '"';
}
if ($attr === array()) {
$attributes = '';
} else {
$attributes = ' ' . implode(" ", $attr);
}
if ($this->_singleTag) {
if ($this->_isXhtml) {
$endTag = ' />';
} else {
$endTag = '>';
}
$startTag = '<' . $this->_tag . $attributes;
return $startTag . $endTag;
} else {
if (! is_null($this->_children) && is_array($this->_children)) {
$childRes = array();
foreach ($this->_children as $child) {
if ($child instanceof TF_Html) {
$x = str_ireplace(
"\r\n",
"\r\n" .
TF_Html::INDENT,
$child->__toString());
$childRes[] = $x;
} else if (is_string(
$child)) {
$childRes[] = $child;
} else {
try {
$childRes[] = (string) $child;
}
catch (Exception $e) {
throw new Zend_Exception(
"Neplatný obsah tagu!");
}
}
}
}
$startTag = '<' . $this->_tag . $attributes . '>';
$endTag = '</' . $this->_tag . '>';
if ($this->_stripSpaces) {
return $startTag . implode('', $childRes) .
$endTag;
} else {
return $startTag . "\r\n" . TF_Html::INDENT .
implode(
"\r\n" .
TF_Html::INDENT,
$childRes) .
"\r\n" . $endTag;
}
}
}
/**
* setStripSpaces
*/
public function setStripSpaces($flag){
$this->_stripSpaces = $flag;
} /* of setStripSpaces -------------------------------------*/
function addChild ($child, $content = null)
{
if ($child instanceof TF_Html) {
$this->_children[] = $child;
return $this;
}
if (is_null($child)) {
return $this;
}
if (is_string((string) $child)) {
if (is_null($content)) {
$this->_children[] = $child;
return $this;
} else {
$this->_children[] = new TF_Html($child,
$content);
return $this;
}
}
throw new Zend_Exception("Invalid child", 500);
}
function addChildByReference (&$child)
{
if ($child instanceof TF_Html) {
$this->_children[] = $child;
return $this;
} else
throw new Zend_Exception("Invalid child", 500);
}
function setAttributes ($attributes, $clear = false)
{
if ($clear) {
$this->_attributes = array();
}
foreach ($attributes as $attribute => $value) {
$this->_attributes[$attribute] = $value;
}
}
}
ACC SHELL 2018