From 2ef85ec182278544ed7a625a319b8b0ee4edbc74 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Fri, 7 Nov 2008 15:33:07 +0000 Subject: First version of it_html based on objects --- it_tag.class | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 it_tag.class (limited to 'it_tag.class') diff --git a/it_tag.class b/it_tag.class new file mode 100644 index 0000000..f2b0fdc --- /dev/null +++ b/it_tag.class @@ -0,0 +1,113 @@ +. +** +** UltraHTML 3000 tool layer. Tags are now objects, used by it_html +** +**/ + +class it_tag extends ArrayObject +{ + var $tag; + var $attributes = array(); + var $prefix = ""; + var $suffix = ""; + +function __construct($tag, $values = array()) +{ + $this->tag = $tag; + $this->offsetSet(0, $values); +} + +function offsetSet($index, $value) +{ + if (is_string($index)) + { + $this->attributes[$index] = $value; + } + else if (is_array($value)) + { + foreach ($value as $key => $val) + $this->offsetSet($key, $val); + } + else + { + if (is_string($value)) + { + if ($errortype = $GLOBALS['it_html']->p['reportquote']) + trigger_error("Unquoted '$value' at " . it_debug::backtrace(), $errortype); + if ($GLOBALS['it_html']->p['autoquote']) + $value = new it_q($value); + } + + parent::offsetSet($index, $value); + } +} + +function __toString() +{ + $result = array($this->prefix, "<$this->tag"); + + foreach ($this->attributes as $key => $value) + { + if (($value === null) || ($value === false)) # null or false: omit whole tag + ; + else if (isset($value) && $value !== true) # normal case: value + $result[] = " $key=\"" . (preg_match("/[<>&\"'\n\x80-\x9f]/", $value) ? str_replace("\n", " ", new it_q($value)) : $value) . '"'; + else # true: tag without value + $result[] = ($GLOBALS['it_html']->p['htmltype'] == 'html') ? " $key" : " $key=\"$key\""; + } + + $newline = isset($GLOBALS['it_html']->hasnonewline[$this->tag]) ? "" : "\n"; + + if (count($this) || preg_match('/^(a|div|iframe|script|span|td|textarea)$/i', $this->tag)) + { + $result[] = ">"; + + $data = join("", $this->getArrayCopy()); + + # Ultra XML PrettyPrinter 3000 [\] by SCA + if ($GLOBALS['it_html']->p['prettyprint'] && $newline && (substr($data, -1, 1) == "\n") && (strpos($data, 'p['htmltype'] == 'html') + $result[] = ">$newline"; + else + $result[] = " />$newline"; + + if ($GLOBALS['debug_srclines']) + array_unshift($result, ""); + + $result[] = $this->suffix; + + return join("", $result); +} + +function clear() +{ + $this->exchangeArray(array()); +} + +} + +?> -- cgit v1.2.3