<?php
/**
 * Last update thread for MyBB 1.2.9
 * Copyright 2007 chaimeNetWork, All Rights Reserved
 *
 * Website: http://www.chaime.net
 * E-mail: webmaster@chaime.net
 *
 * July 19, 2007
 */
    define("IN_MYBB", 1);
    require "global.php";
    $unviewable = get_unviewable_forums();
    if($unviewable)
    {
        $unviewwhere = " AND fid NOT IN ($unviewable)";
    }
    $altbg  = "trow2";
    $threadlist = '';
    $query = mysql_query("
        SELECT t.*, u.username
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC 
        LIMIT 0, 10"
    );
    while($thread = $db->fetch_array($query))
    {
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
        // Don't link to guest's profiles (they have no profile).
        if($thread['lastposteruid'] == 0)
        {
            $lastposterlink = $thread['lastposter'];
        }
        else
        {
//            $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
            $lastposterlink = "
			<a href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid={$thread['lastposteruid']}\" target=\"_blank\">{$thread['lastposter']}</a>";
        }
        if(my_strlen($thread['subject']) > 40)
        {
            $thread['subject'] = my_substr($thread['subject'], 0, 40) . "...";
        }
        $thread['subject'] = htmlspecialchars_uni($thread['subject']);
        $threadlist .= "<tr>
        <td class=\"{$altbg}\">
        <strong><a href=\"{$mybb->settings['bburl']}/showthread.php?tid={$thread['tid']}&action=lastpost\" target=\"_blank\">{$thread['subject']}</a></strong>
        <span class=\"smalltext\"><br />
        {$lang->latest_threads_lastpost} {$lastposterlink} 
        {$lastpostdate} {$lastposttime} ({$thread['replies']}/{$thread['views']})
        </span>
        </td>
        </tr>";
        $altbg = alt_trow();
    }
    if($threadlist)
    { // show the table only if there are threads
        $latestthreads  = "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">
        <tr>
        <td class=\"thead\"><strong>{$lang->latest_threads}</strong></td>
        </tr>
        {$threadlist}
        </table>
        <br />";
    }

echo "<html>
<head>
<title>กระทู้ล่าสุด</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"{$theme['css_url']}\" />
</head>
<body>
{$latestthreads}
</body>
</html>";

?>
