function catalog_build($action, $settings, $board) { global $config; // Possible values for $action: // - all (rebuild everything, initialization) // - news (news has been updated) // - boards (board list changed) // - post (a reply has been made) // - post-thread (a thread has been made) if ($settings['all']) { $boards = listBoards(TRUE); } else { $boards = explode(' ', $settings['boards']); } if ($action == 'all') { foreach ($boards as $board) { $b = new Catalog(); if ($config['smart_build']) { file_unlink($config['dir']['home'] . $board . '/catalog.html'); } else { $b->build($settings, $board); } if (php_sapi_name() === "cli") { echo "Rebuilding {$board} catalog...\n"; } } } elseif ($action == 'post-thread' || $settings['update_on_posts'] && $action == 'post' || $settings['update_on_posts'] && $action == 'post-delete' && in_array($board, $boards) | $settings['all']) { $b = new Catalog(); if ($config['smart_build']) { file_unlink($config['dir']['home'] . $board . '/catalog.html'); } else { $b->build($settings, $board); } } }
/** * Build and save the HTML of the catalog for the Ukko theme */ public function buildUkko() { global $config; $ukkoSettings = themeSettings('ukko'); $queries = array(); $threads = array(); $exclusions = explode(' ', $ukkoSettings['exclude']); $boards = array_diff(listBoards(true), $exclusions); foreach ($boards as $b) { if (array_key_exists($b, $this->threadsCache)) { $threads = array_merge($threads, $this->threadsCache[$b]); } else { $queries[] = $this->buildThreadsQuery($b); } } // Fetch threads from boards that haven't beenp processed yet if (!empty($queries)) { $sql = implode(' UNION ALL ', $queries); $res = query($sql) or error(db_error()); $threads = array_merge($threads, $res->fetchAll(PDO::FETCH_ASSOC)); } // Sort in bump order usort($threads, function ($a, $b) { return strcmp($b['bump'], $a['bump']); }); // Generate data for the template $recent_posts = $this->generateRecentPosts($threads); $this->saveForBoard($ukkoSettings['uri'], $recent_posts, $config['root'] . $ukkoSettings['uri']); }
/** * Obtain list of all threads from all non-excluded boards */ private function fetchThreads() { $query = ''; $boards = listBoards(true); foreach ($boards as $b) { if (in_array($b, $this->settings['exclude'])) { continue; } // Threads are those posts that have no parent thread $query .= "SELECT *, '{$b}' AS `board` FROM ``posts_{$b}`` " . "WHERE `thread` IS NULL UNION ALL "; } $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query); $result = query($query) or error(db_error()); return $result->fetchAll(PDO::FETCH_ASSOC); }
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 .= '<empty>'; } 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>') . ' — 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; }
function createBoardlist($mod = false) { global $config; if (!isset($config['boards'])) { return array('top' => '', 'bottom' => ''); } $xboards = listBoards(); $boards = array(); foreach ($xboards as $val) { $boards[$val['uri']] = $val['title']; } $body = doBoardListPart($config['boards'], $mod ? '?/' : $config['root'], $boards); if ($config['boardlist_wrap_bracket'] && !preg_match('/\\] $/', $body)) { $body = '[' . $body . ']'; } $body = trim($body); // Message compact-boardlist.js faster, so that page looks less ugly during loading $top = "<script type='text/javascript'>if (typeof do_boardlist != 'undefined') do_boardlist();</script>"; return array('top' => '<div class="boardlist">' . $body . '</div>' . $top, 'bottom' => '<div class="boardlist bottom">' . $body . '</div>'); }
<?php require 'inc/functions.php'; if (!$config['search']['enable']) { die(_("Post search is disabled")); } $queries_per_minutes = $config['search']['queries_per_minutes']; $queries_per_minutes_all = $config['search']['queries_per_minutes_all']; $search_limit = $config['search']['search_limit']; if (isset($config['search']['boards'])) { $boards = $config['search']['boards']; } else { $boards = listBoards(TRUE); } $body = Element('search_form.html', array('boards' => $boards, 'b' => isset($_GET['board']) ? $_GET['board'] : false, 'search' => isset($_GET['search']) ? str_replace('"', '"', utf8tohtml($_GET['search'])) : false)); if (isset($_GET['search']) && !empty($_GET['search']) && isset($_GET['board']) && in_array($_GET['board'], $boards)) { $phrase = $_GET['search']; $_body = ''; $query = prepare("SELECT COUNT(*) FROM ``search_queries`` WHERE `ip` = :ip AND `time` > :time"); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':time', time() - $queries_per_minutes[1] * 60); $query->execute() or error(db_error($query)); if ($query->fetchColumn() > $queries_per_minutes[0]) { error(_('Wait a while before searching again, please.')); } $query = prepare("SELECT COUNT(*) FROM ``search_queries`` WHERE `time` > :time"); $query->bindValue(':time', time() - $queries_per_minutes_all[1] * 60); $query->execute() or error(db_error($query)); if ($query->fetchColumn() > $queries_per_minutes_all[0]) { error(_('Wait a while before searching again, please.')); }
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)); }
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)); }
function mod_debug_recent_posts() { global $pdo, $config; $limit = 500; $boards = listBoards(); // Manually build an SQL query $query = 'SELECT * FROM ('; foreach ($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` ORDER BY `time` DESC LIMIT ' . $limit, $query); $query = query($query) or error(db_error()); $posts = $query->fetchAll(PDO::FETCH_ASSOC); // Fetch recent posts from flood prevention cache $query = query("SELECT * FROM ``flood`` ORDER BY `time` DESC") or error(db_error()); $flood_posts = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($posts as &$post) { $post['snippet'] = pm_snippet($post['body']); foreach ($flood_posts as $flood_post) { if ($flood_post['time'] == $post['time'] && $flood_post['posthash'] == make_comment_hex($post['body_nomarkup']) && $flood_post['filehash'] == $post['filehash']) { $post['in_flood_table'] = true; } } } mod_page(_('Debug: Recent posts'), 'mod/debug/recent_posts.html', array('posts' => $posts, 'flood_posts' => $flood_posts)); }
<?php $theme = array(); // Theme name $theme['name'] = 'Catalog'; // Description (you can use Tinyboard markup here) $theme['description'] = 'Show a post catalog.'; $theme['version'] = 'v0.2.1'; // Theme configuration $theme['config'] = array(); $theme['config'][] = array('title' => 'Title', 'name' => 'title', 'type' => 'text', 'default' => 'Catalog'); $__boards = listBoards(); $__default_boards = array(); foreach ($__boards as $__board) { $__default_boards[] = $__board['uri']; } $theme['config'][] = array('title' => 'Included boards', 'name' => 'boards', 'type' => 'text', 'comment' => '(space seperated)', 'default' => implode(' ', $__default_boards)); $theme['config'][] = array('title' => 'Update on new posts', 'name' => 'update_on_posts', 'type' => 'checkbox', 'default' => false, 'comment' => 'Without this checked, the catalog only updates on new threads.'); $theme['config'][] = array('title' => 'Enable Ukko catalog', 'name' => 'enable_ukko', 'type' => 'checkbox', 'default' => false, 'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.'); $theme['config'][] = array('title' => 'Use tooltipster', 'name' => 'use_tooltipster', 'type' => 'checkbox', 'default' => true, 'comment' => 'Check this if you wish to show a nice tooltip with info about the thread on mouse over.'); // Unique function name for building everything $theme['build_function'] = 'catalog_build';
function form_newBan($ip = null, $reason = '', $continue = false, $delete = false, $board = false, $allow_public = false) { global $config, $mod; $boards = listBoards(); $__boards = '<li><input type="radio" checked="checked" name="board" id="board_*" value=""/> <label style="display:inline" for="board_*"><em>' . _('all boards') . '</em></label></li>'; foreach ($boards as &$_board) { $__boards .= '<li>' . '<input type="radio" name="board" id="board_' . $_board['uri'] . '" value="' . $_board['uri'] . '">' . '<label style="display:inline" for="board_' . $_board['uri'] . '"> ' . ($_board['uri'] == '*' ? '<em>"*"</em>' : sprintf($config['board_abbreviation'], $_board['uri'])) . ' - ' . $_board['title'] . '</label>' . '</li>'; } return '<fieldset><legend>New ban</legend>' . '<form action="?/ban" method="post">' . ($continue ? '<input type="hidden" name="continue" value="' . htmlentities($continue) . '" />' : '') . ($delete || $allow_public ? '<input type="hidden" name="' . (!$allow_public ? 'delete' : 'post') . '" value="' . htmlentities($delete) . '" />' : '') . ($board ? '<input type="hidden" name="board" value="' . htmlentities($board) . '" />' : '') . '<table>' . '<tr>' . '<th><label for="ip">IP ' . ($config['ban_cidr'] ? '<span class="unimportant">(or subnet)' : '') . '</span></label></th>' . '<td><input type="text" name="ip" id="ip" size="30" maxlength="30" ' . (isset($ip) ? 'value="' . htmlentities($ip) . '" ' : '') . '/></td>' . '</tr>' . '<tr>' . '<th><label for="reason">Reason</label></th>' . '<td><textarea name="reason" id="reason" rows="5" cols="30">' . htmlentities($reason) . '</textarea></td>' . '</tr>' . ($mod['type'] >= $config['mod']['public_ban'] && $allow_public ? '<tr>' . '<th><label for="message">Message</label></th>' . '<td><input type="checkbox" id="public_message" name="public_message"/>' . ' <input type="text" name="message" id="message" size="35" maxlength="200" value="' . htmlentities($config['mod']['default_ban_message']) . '" />' . ' <span class="unimportant">(public; attached to post)</span></td>' . '<script type="text/javascript">' . 'document.getElementById(\'message\').disabled = true;' . 'document.getElementById(\'public_message\').onchange = function() {' . 'document.getElementById(\'message\').disabled = !this.checked;' . '}' . '</script>' . '</tr>' : '') . '<tr>' . '<th><label for="length">Length</label></th>' . '<td><input type="text" name="length" id="length" size="20" maxlength="40" />' . ' <span class="unimportant">(eg. "2d1h30m" or "2 days")</span></td>' . '</tr>' . '<tr>' . '<th>Board</th>' . '<td><ul style="list-style:none;padding:2px 5px">' . $__boards . '</tl></td>' . '</tr>' . '<tr>' . '<td></td>' . '<td><input name="new_ban" type="submit" value="New Ban" /></td>' . '</tr>' . '</table>' . '</form>' . '</fieldset>'; }
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))); }
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)); }
function mod_rebuild() { global $config, $twig; if (!hasPermission($config['mod']['rebuild'])) { error($config['error']['noaccess']); } if (isset($_POST['rebuild'])) { $log = array(); $boards = listBoards(); $rebuilt_scripts = array(); if (isset($_POST['rebuild_cache'])) { if ($config['cache']['enabled']) { $log[] = 'Flushing cache'; Cache::flush(); } $log[] = 'Clearing template cache'; load_twig(); $twig->clearCacheFiles(); } if (isset($_POST['rebuild_themes'])) { $log[] = 'Regenerating theme files'; rebuildThemes('all'); } if (isset($_POST['rebuild_javascript'])) { $log[] = 'Rebuilding <strong>' . $config['file_script'] . '</strong>'; buildJavascript(); $rebuilt_scripts[] = $config['file_script']; } foreach ($boards as $board) { if (!(isset($_POST['boards_all']) || isset($_POST['board_' . $board['uri']]))) { continue; } openBoard($board['uri']); if (isset($_POST['rebuild_index'])) { buildIndex(); $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Creating index pages'; } if (isset($_POST['rebuild_javascript']) && !in_array($config['file_script'], $rebuilt_scripts)) { $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Rebuilding <strong>' . $config['file_script'] . '</strong>'; buildJavascript(); $rebuilt_scripts[] = $config['file_script']; } if (isset($_POST['rebuild_thread'])) { $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Rebuilding thread #' . $post['id']; buildThread($post['id']); } } } mod_page(_('Rebuild'), 'mod/rebuilt.html', array('logs' => $log)); return; } mod_page(_('Rebuild'), 'mod/rebuild.html', array('boards' => listBoards())); }
public static function sidebar($settings) { global $config, $board; return Element('themes/frameset/sidebar.html', array('settings' => $settings, 'config' => $config, 'boards' => listBoards())); }
if (!(strlen($title) < 40)) { error(_('Invalid title')); } if (!(strlen($subtitle) < 200)) { error(_('Invalid subtitle')); } if (!preg_match('/^[a-zA-Z0-9._]{1,30}$/', $username)) { error(_('Invalid username')); } if ($resp !== '1') { error($config['error']['captcha']); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $email = ''; } foreach (listBoards() as $i => $board) { if ($board['uri'] == $uri) { error(_('Board already exists!')); } } foreach ($config['banned_boards'] as $i => $w) { if ($w[0] !== '/') { if (strpos($uri, $w) !== false) { error(_("Cannot create board with banned word {$w}")); } } else { if (preg_match($w, $uri)) { error(_("Cannot create board matching banned pattern {$w}")); } } }
// SQL installation buildJavascript(); $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql."); // This code is probably horrible, but what I'm trying // to do is find all of the SQL queires and put them // in an array. preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries); $queries = $queries[2]; $queries[] = Element('posts.sql', array('board' => 'b')); $sql_errors = ''; foreach ($queries as &$query) { if (!query($query)) { $sql_errors .= '<li>' . db_error() . '</li>'; } } $boards = listBoards(); foreach ($boards as &$_board) { setupBoard($_board); buildIndex(); } $page['title'] = 'Installation complete'; $page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. Please remember to report any bugs you discover. <a href="http://tinyboard.org/docs/?p=Config">How do I edit the config files?</a></p>'; if (!empty($sql_errors)) { $page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a Tinyboard installation; if so, you can probably ignore this.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul><p><a href="?step=5">Ignore errors and complete installation.</a></p></div>'; } else { file_write($config['has_installed'], VERSION); if (!file_unlink(__FILE__)) { $page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>'; } } echo Element('page.html', $page);
<title>Project Manager</title> <link rel="stylesheet" href="css/global.css" media="screen" title="no title" charset="utf-8"> <link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'> </head> <body> <div class="container"> <h1>Project Manager</h1> </div> <div class="container"> <button class="button" onClick="showCreate(this)" type="button" name="button"> Create Project </button> <br class="clear" /> </div> <div class="container boardLister"> <?php echo listBoards($boards); ?> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { }); function showCreate(elm) { var daHeight = $(elm).height(); var pos = $(elm).position(); dropDown = '<div class="createProject"> <h4> Create a Project </h4> <label for="title"> Title </label> <input id="createProj" type="text" name="name" placeholder="The Title"> <button onClick="createProject(this)" class="submit" type="button" name="button">Create</button> </div>'; $(dropDown).appendTo("body").css("top", (pos.top + (daHeight * 3.5)) + "px").css("left", pos.left + "px"); } function createProject(elm) {