<?php
switch(strtolower($_GET['subsec']))
{
case "view":
if(!isset($_GET['id']))
{
// $mysql = new mysql(DB_MAIN);
$sel = $mysql->select(PRE."members", "active='yes'", "id", "ASC");
echo '<ul>';
while($a = mysql_fetch_assoc($sel))
{
if($a['groups'] == "1")
{
$username = '<span style="color:#F60; font-weight: bolder;">'.$a['username'].'</span>';
} else {
$username = $a['username'];
}
echo '<li><a href="Blogs/View/'.str_replace(" ", "_",$a['username']).'/">'.$username.'\'s Blog</a></li>';
}
echo '</ul>';
} else {
// $mysql = new mysql(DB_MAIN);
$sel = $mysql->select(PRE."blogs", "userid='".$_GET['id']."'", "id", "DESC");
$rows = mysql_num_rows($sel);
echo '<a href="Blogs/View/">View all blogs</a><br />';
if($rows == "0")
{
echo "This user has no blog posts";
} else {
for($i = 0; $i < $rows; $i++)
{
if($i % 2)
{
$style = "row1";
} else {
$style = "row2";
}
$a = mysql_fetch_assoc($sel);
$avvy = getuserinfo("avatar", $a['userid']);
$crows = mysql_num_rows($mysql->select(PRE."blog_comments", "id='".$a['postid']."' AND user='".str_replace("_", " ",$a['userid'])."'", "postid", "DESC", "1"));
echo '<div class="content-title">'.$a['subject'].'</div>
<div class="'.$style.'" style="float:left; width: 100%; vertical-align:top;"><img style="float:right;" src="avatar.php?f='.$avvy.'" alt="'.$a['userid'].'\'s Avatar" />'.stripslashes(parse(strip_tags($a['message']))).'</div>';
echo '<div style="float:left; width: 50%; background: #DDD; color: #333;"><a href="Blogs/Comment/'.str_replace(" ", "_",$a['userid']).'&pid='.$a['postid'].'">Comments ('.$crows.')</a> ';
if($_COOKIE['user'] == $_GET['id'])
{
echo '<a href="Blogs/Edit/'.$a['postid'].'/">Edit this post</a>';
}
echo '</div><div style="float: right;text-align:right; width: 50%;background: #DDD; color: #333;">Posted '.date(DATE, $a['date']).'; Category: '.$a['cat'].'</div>';
}
}
}
break;
case "post":
echo '<fieldset>
<form action="misc/blog-post.php" method="post">
<div class="formtext">Category:</div>
<div class="formdiv"><select name="cat">';
$cats = getuserinfo("blogcats");
$expl = explode(",", $cats);
foreach($expl as $cat)
{
echo '<option value="'.$cat.'">'.$cat.'</option>'."\n";
}
echo '</select></div>
<div class="formtext">Subject:</div><div class="formdiv"><input type="text" name="subject" /></div>
<div class="formtext">Message</div>
<div class="formdiv"><textarea name="message" class="wysiwyg" rows="20" cols="60"></textarea></div>
<div class="buttondiv"><input type="submit" name="submit" value="BlogIt!" /></div>
</form>
</fieldset>';
break;
case "edit":
if(!isset($_GET['id']))
{
echo '<div class="error">You must specify what post to edit</div>';
} else {
$mem = $mysql->select(PRE."members", "id='".$_COOKIE['mid']."'", "id", "DESC", "1");
$mem2 = mysql_fetch_assoc($mem);
$blog = $mysql->select(PRE."blogs", "postid='".$_GET['id']."' AND userid='".str_replace("_", " ",$mem2['username'])."'", "id", "DESC", "1");
while($b = mysql_fetch_assoc($blog))
{
echo '<fieldset>
<form action="misc/blog-edit.php" method="post">
<div class="formtext">Category:</div>
<div class="formdiv"><select name="cat">';
$cats = getuserinfo("blogcats");
$expl = explode(",", $cats);
foreach($expl as $cat)
{
if($cat == $b['cat'])
{
echo '<option value="'.$cat.'" selected="selected">'.$cat.'</option>'."\n";
} else {
echo '<option value="'.$cat.'">'.$cat.'</option>'."\n";
}
}
echo '</select></div>
<div class="formtext">Subject:</div><div class="formdiv"><input type="text" name="subject" value="'.$b["subject"].'" /></div>
<div class="formtext">Message</div>
<div class="formdiv"><textarea name="message" class="wysiwyg" rows="20" cols="60">'.stripslashes($b["message"]).'</textarea></div>
<div class="buttondiv"><input type="hidden" name="id" value="'.$_GET['id'].'" /><input type="submit" name="submit" value="BlogIt!" /></div>
</form>
</fieldset>';
}
}
break;
case "comment":
if(!isset($_GET['id']))
{
echo "You must provide a user!";
} else {
echo '<div style="width: 100%; float: left; text-align: center;"><a href="Blogs/View/'.$_GET['id'].'/">Back to '.$_GET['id'].'\'s blog</a> ¦ <a href="Blogs/View/">View all blogs</a></div><br />';
if(!isset($_GET['pid']))
{
echo "You must provide a post to comment on!";
} else {
$csel = $mysql->select(PRE."blog_comments", "user='".str_replace("_", " ",$_GET['id'])."' AND id='".$_GET['pid']."'", "id", "DESC");
$sel = $mysql->select(PRE."blogs", "userid='".str_replace("_", " ",$_GET['id'])."' AND postid='".$_GET['pid']."'", "id", "DESC", "1");
$a = mysql_fetch_assoc($sel);
echo '<div class="content-title">'.$a['subject'].'</div>
<div class="'.$style.'" style="float:left; width: 100%;">'.parse(strip_tags($a['message'])).'</div>';
$rows = mysql_num_rows($csel);
if(!$rows)
{
echo("No comments yet!");
} else {
if($rows == "1")
{
$a = array("is", "comment");
} else {
$a = array("are", "comments");
}
echo 'There '.$a["0"].' '.$rows.' '.$a["1"];
for($i = 0; $i < $rows; $i++)
{
if($i % 2)
{
$style = "row1";
} else {
$style = "row2";
}
$tcom = mysql_fetch_assoc($csel);
if(mysql_num_rows($mysql->select(PRE."members", "username='".$tcom['username']."'", "id", "DESC", "1")) == "0")
{
$name = '<a href="javascript:email(\''.$email[0].'\',\''.$email[1].'\');">'.$tcom["username"].'</a>';
} else {
$name = '<a href="Members/Profile/'.str_replace(" ", "_",$tcom["username"]).'/">'.$tcom["username"].'</a>';
}
$email = explode("@", $tcom['email']);
$message = nl2br(stripslashes($tcom['message']));
$date = date(DATE , $tcom['date']);
$id = $tcom['id'];
echo "<div class=\"".$style."\" style=\"margin-top: 5px;float: left; width: 100%;\">
<div style=\"width: 15%; float: left;\">$name<br />
$date</div>
<div style=\"width: 80%; float: right;\">$message</div>
</div>";
}
}
echo "<hr style=\"width: 95%; float: left;\" /><div style=\"margin-bottom: 60px; height: 100px; float: left;\"><form method=\"post\" action=\"misc/blog-comment-in.php\"><div style=\"float: left;\">Post a Comment.</div>";
if(!isset($_COOKIE['mid']))
{
echo "<div class=\"formtext\">Username</div>
<div class=\"formdiv\"><input name=\"username\" type=\"text\" /></div>
<div class=\"formtext\">Email</div>
<div class=\"formdiv\"><input name=\"email\" type=\"hidden\" /></div>";
} else {
echo '<div><input type="hidden" name="username" value="'.$_COOKIE["user"].'" />
<input type="hidden" name="email" value="'.getuserinfo("email").'" /></div>';
}
echo "<div class=\"formtext\">Message</div>
<div class=\"formdiv\">
<textarea name=\"message\" class=\"wysiwyg\" cols=\"60\" rows=\"14\"></textarea>
</div>
<div style=\"float: left; width:100%; text-align: center;\">
<input type=\"submit\" name=\"Submit\" value=\"Submit\" />
<input type=\"reset\" name=\"Reset\" value=\"Reset\" />
<input type=\"hidden\" name=\"user\" value=\"".$_GET['id']."\" />
<input type=\"hidden\" name=\"pid\" value=\"".$_GET['pid']."\" />
</div>
</form></div>";
if(isset($_GET['cerror']))
{
echo '<div class="error">Error: You skipped some info. Please fill it all out</div>';
}
}
}
break;
}
?>