summaryrefslogtreecommitdiff
path: root/it_html.class
diff options
context:
space:
mode:
authorUrban Müller2012-08-07 13:41:07 +0000
committerUrban Müller2012-08-07 13:41:07 +0000
commitf88c44e2a8564705d65623a01b2956df3c85bbad (patch)
tree417aa7a186074319d8f48e4f77910fd84dd7dda2 /it_html.class
parent07107a5374004f2f3b2e035b3b4dfb9293184e3b (diff)
downloaditools-f88c44e2a8564705d65623a01b2956df3c85bbad.tar.gz
itools-f88c44e2a8564705d65623a01b2956df3c85bbad.tar.bz2
itools-f88c44e2a8564705d65623a01b2956df3c85bbad.zip
support it_tag built in C
Diffstat (limited to 'it_html.class')
-rw-r--r--it_html.class87
1 files changed, 48 insertions, 39 deletions
diff --git a/it_html.class b/it_html.class
index 66c751a..fa99af8 100644
--- a/it_html.class
+++ b/it_html.class
@@ -24,6 +24,36 @@
** echo html(head('title' => 'hello'), body(h1('hello'), p('Hello world!')));
**/
+/**
+ * Parse an arg array (mixed key=>value pairs and strings) and return it
+ * as array(0 => all numerical args concatenated, 1 => array(key=>value pairs)
+ * php version if c extension is not loaded
+ */
+if (!function_exists("it_parse_args")) {
+function it_parse_args($args)
+{
+ $p = array();
+ foreach ($args as $arg)
+ {
+ if (is_array($arg))
+ {
+ foreach ($arg as $key => $value)
+ {
+ if (is_int($key))
+ $data .= it_taintcheck($value);
+ else
+ $p[$key] = $value;
+ }
+ }
+ else
+ $data .= it_taintcheck($arg);
+ }
+
+ return array($data, $p);
+}
+}
+
+
class it_html
{
@@ -47,6 +77,7 @@ function it_html($p = array())
'moretags' => '', # Comma-separated list of tag-functions to generate additionally to 'tags'
'name' => 'it_html', # Name of global variable $this is assigned to (string), XXX Copy and paste in configure() to keep PHP4 compatibility
'nonewlinetags' => 'a,b,em,img,input,label,span,noscript', # tags that do not like newlines after them
+ 'alwaysclosetags' => 'a,div,iframe,pre,script,span,tbody,td,tfoot,thead,textarea', # tags which always get a close tag
'notexported' => 'configure,sanitize',# Those methods are not exported
'prettyprint' => it::is_devel(), # Should output be prettily indented?
'show_boot_dom' => false, # If true, append invisible <div id="it_boot_dom"> at the end of body
@@ -66,7 +97,10 @@ function it_html($p = array())
'xhtml-mobile' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">'
);
- $this->hasnonewline = array_flip(explode(',', $this->p['nonewlinetags']));
+ # Since name is given as param, it is our duty to store it, not our caller's.
+ $GLOBALS[$this->p['name']] =& $this;
+
+ it_html::configure(array('name' => $this->p['name']));
$notexported = array_flip(explode(',', "dummy," . $this->p['notexported'])); # dummy keeps values > 0
# Create global functions for _tags
@@ -91,9 +125,6 @@ function it_html($p = array())
}
eval(join('', (array)$code));
-
- # Since name is given as param, it is our duty to store it, not our caller's.
- $GLOBALS[$this->p['name']] =& $this;
}
@@ -104,9 +135,11 @@ function it_html($p = array())
*/
function configure($p)
{
- $p += array('name' => "it_html"); # XXX Copy and paste from constructor to keep PHP4 compatibility
- $GLOBALS[$p['name']]->p = $p + (array)$GLOBALS[$p['name']]->p;
- $GLOBALS[$p['name']]->hasnonewline = array_flip(explode(',', $GLOBALS[$p['name']]->p['nonewlinetags']));
+ $ithtml = $GLOBALS[$p['name'] ? $p['name'] : "it_html"];
+ $ithtml->p = $p + (array)$ithtml->p;
+ $ithtml->hasnonewline = array_flip(explode(',', $ithtml->p['nonewlinetags']));
+ $ithtml->alwaysclose = array_flip(explode(',', $ithtml->p['alwaysclosetags']));
+ $ithtml->fasttag = (function_exists("it_tag") && $ithtml->p['name'] == "it_html" && !$GLOBALS['debug_srclines'] && !$GLOBALS['debug_utf8check'] && $ithtml->p['charset'] == "utf-8" && !$ithtml->p['prettyprint']) || $GLOBALS['debug_fasttag'];
}
/**
@@ -120,7 +153,7 @@ function configure($p)
*/
function html($args)
{
- list($data, $p) = $this->_parse_args($args);
+ list($data, $p) = it_parse_args($args);
$p += $this->p;
$html = ($p['doctype'] ? $p['doctype'] : $this->doctypes[$p['htmltype']]) . "\n" .
@@ -145,7 +178,7 @@ function head($args = array())
{
if (!$this->head_sent++)
{
- list($data, $p) = $this->_parse_args($args);
+ list($data, $p) = it_parse_args($args);
$p += $this->p;
$this->p = ($p += array('content-type' => "text/html; charset={$p['charset']}"));
@@ -229,33 +262,6 @@ function body($args)
/**
- * INTERNAL: Parse an arg array (mixed key=>value pairs and strings) and return it
- * as array(0 => all numerical args concatenated, 1 => array(key=>value pairs)
- */
-function _parse_args($args)
-{
- $p = array();
- foreach ($args as $arg)
- {
- if (is_array($arg))
- {
- foreach ($arg as $key => $value)
- {
- if (is_int($key))
- $data .= it_taintcheck($value);
- else
- $p[$key] = $value;
- }
- }
- else
- $data .= it_taintcheck($arg);
- }
-
- return array($data, $p);
-}
-
-
-/**
* function div($args...)
* Return a <div>...</div> element
* Any strings in the argument list will be content of the <div>
@@ -271,7 +277,10 @@ function _parse_args($args)
*/
function _tag($name, $args)
{
- list($data, $attr) = $this->_parse_args($args);
+ if ($this->fasttag)
+ return it_tag($name, $args);
+
+ list($data, $attr) = it_parse_args($args);
$newline = isset($this->hasnonewline[$name]) ? "" : "\n";
@@ -303,7 +312,7 @@ function _tag($name, $args)
}
# Apply a kind of magic... this needs further investigation
- if (isset($data) || preg_match('/^(a|div|iframe|pre|script|span|tbody|td|tfoot|thead|textarea)$/i', $name))
+ if (isset($data) || isset($this->alwaysclose[$name]))
$result .= ">$data</$name>$newline";
elseif ($this->p['htmltype'] == 'html')
$result .= ">$newline";
@@ -505,7 +514,7 @@ function Q($string)
function U(/* ... */)
{
$args = func_get_args();
- list($base, $params) = it_html::_parse_args($args);
+ list($base, $params) = it_parse_args($args);
if (!isset($base))
$base = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);