<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>My LiveJournal Log, Mirrored!</title>
  </head>
  <body>

<?
function GetChildren($vals, &$i)
{
	$children = array();
	if ($vals[$i]['value'])
		array_push($children, $vals[$i]['value']);

	while (++$i < count($vals)) { // so pra nao botar while true ;-)
		switch ($vals[$i]['type']) {
		case 'cdata':
			array_push($children, $vals[$i]['value']);
			break;

		case 'complete':
			array_push($children, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'value' => $vals[$i]['value']));
			break;

		case 'open':
			array_push($children, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => GetChildren($vals, $i)));
			break;

		case 'close':
			return $children;
		}
	}
}

function GetXMLTree($file)
{
	$data = implode('', file($file));
	$p = xml_parser_create();
	xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 0);
	xml_parse_into_struct($p, $data, &$vals, &$index);
	xml_parser_free($p);

	$tree = array();
	$i = 0;
	array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => GetChildren($vals, $i)));
	return $tree;
}

$lj = GetXMLTree("journal");
$num = (int)(sizeof($lj[0]['children']) / 2);

$start = $num - $offset;

for ($i = $start; $i > 0 && $i + 10 > $start; $i--) {
	$spot = ($i - 1) * 2 + 1;
	$logtime = $lj[0]['children'][$spot]['children'][5]['value'];
	$subject = $lj[0]['children'][$spot]['children'][7]['value'];
	$event = $lj[0]['children'][$spot]['children'][9]['value'];
	$music = $lj[0]['children'][$spot]['children'][15]['value'];
	$mood = $lj[0]['children'][$spot]['children'][17]['value'];

	$entry = eregi_replace("\n", "<br />", $event);
	print "<font face=\"Verdana,Arial,Helvetica\" size=\"2\"><b>$logtime - <font color=\"red\">$subject</font></b><br />";
	if ($music) {
		print "<b>Current Music:</b> $music<br />";
	}
	if ($mood) {
		print "<b>Current Mood:</b> $mood<br />";
	}
	print "<br />$entry\n<br /></font><hr />";
}

if ($offset != 0) {
	$prev = max(0, $offset - 10);
	if ($prev > 0) {
		print "<a href=\"?offset=0\">Newest</a>";
		print " | ";
	}
	print "<a href=\"?offset=$prev\">Newer</a>";
}

if ($offset + 10 < $num) {
	if ($offset != 0) {
		print " | ";
	}
	$next = min($num - 1, $offset + 10);
	$last = $num - 10;
	print "<a href=\"?offset=$next\">Older</a>";
	if ($last > $next) {
		print " | ";
		print "<a href=\"?offset=$last\">Oldest</a>";
	}
}

?>
<!--
    <p>
      <a href="http://validator.w3.org/check?uri=<? echo "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ?>"><img
      src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!"
      height="31" width="88" border="0" /></a>
    </p>
-->
  </body>
</html>
