コード例 #1
0
ファイル: functions.php プロジェクト: carriercomm/Tinyboard
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}");
    }
    $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']);
    }
    $body = Element('thread.html', array('board' => $board, 'thread' => $thread, 'body' => $thread->build(), 'config' => $config, 'id' => $id, 'mod' => $mod, 'antibot' => $mod || $return ? false : create_antibot($board['uri'], $id), 'boardlist' => createBoardlist($mod), 'return' => $mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']));
    if ($config['try_smarter'] && !$mod) {
        $build_pages[] = thread_find_page($id);
    }
    if ($return) {
        return $body;
    }
    file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body);
    // 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);
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: Cipherwraith/infinity
function buildThread50($id, $return = false, $mod = false, $thread = null, $antibot = false)
{
    global $board, $config, $build_pages;
    $id = round($id);
    if ($antibot) {
        $antibot->reset();
    }
    if (!$thread) {
        $query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit", $board['uri']));
        $query->bindValue(':id', $id, PDO::PARAM_INT);
        $query->bindValue(':limit', $config['noko50_count'] + 1, PDO::PARAM_INT);
        $query->execute() or error(db_error($query));
        $num_images = 0;
        while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
            if (!isset($thread)) {
                $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
            } else {
                if ($post['files']) {
                    $num_images += $post['num_files'];
                }
                $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
            }
        }
        // Check if any posts were found
        if (!isset($thread)) {
            error($config['error']['nonexistant']);
        }
        if ($query->rowCount() == $config['noko50_count'] + 1) {
            $count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL\n\t\t\t\t\t\t  SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
            $count->bindValue(':thread', $id, PDO::PARAM_INT);
            $count->execute() or error(db_error($count));
            $c = $count->fetch();
            $thread->omitted = $c['num'] - $config['noko50_count'];
            $c = $count->fetch();
            $thread->omitted_images = $c['num'] - $num_images;
        }
        $thread->posts = array_reverse($thread->posts);
    } else {
        $allPosts = $thread->posts;
        $thread->posts = array_slice($allPosts, -$config['noko50_count']);
        $thread->omitted += count($allPosts) - count($thread->posts);
        foreach ($allPosts as $index => $post) {
            if ($index == count($allPosts) - count($thread->posts)) {
                break;
            }
            if ($post->files) {
                $thread->omitted_images += $post->num_files;
            }
        }
    }
    $hasnoko50 = $thread->postCount() >= $config['noko50_min'];
    $body = Element('thread.html', array('board' => $board, 'thread' => $thread, 'body' => $thread->build(false, true), 'config' => $config, 'id' => $id, 'mod' => $mod, 'hasnoko50' => $hasnoko50, 'isnoko50' => true, 'antibot' => $mod ? false : ($antibot ? $antibot : create_antibot($board['uri'], $id)), 'boardlist' => createBoardlist($mod), 'return' => $mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']));
    if ($return) {
        return $body;
    } else {
        file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body);
    }
}
コード例 #3
0
ファイル: functions.php プロジェクト: npfriday/Tinyboard
function buildThread($id, $return = false, $mod = false)
{
    global $board, $config;
    $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}");
    }
    $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()) {
        if (!isset($thread)) {
            $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod);
        } else {
            $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], $mod ? '?/' : $config['root'], $mod));
        }
    }
    // Check if any posts were found
    if (!isset($thread)) {
        error($config['error']['nonexistant']);
    }
    $body = Element('thread.html', array('board' => $board, 'body' => $thread->build(), 'config' => $config, 'id' => $id, 'mod' => $mod, 'antibot' => $mod ? false : create_antibot($board['uri'], $id), 'boardlist' => createBoardlist($mod), 'return' => $mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['uri'] . '/' . $config['file_index']));
    if ($return) {
        return $body;
    }
    file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body);
}