1 <?php rcs_id('$Id: HtmlElement.php,v 1.11 2002-01-24 21:21:37 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 pre (/*...*/) {
175 $el = new HtmlElement('pre');
176 $el->_init(func_get_args());
180 function blockquote (/*...*/) {
181 $el = new HtmlElement('blockquote');
182 $el->_init(func_get_args());
186 function span (/*...*/) {
187 $el = new HtmlElement('span');
188 $el->_init(func_get_args());
192 function em (/*...*/) {
193 $el = new HtmlElement('em');
194 $el->_init(func_get_args());
198 function strong (/*...*/) {
199 $el = new HtmlElement('strong');
200 $el->_init(func_get_args());
204 function small (/*...*/) {
205 $el = new HtmlElement('small');
206 $el->_init(func_get_args());
210 function tt (/*...*/) {
211 $el = new HtmlElement('tt');
212 $el->_init(func_get_args());
216 function u (/*...*/) {
217 $el = new HtmlElement('u');
218 $el->_init(func_get_args());
222 function sup (/*...*/) {
223 $el = new HtmlElement('sup');
224 $el->_init(func_get_args());
228 function sub (/*...*/) {
229 $el = new HtmlElement('sub');
230 $el->_init(func_get_args());
234 function ul (/*...*/) {
235 $el = new HtmlElement('ul');
236 $el->_init(func_get_args());
240 function ol (/*...*/) {
241 $el = new HtmlElement('ol');
242 $el->_init(func_get_args());
246 function dl (/*...*/) {
247 $el = new HtmlElement('dl');
248 $el->_init(func_get_args());
252 function li (/*...*/) {
253 $el = new HtmlElement('li');
254 $el->_init(func_get_args());
258 function dt (/*...*/) {
259 $el = new HtmlElement('dt');
260 $el->_init(func_get_args());
264 function dd (/*...*/) {
265 $el = new HtmlElement('dd');
266 $el->_init(func_get_args());
270 function table (/*...*/) {
271 $el = new HtmlElement('table');
272 $el->_init(func_get_args());
276 function caption (/*...*/) {
277 $el = new HtmlElement('caption');
278 $el->_init(func_get_args());
282 function thead (/*...*/) {
283 $el = new HtmlElement('thead');
284 $el->_init(func_get_args());
288 function tbody (/*...*/) {
289 $el = new HtmlElement('tbody');
290 $el->_init(func_get_args());
294 function tfoot (/*...*/) {
295 $el = new HtmlElement('tfoot');
296 $el->_init(func_get_args());
300 function tr (/*...*/) {
301 $el = new HtmlElement('tr');
302 $el->_init(func_get_args());
306 function td (/*...*/) {
307 $el = new HtmlElement('td');
308 $el->_init(func_get_args());
312 function th (/*...*/) {
313 $el = new HtmlElement('th');
314 $el->_init(func_get_args());
318 function form (/*...*/) {
319 $el = new HtmlElement('form');
320 $el->_init(func_get_args());
324 function input (/*...*/) {
325 $el = new HtmlElement('input');
326 $el->_init(func_get_args());
330 function getTagProperties($tag) {
331 $props = &$GLOBALS['HTML_TagProperties'];
332 return isset($props[$tag]) ? $props[$tag] : 0;
335 function _setTagProperty($prop_flag, $tags) {
336 $props = &$GLOBALS['HTML_TagProperties'];
337 if (is_string($tags))
338 $tags = preg_split('/\s+/', $tags);
339 foreach ($tags as $tag) {
340 if (isset($props[$tag]))
341 $props[$tag] |= $prop_flag;
343 $props[$tag] = $prop_flag;
348 define('HTMLTAG_EMPTY', 1);
349 define('HTMLTAG_INLINE', 2);
350 define('HTMLTAG_ACCEPTS_INLINE', 4);
353 HTML::_setTagProperty(HTMLTAG_EMPTY,
354 'area base basefont br col frame hr img input isindex link meta param');
355 HTML::_setTagProperty(HTMLTAG_ACCEPTS_INLINE,
357 'b big i small tt ' // %fontstyle
358 . 's strike u ' // (deprecated)
359 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
360 . 'a img object br script map q sub sup span bdo '//%special
361 . 'button input label select textarea ' //%formctl
363 // %block elements which contain inline content
364 . 'address h1 h2 h3 h4 h5 h6 p pre '
365 // %block elements which contain either block or inline content
368 // other with inline content
369 . 'caption dt label legend '
370 // other with either inline or block
371 . 'dd del ins li td th ');
373 HTML::_setTagProperty(HTMLTAG_INLINE,
375 'b big i small tt ' // %fontstyle
376 . 's strike u ' // (deprecated)
377 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
378 . 'a img object br script map q sub sup span bdo '//%special
379 . 'button input label select textarea ' //%formctl
383 // (c-file-style: "gnu")
388 // c-hanging-comment-ender-p: nil
389 // indent-tabs-mode: nil