1 <?php rcs_id('$Id: HtmlElement.php,v 1.6 2002-01-22 03:17:47 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 function _emptyTag () {
24 return substr($this->_startTag(), 0, -1) . " />";
28 return ($this->_properties & HTMLTAG_EMPTY) != 0;
31 function hasInlineContent () {
32 return ($this->_properties & HTMLTAG_ACCEPTS_INLINE) != 0;
35 function isInlineElement () {
36 return ($this->_properties & HTMLTAG_INLINE) != 0;
40 function HTML ($tag /* , ... */) {
41 $el = new HtmlElement($tag);
42 if (func_num_args() > 1)
43 $el->_init(array_slice(func_get_args(), 1));
47 define('NBSP', "\xA0"); // iso-8859-x non-breaking space.
50 function raw ($html_text) {
51 return new RawXML($html_text);
55 function link (/*...*/) {
56 $el = new HtmlElement('link');
57 $el->_init(func_get_args());
61 function style (/*...*/) {
62 $el = new HtmlElement('style');
63 $el->_init(func_get_args());
67 function script (/*...*/) {
68 $el = new HtmlElement('script');
69 $el->_init(func_get_args());
73 function noscript (/*...*/) {
74 $el = new HtmlElement('noscript');
75 $el->_init(func_get_args());
80 function a (/*...*/) {
81 $el = new HtmlElement('a');
82 $el->_init(func_get_args());
86 function img (/*...*/) {
87 $el = new HtmlElement('img');
88 $el->_init(func_get_args());
92 function br (/*...*/) {
93 $el = new HtmlElement('br');
94 $el->_init(func_get_args());
98 function h1 (/*...*/) {
99 $el = new HtmlElement('h1');
100 $el->_init(func_get_args());
104 function h1 (/*...*/) {
105 $el = new HtmlElement('h1');
106 $el->_init(func_get_args());
110 function h2 (/*...*/) {
111 $el = new HtmlElement('h2');
112 $el->_init(func_get_args());
116 function h3 (/*...*/) {
117 $el = new HtmlElement('h3');
118 $el->_init(func_get_args());
122 function h4 (/*...*/) {
123 $el = new HtmlElement('h4');
124 $el->_init(func_get_args());
128 function h5 (/*...*/) {
129 $el = new HtmlElement('h5');
130 $el->_init(func_get_args());
134 function h6 (/*...*/) {
135 $el = new HtmlElement('h6');
136 $el->_init(func_get_args());
140 function div (/*...*/) {
141 $el = new HtmlElement('div');
142 $el->_init(func_get_args());
146 function p (/*...*/) {
147 $el = new HtmlElement('p');
148 $el->_init(func_get_args());
152 function blockquote (/*...*/) {
153 $el = new HtmlElement('blockquote');
154 $el->_init(func_get_args());
158 function span (/*...*/) {
159 $el = new HtmlElement('span');
160 $el->_init(func_get_args());
164 function em (/*...*/) {
165 $el = new HtmlElement('em');
166 $el->_init(func_get_args());
170 function strong (/*...*/) {
171 $el = new HtmlElement('strong');
172 $el->_init(func_get_args());
176 function small (/*...*/) {
177 $el = new HtmlElement('small');
178 $el->_init(func_get_args());
182 function tt (/*...*/) {
183 $el = new HtmlElement('tt');
184 $el->_init(func_get_args());
188 function u (/*...*/) {
189 $el = new HtmlElement('u');
190 $el->_init(func_get_args());
194 function sup (/*...*/) {
195 $el = new HtmlElement('sup');
196 $el->_init(func_get_args());
200 function sub (/*...*/) {
201 $el = new HtmlElement('sub');
202 $el->_init(func_get_args());
206 function ul (/*...*/) {
207 $el = new HtmlElement('ul');
208 $el->_init(func_get_args());
212 function ol (/*...*/) {
213 $el = new HtmlElement('ol');
214 $el->_init(func_get_args());
218 function dl (/*...*/) {
219 $el = new HtmlElement('dl');
220 $el->_init(func_get_args());
224 function li (/*...*/) {
225 $el = new HtmlElement('li');
226 $el->_init(func_get_args());
230 function dt (/*...*/) {
231 $el = new HtmlElement('dt');
232 $el->_init(func_get_args());
236 function dd (/*...*/) {
237 $el = new HtmlElement('dd');
238 $el->_init(func_get_args());
242 function table (/*...*/) {
243 $el = new HtmlElement('table');
244 $el->_init(func_get_args());
248 function caption (/*...*/) {
249 $el = new HtmlElement('caption');
250 $el->_init(func_get_args());
254 function thead (/*...*/) {
255 $el = new HtmlElement('thead');
256 $el->_init(func_get_args());
260 function tbody (/*...*/) {
261 $el = new HtmlElement('tbody');
262 $el->_init(func_get_args());
266 function tfoot (/*...*/) {
267 $el = new HtmlElement('tfoot');
268 $el->_init(func_get_args());
272 function tr (/*...*/) {
273 $el = new HtmlElement('tr');
274 $el->_init(func_get_args());
278 function td (/*...*/) {
279 $el = new HtmlElement('td');
280 $el->_init(func_get_args());
284 function th (/*...*/) {
285 $el = new HtmlElement('th');
286 $el->_init(func_get_args());
290 function form (/*...*/) {
291 $el = new HtmlElement('form');
292 $el->_init(func_get_args());
296 function input (/*...*/) {
297 $el = new HtmlElement('input');
298 $el->_init(func_get_args());
302 function getTagProperties($tag) {
303 $props = &$GLOBALS['HTML_TagProperties'];
304 return isset($props[$tag]) ? $props[$tag] : 0;
307 function _setTagProperty($prop_flag, $tags) {
308 $props = &$GLOBALS['HTML_TagProperties'];
309 if (is_string($tags))
310 $tags = preg_split('/\s+/', $tags);
311 foreach ($tags as $tag) {
312 if (isset($props[$tag]))
313 $props[$tag] |= $prop_flag;
315 $props[$tag] = $prop_flag;
320 define('HTMLTAG_EMPTY', 1);
321 define('HTMLTAG_INLINE', 2);
322 define('HTMLTAG_ACCEPTS_INLINE', 4);
325 HTML::_setTagProperty(HTMLTAG_EMPTY,
326 'area base basefont br col frame hr img input isindex link meta param');
327 HTML::_setTagProperty(HTMLTAG_ACCEPTS_INLINE,
329 'b big i small tt ' // %fontstyle
330 . 's strike u ' // (deprecated)
331 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
332 . 'a img object br script map q sub sup span bdo '//%special
333 . 'button input label select textarea ' //%formctl
335 // %block elements which contain inline content
336 . 'address h1 h2 h3 h4 h5 h6 p pre '
337 // %block elements which contain either block or inline content
340 // other with inline content
341 . 'caption dt label legend '
342 // other with either inline or block
343 . 'dd del ins li td th ');
345 HTML::_setTagProperty(HTMLTAG_INLINE,
347 'b big i small tt ' // %fontstyle
348 . 's strike u ' // (deprecated)
349 . 'abbr acronym cite code dfn em kbd samp strong var ' //%phrase
350 . 'a img object br script map q sub sup span bdo '//%special
351 . 'button input label select textarea ' //%formctl
355 // (c-file-style: "gnu")
360 // c-hanging-comment-ender-p: nil
361 // indent-tabs-mode: nil