summaryrefslogtreecommitdiff
path: root/html.class
diff options
context:
space:
mode:
authorChristian Schneider2006-12-12 13:38:57 +0000
committerChristian Schneider2006-12-12 13:38:57 +0000
commitfd9171e0df775da9c4a3ea22e8f95ec75d3b3897 (patch)
tree53e93e18851d1c780f73e5464b89b1aad87f598c /html.class
parentee2fcb5bbc9b9db282a4668c50d87447b2114886 (diff)
downloaditools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.tar.gz
itools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.tar.bz2
itools-fd9171e0df775da9c4a3ea22e8f95ec75d3b3897.zip
Merged revisions 13944-15067 via svnmerge from
svn+ssh://rdc.rim.ch/rdc/svn/itools/devel-redesign ........ r13945 | weber | 2006-10-26 16:13:44 +0200 (Thu, 26 Oct 2006) | 2 lines omit null attributes, true means add name only. select() supports optgroups ........ r13946 | weber | 2006-10-26 16:22:42 +0200 (Thu, 26 Oct 2006) | 2 lines Removed cruft ........ r13989 | cschneid | 2006-10-27 18:32:11 +0200 (Fri, 27 Oct 2006) | 1 line Removed more cruft ........ r13991 | cschneid | 2006-10-28 19:36:35 +0200 (Sat, 28 Oct 2006) | 1 line Make adserver output xhtml compliant tags ........ r14093 | weber | 2006-11-06 17:13:23 +0100 (Mon, 06 Nov 2006) | 2 lines title tag can be omitted completely ........ r14096 | weber | 2006-11-06 18:00:43 +0100 (Mon, 06 Nov 2006) | 2 lines Q() doesn't encode newlines, tag() encodes newlines within attributes ........ r14135 | weber | 2006-11-09 02:30:03 +0100 (Thu, 09 Nov 2006) | 2 lines Migrate DB to texts.php on the fly (this functionality will be removed later), use only statictext, not DB ........ r14164 | mueller | 2006-11-09 19:23:40 +0100 (Thu, 09 Nov 2006) | 1 line disable empty options in select ........ r14194 | mueller | 2006-11-13 14:34:25 +0100 (Mon, 13 Nov 2006) | 1 line imply choose() in show() ........ r14212 | weber | 2006-11-13 18:14:33 +0100 (Mon, 13 Nov 2006) | 2 lines Debug output is left-aligned ........ r14231 | cschneid | 2006-11-14 17:09:32 +0100 (Tue, 14 Nov 2006) | 1 line Load js files before dom is ready and prevent loops on static= ........ r14288 | cschneid | 2006-11-15 13:16:54 +0100 (Wed, 15 Nov 2006) | 1 line More compact serialization of arrays ........ r14388 | weber | 2006-11-22 18:19:34 +0100 (Wed, 22 Nov 2006) | 2 lines Add optional IE PNG fix to it_html::img() ........ r14442 | mueller | 2006-11-27 23:22:23 +0100 (Mon, 27 Nov 2006) | 1 line correctly handle <option value=""> ........ r14444 | cschneid | 2006-11-28 12:35:43 +0100 (Tue, 28 Nov 2006) | 1 line Handle null separately to preserve 0 == '0' ........ r14450 | cschneid | 2006-11-28 15:36:45 +0100 (Tue, 28 Nov 2006) | 1 line Style commit (mainly done to test commit-email) ........ r14451 | cschneid | 2006-11-28 15:44:49 +0100 (Tue, 28 Nov 2006) | 1 line Test commit for commit-email ........ r14638 | cschneid | 2006-12-01 14:20:45 +0100 (Fri, 01 Dec 2006) | 1 line Suppress warning in case src file was removed by race ........ r14970 | weber | 2006-12-09 03:07:22 +0100 (Sat, 09 Dec 2006) | 2 lines Added the highly useful timerlog() method from searchlib to justify the supporting code in auto_append.php ;) ........ r14971 | weber | 2006-12-09 03:08:49 +0100 (Sat, 09 Dec 2006) | 2 lines Added set(), made dump_php's return value more convincing ........ r14993 | cschneid | 2006-12-11 14:05:29 +0100 (Mon, 11 Dec 2006) | 1 line Added itjs::send_headers() to send HTTP headers suitable for JSON data ........ r14997 | cschneid | 2006-12-11 14:28:52 +0100 (Mon, 11 Dec 2006) | 1 line Set JSON expiration date for IE ........ r15057 | weber | 2006-12-12 14:02:43 +0100 (Tue, 12 Dec 2006) | 2 lines documentation update ........
Diffstat (limited to 'html.class')
-rw-r--r--html.class72
1 files changed, 54 insertions, 18 deletions
diff --git a/html.class b/html.class
index f23274b..a4657f2 100644
--- a/html.class
+++ b/html.class
@@ -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", "&#10;", 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", "&#10;", 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) === "" ? "&nbsp;" : 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) === "") ? "&nbsp;" : 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";
}