public static function new_ban($mask, $reason, $length = false, $ban_board = false, $mod_id = false, $post = false) { global $mod, $pdo, $board; if ($mod_id === false) { $mod_id = isset($mod['id']) ? $mod['id'] : -1; } $range = self::parse_range($mask); $mask = self::range_to_string($range); $query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)"); $query->bindValue(':ipstart', $range[0]); if ($range[1] !== false && $range[1] != $range[0]) { $query->bindValue(':ipend', $range[1]); } else { $query->bindValue(':ipend', null, PDO::PARAM_NULL); } $query->bindValue(':mod', $mod_id); $query->bindValue(':time', time()); if ($reason !== '') { $reason = escape_markup_modifiers($reason); markup($reason); $query->bindValue(':reason', $reason); } else { $query->bindValue(':reason', null, PDO::PARAM_NULL); } if ($length) { if (is_int($length) || ctype_digit($length)) { $length = time() + $length; } else { $length = self::parse_time($length); } $query->bindValue(':expires', $length); } else { $query->bindValue(':expires', null, PDO::PARAM_NULL); } if ($ban_board) { $query->bindValue(':board', $ban_board); } else { $query->bindValue(':board', null, PDO::PARAM_NULL); } if ($post) { $post['board'] = $board['uri']; $query->bindValue(':post', json_encode($post)); } else { $query->bindValue(':post', null, PDO::PARAM_NULL); } $query->execute() or error(db_error($query)); if (isset($mod['id']) && $mod['id'] == $mod_id) { modLog('Created a new ' . ($length > 0 ? preg_replace('/^(\\d+) (\\w+?)s?$/', '$1-$2', until($length)) : 'permanent') . ' ban on ' . ($ban_board ? '/' . $ban_board . '/' : 'all boards') . ' for ' . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/{$mask}\">{$mask}</a>" : $mask) . ' (<small>#' . $pdo->lastInsertId() . '</small>)' . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); } return $pdo->lastInsertId(); }
function ban($mask, $reason, $length, $board) { global $mod, $pdo; $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board)"); $query->bindValue(':ip', $mask); $query->bindValue(':mod', $mod['id']); $query->bindValue(':time', time()); if ($reason !== '') { markup($reason); $query->bindValue(':reason', $reason); } else { $query->bindValue(':reason', null, PDO::PARAM_NULL); } if ($length > 0) { $query->bindValue(':expires', $length); } else { $query->bindValue(':expires', null, PDO::PARAM_NULL); } if ($board) { $query->bindValue(':board', $board); } else { $query->bindValue(':board', null, PDO::PARAM_NULL); } $query->execute() or error(db_error($query)); modLog('Created a new ' . ($length > 0 ? preg_replace('/^(\\d+) (\\w+?)s?$/', '$1-$2', until($length)) : 'permanent') . ' ban (<small>#' . $pdo->lastInsertId() . '</small>) for ' . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/{$mask}\">{$mask}</a>" : utf8tohtml($mask)) . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); }
$query = prepare(sprintf("SELECT `thread`, `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); if ($post = $query->fetch(PDO::FETCH_ASSOC)) { $thread = false; if ($config['user_moderation'] && $post['thread']) { $thread_query = prepare(sprintf("SELECT `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); $thread_query->bindValue(':id', $post['thread'], PDO::PARAM_INT); $thread_query->execute() or error(db_error($query)); $thread = $thread_query->fetch(PDO::FETCH_ASSOC); } if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password)) { error($config['error']['invalidpassword']); } if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) { error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time']))); } if (isset($_POST['file'])) { // Delete just the file deleteFile($id); modLog("User deleted file from his own post #{$id}"); } else { // Delete entire post deletePost($id); modLog("User deleted his own post #{$id}"); } _syslog(LOG_INFO, 'Deleted post: ' . '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '')); } } buildIndex(); $is_mod = isset($_POST['mod']) && $_POST['mod'];
}, 'random1' => function () { return !is_int(random(null)); }, 'mem1' => function () { return mem('true') <= 0; }, 'upto1' => function ($n) { return count(upto($n % 100)) !== $n % 100; }, 'between1' => function () { return between(5, 10) !== [5, 6, 7, 8, 9, 10]; }, 'b_then' => function ($n) { return branch(thunk($n), null, thunk(true), null) !== $n; }, 'b_else' => function ($n) { return branch(null, thunk($n), thunk(false), null) !== $n; }, 'until1' => function ($n) { $x = $n % 8; return until(function ($args) use($x) { list($m, $arr) = $args; return [$m === $x, [$m + 1, snoc($m, $arr)]]; }, [0, []]) !== [$x + 1, upto($x + 1)]; }, 'trampoline1' => function ($n) { $x = $n % 8; return trampoline(y(function ($f, $m, $n, $_) { return $m < $n ? [false, $f($m + 1, $n)] : [true, $m]; }, 0, $x)) !== $x; }, 'loop1' => function ($x) { $n = $x % 8; $lhs = loop(function ($x, $m) use($n) { return [$m >= $n, snoc($m, $x)]; }, []); $rhs = upto($n + 1); return $lhs === $rhs ? 0 : dump(get_defined_vars()); }, 'y1' => function ($x) { $n = $x % 4;
function mod_ban_post($board, $delete, $post, $token = false) { global $config, $mod; if (!openBoard($board)) { error($config['error']['noboard']); } if (!hasPermission($config['mod']['delete'], $board)) { error($config['error']['noaccess']); } $security_token = make_secure_link_token($board . '/ban/' . $post); $query = prepare(sprintf('SELECT ' . ($config['ban_show_post'] ? '*' : '`ip`, `thread`') . ' FROM ``posts_%s`` WHERE `id` = :id', $board)); $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); if (!($_post = $query->fetch(PDO::FETCH_ASSOC))) { error($config['error']['404']); } $thread = $_post['thread']; $ip = $_post['ip']; if (isset($_POST['new_ban'], $_POST['reason'], $_POST['length'], $_POST['board'])) { require_once 'inc/mod/ban.php'; if (isset($_POST['ip'])) { $ip = $_POST['ip']; } Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board'], false, $config['ban_show_post'] ? $_post : false); if (isset($_POST['public_message'], $_POST['message'])) { // public ban message $length_english = Bans::parse_time($_POST['length']) ? 'for ' . until(Bans::parse_time($_POST['length'])) : 'permanently'; $_POST['message'] = preg_replace('/[\\r\\n]/', '', $_POST['message']); $_POST['message'] = str_replace('%length%', $length_english, $_POST['message']); $_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']); $query = prepare(sprintf('UPDATE ``posts_%s`` SET `body_nomarkup` = CONCAT(`body_nomarkup`, :body_nomarkup) WHERE `id` = :id', $board)); $query->bindValue(':id', $post); $query->bindValue(':body_nomarkup', sprintf("\n<tinyboard ban message>%s</tinyboard>", utf8tohtml($_POST['message']))); $query->execute() or error(db_error($query)); rebuildPost($post); modLog("Attached a public ban message to post #{$post}: " . utf8tohtml($_POST['message'])); buildThread($thread ? $thread : $post); buildIndex(); } elseif (isset($_POST['delete']) && (int) $_POST['delete']) { // Delete post deletePost($post); modLog("Deleted post #{$post}"); // Rebuild board buildIndex(); // Rebuild themes rebuildThemes('post-delete', $board); } header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } $args = array('ip' => $ip, 'hide_ip' => !hasPermission($config['mod']['show_ip'], $board), 'post' => $post, 'board' => $board, 'delete' => (bool) $delete, 'boards' => listBoards(), 'token' => $security_token); mod_page(_('New ban'), 'mod/ban_form.html', $args); }
public static function new_ban($mask, $reason, $length = false, $ban_board = false, $mod_id = false, $post = false) { global $config, $mod, $pdo, $board; if ($mod_id === false) { $mod_id = isset($mod['id']) ? $mod['id'] : -1; } if (!in_array($ban_board, $mod['boards']) && $mod['boards'][0] != '*') { error($config['error']['noaccess']); } $range = self::parse_range($mask); $mask = self::range_to_string($range); $query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)"); $query->bindValue(':ipstart', $range[0]); if ($range[1] !== false && $range[1] != $range[0]) { $query->bindValue(':ipend', $range[1]); } else { $query->bindValue(':ipend', null, PDO::PARAM_NULL); } $query->bindValue(':mod', $mod_id); $query->bindValue(':time', time()); if ($reason !== '') { $reason = escape_markup_modifiers($reason); markup($reason); $query->bindValue(':reason', $reason); } else { $query->bindValue(':reason', null, PDO::PARAM_NULL); } if ($length) { if (is_int($length) || ctype_digit($length)) { $length = time() + $length; } else { $length = self::parse_time($length); } $query->bindValue(':expires', $length); } else { $query->bindValue(':expires', null, PDO::PARAM_NULL); } if ($ban_board) { $query->bindValue(':board', $ban_board); } else { $query->bindValue(':board', null, PDO::PARAM_NULL); } if ($post) { $post['board'] = $board['uri']; $match_urls = '(?xi)\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'".,<>?«»“”‘’]))'; $matched = array(); preg_match_all("#{$match_urls}#im", $post['body_nomarkup'], $matched); if (isset($matched[0]) && $matched[0]) { $post['body'] = str_replace($matched[0], '###Link-Removed###', $post['body']); $post['body_nomarkup'] = str_replace($matched[0], '###Link-Removed###', $post['body_nomarkup']); } $query->bindValue(':post', json_encode($post)); } else { $query->bindValue(':post', null, PDO::PARAM_NULL); } $query->execute() or error(db_error($query)); if (isset($mod['id']) && $mod['id'] == $mod_id) { modLog('Created a new ' . ($length > 0 ? preg_replace('/^(\\d+) (\\w+?)s?$/', '$1-$2', until($length)) : 'permanent') . ' ban on ' . ($ban_board ? '/' . $ban_board . '/' : 'all boards') . ' for ' . (filter_var($mask, FILTER_VALIDATE_IP) !== false ? "<a href=\"?/IP/{$mask}\">{$mask}</a>" : $mask) . ' (<small>#' . $pdo->lastInsertId() . '</small>)' . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); } if (!$config['cron_bans']) { rebuildThemes('bans'); } return $pdo->lastInsertId(); }
function getLangs() { $langs = array(); $pattern = "/(Language:)([\\w\\W\\s][^\\]]+)(\\]{2})/"; foreach (preg_split('/\\r\\n|\\r|\\n/', $this->languages) as $line) { if ($line == '') { continue; } preg_match_all($pattern, $line, $out, PREG_PATTERN_ORDER); if ($out[2][0] != '') { array_push($langs, trim(until("|", $out[2][0]))); } } return $langs; }