26 |
* |
* |
27 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
28 |
* @link http://phphtmllib.sourceforge.net |
* @link http://phphtmllib.sourceforge.net |
29 |
|
* @package phpHtmlLib |
30 |
*/ |
*/ |
31 |
class HTMLTagClass extends XMLTagClass { |
class HTMLTagClass extends XMLTagClass { |
32 |
|
|
|
|
|
|
/** |
|
|
* Flag to tell the renderer not to |
|
|
* place the /> if we are in xhtml |
|
|
* compliant mode. |
|
|
*/ |
|
|
var $_no_finish_slash_xhtml = FALSE; |
|
|
|
|
|
|
|
|
/** |
|
|
* Flag to let us know to render XHTML 1.0 |
|
|
* compliant output. defaulted to FALSE |
|
|
* @var boolean |
|
|
* @access private |
|
|
*/ |
|
|
var $_xhtml_compliant = FALSE; |
|
|
|
|
|
/** |
|
|
* Flag to denote that this tag is |
|
|
* depricated by the HTML standard. |
|
|
* |
|
|
*/ |
|
|
var $_depricated = FALSE; |
|
|
|
|
33 |
/** |
/** |
34 |
* the list of tag attributes that we |
* the list of tag attributes that we |
35 |
* should create a clickable link for |
* should create a clickable link for |
36 |
* when in debug mode. |
* when in debug mode. |
37 |
|
* |
38 |
|
* We comment this declaration out |
39 |
|
* to save memory, since only a small |
40 |
|
* number of tags use it |
41 |
|
* |
42 |
* @var array |
* @var array |
43 |
* @access private |
* @access private |
44 |
*/ |
*/ |
45 |
var $_debug_link_attributes = array("background"); |
//var $_debug_link_attributes = array("background"); |
46 |
|
|
47 |
/** |
/** |
48 |
* The list of attributes not to render |
* The list of attributes not to render |
49 |
* if HTML_RENDER_TYPE is "XHTML STRICT" |
* if $GLOBALS["HTML_RENDER_TYPE"] is "XHTML STRICT" |
50 |
* |
* |
51 |
|
* We comment this declaration out |
52 |
|
* to save memory, since only a small |
53 |
|
* number of tags use it |
54 |
|
* |
55 |
*/ |
*/ |
56 |
var $_xhtml_strict_attributes = array(); |
//var $_xhtml_strict_attributes = array(); |
57 |
|
|
58 |
|
|
59 |
/** |
/** |
61 |
* htmlentities() on if we are in XHTML_STRICT |
* htmlentities() on if we are in XHTML_STRICT |
62 |
* mode. Otherwise the validator complains about |
* mode. Otherwise the validator complains about |
63 |
* html characters such as &. |
* html characters such as &. |
64 |
|
* |
65 |
|
* We comment this declaration out |
66 |
|
* to save memory, since only a small |
67 |
|
* number of tags use it |
68 |
|
* |
69 |
* @var array. |
* @var array. |
70 |
* @access private |
* @access private |
71 |
*/ |
*/ |
72 |
var $_htmlentities_attributes = array(); |
//var $_htmlentities_attributes = array(); |
73 |
|
|
74 |
|
|
75 |
/** |
/** |
91 |
$this->set_tag_attributes( $attributes ); |
$this->set_tag_attributes( $attributes ); |
92 |
} |
} |
93 |
|
|
94 |
|
//set the default tag options |
95 |
|
$this->_set_flags(); |
96 |
|
|
97 |
//add the content if any. |
//add the content if any. |
98 |
$num_args = func_num_args(); |
$num_args = func_num_args(); |
99 |
for ($i = 1; $i < $num_args; $i++) { |
for ($i = 1; $i < $num_args; $i++) { |
105 |
//this is a magic test. It assumes that |
//this is a magic test. It assumes that |
106 |
//someone has created the define for |
//someone has created the define for |
107 |
//HTML_RENDER_TYPE |
//HTML_RENDER_TYPE |
108 |
if ( HTML_RENDER_TYPE == XHTML || |
if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML || |
109 |
HTML_RENDER_TYPE == XHTML_STRICT ) { |
$GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT ) { |
110 |
$this->_xhtml_compliant = TRUE; |
$this->_flags |= _XHTMLCOMPLIANT; |
111 |
|
|
112 |
} |
} |
113 |
|
|
114 |
//if the tag is depricated |
//if the tag is depricated |
115 |
//we raise an alert. |
//we raise an alert. |
116 |
if ( $this->_depricated ) { |
if ( $this->_flags & _DEPRICATED ) { |
117 |
trigger_error(htmlspecialchars($this->_tag) . " has been depricated in HTML 4.0", E_USER_NOTICE); |
trigger_error(htmlspecialchars($this->_tag) . " has been depricated in HTML 4.0", E_USER_NOTICE); |
118 |
} |
} |
119 |
} |
} |
132 |
$this->_prepare_flags(); |
$this->_prepare_flags(); |
133 |
|
|
134 |
if ( $indent_level==NULL ) { |
if ( $indent_level==NULL ) { |
135 |
$indent_level = $this->_indent_level; |
$indent_level = 0; |
136 |
} |
} |
137 |
|
|
138 |
$html = $this->_render_tag($indent_level, $output_debug); |
$html = $this->_render_tag($indent_level, $output_debug); |
139 |
|
|
140 |
if ( $this->_content_required ) { |
if ( $this->_flags & _CONTENTREQUIRED) { |
141 |
$html .= $this->_render_content($indent_level, $output_debug); |
$html .= $this->_render_content($indent_level, $output_debug); |
142 |
} |
} |
143 |
if ( $this->_close_tag_required ) { |
if ( $this->_flags & _CLOSETAGREQUIRED ) { |
144 |
$html .= $this->_render_close_tag($indent_level, $output_debug); |
$html .= $this->_render_close_tag($indent_level, $output_debug); |
145 |
} |
} |
146 |
|
|
200 |
//lets call the special render tag debug function |
//lets call the special render tag debug function |
201 |
return $this->_render_tag_debug( $indent_level ); |
return $this->_render_tag_debug( $indent_level ); |
202 |
} else { |
} else { |
203 |
return XMLTag::_render_open_tag($indent_level, $this->_xhtml_compliant); |
return XMLTag::_render_open_tag($indent_level, $this->_flags & _XHTMLCOMPLIANT); |
204 |
} |
} |
205 |
} |
} |
206 |
|
|
245 |
|
|
246 |
$indent = $this->_render_indent($indent_level, TRUE); |
$indent = $this->_render_indent($indent_level, TRUE); |
247 |
|
|
248 |
$tag_prefix = htmlspecialchars( $this->_tag_prefix ); |
$tag_prefix = htmlspecialchars( (@$this->_tag_prefix ? $this->_tag_prefix : _TAG_PREFIX)); |
249 |
$tab_postfix = htmlspecialchars( $this->_tag_postfix ); |
$tab_postfix = htmlspecialchars( (@$this->_tag_postfix ? $this->_tag_postfix : _TAG_SUFFIX)); |
250 |
$str = $indent . $tag_prefix. "<span class=\"purple\" style=\"white-space:nowrap;\">"; |
$str = $indent . $tag_prefix. "<span class=\"purple\" style=\"white-space:nowrap;\">"; |
251 |
$str .= $this->_tag . "</span>"; |
$str .= $this->_tag . "</span>"; |
252 |
|
|
253 |
if ( $this->_xhtml_compliant && !$this->_always_upper_case ) { |
if ( ($this->_flags & _XHTMLCOMPLIANT) && !($this->_flags & _ALWAYS_UPPERCASE) ) { |
254 |
//we have to have the tag name be lower case. |
//we have to have the tag name be lower case. |
255 |
$str = strtolower( $str ); |
$str = strtolower( $str ); |
256 |
} |
} |
261 |
|
|
262 |
//if we want to output xhtml compliant code, we have to |
//if we want to output xhtml compliant code, we have to |
263 |
//render a special tag closing. |
//render a special tag closing. |
264 |
if ( $this->_xhtml_compliant ) { |
if ( $this->_flags & _XHTMLCOMPLIANT ) { |
265 |
//we have to render a special close for the |
//we have to render a special close for the |
266 |
//open tag, if the tag doesn't require a close |
//open tag, if the tag doesn't require a close |
267 |
//tag or content. |
//tag or content. |
268 |
if ( !$this->_close_tag_required && !$this->_no_finish_slash_xhtml ) { |
if ( !($this->_flags & _CLOSETAGREQUIRED) && !($this->_flags & _NOFINISHSLASHXHTML) ) { |
269 |
$html = $str . " />"; |
$html = $str . " />"; |
270 |
} else { |
} else { |
271 |
$html = $str.">"; |
$html = $str.">"; |
274 |
$html = $str.">"; |
$html = $str.">"; |
275 |
} |
} |
276 |
|
|
277 |
if ( $this->newline_after_opentag ) { |
if ( $this->_flags & _NEWLINEAFTEROPENTAG ) { |
278 |
$html .= "<br>\n"; |
$html .= "<br>\n"; |
279 |
} |
} |
280 |
return $html; |
return $html; |
294 |
|
|
295 |
$html = ''; |
$html = ''; |
296 |
//walk through the content |
//walk through the content |
297 |
foreach ($this->_content as $item) { |
for ($x=0; $x<=$this->_data_count; $x++) { |
298 |
|
$item = &$this->_content[$x]; |
299 |
if (method_exists($item, "render")) { |
if (method_exists($item, "render")) { |
300 |
if ($this->_collapse_flag && method_exists($item, "set_collapse")) { |
if (($this->_flags & _COLLAPSE) && method_exists($item, "set_collapse")) { |
301 |
$item->set_collapse(TRUE, FALSE); |
$item->set_collapse(TRUE, FALSE); |
302 |
} |
} |
303 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
307 |
} |
} |
308 |
$html .= $item->render($indent, TRUE); |
$html .= $item->render($indent, TRUE); |
309 |
} else { |
} else { |
310 |
if ($this->_collapse_flag) { |
if ($this->_flags & _COLLAPSE) { |
311 |
$html .= htmlspecialchars($item); |
$html .= htmlspecialchars($item); |
312 |
} else { |
} else { |
313 |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
if ($indent_level == INDENT_LEFT_JUSTIFY) { |
316 |
$indent = $indent_level + 1; |
$indent = $indent_level + 1; |
317 |
} |
} |
318 |
$indent = $this->_render_indent($indent, TRUE); |
$indent = $this->_render_indent($indent, TRUE); |
319 |
if ( $this->newline_after_opentag ) { |
if ( $this->_flags & _NEWLINEAFTEROPENTAG ) { |
320 |
$item = htmlspecialchars($item); |
$item = htmlspecialchars($item); |
321 |
$item = str_replace("\n", "<br>\n" . $indent, $item); |
$item = str_replace("\n", "<br>\n" . $indent, $item); |
322 |
$html .= $indent . "<span style=\"white-space:nowrap\">" .$item . "</span><br>\n"; |
$html .= $indent . "<span style=\"white-space:nowrap\">" .$item . "</span><br>\n"; |
341 |
function _render_close_tag_debug( $indent_level ) { |
function _render_close_tag_debug( $indent_level ) { |
342 |
|
|
343 |
$indent =""; |
$indent =""; |
344 |
if ( $this->indent_flag && $this->newline_after_opentag ) { |
if ( ($this->_flags & _INDENT) && ($this->_flags & _NEWLINEAFTEROPENTAG) ) { |
345 |
$indent = $this->_render_indent($indent_level, TRUE); |
$indent = $this->_render_indent($indent_level, TRUE); |
346 |
} |
} |
347 |
$str = $indent . "</" . "<span class=\"purple\">"; |
$str = $indent . "</" . "<span class=\"purple\">"; |
348 |
$str .= $this->_tag . "</span>>"; |
$str .= $this->_tag . "</span>>"; |
349 |
|
|
350 |
if ( $this->_xhtml_compliant ) { |
if ( $this->_flags & _XHTMLCOMPLIANT ) { |
351 |
$str = strtolower( $str ); |
$str = strtolower( $str ); |
352 |
} |
} |
353 |
|
|
354 |
if ( $this->newline_after_closetag ) { |
if ( $this->_flags & _NEWLINEAFTERCLOSETAG ) { |
355 |
$str .= "<br>\n"; |
$str .= "<br>\n"; |
356 |
} |
} |
357 |
|
|
386 |
} else if ( $value === NULL ) { |
} else if ( $value === NULL ) { |
387 |
$returnval = " <span class=\"black\">$name</span>"; |
$returnval = " <span class=\"black\">$name</span>"; |
388 |
} else { |
} else { |
389 |
if ( in_array($name, $this->_debug_link_attributes) ) { |
if ( @in_array($name, $this->_debug_link_attributes) ) { |
390 |
//lets create a clickable link for the value |
//lets create a clickable link for the value |
391 |
//of this attribute |
//of this attribute |
392 |
$value = "<a href=\"$value\">$value</a>"; |
$value = "<a href=\"$value\">$value</a>"; |
396 |
} |
} |
397 |
} |
} |
398 |
|
|
399 |
if ( HTML_RENDER_TYPE == XHTML_STRICT && |
if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT && |
400 |
in_array($name, $this->_xhtml_strict_attributes) ) { |
@in_array($name, $this->_xhtml_strict_attributes) ) { |
401 |
$returnval = NULL; |
$returnval = NULL; |
402 |
} |
} |
403 |
} else { |
} else { |
404 |
//hack to make non name-value pair work. |
//hack to make non name-value pair work. |
405 |
//ie <option name=foo value=bar CHECKED> |
//ie <option name=foo value=bar CHECKED> |
406 |
if ( HTML_RENDER_TYPE == XHTML_STRICT && !is_int($name) ) { |
if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT && !is_int($name) ) { |
407 |
//We do this because XHTML STRICT complains about |
//We do this because XHTML STRICT complains about |
408 |
//html characters such as &. So we mask them. |
//html characters such as &. So we mask them. |
409 |
$value = htmlentities($value); |
$value = htmlspecialchars($value); |
410 |
} |
} |
411 |
|
|
412 |
if ( HTML_RENDER_TYPE == XHTML_STRICT && |
if ( $GLOBALS["HTML_RENDER_TYPE"] == XHTML_STRICT && |
413 |
in_array($name, $this->_xhtml_strict_attributes) ) { |
@in_array($name, $this->_xhtml_strict_attributes) ) { |
414 |
$returnval = NULL; |
$returnval = NULL; |
415 |
} else { |
} else { |
416 |
$returnval = XMLTagClass::_build_attribute_string($name, $value); |
if ( ((int)$name - 0) === $name) { |
417 |
|
$returnval = " ".$value; |
418 |
|
} else if ( $value === NULL ) { |
419 |
|
$returnval = " ".$name; |
420 |
|
} else { |
421 |
|
$returnval= " ".$name."=\"".$value."\""; |
422 |
|
} |
423 |
} |
} |
424 |
} |
} |
425 |
return $returnval; |
return $returnval; |
429 |
// Misc functions |
// Misc functions |
430 |
//**************************************************************** |
//**************************************************************** |
431 |
|
|
432 |
|
|
433 |
|
/** |
434 |
|
* This function checks to see if |
435 |
|
* there is only 1 content data, and |
436 |
|
* its not an object, then it auto |
437 |
|
* sets some of the indentation flags |
438 |
|
* |
439 |
|
*/ |
440 |
|
function _prepare_flags() { |
441 |
|
if ($this->_flags & _CONTENTREQUIRED) { |
442 |
|
if ($this->count_content() == 1) { |
443 |
|
if (!is_object($this->_content[0])) { |
444 |
|
//ok looks like this object has only |
445 |
|
//1 data for content and its a string. |
446 |
|
if ( !strstr($this->_content[0], "\n") ) { |
447 |
|
$this->_flags &= ~_NEWLINEAFTEROPENTAG; |
448 |
|
} |
449 |
|
} |
450 |
|
} else if ($this->count_content() == 0) { |
451 |
|
$this->_flags &= ~_NEWLINEAFTEROPENTAG; |
452 |
|
} |
453 |
|
} |
454 |
|
} |
455 |
|
|
456 |
} |
} |
457 |
?> |
?> |