2006-04-16 03:27:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTML_Generator
|
|
|
|
{
|
|
|
|
|
2006-04-16 03:42:25 +00:00
|
|
|
function generateFromTokens($tokens) {
|
|
|
|
$html = '';
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
$html .= $this->generateFromToken($token);
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2006-04-16 03:27:40 +00:00
|
|
|
function generateFromToken($token) {
|
|
|
|
if (is_a($token, 'MF_StartTag')) {
|
|
|
|
$attr = $this->generateAttributes($token->attributes);
|
2006-04-16 03:33:37 +00:00
|
|
|
return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>';
|
2006-04-16 03:27:40 +00:00
|
|
|
|
|
|
|
} elseif (is_a($token, 'MF_EndTag')) {
|
|
|
|
return '</' . $token->name . '>';
|
|
|
|
|
|
|
|
} elseif (is_a($token, 'MF_EmptyTag')) {
|
|
|
|
$attr = $this->generateAttributes($token->attributes);
|
2006-04-17 00:49:15 +00:00
|
|
|
return '<' . $token->name . ($attr ? ' ' : '') . $attr . ' />';
|
2006-04-16 03:27:40 +00:00
|
|
|
|
|
|
|
} elseif (is_a($token, 'MF_Text')) {
|
|
|
|
return htmlentities($token->data, ENT_COMPAT, 'UTF-8');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateAttributes($assoc_array_of_attributes) {
|
|
|
|
$html = '';
|
|
|
|
foreach ($assoc_array_of_attributes as $key => $value) {
|
|
|
|
$html .= $key.'="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'" ';
|
|
|
|
}
|
|
|
|
return rtrim($html);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|