Her er klassen:
<?php
class News
{
var $max_news;
var $max_tegn;
var $pic_sti;
var $news_order;
function News()
{
$this->max_news = $GLOBALS['news_limit'];
$this->max_tegn = $GLOBALS['news_max_tegn'];
$this->pic_sti = $GLOBALS['news_sti'];
$this->news_order = $GLOBALS['news_order'];
}
function Draw($newsid)
{
if ($newsid > 0) {
$query = "SELECT cs_news.*,cs_members.nick FROM cs_news LEFT JOIN cs_members ON cs_news.author = cs_members.id WHERE cs_news.id = ".$newsid;
} else {
$query = "SELECT cs_news.*,cs_members.nick FROM cs_news LEFT JOIN cs_members ON cs_news.author = cs_members.id ORDER BY cs_news.date ".$this->news_order." LIMIT ".$this->max_news;
}
if (ReturnRowsDB($query) <= 0) {
echo "Ingen news";
} else {
$query = QueryDB($query);
while ($row = ResultDB($query)) {
$news_id = $row['id'];
$besked = stripslashes($row['text']);
$besked = nl2br($besked);
$header = stripslashes($row['header']);
$author = stripslashes($row['author']);
if ($row['source']) {
$source = stripslashes($row['source']);
}
if ($row['source_url']) {
$source_url = stripslashes($row['source_url']);
}
if ($row['url']) {
$url = stripslashes($row['url']);
} else {
$url = "
http://".$_SERVER['HTTP_HOST']; }
if (!empty($row['picture_id'])) {
$picture = $row['picture_id'];
} else {
$picture = "nopic.gif";
}
echo '<table class="news_main" cellspacing="0" cellpadding="2" align="center">';
echo '<tr><td class="news_top"></td></tr>';
echo '<tr><td>';
echo VisDato($row['date']).' | <strong><a href="'.$url.'" target="_blank">'.$header.'</a></strong></td></tr>';
echo '<tr><td valign="top">';
echo '<table style="float: right;">';
echo '<tr><td><a href="'.$this->pic_sti.'/'.$picture.'" target="_blank"><img src="'.$this->pic_sti.'/'.$picture.'" width="100" border="0" hspace="5" style="border: 1px solid #333333;"></a><br>';
$tal = ReturnRowsDB("SELECT * FROM cs_newscomments where news_id = '".$news_id."'");
if (!$newsid > 0) {
echo '<div align="center">';
if (strlen($besked) > $this->max_tegn) {
echo "<a href='index.php?side=news&details=1&id=".$news_id."'>Læs mere...</a><br>";
}
echo '<a href="index.php?side=news&details=1&id='.$news_id.'#comments">Diskutér ('.$tal.')</a></div>';
}
echo '<br></td></tr></table>';
echo '<strong>Forfatter:</strong> <a href="index.php?side=profil&id='.$author.'">'.$row['nick'].'</a><br>';
if ($source_url) {
echo '<strong>Kilde:</strong> <a href="'.$source_url.'" target="_blank">'.$source.'</a><br>';
}
echo '<br>';
if (!$newsid > 0 && strlen($besked) > $this->max_tegn) {
echo substr($besked,0,$this->max_tegn)."...";
} else {
echo $besked;
}
if ($newsid > 0) {
echo '<br><br><strong>Link:</strong> <a href="'.$url.'" target="_blank">'.$url.'</a>';
}
echo '</td></tr></table><br>';
if ($newsid > 0) {
include("comments.php");
}
}
}
}
}
?>