Beispiel #1
0
 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`,\n\t\t\t\t(SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`,\n\t\t\t\t(SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`,\n\t\t\t\t'%s' AS `board` FROM ``posts_%s`` WHERE `thread`  IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
             $post['youtube'] = $matches[2];
         }
         if (isset($post['files'])) {
             $files = json_decode($post['files']);
             if ($files[0]->file == 'deleted') {
                 continue;
             }
             $post['file'] = $config['uri_thumb'] . $files[0]->thumb;
         }
         $recent_posts[] = $post;
     }
     $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
     foreach ($required_scripts as $i => $s) {
         if (!in_array($s, $config['additional_javascript'])) {
             $config['additional_javascript'][] = $s;
         }
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
Beispiel #2
0
 public static function news($settings)
 {
     global $config;
     $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
     $news = $query->fetchAll(PDO::FETCH_ASSOC);
     return Element('themes/categories/news.html', array('settings' => $settings, 'config' => $config, 'news' => $news, 'boardlist' => createBoardlist(false)));
 }
Beispiel #3
0
 public static function homepage($settings)
 {
     global $config;
     $settings['no_recent'] = (int) $settings['no_recent'];
     $query = query("SELECT * FROM `news` ORDER BY `time` DESC" . ($settings['no_recent'] ? ' LIMIT ' . $settings['no_recent'] : '')) or error(db_error());
     $news = $query->fetchAll(PDO::FETCH_ASSOC);
     return Element('themes/basic/index.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'news' => $news));
 }
Beispiel #4
0
 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         $post['file'] = $config['uri_thumb'] . $post['thumb'];
         $recent_posts[] = $post;
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
Beispiel #5
0
 public static function news($settings)
 {
     global $config, $board;
     // HTML5
     $body = '<!DOCTYPE html><html>' . '<head>' . '<meta charset="utf-8">' . '<link rel="stylesheet" href="frontpage.css" />' . '<link rel="stylesheet" media="screen" id="stylesheet" href="/stylesheets/style.css">' . '<script type="text/javascript" src="/styleswitch-sidebar.js"></script>' . '<title>' . $settings['title'] . ' - News</title>' . '</head><body>';
     $boardlist = createBoardlist();
     $body .= $boardlist['top'] . '<br />';
     $boards = listBoards();
     $body .= '<div id="maintable"><div id="logo"></div><div id="announcement">Don\'t touch the lights!</div><table style="margin-bottom: 4px; width: 100%;"><tr>';
     // Recent Posts
     $body .= '<td style="width: 100%;"><div class="post_wrap"><div class="post_header"><b>Recent Posts</b></div><div class="post_body"><div class="post_content" style="padding-bottom: 10px;">';
     $query = '';
     foreach ($boards as &$_board) {
         // Block Board
         if ($_board['uri'] != "aurora") {
             $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` UNION ALL ", $_board['uri'], $_board['uri']);
         }
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT 15', $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch()) {
         openBoard($post['board']);
         $body .= '<strong>' . $board['name'] . '</strong>: <a href="' . $config['root'] . $board['dir'] . $config['dir']['res'] . ($post['thread'] ? $post['thread'] : $post['id']) . '.html#' . $post['id'] . '">';
         $snip = pm_snippet($post['body'], 95);
         if ($snip === "<em></em>") {
             $body .= '&lt;empty&gt;';
         } else {
             $body .= $snip;
         }
         $body .= '</a><br />';
     }
     // News
     $body .= '</div></div></div></td></tr></table>';
     $query = query("SELECT * FROM `news` ORDER BY `time` DESC LIMIT 5") or error(db_error());
     if ($query->rowCount() == 0) {
         $body .= '<p style="text-align:center" class="unimportant">(No news to show.)</p>';
     } else {
         // List news
         while ($news = $query->fetch()) {
             $body .= '<div class="post_wrap"><div class="post_header">' . (time() - $news['time'] <= 432000 ? '<em><b><span style="color: #D03030;">*NEW*</span></b></em> ' : '') . ($news['subject'] ? $news['subject'] : '<em>no subject</em>') . ' &mdash; by ' . $news['name'] . ' at ' . strftime($config['post_date'], $news['time']) . '</div><div class="post_body"><div class="post_content">' . $news['body'] . '</div></div></div>';
         }
     }
     // Finish page
     $body .= '<br />';
     $body .= '</div></body></html>';
     return $body;
 }
