diff options
author | Christian Schneider | 2008-11-07 15:33:07 +0000 |
---|---|---|
committer | Christian Schneider | 2008-11-07 15:33:07 +0000 |
commit | 2ef85ec182278544ed7a625a319b8b0ee4edbc74 (patch) | |
tree | 6b21c3b4e843c409fb08ba74f29080092c5cd060 /it_tag.class | |
parent | f2ba0bb34e65be3097b957a144643feeb44f3931 (diff) | |
download | itools-2ef85ec182278544ed7a625a319b8b0ee4edbc74.tar.gz itools-2ef85ec182278544ed7a625a319b8b0ee4edbc74.tar.bz2 itools-2ef85ec182278544ed7a625a319b8b0ee4edbc74.zip |
First version of it_html based on objectsdevel-it_html
Diffstat (limited to 'it_tag.class')
-rw-r--r-- | it_tag.class | 113 |
1 files changed, 113 insertions, 0 deletions
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 @@ +<?php +/* +** $Id$ +** +** Copyright (C) 1995-2008 by the ITools Authors. +** This file is part of ITools - the Internet Tools Library +** +** ITools is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 3 of the License, or +** (at your option) any later version. +** +** ITools is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see <http://www.gnu.org/licenses/>. +** +** 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, '<textarea') === false) && ($data != strip_tags($data))) + $data = str_replace("\n", "\n ", "\n" . trim($data)) . "\n"; + + $result[] = $data; + + $result[] = "</$this->tag>$newline"; + } + else if ($GLOBALS['it_html']->p['htmltype'] == 'html') + $result[] = ">$newline"; + else + $result[] = " />$newline"; + + if ($GLOBALS['debug_srclines']) + array_unshift($result, "<!-- " . trim(it::replace(array('^(it_\w+.class:\d+\s+)+' => "", '^(([\w.]+:\d+\s+){2}).*' => '$1'), it_debug::backtrace())) . " -->"); + + $result[] = $this->suffix; + + return join("", $result); +} + +function clear() +{ + $this->exchangeArray(array()); +} + +} + +?> |