示例#1
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;
 }
示例#2
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));
 }
示例#3
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));
 }
示例#4
0
     $query = prepare("UPDATE `pms` SET `unread` = 0 WHERE `to` = :id");
     $query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
     $query->execute() or error(db_error($query));
     modLog('Marked all PMs as read');
     header('Location: ?/inbox', true, $config['redirect_http']);
 } elseif (preg_match('/^\\/inbox$/', $query, $match)) {
     $query = prepare("SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC");
     $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT);
     $query->execute() or error(db_error($query));
     if ($query->rowCount() == 0) {
         $body = '<p style="text-align:center" class="unimportant">(' . _('No private messages for you.') . ')</p>';
     } else {
         $unread_pms = 0;
         $body = '<table class="modlog"><tr><th>ID</th><th>From</th><th>Date</th><th>Message snippet</th></tr>';
         while ($pm = $query->fetch()) {
             $body .= '<tr' . ($pm['unread'] ? ' style="font-weight:bold"' : '') . '>' . '<td class="minimal"><a href="?/PM/' . $pm['id'] . '">' . $pm['id'] . '</a></td>' . '<td class="minimal">' . ($pm['username'] ? '<a href="?/new_PM/' . $pm['sender'] . '">' . $pm['username'] . '</a>' : '<em>deleted?</em>') . '</td>' . '<td class="minimal">' . strftime($config['post_date'], $pm['time']) . '</td>' . '<td><a href="?/PM/' . $pm['id'] . '">' . pm_snippet($pm['message']) . '</a></td>' . '</tr>';
             if ($pm['unread']) {
                 $unread_pms++;
             }
         }
         $body .= '</table>';
         if ($unread_pms) {
             $body = '<p style="text-align:center" class="unimportant">(<a href="?/inbox/readall">Mark all as read</a>)</p>' . $body;
         }
     }
     echo Element('page.html', array('config' => $config, 'title' => _('PM Inbox') . ' (' . ($query->rowCount() == 0 ? _('empty') : $unread_pms . ' ' . _('unread')) . ')', 'body' => $body, 'mod' => true));
 } elseif (preg_match('/^\\/PM\\/(\\d+)$/', $query, $match)) {
     $id =& $match[1];
     if (hasPermission($config['mod']['master_pm'])) {
         $query = prepare("SELECT `pms`.`id`, `time`, `sender`, `unread`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `pms`.`id` = :id");
     } else {
示例#5
0
文件: pages.php 项目: vicentil/vichan
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));
}
示例#6
0
文件: theme.php 项目: 0151n/vichan
 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));
 }
示例#7
0
function mod_inbox()
{
    global $config, $mod;
    $query = prepare('SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC');
    $query->bindValue(':mod', $mod['id']);
    $query->execute() or error(db_error($query));
    $messages = $query->fetchAll(PDO::FETCH_ASSOC);
    $query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :mod AND `unread` = 1');
    $query->bindValue(':mod', $mod['id']);
    $query->execute() or error(db_error($query));
    $unread = $query->fetchColumn(0);
    foreach ($messages as &$message) {
        $message['snippet'] = pm_snippet($message['message']);
    }
    mod_page(sprintf('%s (%s)', _('PM inbox'), count($messages) > 0 ? $unread . ' unread' : 'empty'), 'mod/inbox.html', array('messages' => $messages, 'unread' => $unread));
}