<?php

include './core.php';
include './lib/parse.class.php';

$news_limit = intval( $settings['news_on_start'] );
$news_result = $MySQL->query( "SELECT
	".$settings['wbb_db'].".bb".$n."_threads.*,
	".$settings['wbb_db'].".bb".$n."_icons.*
	FROM ".$settings['wbb_db'].".bb".$n."_threads
	LEFT JOIN ".$settings['wbb_db'].".bb".$n."_icons USING (iconid)
	WHERE boardid='".intval( $settings['news_board_id'] )."'
	ORDER BY important DESC, starttime DESC LIMIT 0,".$news_limit );

$news = array();
$parse = new parse( null, null, 1, "" );

while( $row = $MySQL->fetch_array( $news_result ) )
{
    $post = $MySQL->query_first("SELECT * FROM ".$settings['wbb_db'].".bb".$n."_posts WHERE threadid='".$row['threadid']."' && userid='".$row['starterid']."' && posttime='".$row['starttime']."'");
    $msg = $parse->doparse($post['message'],$post['allowsmilies'],$post['allowhtml'],$post['allowbbcode'],$post['allowimages']);

    if( strlen( $msg ) > intval( $settings['max_newslength'] ) )
    {
        $msg = substr( $msg, 0, intval( $settings['max_newslength'] ) );
        $msg .= "...\n<br />\n<br />\n[ <a href=\"wbb2/thread.php?threadid=".$row['threadid']."\">weiterlesen...</a> ]";
    }

    $row['message'] = $msg;

    $news[] = $row;
}

$Smarty->assign( 'news', $news );

$page['content'] = $Smarty->fetch( 'news.tpl' );

$Smarty->assign( 'page', $page );
$Smarty->display( 'main.tpl' );

?>