diff options
Diffstat (limited to 'html.class')
-rw-r--r-- | html.class | 72 |
1 files changed, 54 insertions, 18 deletions
@@ -24,11 +24,12 @@ class it_html 'name' => 'it_html', # Name of global variable to use 'oldhtml' => false, 'prettyprint' => false, - 'tags' => 'a,br,form,h1,h2,h3,h4,img,input,li,meta,table,td,th,tr,ul', + 'tags' => 'a,br,form,h1,h2,h3,h4,input,li,meta,table,td,th,tr,ul', 'moretags' => '', 'nonewlinetags' => 'a,img,span', 'preprocess_attr' => array(), 'charset' => "iso-8859-1", + 'ie_png_fix' => false, # To enable, supply URL of a transparent gif (like /images/0.gif) 'show_content_type' => true, 'show_favicon' => true, 'show_boot_dom' => true, @@ -137,17 +138,15 @@ function tag(/* $name, ... */) $result = "<$name"; - # add attributes. If $value === null, use key only (<td nowrap> instead of <td nowrap=""> for old html, <td nowrap="nowrap"> for xhtml style) + # add attributes. If $value === true, use key only (<td nowrap> instead of <td nowrap=""> for old html, <td nowrap="nowrap"> for xhtml style) foreach($attr as $key => $value) { - if ($value === false) # omit whole tag + if (($value === null) || ($value === false)) # null or false: omit whole tag ; - else if (isset($value) && $value !== true) - $result .= " $key=\"" . it_html::Q($value) . '"'; - else if ($this->_oldhtml) - $result .= " $key"; - else - $result .= " $key=\"$key\""; + else if (isset($value) && $value !== true) # normal case: value + $result .= " $key=\"" . str_replace("\n", " ", it_html::Q($value)) . '"'; + else # true: tag without value + $result .= $this->_oldhtml ? " $key" : " $key=\"$key\""; } # Apply a kind of magic... this needs further investigation @@ -190,6 +189,30 @@ function div(/* $class, ... */) /** + * Special img() function patches png transparency for IE 5.5-6 if ie_png_fix is set + * @param ... any number optional data or array of key => value arguments + * @return <img ... /> + */ +function img(/* ... */) +{ + $args = func_get_args(); + + if ($this->_ie_png_fix && preg_match('/MSIE [56]/', $_SERVER['HTTP_USER_AGENT'])) + { + foreach($args as $id => $arg) + if (preg_match('/\.png(\?.*)?$/', $arg['src'])) + { + $args[$id]['style'] = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$arg['src']}',sizingMethod='scale');" . $arg['style']; + $args[$id]['src'] = $this->_ie_png_fix; + } + } + + array_unshift($args, 'img'); + return call_user_func_array(array(&$this, 'tag'), $args); +} + + +/** * Shortcut: return a span of a specific class * @param $class class name or null for no class= tag * @param ... any number optional data or array of key => value arguments @@ -217,7 +240,7 @@ function Q($string) if ($GLOBALS['it_html']->_charset == "iso-8859-1") $string = preg_replace('/[\x80-\x9f]/', ' ', strtr($string, array("\x80"=>"EUR", "\x82"=>"'", "\x84"=>"\"", "\x85"=>"...", "\x8a"=>"S", "\x8c"=>"OE", "\x8e"=>"Z", "\x91"=>"'", "\x92"=>"'", "\x93"=>"\"", "\x94"=>"\"", "\x96"=>"-", "\x97"=>"-", "\x9a"=>"s", "\x9e"=>"z"))); - return str_replace("\n", " ", htmlspecialchars($string)); + return htmlspecialchars($string); } @@ -274,13 +297,14 @@ function U(/* ... */) /** - * Create a dropdown menu object + * Create a dropdown menu object. Warning: encodes html code within options! * @param $tags key => value pairs of <select> tag * @param $options array (value => text) of available options or * string key:val{,key:val} where key will be rawurldecoded so it may contain %2C as comma + * supports optgroups as array (value => optgroup => array(value => text)) * @param $selected optional currently selected value */ -function select($tags, $options, $selected = '') +function select($tags, $options, $selected = null) { # Transmogrify key:val{,key:val} to array(key => val) if (!is_array($options)) @@ -295,9 +319,19 @@ function select($tags, $options, $selected = '') } } - $html = ''; - foreach($options as $value => $text) - $html .= '<option value="'.it_html::Q($value).'"'.(($value == $selected) ? ($this->_oldhtml ? ' selected' : ' selected="selected"') : '').'>'.(trim($text) === "" ? " " : it_html::Q($text))."</option>\n"; + $html = ""; + foreach($options as $value => $option) + { + if (is_array($option)) + { + $grouphtml = ""; + foreach($option as $optval => $opt) + $grouphtml .= $this->tag('option', 'value' => $optval, 'selected' => isset($selected) ? $optval == $selected : false, it_html::Q($opt)); + $html .= $this->tag('optgroup', 'label' => $value, $grouphtml); + } + else + $html .= $this->tag('option', 'value' => $value, 'selected' => isset($selected) ? $value == $selected : false, 'disabled' => $option === "", (trim($option) === "") ? " " : it_html::Q($option)); + } return $this->tag('select', $tags, $html); } @@ -386,7 +420,7 @@ function itjs(/* ... */) * Return HTML header with correct doctype. * * @param any number of text args or array of key => value: - * 'title' HTML title tag + * 'title' optional HTML title tag * 'content-type' optional content type (default: "text/html; charset=iso-8859-1") * 'description' optional data for <meta name="description"> tag * 'doctype' optional <!DOCTYPE HTML PUBLIC...> tag @@ -434,7 +468,9 @@ function head(/* ... */) ); $header = $p['show_content_type'] ? meta(array('http-equiv' => "Content-Type", 'content' => $p['content-type'])) : ""; - $header .= tag('title', it_html::Q($p['title'])); + + if (isset($p['title'])) + $header .= tag('title', it_html::Q($p['title'])); foreach(array('description', 'keywords') as $name) if (!empty($p[$name])) @@ -466,7 +502,7 @@ function head(/* ... */) if ($p['js']) { $js .= $this->itjs("boot.js", array('mode' => "inline")); - $js .= "function it_boot_init(){ window.clearTimeout(window.it_panictimer); " . trim($p['jsboot']) . " }\n"; + $js .= "function it_boot_start(){ " . trim($p['jsboot']) . " }\n"; $js .= "it_boot('/itjs/" . $p['js'] . "');\n"; } |