<?php
include 'config.php';

//Clean up
function clean($str) {
  $str = trim($str);
  if (get_magic_quotes_gpc()) {
    $str = stripslashes($str);
  }
  $str = htmlspecialchars($str);
  $str = str_replace("&amp;", "&", $str);
  return str_replace(",", "&#44;", $str);
}

//Variables
$title = clean($_GET['title']);
$youtube = clean($_GET['youtube']);
$thread = clean($_GET['thread']);

if($youtube == '') {
$myFile = "res/threads.txt";
$fh = fopen($myFile, 'r');
$titleandyoutube = fgets($fh);
fclose($fh);
list ($threadname, $youtubevid, $threadid) = explode("<>", $titleandyoutube);
$title = $threadname;
$youtube = $youtubevid;
$thread = $threadid;
}

//Set up video
$youtube=str_replace("watch?","/",$youtube);
$youtube=str_replace("=","/",$youtube);
$youtubeembed="<object width='425' height='344'>
<param name='movie' value='".$youtube."&hl=en&color1=0x006699&color2=0x54abd6'></param>
<embed src='".$youtube."&hl=en&color1=0x006699&color2=0x54abd6' type='application/x-shockwave-flash' width='425' height='344'></embed>
</object>";

//Make Index
echo '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>'.$bbstitle.'</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body class="mainpage">
<center>';

if($banner == "1") {
echo '<img src="'.$imgbanner.'" />';
}

echo '</center><br />
<div class="outerbox"><div class="innerbox">
<table width="100%" cellpadding="5px"><tr>
<td valign="top">
<h2>'.$title.'</h2>
'.$youtubeembed.'<br />
<a href="'.$path.'/res/'.$thread.'.php">Enter Thread</a>
</td><td valign="top">
';

$list = @file("res/threads.txt");
foreach($list as $line) {
list ($threadname, $youtubevid, $threadid) = explode("<>", $line);
echo "<a href='$path/index.php?title=$threadname&youtube=$youtubevid&thread=$threadid'>$threadname</a><br />"; };

echo '</td>
</table>
</div></div></tr>
<br />
<div class="outerbox"><div class="innerbox"><table width="100%" cellpadding="5px">
<form action="post.php" method="post">
<p>Name: <input type="text" name="name" />
Title: <input type="text" name="title" /><br />
Youtube: <input type="text" name="youtube" />
<input type="submit" value="Post"></p>
<textarea name="comment" rows="6" cols="60"></textarea></p>
</form>
</div></div></table>
</body>
</html>';
?>