Ejemplo n.º 1
0
// License: GPL 2.0
// --------------------------------------------------------------
define('BB_LOCATION', 'topics');
include '../../mainfile.php';
$rmCodes->add('quote', 'bXFunctions::quote_code');
$myts =& MyTextSanitizer::getInstance();
$id = rmc_server_var($_GET, 'id', '');
$pid = rmc_server_var($_GET, 'pid', 0);
$op = rmc_server_var($_GET, 'op', '');
if ($id == '' && $pid <= 0) {
    redirect_header('./', 2, __('Specified topic does not exists!', 'bxpress'));
    die;
}
$db = XoopsDatabaseFactory::getDatabaseConnection();
if ($pid) {
    $id = bXFunctions::pageFromPID($pid);
} elseif ($op == 'new' && $xoopsUser) {
    $result = $db->query('SELECT MIN(id_post) FROM ' . $db->prefix('mod_bxpress_posts') . " WHERE id_topic='{$id}' AND post_time>" . $xoopsUser->getVar('last_login'));
    list($newid) = $db->fetchRow($result);
    if ($newid) {
        header('Location: topic.php?pid=' . $newid . '#p' . $newid);
    } else {
        // If there is no new post, we go to the last post
        header('Location: topic.php?id=' . $id . '&op=last');
    }
    die;
} elseif ($op == 'last') {
    $result = $db->query('SELECT MAX(id_post) FROM ' . $db->prefix('mod_bxpress_posts') . " WHERE id_topic='{$id}'");
    list($lastid) = $db->fetchRow($result);
    if ($lastid) {
        header('Location: topic.php?pid=' . $lastid . '#p' . $lastid);