mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-28 09:20:58 +01:00
Merge pull request #796 from Zankaria/mod-use-di
Add the context dependency injection container to the mod pages
This commit is contained in:
commit
84a3bedd18
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2013 Tinyboard Development Group
|
||||
*/
|
||||
use Vichan\Context;
|
||||
use Vichan\Functions\Format;
|
||||
|
||||
use Vichan\Functions\Net;
|
||||
@ -30,8 +30,8 @@ function mod_page($title, $template, $args, $subtitle = false) {
|
||||
);
|
||||
}
|
||||
|
||||
function mod_login($redirect = false) {
|
||||
global $config;
|
||||
function mod_login(Context $ctx, $redirect = false) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$args = [];
|
||||
|
||||
@ -67,22 +67,23 @@ function mod_login($redirect = false) {
|
||||
mod_page(_('Login'), $config['file_mod_login'], $args);
|
||||
}
|
||||
|
||||
function mod_confirm($request) {
|
||||
global $config;
|
||||
function mod_confirm(Context $ctx, $request) {
|
||||
$config = $ctx->get('config');
|
||||
mod_page(_('Confirm action'), $config['file_mod_confim'], array('request' => $request, 'token' => make_secure_link_token($request)));
|
||||
}
|
||||
|
||||
function mod_logout() {
|
||||
global $config;
|
||||
function mod_logout(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
destroyCookies();
|
||||
|
||||
header('Location: ?/', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_dashboard() {
|
||||
global $config, $mod;
|
||||
function mod_dashboard(Context $ctx) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$args = array();
|
||||
$args = [];
|
||||
|
||||
$args['boards'] = listBoards();
|
||||
|
||||
@ -173,8 +174,8 @@ function mod_dashboard() {
|
||||
mod_page(_('Dashboard'), $config['file_mod_dashboard'], $args);
|
||||
}
|
||||
|
||||
function mod_search_redirect() {
|
||||
global $config;
|
||||
function mod_search_redirect(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['search']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -196,7 +197,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']))
|
||||
@ -222,7 +223,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
|
||||
$query = str_replace('`', '!`', $query);
|
||||
|
||||
// Array of phrases to match
|
||||
$match = array();
|
||||
$match = [];
|
||||
|
||||
// Exact phrases ("like this")
|
||||
if (preg_match_all('/"(.+?)"/', $query, $exact_phrases)) {
|
||||
@ -351,7 +352,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))
|
||||
@ -453,8 +454,9 @@ function mod_edit_board($boardName) {
|
||||
}
|
||||
}
|
||||
|
||||
function mod_new_board() {
|
||||
global $config, $board;
|
||||
function mod_new_board(Context $ctx) {
|
||||
global $board;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['newboard']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -522,8 +524,9 @@ function mod_new_board() {
|
||||
mod_page(_('New board'), $config['file_mod_board'], array('new' => true, 'token' => make_secure_link_token('new-board')));
|
||||
}
|
||||
|
||||
function mod_noticeboard($page_no = 1) {
|
||||
global $config, $pdo, $mod;
|
||||
function mod_noticeboard(Context $ctx, $page_no = 1) {
|
||||
global $pdo, $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($page_no < 1)
|
||||
error($config['error']['404']);
|
||||
@ -577,8 +580,8 @@ function mod_noticeboard($page_no = 1) {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_noticeboard_delete($id) {
|
||||
global $config;
|
||||
function mod_noticeboard_delete(Context $ctx, $id) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['noticeboard_delete']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -595,8 +598,9 @@ function mod_noticeboard_delete($id) {
|
||||
header('Location: ?/noticeboard', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_news($page_no = 1) {
|
||||
global $config, $pdo, $mod;
|
||||
function mod_news(Context $ctx, $page_no = 1) {
|
||||
global $pdo, $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($page_no < 1)
|
||||
error($config['error']['404']);
|
||||
@ -642,8 +646,8 @@ function mod_news($page_no = 1) {
|
||||
mod_page(_('News'), $config['file_mod_news'], array('news' => $news, 'count' => $count, 'token' => make_secure_link_token('edit_news')));
|
||||
}
|
||||
|
||||
function mod_news_delete($id) {
|
||||
global $config;
|
||||
function mod_news_delete(Context $ctx, $id) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['news_delete']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -657,8 +661,8 @@ function mod_news_delete($id) {
|
||||
header('Location: ?/edit_news', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_log($page_no = 1) {
|
||||
global $config;
|
||||
function mod_log(Context $ctx, $page_no = 1) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($page_no < 1)
|
||||
error($config['error']['404']);
|
||||
@ -682,8 +686,8 @@ function mod_log($page_no = 1) {
|
||||
mod_page(_('Moderation log'), $config['file_mod_log'], array('logs' => $logs, 'count' => $count));
|
||||
}
|
||||
|
||||
function mod_user_log($username, $page_no = 1) {
|
||||
global $config;
|
||||
function mod_user_log(Context $ctx, $username, $page_no = 1) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($page_no < 1)
|
||||
error($config['error']['404']);
|
||||
@ -709,8 +713,8 @@ function mod_user_log($username, $page_no = 1) {
|
||||
mod_page(_('Moderation log'), $config['file_mod_log'], array('logs' => $logs, 'count' => $count, 'username' => $username));
|
||||
}
|
||||
|
||||
function mod_board_log($board, $page_no = 1, $hide_names = false, $public = false) {
|
||||
global $config;
|
||||
function mod_board_log(Context $ctx, $board, $page_no = 1, $hide_names = false, $public = false) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($page_no < 1)
|
||||
error($config['error']['404']);
|
||||
@ -745,10 +749,10 @@ function mod_board_log($board, $page_no = 1, $hide_names = false, $public = fals
|
||||
mod_page(_('Board log'), $config['file_mod_log'], 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) {
|
||||
$config = $ctx->get('config');
|
||||
require_once($config['dir']['themes'].'/catalog/theme.php');
|
||||
$settings = array();
|
||||
$settings = [];
|
||||
$settings['boards'] = $boardName;
|
||||
$settings['update_on_posts'] = true;
|
||||
$settings['title'] = 'Catalog';
|
||||
@ -757,8 +761,9 @@ function mod_view_catalog($boardName) {
|
||||
echo $catalog->build($settings, $boardName, true);
|
||||
}
|
||||
|
||||
function mod_view_board($boardName, $page_no = 1) {
|
||||
global $config, $mod;
|
||||
function mod_view_board(Context $ctx, $boardName, $page_no = 1) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($boardName))
|
||||
error($config['error']['noboard']);
|
||||
@ -776,8 +781,9 @@ function mod_view_board($boardName, $page_no = 1) {
|
||||
echo Element($config['file_board_index'], $page);
|
||||
}
|
||||
|
||||
function mod_view_thread($boardName, $thread) {
|
||||
global $config, $mod;
|
||||
function mod_view_thread(Context $ctx, $boardName, $thread) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($boardName))
|
||||
error($config['error']['noboard']);
|
||||
@ -786,8 +792,9 @@ function mod_view_thread($boardName, $thread) {
|
||||
echo $page;
|
||||
}
|
||||
|
||||
function mod_view_thread50($boardName, $thread) {
|
||||
global $config, $mod;
|
||||
function mod_view_thread50(Context $ctx, $boardName, $thread) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($boardName))
|
||||
error($config['error']['noboard']);
|
||||
@ -796,9 +803,9 @@ function mod_view_thread50($boardName, $thread) {
|
||||
echo $page;
|
||||
}
|
||||
|
||||
function mod_ip_remove_note($cloaked_ip, $id) {
|
||||
function mod_ip_remove_note(Context $ctx, $cloaked_ip, $id) {
|
||||
$ip = uncloak_ip($cloaked_ip);
|
||||
global $config, $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['remove_notes']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -818,9 +825,10 @@ function mod_ip_remove_note($cloaked_ip, $id) {
|
||||
|
||||
|
||||
|
||||
function mod_ip($cip) {
|
||||
function mod_ip(Context $ctx, $cip) {
|
||||
$ip = uncloak_ip($cip);
|
||||
global $config, $mod;
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
|
||||
error("Invalid IP address.");
|
||||
@ -863,9 +871,9 @@ function mod_ip($cip) {
|
||||
}
|
||||
|
||||
|
||||
$args = array();
|
||||
$args = [];
|
||||
$args['ip'] = $ip;
|
||||
$args['posts'] = array();
|
||||
$args['posts'] = [];
|
||||
|
||||
if ($config['mod']['dns_lookup'] && empty($config['ipcrypt_key']))
|
||||
$args['hostname'] = rDNS($ip);
|
||||
@ -888,7 +896,7 @@ function mod_ip($cip) {
|
||||
}
|
||||
|
||||
if (!isset($args['posts'][$board['uri']]))
|
||||
$args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
|
||||
$args['posts'][$board['uri']] = array('board' => $board, 'posts' => []);
|
||||
$args['posts'][$board['uri']]['posts'][] = $po->build(true);
|
||||
}
|
||||
}
|
||||
@ -913,7 +921,7 @@ function mod_ip($cip) {
|
||||
$query->execute() or error(db_error($query));
|
||||
$args['logs'] = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
$args['logs'] = array();
|
||||
$args['logs'] = [];
|
||||
}
|
||||
|
||||
$args['security_token'] = make_secure_link_token('IP/' . $cip);
|
||||
@ -921,8 +929,8 @@ function mod_ip($cip) {
|
||||
mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($cip)), $config['file_mod_view_ip'], $args, $args['hostname']);
|
||||
}
|
||||
|
||||
function mod_edit_ban($ban_id) {
|
||||
global $mod, $config;
|
||||
function mod_edit_ban(Context $ctx, $ban_id) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['edit_ban']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -971,9 +979,8 @@ function mod_edit_ban($ban_id) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function mod_ban() {
|
||||
global $config;
|
||||
function mod_ban(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['ban']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -991,9 +998,9 @@ function mod_ban() {
|
||||
header('Location: ?/', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_bans() {
|
||||
global $config;
|
||||
function mod_bans(Context $ctx) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['view_banlist']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -1002,7 +1009,7 @@ function mod_bans() {
|
||||
if (!hasPermission($config['mod']['unban']))
|
||||
error($config['error']['noaccess']);
|
||||
|
||||
$unban = array();
|
||||
$unban = [];
|
||||
foreach ($_POST as $name => $unused) {
|
||||
if (preg_match('/^ban_(\d+)$/', $name, $match))
|
||||
$unban[] = $match[1];
|
||||
@ -1026,8 +1033,9 @@ function mod_bans() {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_bans_json() {
|
||||
global $config, $mod;
|
||||
function mod_bans_json(Context $ctx) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['ban']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -1038,8 +1046,9 @@ function mod_bans_json() {
|
||||
Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']);
|
||||
}
|
||||
|
||||
function mod_ban_appeals() {
|
||||
global $config, $board;
|
||||
function mod_ban_appeals(Context $ctx) {
|
||||
global $board;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['view_ban_appeals']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -1085,16 +1094,16 @@ function mod_ban_appeals() {
|
||||
$query = query(sprintf("SELECT `num_files`, `files` FROM ``posts_%s`` WHERE `id` = " .
|
||||
(int)$ban['post']['id'], $board['uri']));
|
||||
if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$_post['files'] = $_post['files'] ? json_decode($_post['files']) : array();
|
||||
$_post['files'] = $_post['files'] ? json_decode($_post['files']) : [];
|
||||
$ban['post'] = array_merge($ban['post'], $_post);
|
||||
} else {
|
||||
$ban['post']['files'] = array(array());
|
||||
$ban['post']['files'] = array([]);
|
||||
$ban['post']['files'][0]['file'] = 'deleted';
|
||||
$ban['post']['files'][0]['thumb'] = false;
|
||||
$ban['post']['num_files'] = 1;
|
||||
}
|
||||
} else {
|
||||
$ban['post']['files'] = array(array());
|
||||
$ban['post']['files'] = array([]);
|
||||
$ban['post']['files'][0]['file'] = 'deleted';
|
||||
$ban['post']['files'][0]['thumb'] = false;
|
||||
$ban['post']['num_files'] = 1;
|
||||
@ -1114,8 +1123,8 @@ function mod_ban_appeals() {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_lock($board, $unlock, $post) {
|
||||
global $config;
|
||||
function mod_lock(Context $ctx, $board, $unlock, $post) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1148,8 +1157,8 @@ function mod_lock($board, $unlock, $post) {
|
||||
event('lock', $post);
|
||||
}
|
||||
|
||||
function mod_sticky($board, $unsticky, $post) {
|
||||
global $config;
|
||||
function mod_sticky(Context $ctx, $board, $unsticky, $post) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1170,8 +1179,8 @@ 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) {
|
||||
global $config;
|
||||
function mod_cycle(Context $ctx, $board, $uncycle, $post) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1192,8 +1201,8 @@ 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) {
|
||||
global $config;
|
||||
function mod_bumplock(Context $ctx, $board, $unbumplock, $post) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1214,8 +1223,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']);
|
||||
@ -1316,8 +1325,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']);
|
||||
@ -1386,7 +1395,7 @@ function mod_move($originBoard, $postID) {
|
||||
$query->bindValue(':id', $postID, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$replies = array();
|
||||
$replies = [];
|
||||
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$post['mod'] = true;
|
||||
@ -1450,7 +1459,7 @@ function mod_move($originBoard, $postID) {
|
||||
|
||||
|
||||
if (!empty($post['tracked_cites'])) {
|
||||
$insert_rows = array();
|
||||
$insert_rows = [];
|
||||
foreach ($post['tracked_cites'] as $cite) {
|
||||
$insert_rows[] = '(' .
|
||||
$pdo->quote($board['uri']) . ', ' . $newPostID . ', ' .
|
||||
@ -1526,8 +1535,8 @@ function mod_move($originBoard, $postID) {
|
||||
mod_page(_('Move thread'), $config['file_mod_move'], array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token));
|
||||
}
|
||||
|
||||
function mod_ban_post($board, $delete, $post, $token = false) {
|
||||
global $config, $mod;
|
||||
function mod_ban_post(Context $ctx, $board, $delete, $post, $token = false) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1596,8 +1605,8 @@ function mod_ban_post($board, $delete, $post, $token = false) {
|
||||
mod_page(_('New ban'), $config['file_mod_ban_form'], $args);
|
||||
}
|
||||
|
||||
function mod_edit_post($board, $edit_raw_html, $postID) {
|
||||
global $config, $mod;
|
||||
function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1673,8 +1682,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) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1694,8 +1703,8 @@ function mod_delete($board, $post) {
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_deletefile($board, $post, $file) {
|
||||
global $config, $mod;
|
||||
function mod_deletefile(Context $ctx, $board, $post, $file) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1717,8 +1726,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) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
@ -1762,8 +1771,9 @@ 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 $board;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$global = (bool)$global;
|
||||
|
||||
@ -1800,8 +1810,8 @@ function mod_deletebyip($boardName, $post, $global = false) {
|
||||
|
||||
@set_time_limit($config['mod']['rebuild_timelimit']);
|
||||
|
||||
$threads_to_rebuild = array();
|
||||
$threads_deleted = array();
|
||||
$threads_to_rebuild = [];
|
||||
$threads_deleted = [];
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
openBoard($post['board']);
|
||||
|
||||
@ -1838,8 +1848,9 @@ 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) {
|
||||
global $config, $mod;
|
||||
function mod_user(Context $ctx, $uid) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -1859,7 +1870,7 @@ function mod_user($uid) {
|
||||
$board = $board['uri'];
|
||||
}
|
||||
|
||||
$boards = array();
|
||||
$boards = [];
|
||||
foreach ($_POST as $name => $value) {
|
||||
if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
|
||||
$boards[] = $matches[1];
|
||||
@ -1950,7 +1961,7 @@ function mod_user($uid) {
|
||||
$query->execute() or error(db_error($query));
|
||||
$log = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
$log = array();
|
||||
$log = [];
|
||||
}
|
||||
|
||||
$user['boards'] = explode(',', $user['boards']);
|
||||
@ -1963,7 +1974,7 @@ function mod_user($uid) {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_user_new() {
|
||||
function mod_user_new(Context $ctx) {
|
||||
global $pdo, $config;
|
||||
|
||||
if (!hasPermission($config['mod']['createusers']))
|
||||
@ -1983,7 +1994,7 @@ function mod_user_new() {
|
||||
$board = $board['uri'];
|
||||
}
|
||||
|
||||
$boards = array();
|
||||
$boards = [];
|
||||
foreach ($_POST as $name => $value) {
|
||||
if (preg_match('/^board_(' . $config['board_regex'] . ')$/u', $name, $matches) && in_array($matches[1], $_boards))
|
||||
$boards[] = $matches[1];
|
||||
@ -2016,8 +2027,8 @@ function mod_user_new() {
|
||||
}
|
||||
|
||||
|
||||
function mod_users() {
|
||||
global $config;
|
||||
function mod_users(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['manageusers']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2037,8 +2048,8 @@ function mod_users() {
|
||||
mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), $config['file_mod_users'], array('users' => $users));
|
||||
}
|
||||
|
||||
function mod_user_promote($uid, $action) {
|
||||
global $config;
|
||||
function mod_user_promote(Context $ctx, $uid, $action) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['promoteusers']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2080,7 +2091,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']))
|
||||
@ -2135,8 +2146,9 @@ function mod_pm($id, $reply = false) {
|
||||
}
|
||||
}
|
||||
|
||||
function mod_inbox() {
|
||||
global $config, $mod;
|
||||
function mod_inbox(Context $ctx) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$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']);
|
||||
@ -2159,8 +2171,9 @@ function mod_inbox() {
|
||||
}
|
||||
|
||||
|
||||
function mod_new_pm($username) {
|
||||
global $config, $mod;
|
||||
function mod_new_pm(Context $ctx, $username) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['create_pm']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2207,8 +2220,9 @@ function mod_new_pm($username) {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_rebuild() {
|
||||
global $config, $twig;
|
||||
function mod_rebuild(Context $ctx) {
|
||||
global $twig;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['rebuild']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2216,9 +2230,9 @@ function mod_rebuild() {
|
||||
if (isset($_POST['rebuild'])) {
|
||||
@set_time_limit($config['mod']['rebuild_timelimit']);
|
||||
|
||||
$log = array();
|
||||
$log = [];
|
||||
$boards = listBoards();
|
||||
$rebuilt_scripts = array();
|
||||
$rebuilt_scripts = [];
|
||||
|
||||
if (isset($_POST['rebuild_cache'])) {
|
||||
if ($config['cache']['enabled']) {
|
||||
@ -2279,8 +2293,9 @@ function mod_rebuild() {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_reports() {
|
||||
global $config, $mod;
|
||||
function mod_reports(Context $ctx) {
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['reports']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2290,16 +2305,16 @@ function mod_reports() {
|
||||
$query->execute() or error(db_error($query));
|
||||
$reports = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$report_queries = array();
|
||||
$report_queries = [];
|
||||
foreach ($reports as $report) {
|
||||
if (!isset($report_queries[$report['board']]))
|
||||
$report_queries[$report['board']] = array();
|
||||
$report_queries[$report['board']] = [];
|
||||
$report_queries[$report['board']][] = $report['post'];
|
||||
}
|
||||
|
||||
$report_posts = array();
|
||||
$report_posts = [];
|
||||
foreach ($report_queries as $board => $posts) {
|
||||
$report_posts[$board] = array();
|
||||
$report_posts[$board] = [];
|
||||
|
||||
$query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
@ -2362,8 +2377,8 @@ function mod_reports() {
|
||||
mod_page(sprintf('%s (%d)', _('Report queue'), $count), $config['file_mod_reports'], array('reports' => $body, 'count' => $count));
|
||||
}
|
||||
|
||||
function mod_report_dismiss($id, $action) {
|
||||
global $config;
|
||||
function mod_report_dismiss(Context $ctx, $id, $action) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$query = prepare("SELECT `post`, `board`, `ip` FROM ``reports`` WHERE `id` = :id");
|
||||
$query->bindValue(':id', $id);
|
||||
@ -2408,8 +2423,9 @@ function mod_report_dismiss($id, $action) {
|
||||
header('Location: ?/reports', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_recent_posts($lim) {
|
||||
global $config, $mod, $pdo;
|
||||
function mod_recent_posts(Context $ctx, $lim) {
|
||||
global $mod, $pdo;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['recent']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2417,7 +2433,7 @@ function mod_recent_posts($lim) {
|
||||
$limit = (is_numeric($lim))? $lim : 25;
|
||||
$last_time = (isset($_GET['last']) && is_numeric($_GET['last'])) ? $_GET['last'] : 0;
|
||||
|
||||
$mod_boards = array();
|
||||
$mod_boards = [];
|
||||
$boards = listBoards();
|
||||
|
||||
//if not all boards
|
||||
@ -2464,8 +2480,9 @@ function mod_recent_posts($lim) {
|
||||
|
||||
}
|
||||
|
||||
function mod_config($board_config = false) {
|
||||
global $config, $mod, $board;
|
||||
function mod_config(Context $ctx, $board_config = false) {
|
||||
global $mod, $board;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if ($board_config && !openBoard($board_config))
|
||||
error($config['error']['noboard']);
|
||||
@ -2576,7 +2593,7 @@ function mod_config($board_config = false) {
|
||||
|
||||
if ($config['minify_html'])
|
||||
$config_append = str_replace("\n", '
', $config_append);
|
||||
$page = array();
|
||||
$page = [];
|
||||
$page['title'] = 'Cannot write to file!';
|
||||
$page['config'] = $config;
|
||||
$page['body'] = '
|
||||
@ -2604,8 +2621,8 @@ function mod_config($board_config = false) {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_themes_list() {
|
||||
global $config;
|
||||
function mod_themes_list(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2619,7 +2636,7 @@ function mod_themes_list() {
|
||||
$themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Scan directory for themes
|
||||
$themes = array();
|
||||
$themes = [];
|
||||
while ($file = readdir($dir)) {
|
||||
if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) {
|
||||
$themes[$file] = Vichan\Functions\Theme\load_theme_config($file);
|
||||
@ -2638,8 +2655,8 @@ function mod_themes_list() {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_theme_configure($theme_name) {
|
||||
global $config;
|
||||
function mod_theme_configure(Context $ctx, $theme_name) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2720,8 +2737,8 @@ function mod_theme_configure($theme_name) {
|
||||
));
|
||||
}
|
||||
|
||||
function mod_theme_uninstall($theme_name) {
|
||||
global $config;
|
||||
function mod_theme_uninstall(Context $ctx, $theme_name) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2737,8 +2754,8 @@ function mod_theme_uninstall($theme_name) {
|
||||
header('Location: ?/themes', true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_theme_rebuild($theme_name) {
|
||||
global $config;
|
||||
function mod_theme_rebuild(Context $ctx, $theme_name) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['themes']))
|
||||
error($config['error']['noaccess']);
|
||||
@ -2778,16 +2795,17 @@ 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) {
|
||||
global $config, $mod, $board;
|
||||
function mod_edit_page(Context $ctx, $id) {
|
||||
global $mod, $board;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$query = prepare('SELECT * FROM ``pages`` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $id);
|
||||
@ -2857,8 +2875,9 @@ function mod_edit_page($id) {
|
||||
mod_page(sprintf(_('Editing static page: %s'), $page['name']), $config['file_mod_edit_page'], array('page' => $page, 'token' => make_secure_link_token("edit_page/$id"), 'content' => prettify_textarea($content), 'board' => $board));
|
||||
}
|
||||
|
||||
function mod_pages($board = false) {
|
||||
global $config, $mod, $pdo;
|
||||
function mod_pages(Context $ctx, $board = false) {
|
||||
global $mod, $pdo;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (empty($board))
|
||||
$board = false;
|
||||
@ -2911,10 +2930,10 @@ function mod_pages($board = false) {
|
||||
mod_page(_('Pages'), $config['file_mod_pages'], 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 = array();
|
||||
$args = [];
|
||||
|
||||
if (isset($_POST['board'], $_POST['thread'])) {
|
||||
$where = '`board` = ' . $pdo->quote($_POST['board']);
|
||||
@ -2948,7 +2967,7 @@ function mod_debug_antispam() {
|
||||
mod_page(_('Debug: Anti-spam'), $config['file_mod_debug_antispam'], $args);
|
||||
}
|
||||
|
||||
function mod_debug_recent_posts() {
|
||||
function mod_debug_recent_posts(Context $ctx) {
|
||||
global $pdo, $config;
|
||||
|
||||
$limit = 500;
|
||||
@ -2982,8 +3001,8 @@ function mod_debug_recent_posts() {
|
||||
mod_page(_('Debug: Recent posts'), $config['file_mod_debug_recent_posts'], array('posts' => $posts, 'flood_posts' => $flood_posts));
|
||||
}
|
||||
|
||||
function mod_debug_sql() {
|
||||
global $config;
|
||||
function mod_debug_sql(Context $ctx) {
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['debug_sql']))
|
||||
error($config['error']['noaccess']);
|
||||
|
28
mod.php
28
mod.php
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014 Tinyboard Development Group
|
||||
*/
|
||||
|
||||
require_once 'inc/bootstrap.php';
|
||||
|
||||
if ($config['debug'])
|
||||
if ($config['debug']) {
|
||||
$parse_start_time = microtime(true);
|
||||
}
|
||||
|
||||
require_once 'inc/mod/pages.php';
|
||||
|
||||
@ -15,7 +15,7 @@ check_login(true);
|
||||
|
||||
$query = isset($_SERVER['QUERY_STRING']) ? rawurldecode($_SERVER['QUERY_STRING']) : '';
|
||||
|
||||
$pages = array(
|
||||
$pages = [
|
||||
'' => ':?/', // redirect to dashboard
|
||||
'/' => 'dashboard', // dashboard
|
||||
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
|
||||
@ -109,14 +109,14 @@ $pages = array(
|
||||
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread',
|
||||
|
||||
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
|
||||
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
|
||||
str_replace([ '%d','%s' ], [ '(\d+)', '[a-z0-9-]+' ], preg_quote($config['file_page50_slug'], '!')) => 'view_thread50',
|
||||
'/(\%b)/' . preg_quote($config['dir']['res'], '!') .
|
||||
str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread',
|
||||
);
|
||||
str_replace([ '%d','%s' ], [ '(\d+)', '[a-z0-9-]+' ], preg_quote($config['file_page_slug'], '!')) => 'view_thread',
|
||||
];
|
||||
|
||||
|
||||
if (!$mod) {
|
||||
$pages = array('!^(.+)?$!' => 'login');
|
||||
$pages = [ '!^(.+)?$!' => 'login' ];
|
||||
} elseif (isset($_GET['status'], $_GET['r'])) {
|
||||
header('Location: ' . $_GET['r'], true, (int)$_GET['status']);
|
||||
exit;
|
||||
@ -126,18 +126,21 @@ if (isset($config['mod']['custom_pages'])) {
|
||||
$pages = array_merge($pages, $config['mod']['custom_pages']);
|
||||
}
|
||||
|
||||
$new_pages = array();
|
||||
$new_pages = [];
|
||||
foreach ($pages as $key => $callback) {
|
||||
if (is_string($callback) && preg_match('/^secure /', $callback))
|
||||
if (is_string($callback) && preg_match('/^secure /', $callback)) {
|
||||
$key .= '(/(?P<token>[a-f0-9]{8}))?';
|
||||
}
|
||||
$key = str_replace('\%b', '?P<board>' . sprintf(substr($config['board_path'], 0, -1), $config['board_regex']), $key);
|
||||
$new_pages[(!empty($key) and $key[0] == '!') ? $key : '!^' . $key . '(?:&[^&=]+=[^&]*)*$!u'] = $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'];
|
||||
@ -172,11 +175,11 @@ foreach ($pages as $uri => $handler) {
|
||||
}
|
||||
|
||||
if ($config['debug']) {
|
||||
$debug['mod_page'] = array(
|
||||
$debug['mod_page'] = [
|
||||
'req' => $query,
|
||||
'match' => $uri,
|
||||
'handler' => $handler,
|
||||
);
|
||||
];
|
||||
$debug['time']['parse_mod_req'] = '~' . round((microtime(true) - $parse_start_time) * 1000, 2) . 'ms';
|
||||
}
|
||||
|
||||
@ -204,4 +207,3 @@ foreach ($pages as $uri => $handler) {
|
||||
}
|
||||
|
||||
error($config['error']['404']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user