function HTMLDocument($input, $insert='', $inject=false, $footer='') {
//
// Apply parsing that only needs to be done once..
//
// Remove titles if option is enabled
if ( $this->htmlOptions['stripTitle'] ) {
$input = preg_replace('#
#is', '', $input, 1);
}
// Remove and record a href
$input = preg_replace_callback('#]{1,1000}))(?(1)\\1|)[^>]*>#i', 'html_stripBase', $input, 1);
// Proxify url= values in meta redirects
$input = preg_replace_callback('#content\s*=\s*(["\\\'])?[0-9]+\s*;\s*url=([\\\'"]|&\#39;)?((?(?<=")[^"]+|(?(?<=\\\')[^\\\']+|[^\\\'" >]+)))(?(2)\\2|)(?(1)\\1|)#i', 'html_metaRefresh', $input, 1);
// Process forms
$input = preg_replace_callback('##is', 'html_form', $input);
// Remove scripts blocks (avoids individual processing below)
if ( $this->htmlOptions['strJS'] ) {
$input = preg_replace('##is', '', $input);
}
//
// Split up the document into its different types and parse them
//
// Build up new document into this var
$new = '';
$offset = 0;
// Find instances of script or style blocks
while ( preg_match('#<(s(?:cript|tyle))[^>]*>#i', $input, $match, PREG_OFFSET_CAPTURE, $offset) ) {
// What type of block is this?
$block = strtolower($match[1][0]);
// Start position of content
$outerStart = $match[0][1];
$innerStart = $outerStart + strlen($match[0][0]);
// Determine type of end tag and find it's position
$endTag = "$block>";
$innerEnd = stripos($input, $endTag, $innerStart);
$outerEnd = $innerEnd + strlen($endTag);
// Parse everything up till here and add to the new document
$new .= $this->HTML(substr($input, $offset, $innerStart - $offset));
// Find parsing function
$parseFunction = $block == 'style' ? 'CSS' : 'JS' ;
// Add the parsed block
$new .= $this->$parseFunction(substr($input, $innerStart, $innerEnd - $innerStart));
// Move offset to new position
$offset = $innerEnd;
}
// And add the final chunk (between last script/style block and end of doc)
$new .= $this->HTML(substr($input, $offset));
// Replace input with the updated document
$input = $new;
// Encode the page
if ( $this->htmlOptions['encp'] ) {
$input = encodePage($input);
}
//
// Now add our own code bits
//
// Insert our mini form after the
if ( $insert !== false ) {
// Check for a frameset
if ( ( $useFrames = stripos($input, '