<?php
$title = "FishSOOP";
ini_set('include_path', './' . PATH_SEPARATOR . '../' . PATH_SEPARATOR . ini_get('include_path'));
include_once("include/header.php");

$dom = new DOMDocument;
$dom->loadHTMLFile('../fishsoop/index.html');
$dom->formatOutput = true;

// Create the output document
$ndom = new DOMDocument;
$ndom->formatOutput = true;

$xpath = new DOMXPath($dom);
$nodes = $xpath->query('/html/body/*');

// Copy it to the output document
foreach ($nodes as $rec) {
	$node = $ndom->importNode($rec,true);
	$ndom->appendChild($node);
}

// Delete the first and last node
$ndom->removeChild($ndom->firstChild);  // imos header
$ndom->removeChild($ndom->lastChild);   // copyright footer

// Fix the anchors
foreach($ndom->getElementsByTagName('a') as $a ) {
	if ($a->hasAttribute('href')) {
		$href = $a->getAttribute('href');
		$a->setAttribute('href','../fishsoop/'.$href);
	}
}

// Fix the images
foreach($ndom->getElementsByTagName('img') as $img ) {
	if ($img->hasAttribute('src')) {
		$src = $img->getAttribute('src');
		$img->setAttribute('src','../fishsoop/'.$src);
	}
}

// dump/save it
echo $ndom->saveHTML();

include("include/footer.php");

?>
