summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2006-12-24 01:08:27 +0000
committerUrban Müller2006-12-24 01:08:27 +0000
commitad91e2b50a2b5d2fdc704dd3b594f01386b460fd (patch)
tree9069f2b82e4ee07995452a9c1271c4177ebbccf6
parent33a8aa16c8720928d09c0b1958fee155e62cf407 (diff)
downloaditools-ad91e2b50a2b5d2fdc704dd3b594f01386b460fd.tar.gz
itools-ad91e2b50a2b5d2fdc704dd3b594f01386b460fd.tar.bz2
itools-ad91e2b50a2b5d2fdc704dd3b594f01386b460fd.zip
faster, pussycat!
-rw-r--r--html.class48
1 files changed, 21 insertions, 27 deletions
diff --git a/html.class b/html.class
index 8281560..8bde4dd 100644
--- a/html.class
+++ b/html.class
@@ -35,6 +35,7 @@ class it_html
'show_boot_dom' => true,
);
var $tags_seen = array('body' => true); # body always counts as seen
+ var $_hasnonewline = array();
/**
* Create a HTML object and global functions for all methods (exlcluding
@@ -61,36 +62,22 @@ function it_html($config = array())
if (isset($this->_oldhtml) && !$this->_htmltype)
$this->_htmltype = $this->_oldhtml ? "html" : "xhtml";
$this->_oldhtml = $this->_htmltype == "html";
+ $this->_hasnonewline = array_flip(explode(',', "dummy," . $this->_nonewlinetags)); # dummy keeps values >0
# Create global functions from all methods and names in $config['tags'] and $config['moretags']
- $methods = get_class_methods(get_class($this));
$funcs = array_unique(array_merge($methods, explode(',', $this->_tags), explode(',', $this->_moretags)));
- $nonewlinetags = explode(',', $this->_nonewlinetags);
- foreach($funcs as $func)
- {
- # Do not globalise 'private' functions starting in '_' or for our constructor
- if (preg_match('/^_/', $func) || is_a($this, $func) || empty($func) || function_exists($func))
- continue;
-
- $funcargs = array();
- if (in_array($func, $nonewlinetags))
- $funcargs += array('nonewline' => true);
-
- $funcconfig = $funcargs ? 'array_push($args, '.strtr(var_export($funcargs, true), array("\n" => '')).'); ' : '';
-
- $code = "function $func() { \$args = func_get_args(); $funcconfig";
- if (!in_array($func, $methods)) # No special case: generate call to tag()
- {
- $code .= "array_unshift(\$args, '$func');";
- $func = 'tag';
- }
+ # Create global functions for _tags
+ foreach (array_merge(explode(',', $this->_tags), explode(',', $this->_moretags)) as $func)
+ if (!function_exists($func) && $func)
+ $code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['it_html']->_tag('$func', \$args);}";
- $code .= "return call_user_func_array(array(&\$GLOBALS['$this->_name'], '$func'), \$args); }";
+ # Create global functions for it_html methods
+ foreach (get_class_methods(get_class($this)) as $func)
+ if (!preg_match('/^_/', $func) && !is_a($this, $func) && $func && !function_exists($func))
+ $code[$func] = "function $func() { \$args = func_get_args(); return call_user_func_array(array(&\$GLOBALS['$this->_name'], '$func'), \$args);}";
- debug(get_class($this).': code: '.$code, 8);
- eval($code);
- }
+ eval(join("", array_values($code))); # putting things in assoc array prevents redeclarations
# Since name is given as param, it is our duty to store it, not our caller's.
$GLOBALS[$this->_name] =& $this;
@@ -108,6 +95,14 @@ function tag(/* $name, ... */)
$args = func_get_args();
$name = array_shift($args);
+ return $this->_tag($name, $args);
+}
+
+/**
+ * Internal: Create html tag from name and args array
+ */
+function _tag($name, $args)
+{
$data = null;
$attr = array();
@@ -129,8 +124,7 @@ function tag(/* $name, ... */)
$data .= $arg;
}
- $newline = empty($attr['nonewline']) ? "\n" : "";
- unset($attr['nonewline']);
+ $newline = $this->_hasnonewline[$name] ? "" : "\n";
# Ultra XML PrettyPrinter 3000 [\] by SCA
if ($this->_prettyprint && $newline && (substr($data, -1, 1) == "\n") && (strpos($data, '<textarea') === false) && ($data != strip_tags($data)))
@@ -144,7 +138,7 @@ function tag(/* $name, ... */)
if (($value === null) || ($value === false)) # null or false: omit whole tag
;
else if (isset($value) && $value !== true) # normal case: value
- $result .= " $key=\"" . str_replace("\n", "&#10;", it_html::Q($value)) . '"';
+ $result .= " $key=\"" . (preg_match("/[<>&\"'\n\x80-\x9f]/", $value) ? str_replace("\n", "&#10;", it_html::Q($value)) : $value) . '"';
else # true: tag without value
$result .= $this->_oldhtml ? " $key" : " $key=\"$key\"";
}