Beispiel #6
0
 public function build($settings, $board_name)
 {
     global $config, $board;
     openBoard($board_name);
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']);
         $post['board_name'] = $board['name'];
         $post['file'] = $config['uri_thumb'] . $post['thumb'];
         if ($post['embed'] && preg_match('/^https?:\\/\\/(\\w+\\.)?(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/)([a-zA-Z0-9\\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) {
             $post['youtube'] = $matches[2];
         }
         $recent_posts[] = $post;
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats, 'board' => $board_name, 'link' => $config['root'] . $board['dir'])));
 }
Beispiel #7
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);
    }
}
Beispiel #8
0
 public function homepage($settings)
 {
     global $config, $board;
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $boards = listBoards();
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `files` IS NOT NULL UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_posts'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($post['body'] != "") {
             $post['snippet'] = pm_snippet($post['body'], 128);
         } else {
             $post['snippet'] = "<em>" . _("(no comment)") . "</em>";
         }
         $post['board_name'] = $board['name'];
         $recent_posts[] = $post;
     }
     // Total posts
     $query = 'SELECT SUM(`top`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT MAX(`id`) AS `top` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['total_posts'] = number_format($query->fetchColumn());
     // Unique IPs
     $query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `ip` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['unique_posters'] = number_format($query->fetchColumn());
     // Active content
     $query = 'SELECT DISTINCT(`files`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `files` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ' WHERE `num_files` > 0) AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $files = $query->fetchAll();
     $stats['active_content'] = 0;
     foreach ($files as &$file) {
         preg_match_all('/"size":([0-9]*)/', $file[0], $matches);
         $stats['active_content'] += array_sum($matches[1]);
     }
     return Element('themes/recent_textonly/recent_textonly.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_posts' => $recent_posts, 'stats' => $stats));
 }
