Ejemplo n.º 1
0
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);
    }
}
Ejemplo n.º 2
0
function mod_recent_posts($lim)
{
    global $config, $mod, $pdo;
    if (!hasPermission($config['mod']['recent'])) {
        error($config['error']['noaccess']);
    }
    $limit = is_numeric($lim) ? $lim : 25;
    $last_time = isset($_GET['last']) && is_numeric($_GET['last']) ? $_GET['last'] : 0;
    $mod_boards = array();
    $boards = listBoards();
    //if not all boards
    if ($mod['boards'][0] != '*') {
        foreach ($boards as $board) {
            if (in_array($board['uri'], $mod['boards'])) {
                $mod_boards[] = $board;
            }
        }
    } else {
        $mod_boards = $boards;
    }
    // Manually build an SQL query
    $query = 'SELECT * FROM (';
    foreach ($mod_boards as $board) {
        $query .= sprintf('SELECT *, %s AS `board` FROM ``posts_%s`` UNION ALL ', $pdo->quote($board['uri']), $board['uri']);
    }
    // Remove the last "UNION ALL" seperator and complete the query
    $query = preg_replace('/UNION ALL $/', ') AS `all_posts` WHERE (`time` < :last_time OR NOT :last_time) ORDER BY `time` DESC LIMIT ' . $limit, $query);
    $query = prepare($query);
    $query->bindValue(':last_time', $last_time);
    $query->execute() or error(db_error($query));
    $posts = $query->fetchAll(PDO::FETCH_ASSOC);
    foreach ($posts as &$post) {
        openBoard($post['board']);
        if (!$post['thread']) {
            // Still need to fix this:
            $po = new Thread($post, '?/', $mod, false);
            $post['built'] = $po->build(true);
        } else {
            $po = new Post($post, '?/', $mod);
            $post['built'] = $po->build(true);
        }
        $last_time = $post['time'];
    }
    echo mod_page(_('Recent posts'), 'mod/recent_posts.html', array('posts' => $posts, 'limit' => $limit, 'last_time' => $last_time));
}
Ejemplo n.º 3
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}");
    }
    $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);
    }
}
Ejemplo n.º 4
0
 public function build($mod = false)
 {
     global $config, $board;
     $boards = listBoards();
     $body = '';
     $overflow = array();
     $board = array('url' => $this->settings['uri'], 'name' => $this->settings['title'], 'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit']));
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], explode(' ', $this->settings['exclude']))) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
     $query = query($query) or error(db_error());
     $count = 0;
     $threads = array();
     while ($post = $query->fetch()) {
         if (!isset($threads[$post['board']])) {
             $threads[$post['board']] = 1;
         } else {
             $threads[$post['board']] += 1;
         }
         if ($count < $this->settings['thread_limit']) {
             $config['uri_thumb'] = '/' . $post['board'] . '/thumb/';
             $config['uri_img'] = '/' . $post['board'] . '/src/';
             $board['dir'] = $post['board'] . '/';
             $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
             $posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
             $posts->bindValue(':id', $post['id']);
             $posts->bindValue(':limit', $post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'], PDO::PARAM_INT);
             $posts->execute() or error(db_error($posts));
             $num_images = 0;
             while ($po = $posts->fetch()) {
                 $config['uri_thumb'] = '/' . $post['board'] . '/thumb/';
                 $config['uri_img'] = '/' . $post['board'] . '/src/';
                 if ($po['files']) {
                     $num_images++;
                 }
                 $thread->add(new Post($po, $mod ? '?/' : $config['root'], $mod));
             }
             if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
                 $ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
                 $ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
                 $ct->execute() or error(db_error($count));
                 $c = $ct->fetch();
                 $thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
                 $c = $ct->fetch();
                 $thread->omitted_images = $c['num'] - $num_images;
             }
             $thread->posts = array_reverse($thread->posts);
             $body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
             $body .= $thread->build(true);
         } else {
             $page = 'index';
             if (floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
                 $page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
             }
             $overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
         }
         $count += 1;
     }
     $body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
     $body .= '<script type="text/javascript" src="/' . $this->settings['uri'] . '/ukko.js"></script>';
     $config['default_stylesheet'] = array('Yotsuba B', $config['stylesheets']['Yotsuba B']);
     return Element('index.html', array('config' => $config, 'board' => $board, 'no_post_form' => true, 'body' => $body, 'mod' => $mod, 'boardlist' => createBoardlist($mod)));
 }
Ejemplo n.º 5
0
 /**
  * Build the HTML of a single thread in the catalog
  */
 private function buildOne($post, $mod = false)
 {
     global $config;
     openBoard($post['board']);
     $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
     $replies = $this->fetchReplies($post['board'], $post['id']);
     // Number of replies to a thread that are displayed beneath it
     $preview_count = $post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'];
     // Chomp the last few replies
     $disp_replies = array_splice($replies, 0, $preview_count);
     $disp_img_count = 0;
     foreach ($disp_replies as $reply) {
         if ($reply['files'] !== '') {
             ++$disp_img_count;
         }
         // Append the reply to the thread as it's being built
         $thread->add(new Post($reply, $mod ? '?/' : $config['root'], $mod));
     }
     // Count the number of omitted image replies
     $omitted_img_count = count(array_filter($replies, function ($p) {
         return $p['files'] !== '';
     }));
     // Set the corresponding omitted numbers on the thread
     if (!empty($replies)) {
         $thread->omitted = count($replies);
         $thread->omitted_images = $omitted_img_count;
     }
     // Board name and link
     $html = '<h2><a href="' . $config['root'] . $post['board'] . '/">/' . $post['board'] . '/</a></h2>';
     // The thread itself
     $html .= $thread->build(true);
     return $html;
 }
Ejemplo n.º 6
0
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);
}