diff --git a/inc/bans.php b/inc/bans.php index 9ee41339..d97451cf 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -285,68 +285,68 @@ class Bans { } } - static public function stream_json($out = false, $filter_ips = false, $filter_staff = false, $board_access = false, $hide_regexes = []) { - $query = query("SELECT ``bans``.*, `username` FROM ``bans`` - LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` - ORDER BY `created` DESC") or error(db_error()); - $bans = $query->fetchAll(PDO::FETCH_ASSOC); - + static public function stream_json($filter_ips = false, $filter_staff = false, $board_access = false, $hide_message = false) { if ($board_access && $board_access[0] == '*') { $board_access = false; } - $out ? fputs($out, "[") : print("["); + $query = query("SELECT ``bans``.*, `username` FROM ``bans`` + LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` + ORDER BY `created` DESC") or error(db_error()); - $end = end($bans); + print('['); - foreach ($bans as &$ban) { - $ban['mask'] = self::range_to_string([$ban['ipstart'], $ban['ipend']]); + $has_previous = false; - $hide_message = false; - foreach ($hide_regexes as $regex) { - if(preg_match($regex, $ban['reason'])) { - $hide_message = true; - break; + while (true) { + $ban = $query->fetch(PDO::FETCH_ASSOC); + + if (\is_array($ban)) { + $ban['mask'] = self::range_to_string([$ban['ipstart'], $ban['ipend']]); + + if ($ban['post'] && !$hide_message) { + $post = \json_decode($ban['post']); + $ban['message'] = isset($post->body) ? $post->body : 0; } - } + unset($ban['ipstart'], $ban['ipend'], $ban['post'], $ban['creator']); - if ($ban['post'] && !$hide_message) { - $post = json_decode($ban['post']); - $ban['message'] = isset($post->body) ? $post->body : 0; - } - unset($ban['ipstart'], $ban['ipend'], $ban['post'], $ban['creator']); - - if ($board_access === false || in_array ($ban['board'], $board_access)) { - $ban['access'] = true; - } - - if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) { - $ban['single_addr'] = true; - } - if ($filter_staff || ($board_access !== false && !in_array($ban['board'], $board_access))) { - $ban['username'] = '?'; - } - if ($filter_ips || ($board_access !== false && !in_array($ban['board'], $board_access))) { - @list($ban['mask'], $subnet) = explode("/", $ban['mask']); - $ban['mask'] = preg_split("/[\.:]/", $ban['mask']); - $ban['mask'] = array_slice($ban['mask'], 0, 2); - $ban['mask'] = implode(".", $ban['mask']); - $ban['mask'] .= ".x.x"; - if (isset ($subnet)) { - $ban['mask'] .= "/$subnet"; + if ($board_access === false || in_array ($ban['board'], $board_access)) { + $ban['access'] = true; } - $ban['masked'] = true; - } - $json = json_encode($ban); - $out ? fputs($out, $json) : print($json); + if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) { + $ban['single_addr'] = true; + } + if ($filter_staff || ($board_access !== false && !\in_array($ban['board'], $board_access))) { + $ban['username'] = '?'; + } + if ($filter_ips || ($board_access !== false && !\in_array($ban['board'], $board_access))) { + @list($ban['mask'], $subnet) = explode("/", $ban['mask']); + $ban['mask'] = \preg_split("/[\.:]/", $ban['mask']); + $ban['mask'] = \array_slice($ban['mask'], 0, 2); + $ban['mask'] = \implode(".", $ban['mask']); + $ban['mask'] .= ".x.x"; + if (isset($subnet)) { + $ban['mask'] .= "/$subnet"; + } + $ban['masked'] = true; + } - if ($ban['id'] != $end['id']) { - $out ? fputs($out, ",") : print(","); + $json = \json_encode($ban); + + // Add a comma if there's a previous row. + if ($has_previous) { + print(','); + } + $has_previous = true; + + print($json); + } else { + break; } } - $out ? fputs($out, "]") : print("]"); + print(']'); } static public function seen($ban_id) { diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 17d2ef74..1e8b47f4 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1192,7 +1192,7 @@ function mod_bans_json(Context $ctx) { // Compress the json for faster loads if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); - Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); + Bans::stream_json(false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); } function mod_ban_appeals(Context $ctx) { diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php index d56a6481..f2df83eb 100644 --- a/templates/themes/public_banlist/theme.php +++ b/templates/themes/public_banlist/theme.php @@ -1,57 +1,55 @@ $config, - 'mod' => false, - #'hide_dashboard_link' => true, - 'title' => _("Ban list"), - 'subtitle' => "", + return Element('page.html', [ + 'config' => $config, + 'mod' => false, + 'title' => _("Ban list"), + 'subtitle' => "", 'boardlist' => createBoardlist(), - #'nojavascript' => true, - 'body' => Element('mod/ban_list.html', array( - 'mod' => false, - 'boards' => "[]", - 'token' => false, - 'token_json' => false, + 'body' => Element('mod/ban_list.html', [ + 'mod' => false, + 'boards' => "[]", + 'token' => false, + 'token_json' => false, 'uri_json' => $config['dir']['home'] . $settings['file_json'], - )) - )); - } - }; - -?> + ]) + ]); + } +};