Beispiel #9
0
 public function homepage($settings)
 {
     global $config, $board;
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $boards = listBoards();
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` WHERE `file` IS NOT NULL AND `file` != 'deleted' AND `thumb` != 'spoiler' UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_images'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch()) {
         openBoard($post['board']);
         // board settings won't be available in the template file, so generate links now
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']) . '#' . $post['id'];
         $post['src'] = $config['uri_thumb'] . $post['thumb'];
         $recent_images[] = $post;
     }
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_posts'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch()) {
         openBoard($post['board']);
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $post['id']) . '#' . $post['id'];
         $post['snippet'] = pm_snippet($post['body'], 30);
         $post['board_name'] = $board['name'];
         $recent_posts[] = $post;
     }
     // Total posts
     $query = 'SELECT SUM(`top`) AS `count` FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT MAX(`id`) AS `top` FROM `posts_%s` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $res = $query->fetch();
     $stats['total_posts'] = number_format($res['count']);
     // Unique IPs
     $query = 'SELECT COUNT(DISTINCT(`ip`)) AS `count` FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `ip` FROM `posts_%s` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $res = $query->fetch();
     $stats['unique_posters'] = number_format($res['count']);
     // Active content
     $query = 'SELECT SUM(`filesize`) AS `count` FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `filesize` FROM `posts_%s` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $res = $query->fetch();
     $stats['active_content'] = $res['count'];
     return Element('themes/recent/recent.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats));
 }
Beispiel #10
0
 private function saveForBoard($board_name, $recent_posts, $board_link = null)
 {
     global $board, $config;
     if ($board_link === null) {
         $board_link = $config['root'] . $board['dir'];
     }
     $required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js', 'js/catalog.js');
     // Include scripts that haven't been yet included
     foreach ($required_scripts as $i => $s) {
         if (!in_array($s, $config['additional_javascript'])) {
             $config['additional_javascript'][] = $s;
         }
     }
     file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', array('settings' => $this->settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => array(), 'recent_posts' => $recent_posts, 'stats' => array(), 'board' => $board_name, 'link' => $board_link)));
 }
Beispiel #11
0
 public static function install($settings)
 {
     global $config;
     return Element('themes/zine/zine.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist()));
 }
Beispiel #12
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);
    }
}
Beispiel #13
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)));
 }
Beispiel #14
0
 public function homepage($settings)
 {
     global $config, $board;
     $recent_images = array();
     $recent_posts = array();
     $stats = array();
     $boards = listBoards();
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `files` IS NOT NULL UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_images'], $query);
     if ($query == '') {
         error(_("Can't build the RecentPosts theme, because there are no boards to be fetched."));
     }
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         if (isset($post['files'])) {
             $files = json_decode($post['files']);
         }
         if ($files[0]->file == 'deleted') {
             continue;
         }
         // board settings won't be available in the template file, so generate links now
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($files) {
             if ($files[0]->thumb == 'spoiler') {
                 $tn_size = @getimagesize($config['spoiler_image']);
                 $post['src'] = $config['spoiler_image'];
                 $post['thumbwidth'] = $tn_size[0];
                 $post['thumbheight'] = $tn_size[1];
             } else {
                 $post['src'] = $config['uri_thumb'] . $files[0]->thumb;
             }
         }
         $recent_images[] = $post;
     }
     $query = '';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int) $settings['limit_posts'], $query);
     $query = query($query) or error(db_error());
     while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
         openBoard($post['board']);
         $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id'];
         if ($post['body'] != "") {
             $post['snippet'] = pm_snippet($post['body'], 30);
         } else {
             $post['snippet'] = "<em>" . _("(no comment)") . "</em>";
         }
         $post['board_name'] = $board['name'];
         $recent_posts[] = $post;
     }
     // Total posts
     $query = 'SELECT SUM(`top`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT MAX(`id`) AS `top` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['total_posts'] = number_format($query->fetchColumn());
     // Unique IPs
     $query = 'SELECT COUNT(DISTINCT(`ip`)) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `ip` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ') AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $stats['unique_posters'] = number_format($query->fetchColumn());
     // Active content
     $query = 'SELECT DISTINCT(`files`) FROM (';
     foreach ($boards as &$_board) {
         if (in_array($_board['uri'], $this->excluded)) {
             continue;
         }
         $query .= sprintf("SELECT `files` FROM ``posts_%s`` UNION ALL ", $_board['uri']);
     }
     $query = preg_replace('/UNION ALL $/', ' WHERE `num_files` > 0) AS `posts_all`', $query);
     $query = query($query) or error(db_error());
     $files = $query->fetchAll();
     $stats['active_content'] = 0;
     foreach ($files as &$file) {
         preg_match_all('/"size":([0-9]*)/', $file[0], $matches);
         $stats['active_content'] += array_sum($matches[1]);
     }
     return Element('themes/recent/recent.html', array('settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, 'stats' => $stats));
 }
Beispiel #15
0
 /**
  * Query the required information and generate the HTML
  */
 public function build($mod = false)
 {
     if (!isset($this->settings)) {
         error('Theme is not configured properly.');
     }
     global $config;
     $html = '';
     $overflow = array();
     // Fetch threads from all boards and chomp the first 'n' posts, depending
     // on the setting
     $threads = $this->shuffleThreads($this->fetchThreads());
     $total_count = count($threads);
     // Top threads displayed on load
     $top_threads = array_splice($threads, 0, $this->settings['thread_limit']);
     // Number of processed threads by board
     $counts = array();
     // Output threads up to the specified limit
     foreach ($top_threads as $post) {
         if (array_key_exists($post['board'], $counts)) {
             ++$counts[$post['board']];
         } else {
             $counts[$post['board']] = 1;
         }
         $html .= $this->buildOne($post, $mod);
     }
     foreach ($threads as $post) {
         if (array_key_exists($post['board'], $counts)) {
             ++$counts[$post['board']];
         } else {
             $counts[$post['board']] = 1;
         }
         $page = 'index';
         $board_page = floor($counts[$post['board']] / $config['threads_per_page']);
         if ($board_page > 0) {
             $page = $board_page + 1;
         }
         $overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
     }
     $html .= '<script>var ukko_overflow = ' . json_encode($overflow) . '</script>';
     $html .= '<script type="text/javascript" src="/' . $this->settings['uri'] . '/semirand.js"></script>';
     return Element('index.html', array('config' => $config, 'board' => array('url' => $this->settings['uri'], 'title' => $this->settings['title'], 'subtitle' => str_replace('%s', $this->settings['thread_limit'], strval(min($this->settings['subtitle'], $total_count)))), 'no_post_form' => true, 'body' => $html, 'mod' => $mod, 'boardlist' => createBoardlist($mod)));
 }
Beispiel #16
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);
}