<?php
include("header.php");
if(!$_GET['id'])
{
//Get all articles for display in the front page
$query = "SELECT article_id FROM tblArticle ORDER BY article_id DESC";
$result = $db->doQuery($query);
while($row = $result->getArray())
{
$article = new Article($db, $row['article_id']);
$article->setBody(replaceSmilies($article->getBody(), $db));
$articles[] = array('id' => $article->getId(),
'body' => $article->getBody(),
'title' => $article->getTitle(),
'numComments' => $article->getNumComments(),
'date' => $article->getDate());
}
$template->assign('articles', $articles);
}
else
{
//Get the article from the database
$query = "SELECT article_id FROM tblArticle WHERE article_id = " . $_GET['id'];
$result = $db->doQuery($query);
$row = $result->getArray();
$article = new Article($db, $row['article_id']);
$article->setBody(replaceSmilies($article->getBody(), $db));
$query2 = "SELECT photo_filename FROM tblArticlePhoto WHERE photo_article_id = " . $article->getId();
$photo_file = "";
if($result2 = $db->doQuery($query2))
{
if($result2->getNumRows() > 0)
{
$row2 = $result2->getArray();
$photo_file = "./img/upload/" . $row2['photo_filename'];
$dimensions = getimagesize($photo_file);
if(($dimensions[0] > 400) OR ($dimensions[1] > 400))
{
$dimensions2 = imageResize($dimensions[0], $dimensions[1], 400);
}
else
{
$dimensions2 = array('width' => $dimensions[0],
'height' => $dimensions[1]);
}
}
}
$article_arr = array('title' => $article->getTitle(),
'body' => $article->getBody(),
'numComments' => $article->getNumComments(),
'photo_file' => $photo_file,
'dimensions' => $dimensions2,
'date' => $article->getDate());
$template->assign('article', $article_arr);
if($comments = $article->getComments())
{
foreach($comments as $comment)
{
$comment->setBody(replaceSmilies($comment->getBody(), $db));
$comment->setBody(replaceBadWords($comment->getBody(), $db));
$comments_arr[] = array('title' => $comment->getTitle(),
'name' => $comment->getName(),
'web' => $comment->getWeb(),
'body' => $comment->getBody(),
'date' => $comment->getDate());
}
}
$template->assign('comments', $comments_arr);
//Lets display the available smilies
$query = "SELECT * FROM tblSmilie";
$result = $db->doQuery($query);
while($row = $result->getarray())
{
$smilie = new Smilie($db, $row['smilie_id']);
$smilies[] = array('file' => $smilie->getFile(),
'code' => $smilie->getCode());
}
$template->assign('smilies', $smilies);
}
$template->display($config['theme'].'/article.tpl');
include("footer.php");
?>