<?php 
require "blog_class.php";

$full_path = $_SERVER['REQUEST_URI'];
$script = $_SERVER['SCRIPT_NAME'];
$fixed_path = ereg_replace("^$script","",$full_path);// remove script name from path
$path_arr = explode("/", $fixed_path);
$blog_title = $path_arr[1]; 
$action = $path_arr[2];

if (!isset($blog_title))
{ // ---------------------------- LAST FOUR BLOG ENTRIES ----------------------------
$page = " class=\"blog\"";
$title = "WebFu Web Development Weblog";
$tagline = "WebFu Web Development Weblog";
include "begin.php";
$entry = last_four_blog_entries();
?>

<div id="main" class="weblog">

<div id="blog_sidebar">
<!-- Archive -->
<!-- Random Older Entries -->
<!-- Browse by Category -->
</div> <!-- BLOG SIDEBAR -->

<div id="blogpost_1">
<?php 
$weblog[1] = new blog($entry[1]);
$weblog[1]->printBlog(FALSE); 
?>

</div> <!-- BLOGPOST 1 -->

<div id="blogposts">
<div id="blogpost_2">
<?php 
	$weblog[2] = new blog($entry[2]);
	if (!$weblog[2]->failed)
		{$weblog[2]->printBlog(FALSE);}
	?>
	
	</div> <!-- BLOGPOST 2 -->
	<div id="blogpost_3">
	<?php 
	$weblog[3] = new blog($entry[3]);
	if (!$weblog[3]->failed)
	$weblog[3]->printBlog(FALSE); 
	?>
	
	</div> <!-- BLOGPOST 3 -->
	<div id="blogpost_4">
	<?php 
	$weblog[4] = new blog($entry[4]);
	if (!$weblog[4]->failed)
	$weblog[4]->printBlog(FALSE); 
	?>
	</div> <!-- BLOGPOST 4 -->
</div> <!-- BLOGPOSTS -->

</div> <!-- MAIN -->
<?php
}

else
{ // ---------------------------- SPECIFIC BLOG ENTRY ----------------------------
if ($blog_title == "comment")
	{
	include "connect.php";
	$blog_id = $_POST['blog_id'];
	$name = $_POST['name'];
	$url = $_POST['url'];
	$comment = strip_crap($_POST['comment']);
	$date = date("Y-m-d");
	//store info
	$sql = "insert into blog_comments (blog_id, poster_name, poster_url, comment_date, comment_text) values ('$blog_id', '$name', '$url', '$date', '$comment')";
	mysql_query($sql) or die(mysql_error());	
	
	//Now set $blog_title to the correct URL so the rest of the routine will run okay
	$blog_title = $_POST['blog_title'];
	}

//INITIALIZE BLOG ENTRY
$blog_id = find_blog_id($blog_title);
$weblog = new blog($blog_id);
	
$title = "$weblog->title - WebFu Web Development Weblog";
$tagline = "$weblog->title";
include "begin.php";
	
echo "<div id=\"main\" class=\"weblog_entry\">\n";

//MAIN BLOG ENTRY
if ($weblog->failed) {echo "Weblog Entry Not Found";}
else {
	$weblog->printBlog(TRUE); 
	}	
echo "</div>\n";
} //end specific blog entry
?>

<?php require "end.php" ?>