LoadHTMLFile($index_file);
$form_source = "
Comments
\n\n";
if (isset($_SESSION['passcode']) && isset($_POST['passcode']) && $_SESSION['passcode'] == $_POST['passcode']) {
write_comment();
$form_source .= "Thank you for your comment
";
} else if (check_answers()) {
$form_source .= comment_form();
} else if (TRUE) {
// This is a demo of Lemur CATTA Phase 2
// Normally, we would want some kind of secure content management system instead of hardcoded PHP
$form_source .= create_quiz();
} else {
$external_document = new DOMDocument;
$external_document->LoadHTMLFile($random_file);
$form_source .= create_form($index_document, $external_document);
}
//
$xpath = new DOMXPath($index_document);
$paragraph_elements = $xpath->query("//div[@class='paragraph Body']");
$last_paragraph = $paragraph_elements->item($paragraph_elements->length - 1);
$form_paragraph = $last_paragraph->cloneNode();
$last_paragraph->parentNode->appendChild($form_paragraph);
$form_paragraph->nodeValue = "%%INSERT FORM HERE%%\n%%INSERT COMMENTS HERE%%"; // OK this is just lazy, but I'm too sleepy to deal with the DOM right now
// iWeb uses relative paths, so I need to edit those and this little hack seems the easiest way
$index_source = $index_document->saveHTML();
$index_source = str_replace('href="', 'href="../motherfucker/Index/', $index_source);
$index_source = str_replace('src="', 'src="../motherfucker/Index/', $index_source);
$index_source = str_replace('Index/..', '', $index_source);
$index_source = str_replace('url(..', 'url(../motherfucker', $index_source);
$index_source = str_replace('href="../motherfucker/Index/http', 'href="http', $index_source);
$index_source = str_replace('>motherfucker', '>Lemur CATTA', $index_source);
$index_source = str_replace('%%INSERT FORM HERE%%', $form_source . "\n\n", $index_source);
$index_source = str_replace('%%INSERT COMMENTS HERE%%', read_comments(), $index_source);
echo $index_source;
?>