Exemple #1
0
function buildThread($id, $return = false, $mod = false)
{
    global $board, $config, $build_pages;
    $id = round($id);
    if (event('build-thread', $id)) {
        return;
    }
    if ($config['cache']['enabled'] && !$mod) {
        // Clear cache
        cache::delete("thread_index_{$board['uri']}_{$id}");
        cache::delete("thread_{$board['uri']}_{$id}");
    }
    if ($config['try_smarter'] && !$mod) {
        $build_pages[] = thread_find_page($id);
    }
    if (!$config['smart_build'] || $return || $mod) {
        $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri']));
        $query->bindValue(':id', $id, PDO::PARAM_INT);
        $query->execute() or error(db_error($query));
        while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
            if (!isset($thread)) {
                $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
            } else {
                $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
            }
        }
        // Check if any posts were found
        if (!isset($thread)) {
            error($config['error']['nonexistant']);
        }
        $hasnoko50 = $thread->postCount() >= $config['noko50_min'];
        $antibot = $mod || $return ? false : create_antibot($board['uri'], $id);
        $body = Element('thread.html', array('board' => $board, 'thread' => $thread, 'body' => $thread->build(), 'config' => $config, 'id' => $id, 'mod' => $mod, 'hasnoko50' => $hasnoko50, 'isnoko50' => false, 'antibot' => $antibot, 'boardlist' => createBoardlist($mod), 'return' => $mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']));
        // json api
        if ($config['api']['enabled']) {
            $api = new Api();
            $json = json_encode($api->translateThread($thread));
            $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json';
            file_write($jsonFilename, $json);
        }
    } else {
        $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json';
        file_unlink($jsonFilename);
    }
    if ($config['smart_build'] && !$return && !$mod) {
        $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id);
        file_unlink($noko50fn);
        file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id));
    } else {
        if ($return) {
            return $body;
        } else {
            $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id);
            if ($hasnoko50 || file_exists($noko50fn)) {
                buildThread50($id, $return, $mod, $thread, $antibot);
            }
            file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body);
        }
    }
}
Exemple #2
0
function mod_view_thread50($boardName, $thread)
{
    global $config, $mod;
    if (!openBoard($boardName)) {
        error($config['error']['noboard']);
    }
    $page = buildThread50($thread, true, $mod);
    echo $page;
}