diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 3765c61c..741d2268 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1,9 +1,9 @@ $request, 'token' => make_secure_link_token($request)); +function mod_confirm(Context $ctx, $request) { + $args = [ 'request' => $request, 'token' => make_secure_link_token($request) ]; if(isset($_GET['thread'])) { $args['rest'] = 'thread=' . $_GET['thread']; } mod_page(_('Confirm action'), 'mod/confirm.html', $args); } -function mod_logout() { +function mod_logout(Context $ctx) { global $config; destroyCookies(); header('Location: ?/', true, $config['redirect_http']); } -function mod_dashboard() { +function mod_dashboard(Context $ctx) { global $config, $mod; $args = []; @@ -190,7 +190,7 @@ function mod_dashboard() { mod_page(_('Dashboard'), 'mod/dashboard.html', $args); } -function mod_search_redirect() { +function mod_search_redirect(Context $ctx) { global $config; if (!hasPermission($config['mod']['search'])) @@ -213,7 +213,7 @@ function mod_search_redirect() { } } -function mod_search($type, $search_query_escaped, $page_no = 1) { +function mod_search(Context $ctx, $type, $search_query_escaped, $page_no = 1) { global $pdo, $config; if (!hasPermission($config['mod']['search'])) @@ -368,7 +368,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) { )); } -function mod_edit_board($boardName) { +function mod_edit_board(Context $ctx, $boardName) { global $board, $config; if (!openBoard($boardName)) @@ -470,7 +470,7 @@ function mod_edit_board($boardName) { } } -function mod_new_board() { +function mod_new_board(Context $ctx) { global $config, $board; if (!hasPermission($config['mod']['newboard'])) @@ -536,7 +536,7 @@ function mod_new_board() { mod_page(_('New board'), 'mod/board.html', array('new' => true, 'token' => make_secure_link_token('new-board'))); } -function mod_noticeboard($page_no = 1) { +function mod_noticeboard(Context $ctx, $page_no = 1) { global $config, $pdo, $mod; if ($page_no < 1) @@ -591,7 +591,7 @@ function mod_noticeboard($page_no = 1) { )); } -function mod_noticeboard_delete($id) { +function mod_noticeboard_delete(Context $ctx, $id) { global $config; if (!hasPermission($config['mod']['noticeboard_delete'])) @@ -609,7 +609,7 @@ function mod_noticeboard_delete($id) { header('Location: ?/noticeboard', true, $config['redirect_http']); } -function mod_news($page_no = 1) { +function mod_news(Context $ctx, $page_no = 1) { global $config, $pdo, $mod; if ($page_no < 1) @@ -656,7 +656,7 @@ function mod_news($page_no = 1) { mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count, 'token' => make_secure_link_token('edit_news'))); } -function mod_news_delete($id) { +function mod_news_delete(Context $ctx, $id) { global $config; if (!hasPermission($config['mod']['news_delete'])) @@ -671,7 +671,7 @@ function mod_news_delete($id) { header('Location: ?/edit_news', true, $config['redirect_http']); } -function mod_log($page_no = 1) { +function mod_log(Context $ctx, $page_no = 1) { global $config; if ($page_no < 1) @@ -696,7 +696,7 @@ function mod_log($page_no = 1) { mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count)); } -function mod_user_log($username, $page_no = 1) { +function mod_user_log(Context $ctx, $username, $page_no = 1) { global $config; if ($page_no < 1) @@ -733,7 +733,7 @@ function protect_ip($entry) { return preg_replace(array($ipv4_link_regex, $ipv6_link_regex), "xxxx", $entry); } -function mod_board_log($board, $page_no = 1, $hide_names = false, $public = false) { +function mod_board_log(Context $ctx, $board, $page_no = 1, $hide_names = false, $public = false) { global $config; if ($page_no < 1) @@ -766,8 +766,8 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals mod_page(_('Board log'), 'mod/log.html', array('logs' => $logs, 'count' => $count, 'board' => $board, 'hide_names' => $hide_names, 'public' => $public)); } -function mod_view_catalog($boardName) { - global $config, $mod; +function mod_view_catalog(Context $ctx, $boardName) { + global $config; require_once($config['dir']['themes'].'/catalog/theme.php'); $settings = []; $settings['boards'] = $boardName; @@ -798,7 +798,7 @@ function mod_view_catalog($boardName) { } } -function mod_view_board($boardName, $page_no = 1) { +function mod_view_board(Context $ctx, $boardName, $page_no = 1) { global $config, $mod; if (!openBoard($boardName)){ @@ -829,7 +829,7 @@ function mod_view_board($boardName, $page_no = 1) { echo Element('index.html', $page); } -function mod_view_thread($boardName, $thread) { +function mod_view_thread(Context $ctx, $boardName, $thread) { global $config, $mod; if (!openBoard($boardName)) @@ -839,7 +839,7 @@ function mod_view_thread($boardName, $thread) { echo $page; } -function mod_view_thread50($boardName, $thread) { +function mod_view_thread50(Context $ctx, $boardName, $thread) { global $config, $mod; if (!openBoard($boardName)) @@ -849,7 +849,7 @@ function mod_view_thread50($boardName, $thread) { echo $page; } -function mod_ip_remove_note($ip, $id) { +function mod_ip_remove_note(Context $ctx, $ip, $id) { global $config, $mod; if (!hasPermission($config['mod']['remove_notes'])) @@ -868,7 +868,7 @@ function mod_ip_remove_note($ip, $id) { header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); } -function mod_ip($ip, string $encoded_cursor = '') { +function mod_ip(Context $ctx, $ip, string $encoded_cursor = '') { global $config, $mod; if (filter_var($ip, FILTER_VALIDATE_IP) === false) @@ -1078,7 +1078,7 @@ function mod_ban() { header('Location: ?/', true, $config['redirect_http']); } -function mod_warning() { +function mod_warning(Context $ctx) { global $config; if (!hasPermission($config['mod']['warning'])) @@ -1095,7 +1095,7 @@ function mod_warning() { header('Location: ?/', true, $config['redirect_http']); } -function mod_bans() { +function mod_bans(Context $ctx) { global $config; global $mod; @@ -1130,7 +1130,7 @@ function mod_bans() { )); } -function mod_bans_json() { +function mod_bans_json(Context $ctx) { global $config, $mod; if (!hasPermission($config['mod']['ban'])) @@ -1142,7 +1142,7 @@ function mod_bans_json() { Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); } -function mod_ban_appeals() { +function mod_ban_appeals(Context $ctx) { global $config, $board; if (!hasPermission($config['mod']['view_ban_appeals'])) @@ -1224,7 +1224,7 @@ function mod_ban_appeals() { )); } -function mod_lock($board, $unlock, $post) { +function mod_lock(Context $ctx, $board, $unlock, $post) { global $config; if (!openBoard($board)) @@ -1260,7 +1260,7 @@ function mod_lock($board, $unlock, $post) { event('lock', $post); } -function mod_sticky($board, $unsticky, $post) { +function mod_sticky(Context $ctx, $board, $unsticky, $post) { global $config; if (!openBoard($board)) @@ -1284,7 +1284,7 @@ function mod_sticky($board, $unsticky, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } -function mod_cycle($board, $uncycle, $post) { +function mod_cycle(Context $ctx, $board, $uncycle, $post) { global $config; if (!openBoard($board)) @@ -1306,7 +1306,7 @@ function mod_cycle($board, $uncycle, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } -function mod_bumplock($board, $unbumplock, $post) { +function mod_bumplock(Context $ctx, $board, $unbumplock, $post) { global $config; if (!openBoard($board)) @@ -1328,8 +1328,8 @@ function mod_bumplock($board, $unbumplock, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } -function mod_move_reply($originBoard, $postID) { - global $board, $config, $mod; +function mod_move_reply(Context $ctx, $originBoard, $postID) { + global $board, $config; if (!openBoard($originBoard)) error($config['error']['noboard']); @@ -1432,8 +1432,8 @@ function mod_move_reply($originBoard, $postID) { } -function mod_move($originBoard, $postID) { - global $board, $config, $mod, $pdo; +function mod_move(Context $ctx, $originBoard, $postID) { + global $board, $config, $pdo; if (!openBoard($originBoard)) error($config['error']['noboard']); @@ -1657,8 +1657,9 @@ function mod_merge($originBoard, $postID) { $query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL', $originBoard)); $query->bindValue(':id', $postID); $query->execute() or error(db_error($query)); - if (!$post = $query->fetch(PDO::FETCH_ASSOC)) + if (!$post = $query->fetch(PDO::FETCH_ASSOC)) { error($config['error']['404']); + } $sourceOp = ""; if ($post['thread']){ $sourceOp = $post['thread']; @@ -1886,7 +1887,7 @@ function mod_merge($originBoard, $postID) { mod_page(_('Merge thread'), 'mod/merge.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); } -function mod_ban_post($board, $delete, $post, $token = false) { +function mod_ban_post(Context $ctx, $board, $delete, $post, $token = false) { global $config, $mod; if (!openBoard($board)) @@ -1998,7 +1999,7 @@ function mod_ban_post($board, $delete, $post, $token = false) { 'board' => $board, 'delete' => (bool)$delete, 'boards' => listBoards(), - 'reasons' => $config['ban_reasons'], + 'reasons' => $config['ban_reasons'], 'token' => $security_token ); @@ -2009,7 +2010,7 @@ function mod_ban_post($board, $delete, $post, $token = false) { mod_page(_('New ban'), 'mod/ban_form.html', $args); } -function mod_warning_post($board,$post, $token = false) { +function mod_warning_post(Context $ctx, $board, $post, $token = false) { global $config, $mod; if (!openBoard($board)) @@ -2109,8 +2110,8 @@ function mod_warning_post($board,$post, $token = false) { mod_page(_('New warning'), 'mod/warning_form.html', $args); } -function mod_edit_post($board, $edit_raw_html, $postID) { - global $config, $mod; +function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) { + global $config; if (!openBoard($board)) error($config['error']['noboard']); @@ -2186,8 +2187,8 @@ function mod_edit_post($board, $edit_raw_html, $postID) { } } -function mod_delete($board, $post) { - global $config, $mod; +function mod_delete(Context $ctx, $board, $post) { + global $config; if (!openBoard($board)) error($config['error']['noboard']); @@ -2252,8 +2253,8 @@ function mod_delete($board, $post) { } } -function mod_deletefile($board, $post, $file) { - global $config, $mod; +function mod_deletefile(Context $ctx, $board, $post, $file) { + global $config; if (!openBoard($board)) error($config['error']['noboard']); @@ -2275,8 +2276,8 @@ function mod_deletefile($board, $post, $file) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } -function mod_spoiler_image($board, $post, $file) { - global $config, $mod; +function mod_spoiler_image(Context $ctx, $board, $post, $file) { + global $config; if (!openBoard($board)) error($config['error']['noboard']); @@ -2320,8 +2321,8 @@ function mod_spoiler_image($board, $post, $file) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } -function mod_deletebyip($boardName, $post, $global = false) { - global $config, $mod, $board; +function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) { + global $config, $board; $global = (bool)$global; @@ -2442,7 +2443,7 @@ function mod_deletebyip($boardName, $post, $global = false) { header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } -function mod_user($uid) { +function mod_user(Context $ctx, $uid) { global $config, $mod; if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id'])) @@ -2567,7 +2568,7 @@ function mod_user($uid) { )); } -function mod_user_new() { +function mod_user_new(Context $ctx) { global $pdo, $config; if (!hasPermission($config['mod']['createusers'])) @@ -2620,7 +2621,7 @@ function mod_user_new() { } -function mod_users() { +function mod_users(Context $ctx) { global $config; if (!hasPermission($config['mod']['manageusers'])) @@ -2641,7 +2642,7 @@ function mod_users() { mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), 'mod/users.html', array('users' => $users)); } -function mod_user_promote($uid, $action) { +function mod_user_promote(Context $ctx, $uid, $action) { global $config; if (!hasPermission($config['mod']['promoteusers'])) @@ -2684,7 +2685,7 @@ function mod_user_promote($uid, $action) { header('Location: ?/users', true, $config['redirect_http']); } -function mod_pm($id, $reply = false) { +function mod_pm(Context $ctx, $id, $reply = false) { global $mod, $config; if ($reply && !hasPermission($config['mod']['create_pm'])) @@ -2739,7 +2740,7 @@ function mod_pm($id, $reply = false) { } } -function mod_inbox() { +function mod_inbox(Context $ctx) { 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'); @@ -2763,7 +2764,7 @@ function mod_inbox() { } -function mod_new_pm($username) { +function mod_new_pm(Context $ctx, $username) { global $config, $mod; if (!hasPermission($config['mod']['create_pm'])) @@ -2811,7 +2812,7 @@ function mod_new_pm($username) { )); } -function mod_rebuild() { +function mod_rebuild(Context $ctx) { global $config, $twig; if (!hasPermission($config['mod']['rebuild'])) @@ -2883,7 +2884,7 @@ function mod_rebuild() { )); } -function mod_reports() { +function mod_reports(Context $ctx) { global $config, $mod; if (!hasPermission($config['mod']['reports'])) @@ -2987,7 +2988,7 @@ function mod_reports() { ); } -function mod_report_dismiss($id, $all = false) { +function mod_report_dismiss(Context $ctx, $id, $all = false) { global $config; $query = prepare("SELECT `post`, `board`, `ip` FROM ``reports`` WHERE `id` = :id"); @@ -3024,7 +3025,7 @@ function mod_report_dismiss($id, $all = false) { header('Location: ?/reports', true, $config['redirect_http']); } -function mod_recent_posts($lim,$board_list = false,$json=false) { +function mod_recent_posts(Context $ctx, $lim, $board_list = false, $json = false) { global $config, $mod, $pdo; if (!hasPermission($config['mod']['recent'])) @@ -3122,7 +3123,7 @@ function mod_recent_posts($lim,$board_list = false,$json=false) { } } -function mod_config($board_config = false) { +function mod_config(Context $ctx, $board_config = false) { global $config, $mod, $board; if ($board_config && !openBoard($board_config)) @@ -3262,7 +3263,7 @@ function mod_config($board_config = false) { )); } -function mod_themes_list() { +function mod_themes_list(Context $ctx) { global $config; if (!hasPermission($config['mod']['themes'])) @@ -3296,7 +3297,7 @@ function mod_themes_list() { )); } -function mod_theme_configure($theme_name) { +function mod_theme_configure(Context $ctx, $theme_name) { global $config; if (!hasPermission($config['mod']['themes'])) @@ -3378,7 +3379,7 @@ function mod_theme_configure($theme_name) { )); } -function mod_theme_uninstall($theme_name) { +function mod_theme_uninstall(Context $ctx, $theme_name) { global $config; if (!hasPermission($config['mod']['themes'])) @@ -3395,7 +3396,7 @@ function mod_theme_uninstall($theme_name) { header('Location: ?/themes', true, $config['redirect_http']); } -function mod_theme_rebuild($theme_name) { +function mod_theme_rebuild(Context $ctx, $theme_name) { global $config; if (!hasPermission($config['mod']['themes'])) @@ -3436,15 +3437,15 @@ function delete_page_base($page = '', $board = false) { header('Location: ?/edit_pages' . ($board ? ('/' . $board) : ''), true, $config['redirect_http']); } -function mod_delete_page($page = '') { - delete_page_base($page); +function mod_delete_page(Context $ctx, $page = '') { + delete_page_base($ctx, $page); } -function mod_delete_page_board($page = '', $board = false) { - delete_page_base($page, $board); +function mod_delete_page_board(Context $ctx, $page = '', $board = false) { + delete_page_base($ctx, $page, $board); } -function mod_edit_page($id) { +function mod_edit_page(Context $ctx, $id) { global $config, $mod, $board; $query = prepare('SELECT * FROM ``pages`` WHERE `id` = :id'); @@ -3515,7 +3516,7 @@ function mod_edit_page($id) { mod_page(sprintf(_('Editing static page: %s'), $page['name']), 'mod/edit_page.html', array('page' => $page, 'token' => make_secure_link_token("edit_page/$id"), 'content' => prettify_textarea($content), 'board' => $board)); } -function mod_pages($board = false) { +function mod_pages(Context $ctx, $board = false) { global $config, $mod, $pdo; if (empty($board)) @@ -3569,7 +3570,7 @@ function mod_pages($board = false) { mod_page(_('Pages'), 'mod/pages.html', array('pages' => $pages, 'token' => make_secure_link_token('edit_pages' . ($board ? ('/' . $board) : '')), 'board' => $board)); } -function mod_debug_antispam() { +function mod_debug_antispam(Context $ctx) { global $pdo, $config; $args = []; @@ -3606,7 +3607,7 @@ function mod_debug_antispam() { mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args); } -function mod_debug_recent_posts() { +function mod_debug_recent_posts(Context $ctx) { global $pdo, $config; $limit = 500; @@ -3640,7 +3641,7 @@ function mod_debug_recent_posts() { mod_page(_('Debug: Recent posts'), 'mod/debug/recent_posts.html', array('posts' => $posts, 'flood_posts' => $flood_posts)); } -function mod_debug_sql() { +function mod_debug_sql(Context $ctx) { global $config; if (!hasPermission($config['mod']['debug_sql'])) diff --git a/mod.php b/mod.php index b799857a..220ebf02 100644 --- a/mod.php +++ b/mod.php @@ -148,9 +148,11 @@ foreach ($pages as $key => $callback) { } $pages = $new_pages; +$ctx = Vichan\build_context($config); + foreach ($pages as $uri => $handler) { if (preg_match($uri, $query, $matches)) { - $matches = array_slice($matches, 1); + $matches[0] = $ctx; // Replace the text captured by the full pattern with a reference to the context. if (isset($matches['board'])) { $board_match = $matches['board'];