_clean_utf8 = $config->get('Core', 'CleanUTF8DuringGeneration'); $this->_xhtml = $config->get('Core', 'XHTML'); if (!$tokens) return ''; foreach ($tokens as $token) { $html .= $this->generateFromToken($token); } return $html; } /** * Generates HTML from a single token. * @param $token HTMLPurifier_Token object. * @return Generated HTML */ function generateFromToken($token) { if (!isset($token->type)) return ''; if ($token->type == 'start') { $attr = $this->generateAttributes($token->attributes); return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>'; } elseif ($token->type == 'end') { return 'name . '>'; } elseif ($token->type == 'empty') { $attr = $this->generateAttributes($token->attributes); return '<' . $token->name . ($attr ? ' ' : '') . $attr . ( $this->_xhtml ? ' /': '' ) . '>'; } elseif ($token->type == 'text') { return $this->escape($token->data); } else { return ''; } } /** * Generates attribute declarations from attribute array. * @param $assoc_array_of_attributes Attribute array * @return Generate HTML fragment for insertion. */ function generateAttributes($assoc_array_of_attributes) { $html = ''; foreach ($assoc_array_of_attributes as $key => $value) { if (!$this->_xhtml) { // remove namespaced attributes if (strpos($key, ':') !== false) continue; // also needed: check for attribute minimization } $html .= $key.'="'.$this->escape($value).'" '; } return rtrim($html); } /** * Escapes raw text data. * @param $string String data to escape for HTML. * @return String escaped data. */ function escape($string) { if ($this->_clean_utf8) $string = HTMLPurifier_Lexer::cleanUTF8($string); return htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); } } ?>