1 <?php rcs_id('$Id: HtmlElement.php,v 1.8 2002-01-22 16:35:56 dairiki Exp $');
3 * Code for writing XML.
5 require_once("lib/XmlElement.php");
10 class HtmlElement extends XmlElement
12 function HtmlElement ($tagname /* , $attr_or_content , ...*/) {
13 $this->_tag = $tagname;
14 $this->_content = array();
15 $this->_properties = HTML::getTagProperties($tagname);
17 if (func_num_args() > 1)
18 $this->_init(array_slice(func_get_args(), 1));
20 $this->_attr = array();
23 /** Add a "tooltip" to an element.
25 * @param $tooltip_text string The tooltip text.
27 function addTooltip ($tooltip_text) {
28 $this->setAttr('title', $tooltip_text);
30 // FIXME: this should be initialized from title by an onLoad() function.
31 // (though, that may not be possible.)
32 $qtooltip = str_replace("'", "\\'", $tooltip_text);
33 $this->setAttr('onmouseover',
34 sprintf('window.status="%s"; return true;',
35 addslashes($tooltip_text)));
36 $this->setAttr('onmouseout', "window.status='';return true;");
39 function _emptyTag () {
40 return substr($this->_startTag(), 0, -1) . " />";
44 return ($this->_properties & HTMLTAG_EMPTY) != 0;
47 function hasInlineContent () {
48 return ($this->_properties & HTMLTAG_ACCEPTS_INLINE) != 0;
51 function isInlineElement () {
52 return ($this->_properties & HTMLTAG_INLINE) != 0;
56 function HTML ($tag /* , ... */) {
57 $el = new HtmlElement($tag);
58 if (func_num_args() > 1)
59 $el->_init(array_slice(func_get_args(), 1));
63 define('NBSP', "\xA0"); // iso-8859-x non-breaking space.
66 function raw ($html_text) {
67 return new RawXML($html_text);
71 function link (/*...*/) {
72 $el = new HtmlElement('link');
73 $el->_init(func_get_args());
77 function style (/*...*/) {
78 $el = new HtmlElement('style');
79 $el->_init(func_get_args());
83 function script (/*...*/) {
84 $el = new HtmlElement('script');
85 $el->_init(func_get_args());
89 function noscript (/*...*/) {
90 $el = new HtmlElement('noscript');
91 $el->_init(func_get_args());
96 function a (/*...*/) {
97 $el = new HtmlElement('a');
98 $el->_init(func_get_args());
102 function img (/*...*/) {
103 $el = new HtmlElement('img');
104 $el->_init(func_get_args());
108 function br (/*...*/) {
109 $el = new HtmlElement('br');
110 $el->_init(func_get_args());
114 function h1 (/*...*/) {
115 $el = new HtmlElement('h1');
116 $el->_init(func_get_args());
120 function h1 (/*...*/) {
121 $el = new HtmlElement('h1');
122 $el->_init(func_get_args());
126 function h2 (/*...*/) {
127 $el = new HtmlElement('h2');
128 $el->_init(func_get_args());
132 function h3 (/*...*/) {
133 $el = new HtmlElement('h3');
134 $el->_init(func_get_args());
138 function h4 (/*...*/) {
139 $el = new HtmlElement('h4');
140 $el->_init(func_get_args());
144 function h5 (/*...*/) {
145 $el = new HtmlElement('h5');
146 $el->_init(func_get_args());
150 function h6 (/*...*/) {
151 $el = new HtmlElement('h6');
152 $el->_init(func_get_args());
156 function hr (/*...*/) {
157 $el = new HtmlElement('hr');
158 $el->_init(func_get_args());
162 function div (/*...*/) {
163 $el = new HtmlElement('div');
164 $el->_init(func_get_args());
168 function p (/*...*/) {
169 $el = new HtmlElement('p');
170 $el->_init(func_get_args());
174 function blockquote (/*...*/) {
175 $el = new HtmlElement('blockquote');
176 $el->_init(func_get_args());
180 function span (/*...*/) {
181 $el = new HtmlElement('span');
182 $el->_init(func_get_args());
186 function em (/*...*/) {
187 $el = new HtmlElement('em');
188 $el->_init(func_get_args());
192 function strong (/*...*/) {
193 $el = new HtmlElement('strong');
194 $el->_init(func_get_args());
198 function small (/*...*/) {
199 $el = new HtmlElement('small');
200 $el->_init(func_get_args());
204 function tt (/*...*/) {
205 $el = new HtmlElement('tt');
206 $el->_init(func_get_args());
210 function u (/*...*/) {
211 $el = new HtmlElement('u');
212 $el->_init(func_get_args());
216 function sup (/*...*/) {
217 $el = new HtmlElement('sup');
218 $el->_init(func_get_args());
222 function sub (/*...*/) {
223 $el = new HtmlElement('sub');
224 $el->_init(func_get_args());
228 function ul (/*...*/) {
229 $el = new HtmlElement('ul');
230 $el->_init(func_get_args());
234 function ol (/*...*/) {
235 $el = new HtmlElement('ol');
236 $el->_init(func_get_args());
240 function dl (/*...*/) {
241 $el = new HtmlElement('dl');
242 $el->_init(func_get_args());
246 function li (/*...*/) {
247 $el = new HtmlElement('li');
248 $el->_init(func_get_args());
252 function dt (/*...*/) {
253 $el = new HtmlElement('dt');
254 $el->_init(func_get_args());
258 function dd (/*...*/) {
259 $el = new HtmlElement('dd');
260 $el->_init(func_get_args());
264 function table (/*...*/) {
265 $el = new HtmlElement('table');
266 $el->_init(func_get_args());
270 function caption (/*...*/) {
271 $el = new HtmlElement('caption');
272 $el->_init(func_get_args());
276 function thead (/*...*/) {
277 $el = new HtmlElement('thead');
278 $el->_init(func_get_args());
282 function tbody (/*...*/) {
283 $el = new HtmlElement('tbody');
284 $el->_init(func_get_args());
288 function tfoot (/*...*/) {
289 $el = new HtmlElement('tfoot');
290 $el->_init(func_get_args());
294 function tr (/*...*/) {
295 $el = new HtmlElement('tr');
296 $el->_init(func_get_args());
300 function td (/*...*/) {
301 $el = new HtmlElement('td');
302 $el->_init(func_get_args());
306 function th (/*...*/) {
307 $el = new HtmlElement('th');
308 $el->_init(func_get_args());
312 function form (/*...*/) {
313 $el = new HtmlElement('form');
314 $el->_init(func_get_args());
318 function input (/*...*/) {
319 $el = new HtmlElement('input');
320 $el->_init(func_get_args());
324 function getTagProperties($tag) {
325 $props = &$GLOBALS['HTML_TagProperties'];
326 return isset($props[$tag]) ? $props[$tag] : 0;
329 function _setTagProperty($prop_flag, $tags) {
330 $props = &$GLOBALS['HTML_TagProperties'];
331 if (is_string($tags))
332 $tags = preg_split('/\s+/', $tags);
333 foreach ($tags as $tag) {
334 if (isset($props[$tag]))
335 $props[$tag] |= $prop_flag;
337 $props[$tag] = $prop_flag;
342 define('HTMLTAG_EMPTY', 1);
343 define('HTMLTAG_INLINE', 2);
344 define('HTMLTAG_ACCEPTS_INLINE', 4);
347 HTML::_setTagProperty(HTMLTAG_EMPTY,
348 'area base basefont br col frame hr img input isindex link meta param');
349 HTML::_setTagProperty(HTMLTAG_ACCEPTS_INLINE,
351 'b big i small tt ' // %fontstyle
352 . 's strike u ' // (deprecated)
353 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
354 . 'a img object br script map q sub sup span bdo '//%special
355 . 'button input label select textarea ' //%formctl
357 // %block elements which contain inline content
358 . 'address h1 h2 h3 h4 h5 h6 p pre '
359 // %block elements which contain either block or inline content
362 // other with inline content
363 . 'caption dt label legend '
364 // other with either inline or block
365 . 'dd del ins li td th ');
367 HTML::_setTagProperty(HTMLTAG_INLINE,
369 'b big i small tt ' // %fontstyle
370 . 's strike u ' // (deprecated)
371 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
372 . 'a img object br script map q sub sup span bdo '//%special
373 . 'button input label select textarea ' //%formctl
377 // (c-file-style: "gnu")
382 // c-hanging-comment-ender-p: nil
383 // indent-tabs-mode: nil