From 96495504631d6a4d466b93a835d7d66853e2e12b Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 02:11:41 +1000
Subject: start on mod interface rewrite
---
inc/mod/pages.php | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
create mode 100644 inc/mod/pages.php
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
new file mode 100644
index 00000000..9d154181
--- /dev/null
+++ b/inc/mod/pages.php
@@ -0,0 +1,132 @@
+ $config,
+ 'mod' => $mod,
+ 'title' => $title,
+ 'body' => Element($template,
+ array_merge(
+ array('config' => $config, 'mod' => $mod),
+ $args
+ )
+ )
+ )
+ );
+}
+
+function mod_login() {
+ $args = array();
+
+ if (isset($_POST['login'])) {
+ // Check if inputs are set and not empty
+ if (!isset($_POST['username'], $_POST['password']) || $_POST['username'] == '' || $_POST['password'] == '') {
+ $args['error'] = $config['error']['invalid'];
+ } elseif (!login($_POST['username'], $_POST['password'])) {
+ if ($config['syslog'])
+ _syslog(LOG_WARNING, 'Unauthorized login attempt!');
+
+ $args['error'] = $config['error']['invalid'];
+ } else {
+ modLog("Logged in.");
+
+ // Login successful
+ // Set cookies
+ setCookies();
+
+ header('Location: ?/', true, $config['redirect_http']);
+ }
+ }
+
+ if (isset($_POST['username']))
+ $args['username'] = $_POST['username'];
+
+ mod_page('Dashboard', 'mod/login.html', $args);
+}
+
+function mod_dashboard() {
+ $args = array();
+
+ $args['boards'] = listBoards();
+
+ mod_page('Dashboard', 'mod/dashboard.html', $args);
+}
+
+function mod_view_board($boardName, $page_no = 1) {
+ global $config, $mod;
+
+ if (!openBoard($boardName))
+ error($config['error']['noboard']);
+
+ if (!$page = index($page_no, $mod)) {
+ error($config['error']['404']);
+ }
+
+ $page['pages'] = getPages(true);
+ $page['pages'][$page_no-1]['selected'] = true;
+ $page['btn'] = getPageButtons($page['pages'], true);
+ $page['mod'] = true;
+ $page['config'] = $config;
+ echo Element('index.html', $page);
+}
+
+function mod_view_thread($boardName, $thread) {
+ global $config, $mod;
+
+ if (!openBoard($boardName))
+ error($config['error']['noboard']);
+
+ $page = buildThread($thread, true, $mod);
+ echo $page;
+}
+
+function mod_page_ip($ip) {
+ global $config, $mod;
+
+ $args = array();
+ $args['ip'] = $ip;
+ $args['posts'] = array();
+
+ $boards = listBoards();
+ foreach ($boards as $board) {
+ $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri']));
+ $query->bindValue(':ip', $ip);
+ $query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ while ($post = $query->fetch()) {
+ if (!$post['thread']) {
+ $po = new Thread(
+ $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'],
+ $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
+ $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'],
+ $post['sage'], $post['embed'], '?/', $mod, false
+ );
+ } else {
+ $po = new Post(
+ $post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'],
+ $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
+ $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod
+ );
+ }
+
+ if (!isset($args['posts'][$board['uri']]))
+ $args['posts'][$board['uri']] = array();
+ $args['posts'][$board['uri']][] = $po->build(true);
+ }
+ }
+
+ mod_page("IP: $ip", 'mod/view_ip.html', $args);
+}
+
--
cgit v1.3
From 78f3ea783394dba14b51b27f7f2db3974ce8b8b3 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 09:29:08 +1000
Subject: View IP adress page, ban form.
---
inc/mod/ban.php | 77 +++++++++++++++++++++++++++++++++++++++++
inc/mod/pages.php | 28 +++++++++++++--
mod.php | 3 +-
templates/mod/ban_form.html | 59 ++++++++++++++++++++++++++++++++
templates/mod/dashboard.html | 81 ++++++++++++++++++++++++++++++++++++++++++++
templates/mod/login.html | 26 ++++++++++++++
templates/mod/view_ip.html | 18 ++++++++++
7 files changed, 289 insertions(+), 3 deletions(-)
create mode 100644 inc/mod/ban.php
create mode 100644 templates/mod/ban_form.html
create mode 100644 templates/mod/dashboard.html
create mode 100644 templates/mod/login.html
create mode 100644 templates/mod/view_ip.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
new file mode 100644
index 00000000..236b2b14
--- /dev/null
+++ b/inc/mod/ban.php
@@ -0,0 +1,77 @@
+bindValue(':ip', $mask);
+ $query->bindValue(':mod', $mod['id']);
+ if ($reason !== '')
+ $query->bindValue(':reason', $reason);
+ else
+ $query->bindValue(':reason', null, PDO::PARAM_NULL);
+
+ if ($length > 0)
+ $query->bindValue(':expires', time() + $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));
+}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 9d154181..c00cd672 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -94,12 +94,17 @@ function mod_view_thread($boardName, $thread) {
function mod_page_ip($ip) {
global $config, $mod;
+ if(filter_var($ip, FILTER_VALIDATE_IP) === false)
+ error("Invalid IP address.");
+
$args = array();
$args['ip'] = $ip;
$args['posts'] = array();
$boards = listBoards();
foreach ($boards as $board) {
+ openBoard($board['uri']);
+
$query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `ip` = :ip ORDER BY `sticky` DESC, `id` DESC LIMIT :limit', $board['uri']));
$query->bindValue(':ip', $ip);
$query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT);
@@ -122,11 +127,30 @@ function mod_page_ip($ip) {
}
if (!isset($args['posts'][$board['uri']]))
- $args['posts'][$board['uri']] = array();
- $args['posts'][$board['uri']][] = $po->build(true);
+ $args['posts'][$board['uri']] = array('board' => $board, 'posts' => array());
+ $args['posts'][$board['uri']]['posts'][] = $po->build(true);
}
}
+ $args['boards'] = $boards;
+
mod_page("IP: $ip", 'mod/view_ip.html', $args);
}
+function mod_page_ban() {
+ if(!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board']))
+ error($config['error']['missedafield']);
+
+ $ip = $_POST['ip'];
+
+ require_once 'inc/mod/ban.php';
+
+ ban($_POST['ip'], $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']);
+
+
+ if(isset($_POST['redirect']))
+ header('Location: ' . $_POST['redirect'], true, $config['redirect_http']);
+ else
+ header('Location: ?/', true, $config['redirect_http']);
+}
+
diff --git a/mod.php b/mod.php
index 0ac83f46..5f2cad56 100644
--- a/mod.php
+++ b/mod.php
@@ -25,10 +25,11 @@ $pages = array(
'!^/$!' => 'dashboard', // dashboard
'!^/IP/(.+)$!' => 'ip', // view ip address
+ '!^/ban$!' => 'ban', // new ban
// This should always be at the end:
'!^/(\w+)/' . preg_quote($config['file_index'], '!') . '?$!' => 'view_board',
- '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!/' => 'view_board',
+ '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_board',
'!^/(\w+)/' . preg_quote($config['dir']['res'], '!') .
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_thread',
);
diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html
new file mode 100644
index 00000000..1b94e725
--- /dev/null
+++ b/templates/mod/ban_form.html
@@ -0,0 +1,59 @@
+
+
diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html
new file mode 100644
index 00000000..2a90d709
--- /dev/null
+++ b/templates/mod/dashboard.html
@@ -0,0 +1,81 @@
+
+
+{% if mod|hasPermission(config.mod.noticeboard) %}
+
+{% endif %}
+
+
+
+{% if mod|hasPermission(config.mod.themes) %}
+
+{% endif %}
+
+
diff --git a/templates/mod/login.html b/templates/mod/login.html
new file mode 100644
index 00000000..5ac308a3
--- /dev/null
+++ b/templates/mod/login.html
@@ -0,0 +1,26 @@
+{% if error %}{{ error }}
{% endif %}
+
diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html
new file mode 100644
index 00000000..3b558e4b
--- /dev/null
+++ b/templates/mod/view_ip.html
@@ -0,0 +1,18 @@
+{% for board_posts in posts %}
+
+{% endfor %}
+
+{% set redirect = '?/IP/' ~ ip %}
+
+
+
--
cgit v1.3
From 2843ddc4826f250a8af6203cff437929ab807a41 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 09:47:27 +1000
Subject: view bans / unban
---
inc/mod/ban.php | 19 ++++++++----
inc/mod/pages.php | 18 ++++++++++--
inc/template.php | 2 +-
templates/mod/view_ip.html | 73 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+), 9 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
index 236b2b14..33b64975 100644
--- a/inc/mod/ban.php
+++ b/inc/mod/ban.php
@@ -10,7 +10,7 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
}
function parse_time($str) {
- if(empty($str))
+ if (empty($str))
return false;
if (($time = @strtotime($str)) !== false)
@@ -55,16 +55,18 @@ function parse_time($str) {
function ban($mask, $reason, $length, $board) {
global $mod;
- $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, UNIX_TIMESTAMP(), :expires, :reason, :board)");
+ $query = prepare("INSERT INTO `bans` VALUES (NULL, :ip, :mod, :time, :expires, :reason, :board)");
$query->bindValue(':ip', $mask);
$query->bindValue(':mod', $mod['id']);
- if ($reason !== '')
+ $query->bindValue(':time', time());
+ if ($reason !== '') {
+ markup($reason);
$query->bindValue(':reason', $reason);
- else
+ } else
$query->bindValue(':reason', null, PDO::PARAM_NULL);
if ($length > 0)
- $query->bindValue(':expires', time() + $length);
+ $query->bindValue(':expires', $length);
else
$query->bindValue(':expires', null, PDO::PARAM_NULL);
@@ -75,3 +77,10 @@ function ban($mask, $reason, $length, $board) {
$query->execute() or error(db_error($query));
}
+
+function unban($id) {
+ $query = prepare("DELETE FROM `bans` WHERE `id` = :id");
+ $query->bindValue(':id', $id);
+ $query->execute() or error(db_error($query));
+}
+
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index c00cd672..e7e4f065 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -94,9 +94,17 @@ function mod_view_thread($boardName, $thread) {
function mod_page_ip($ip) {
global $config, $mod;
- if(filter_var($ip, FILTER_VALIDATE_IP) === false)
+ if (filter_var($ip, FILTER_VALIDATE_IP) === false)
error("Invalid IP address.");
+ if (isset($_POST['ban_id'], $_POST['unban'])) {
+ require_once 'inc/mod/ban.php';
+
+ unban($_POST['ban_id']);
+ header('Location: ?/IP/' . $ip, true, $config['redirect_http']);
+ return;
+ }
+
$args = array();
$args['ip'] = $ip;
$args['posts'] = array();
@@ -134,6 +142,11 @@ function mod_page_ip($ip) {
$args['boards'] = $boards;
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query->bindValue(':ip', $ip);
+ $query->execute() or error(db_error($query));
+ $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
+
mod_page("IP: $ip", 'mod/view_ip.html', $args);
}
@@ -147,8 +160,7 @@ function mod_page_ban() {
ban($_POST['ip'], $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']);
-
- if(isset($_POST['redirect']))
+ if (isset($_POST['redirect']))
header('Location: ' . $_POST['redirect'], true, $config['redirect_http']);
else
header('Location: ?/', true, $config['redirect_http']);
diff --git a/inc/template.php b/inc/template.php
index 8d679d25..ab220454 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -26,7 +26,7 @@ function load_twig() {
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, array(
'autoescape' => false,
- 'cache' => "{$config['dir']['template']}/cache",
+ //'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false),
));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
diff --git a/templates/mod/view_ip.html b/templates/mod/view_ip.html
index 3b558e4b..a9676dd7 100644
--- a/templates/mod/view_ip.html
+++ b/templates/mod/view_ip.html
@@ -11,6 +11,79 @@
{% set redirect = '?/IP/' ~ ip %}
+{% if bans|count > 0 %}
+
+{% endif %}
+
{% endfor %}
-{% set redirect = '?/IP/' ~ ip %}
+{% if mod|hasPermission(config.mod.view_notes) %}
+
+{% endif %}
-{% if bans|count > 0 %}
+{% if bans|count > 0 and mod|hasPermission(config.mod.view_ban) %}
{% endif %}
-
-
+{% if mod|hasPermission(config.mod.ban) %}
+
+{% endif %}
--
cgit v1.3
From d1876a0dd66422570409787bae40aad371011b89 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 20:57:59 +1000
Subject: paginate moderation log
---
inc/mod/pages.php | 6 +++++-
mod.php | 2 +-
templates/mod/log.html | 6 ++++++
3 files changed, 12 insertions(+), 2 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 73015cf9..942cfd50 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -79,7 +79,11 @@ function mod_log($page_no = 1) {
$query->execute() or error(db_error($query));
$logs = $query->fetchAll(PDO::FETCH_ASSOC);
- mod_page('Moderation log', 'mod/log.html', array('logs' => $logs));
+ $query = prepare("SELECT COUNT(*) AS `count` FROM `modlogs`");
+ $query->execute() or error(db_error($query));
+ $count = $query->fetchColumn(0);
+
+ mod_page('Moderation log', 'mod/log.html', array('logs' => $logs, 'count' => $count));
}
function mod_view_board($boardName, $page_no = 1) {
diff --git a/mod.php b/mod.php
index c89c2f01..3aba6fe4 100644
--- a/mod.php
+++ b/mod.php
@@ -24,7 +24,7 @@ $pages = array(
'!^$!' => ':?/', // redirect to dashboard
'!^/$!' => 'dashboard', // dashboard
'!^/log$!' => 'log', // modlog
- '!^/log/(\d+)/$!' => 'log', // modlog
+ '!^/log/(\d+)$!' => 'log', // modlog
'!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work)
diff --git a/templates/mod/log.html b/templates/mod/log.html
index 4f2beb40..fe1c5c1f 100644
--- a/templates/mod/log.html
+++ b/templates/mod/log.html
@@ -31,3 +31,9 @@
{% endfor %}
+
+ {% for i in range(0, count / config.mod.modlog_page) %}
+ [{{ i + 1 }}]
+ {% endfor %}
+
+
--
cgit v1.3
From 761cb4feab1a052e2e611a1d09d0a3513e011c06 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 21:43:01 +1000
Subject: ?/users (user list)
---
inc/lib/Twig/Extensions/Extension/Tinyboard.php | 45 +++++++++++++++----------
inc/mod/pages.php | 12 +++++++
mod.php | 4 ++-
templates/mod/log.html | 12 ++++---
4 files changed, 50 insertions(+), 23 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
index 4111fc3c..2691cc55 100644
--- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php
+++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
@@ -10,19 +10,21 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
public function getFilters()
{
return Array(
- 'filesize' => new Twig_Filter_Function('format_bytes', Array('needs_environment' => false)),
- 'truncate' => new Twig_Filter_Function('twig_truncate_filter', array('needs_environment' => false)),
- 'truncate_body' => new Twig_Filter_Function('truncate', array('needs_environment' => false)),
- 'extension' => new Twig_Filter_Function('twig_extension_filter', array('needs_environment' => false)),
- 'sprintf' => new Twig_Filter_Function('sprintf', array('needs_environment' => false)),
- 'capcode' => new Twig_Filter_Function('capcode', array('needs_environment' => false)),
- 'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter', array('needs_environment' => false)),
- 'date' => new Twig_Filter_Function('twig_date_filter', array('needs_environment' => false)),
- 'poster_id' => new Twig_Filter_Function('poster_id', array('needs_environment' => false)),
- 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter', array('needs_environment' => false)),
- 'count' => new Twig_Filter_Function('count', array('needs_environment' => false)),
- 'ago' => new Twig_Filter_Function('ago', array('needs_environment' => false)),
- 'until' => new Twig_Filter_Function('until', array('needs_environment' => false))
+ 'filesize' => new Twig_Filter_Function('format_bytes'),
+ 'truncate' => new Twig_Filter_Function('twig_truncate_filter'),
+ 'truncate_body' => new Twig_Filter_Function('truncate'),
+ 'extension' => new Twig_Filter_Function('twig_extension_filter'),
+ 'sprintf' => new Twig_Filter_Function('sprintf'),
+ 'capcode' => new Twig_Filter_Function('capcode'),
+ 'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter'),
+ 'date' => new Twig_Filter_Function('twig_date_filter'),
+ 'poster_id' => new Twig_Filter_Function('poster_id'),
+ 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter'),
+ 'count' => new Twig_Filter_Function('count'),
+ 'ago' => new Twig_Filter_Function('ago'),
+ 'until' => new Twig_Filter_Function('until'),
+ 'split' => new Twig_Filter_Function('twig_split_filter'),
+ 'push' => new Twig_Filter_Function('twig_push_filter'),
);
}
@@ -34,10 +36,10 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
public function getFunctions()
{
return Array(
- 'time' => new Twig_Filter_Function('time', array('needs_environment' => false)),
- 'timezone' => new Twig_Filter_Function('twig_timezone_function', array('needs_environment' => false)),
- 'hiddenInputs' => new Twig_Filter_Function('hiddenInputs', array('needs_environment' => false)),
- 'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash', array('needs_environment' => false))
+ 'time' => new Twig_Filter_Function('time'),
+ 'timezone' => new Twig_Filter_Function('twig_timezone_function'),
+ 'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'),
+ 'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'),
);
}
@@ -57,6 +59,15 @@ function twig_timezone_function() {
return sprintf("%s%02d", ($hr = (int)floor(($tz = date('Z')) / 3600)) > 0 ? '+' : '-', abs($hr)) . ':' . sprintf("%02d", (($tz / 3600) - $hr) * 60);
}
+function twig_split_filter($str, $delim) {
+ return explode($delim, $str);
+}
+
+function twig_push_filter($array, $value) {
+ array_push($array, $value);
+ return $array;
+}
+
function twig_remove_whitespace_filter($data) {
return preg_replace('/[\t\r\n]/', '', $data);
}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 942cfd50..2b5487fd 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -250,3 +250,15 @@ function mod_delete($board, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
+function mod_users() {
+ global $config;
+ if(!hasPermission($config['mod']['manageusers']))
+ error($config['error']['noaccess']);
+
+ $args = array();
+ $query = query("SELECT *, (SELECT `time` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `last`, (SELECT `text` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `action` FROM `mods` ORDER BY `type` DESC,`id`") or error(db_error());
+ $args['users'] = $query->fetchAll(PDO::FETCH_ASSOC);
+
+ mod_page("Manage users", 'mod/users.html', $args);
+}
+
diff --git a/mod.php b/mod.php
index 3aba6fe4..d95f9552 100644
--- a/mod.php
+++ b/mod.php
@@ -23,10 +23,12 @@ $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
$pages = array(
'!^$!' => ':?/', // redirect to dashboard
'!^/$!' => 'dashboard', // dashboard
+ '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work)
'!^/log$!' => 'log', // modlog
'!^/log/(\d+)$!' => 'log', // modlog
+
+ '!^/users$!' => 'users', // manage users
- '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work)
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
diff --git a/templates/mod/log.html b/templates/mod/log.html
index fe1c5c1f..61243202 100644
--- a/templates/mod/log.html
+++ b/templates/mod/log.html
@@ -31,9 +31,11 @@
{% endfor %}
-
- {% for i in range(0, count / config.mod.modlog_page) %}
- [{{ i + 1 }}]
- {% endfor %}
-
+{% if count > logs|count %}
+
+ {% for i in range(0, count / config.mod.modlog_page) %}
+ [{{ i + 1 }}]
+ {% endfor %}
+
+{% endif %}
--
cgit v1.3
From e49ece459e2ee225ba677f8e0758a38a98b930f5 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 13 Apr 2012 22:00:40 +1000
Subject: new PM
---
inc/mod/auth.php | 13 ++++++++++++
inc/mod/pages.php | 33 +++++++++++++++++++++++++++--
mod.php | 2 +-
templates/mod/new_pm.html | 22 +++++++++++++++++++
templates/mod/users.html | 54 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 121 insertions(+), 3 deletions(-)
create mode 100644 templates/mod/new_pm.html
create mode 100644 templates/mod/users.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/auth.php b/inc/mod/auth.php
index 2e90b757..f9b863c8 100644
--- a/inc/mod/auth.php
+++ b/inc/mod/auth.php
@@ -122,3 +122,16 @@ if (isset($_COOKIE[$config['cookies']['mod']])) {
);
}
+function create_pm_header() {
+ global $mod;
+ $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1");
+ $query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ if ($pm = $query->fetch()) {
+ return Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
+ }
+
+ return false;
+}
+
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 2b5487fd..4903567a 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -252,13 +252,42 @@ function mod_delete($board, $post) {
function mod_users() {
global $config;
- if(!hasPermission($config['mod']['manageusers']))
+
+ if (!hasPermission($config['mod']['manageusers']))
error($config['error']['noaccess']);
$args = array();
$query = query("SELECT *, (SELECT `time` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `last`, (SELECT `text` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `action` FROM `mods` ORDER BY `type` DESC,`id`") or error(db_error());
$args['users'] = $query->fetchAll(PDO::FETCH_ASSOC);
- mod_page("Manage users", 'mod/users.html', $args);
+ mod_page('Manage users', 'mod/users.html', $args);
+}
+
+function mod_new_pm($username) {
+ global $config, $mod;
+
+ if (!hasPermission($config['mod']['create_pm']))
+ error($config['error']['noaccess']);
+
+ $query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
+ $query->bindValue(':username', $username);
+ $query->execute() or error(db_error($query));
+ if (!$id = $query->fetchColumn(0))
+ error($config['error']['404']);
+
+ if (isset($_POST['message'])) {
+ markup($_POST['message']);
+
+ $query = prepare("INSERT INTO `pms` VALUES (NULL, :me, :id, :message, :time, 1)");
+ $query->bindValue(':me', $mod['id']);
+ $query->bindValue(':id', $id);
+ $query->bindValue(':message', $_POST['message']);
+ $query->bindValue(':time', time());
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/', true, $config['redirect_http']);
+ }
+
+ mod_page("New PM for {$username}", 'mod/new_pm.html', array('username' => $username, 'id' => $id));
}
diff --git a/mod.php b/mod.php
index d95f9552..e7134603 100644
--- a/mod.php
+++ b/mod.php
@@ -28,7 +28,7 @@ $pages = array(
'!^/log/(\d+)$!' => 'log', // modlog
'!^/users$!' => 'users', // manage users
-
+ '!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
diff --git a/templates/mod/new_pm.html b/templates/mod/new_pm.html
new file mode 100644
index 00000000..d694bc26
--- /dev/null
+++ b/templates/mod/new_pm.html
@@ -0,0 +1,22 @@
+{#{% if id == mod.id %}
+ {% set username = 'me' %}
+{% endif %}#}
+
+
diff --git a/templates/mod/users.html b/templates/mod/users.html
new file mode 100644
index 00000000..aeacc8b5
--- /dev/null
+++ b/templates/mod/users.html
@@ -0,0 +1,54 @@
+
+
+ | ID |
+ Username |
+ Type |
+ Boards |
+ Last action |
+ … |
+
+
+ {% for user in users %}
+
+ | {{ user.id }} |
+ {{ user.username }} |
+
+ {% if user.type == constant('JANITOR') %}Janitor
+ {% elseif user.type == constant('MOD') %}Mod
+ {% elseif user.type == constant('ADMIN') %}Admin
+ {% endif %}
+ |
+
+ {# This is really messy, but IMO it beats doing it in PHP. #}
+ {% set boards = user.boards|split(',') %}
+ {% set _boards = [] %}
+ {% for board in boards %}
+ {% set _boards = _boards|push(board == '*' ? '*' : config.board_abbreviation|sprintf(board)) %}
+ {% endfor %}
+ {% set _boards = _boards|sort %}
+ {{ _boards|join(', ') }}
+ |
+
+ {% if mod|hasPermission(config.mod.modlog) %}
+ {{ user.last|ago }}
+ {% else %}
+ –
+ {% endif %}
+ |
+
+ {% if mod|hasPermission(config.mod.promoteusers) and user.type < constant('ADMIN') %}
+ ▲
+ {% endif %}
+ {% if mod|hasPermission(config.mod.promoteusers) and user.type > constant('JANITOR') %}
+ ▼
+ {% endif %}
+ {% if mod|hasPermission(config.editusers) or (mod|hasPermission(config.change_password) and mod.id == user.id) %}
+ [edit]
+ {% endif %}
+ {% if mod|hasPermission(config.mod.create_pm) %}
+ [PM]
+ {% endif %}
+ |
+
+ {% endfor %}
+
--
cgit v1.3
From 87281687ed3ed06fd76d7bbb6c29404bb883418a Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Sat, 14 Apr 2012 22:28:21 +1000
Subject: promote/demote users, started on rebuild
---
inc/mod/pages.php | 67 ++++++++++++++++++++++++++++++++++++-------
inc/template.php | 2 +-
mod.php | 3 ++
templates/mod/rebuild.html | 71 ++++++++++++++++++++++++++++++++++++++++++++++
templates/mod/users.html | 6 +++-
5 files changed, 136 insertions(+), 13 deletions(-)
create mode 100644 templates/mod/rebuild.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 4903567a..d78ebf0d 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -143,7 +143,12 @@ function mod_page_ip($ip) {
}
if (isset($_POST['note'])) {
- // TODO: permissions
+ if (hasPermission($config['mod']['create_notes'])) {
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query->bindValue(':ip', $ip);
+ $query->execute() or error(db_error($query));
+ $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ }
markup($_POST['note']);
$query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)');
@@ -194,20 +199,30 @@ function mod_page_ip($ip) {
$args['boards'] = $boards;
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
- $query->bindValue(':ip', $ip);
- $query->execute() or error(db_error($query));
- $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
- $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
- $query->bindValue(':ip', $ip);
- $query->execute() or error(db_error($query));
- $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ if (hasPermission($config['mod']['view_ban'])) {
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query->bindValue(':ip', $ip);
+ $query->execute() or error(db_error($query));
+ $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ if (hasPermission($config['mod']['view_notes'])) {
+ $query = prepare("SELECT `ip_notes`.*, `username` FROM `ip_notes` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
+ $query->bindValue(':ip', $ip);
+ $query->execute() or error(db_error($query));
+ $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC);
+ }
mod_page("IP: $ip", 'mod/view_ip.html', $args);
}
function mod_ban() {
+ global $config;
+
+ if (!hasPermission($config['mod']['ban']))
+ error($config['error']['noaccess']);
+
if (!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'])) {
mod_page("New ban", 'mod/ban_form.html', array());
return;
@@ -263,6 +278,19 @@ function mod_users() {
mod_page('Manage users', 'mod/users.html', $args);
}
+function mod_user_promote($uid, $action) {
+ global $config;
+
+ if (!hasPermission($config['mod']['promoteusers']))
+ error($config['error']['noaccess']);
+
+ $query = prepare("UPDATE `mods` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id");
+ $query->bindValue(':id', $uid);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/users', true, $config['redirect_http']);
+}
+
function mod_new_pm($username) {
global $config, $mod;
@@ -272,8 +300,16 @@ function mod_new_pm($username) {
$query = prepare("SELECT `id` FROM `mods` WHERE `username` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
- if (!$id = $query->fetchColumn(0))
- error($config['error']['404']);
+ if (!$id = $query->fetchColumn(0)) {
+ // Old style ?/PM: by user ID
+ $query = prepare("SELECT `username` FROM `mods` WHERE `id` = :username");
+ $query->bindValue(':username', $username);
+ $query->execute() or error(db_error($query));
+ if ($username = $query->fetchColumn(0))
+ header('Location: ?/new_PM/' . $username, true, $config['redirect_http']);
+ else
+ error($config['error']['404']);
+ }
if (isset($_POST['message'])) {
markup($_POST['message']);
@@ -291,3 +327,12 @@ function mod_new_pm($username) {
mod_page("New PM for {$username}", 'mod/new_pm.html', array('username' => $username, 'id' => $id));
}
+function mod_rebuild() {
+ global $config;
+
+ if (!hasPermission($config['mod']['rebuild']))
+ error($config['error']['noaccess']);
+
+ mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards()));
+}
+
diff --git a/inc/template.php b/inc/template.php
index ab220454..8d679d25 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -26,7 +26,7 @@ function load_twig() {
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, array(
'autoescape' => false,
- //'cache' => "{$config['dir']['template']}/cache",
+ 'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false),
));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
diff --git a/mod.php b/mod.php
index e7134603..f641d371 100644
--- a/mod.php
+++ b/mod.php
@@ -28,8 +28,11 @@ $pages = array(
'!^/log/(\d+)$!' => 'log', // modlog
'!^/users$!' => 'users', // manage users
+ '!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user
'!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
+ '!^/rebuild$!' => 'rebuild', // rebuild static files
+
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
'!^/IP/([\w.:]+)/remove_note/(\d+)$!' => 'ip_remove_note', // remove note from ip address
diff --git a/templates/mod/rebuild.html b/templates/mod/rebuild.html
new file mode 100644
index 00000000..763eb624
--- /dev/null
+++ b/templates/mod/rebuild.html
@@ -0,0 +1,71 @@
+
diff --git a/templates/mod/users.html b/templates/mod/users.html
index aeacc8b5..63d799d5 100644
--- a/templates/mod/users.html
+++ b/templates/mod/users.html
@@ -30,7 +30,11 @@
{% if mod|hasPermission(config.mod.modlog) %}
- {{ user.last|ago }}
+ {% if user.last %}
+ {{ user.last|ago }}
+ {% else %}
+ never
+ {% endif %}
{% else %}
–
{% endif %}
--
cgit v1.3
From de8cc487d81e7cb9a00acee30962aa1933c0c0c6 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Sat, 14 Apr 2012 22:58:36 +1000
Subject: rebuild
---
inc/mod/pages.php | 62 ++++++++++++++++++++++++++++++++++++++++------
templates/mod/rebuild.html | 2 +-
templates/mod/rebuilt.html | 12 +++++++++
3 files changed, 68 insertions(+), 8 deletions(-)
create mode 100644 templates/mod/rebuilt.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index d78ebf0d..d8352671 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -117,6 +117,9 @@ function mod_view_thread($boardName, $thread) {
function mod_ip_remove_note($ip, $id) {
global $config, $mod;
+ if (!hasPermission($config['mod']['remove_notes']))
+ error($config['error']['noaccess']);
+
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
error("Invalid IP address.");
@@ -135,6 +138,9 @@ function mod_page_ip($ip) {
error("Invalid IP address.");
if (isset($_POST['ban_id'], $_POST['unban'])) {
+ if (!hasPermission($config['mod']['unban']))
+ error($config['error']['noaccess']);
+
require_once 'inc/mod/ban.php';
unban($_POST['ban_id']);
@@ -143,12 +149,8 @@ function mod_page_ip($ip) {
}
if (isset($_POST['note'])) {
- if (hasPermission($config['mod']['create_notes'])) {
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
- $query->bindValue(':ip', $ip);
- $query->execute() or error(db_error($query));
- $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
- }
+ if (!hasPermission($config['mod']['create_notes']))
+ error($config['error']['noaccess']);
markup($_POST['note']);
$query = prepare('INSERT INTO `ip_notes` VALUES (NULL, :ip, :mod, :time, :body)');
@@ -328,11 +330,57 @@ function mod_new_pm($username) {
}
function mod_rebuild() {
- global $config;
+ global $config, $twig;
if (!hasPermission($config['mod']['rebuild']))
error($config['error']['noaccess']);
+ if (isset($_POST['rebuild'])) {
+ $log = array();
+ $boards = listBoards();
+ $rebuilt_scripts = array();
+
+ if (isset($_POST['rebuild_cache'])) {
+ $log[] = 'Clearing template cache';
+ load_twig();
+ $twig->clearCacheFiles();
+ }
+
+ if (isset($_POST['rebuild_themes'])) {
+ $log[] = 'Regenerating theme files';
+ rebuildThemes('all');
+ }
+
+ if (isset($_POST['rebuild_javascript'])) {
+ $log[] = 'Rebuilding ' . $config['file_script'] . '';
+ buildJavascript();
+ $rebuilt_scripts[] = $config['file_script'];
+ }
+
+ foreach ($boards as $board) {
+ if (!(isset($_POST['boards_all']) || isset($_POST['boards_' . $board['uri']])))
+ continue;
+
+ openBoard($board['uri']);
+ $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Creating index pages';
+
+ if (!in_array($config['file_script'], $rebuilt_scripts)) {
+ $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding ' . $config['file_script'] . '';
+ buildJavascript();
+ $rebuilt_scripts[] = $config['file_script'];
+ }
+
+ $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
+ while($post = $query->fetch()) {
+ $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding thread #' . $post['id'];
+ buildThread($post['id']);
+ }
+ }
+
+ mod_page("Rebuild", 'mod/rebuilt.html', array('logs' => $log));
+ return;
+ }
+
mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards()));
}
diff --git a/templates/mod/rebuild.html b/templates/mod/rebuild.html
index 763eb624..7a586b95 100644
--- a/templates/mod/rebuild.html
+++ b/templates/mod/rebuild.html
@@ -66,6 +66,6 @@
-
+
diff --git a/templates/mod/rebuilt.html b/templates/mod/rebuilt.html
new file mode 100644
index 00000000..8cc10bf9
--- /dev/null
+++ b/templates/mod/rebuilt.html
@@ -0,0 +1,12 @@
+
+
--
cgit v1.3
From e5c4394185c6af6252f6182337c6431fc07d3a77 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Sun, 15 Apr 2012 20:04:26 +1000
Subject: rebuild wasn't working unless you choes "all boards"
---
inc/mod/pages.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index d8352671..7518b9fb 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -358,7 +358,7 @@ function mod_rebuild() {
}
foreach ($boards as $board) {
- if (!(isset($_POST['boards_all']) || isset($_POST['boards_' . $board['uri']])))
+ if (!(isset($_POST['boards_all']) || isset($_POST['board_' . $board['uri']])))
continue;
openBoard($board['uri']);
--
cgit v1.3
From ad55a634bf3f9301489f5371942c73940361a24c Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 16:40:24 +1000
Subject: various improvements
---
inc/mod/ban.php | 41 +++++++++--------
inc/mod/pages.php | 105 +++++++++++++++++++++++++++++++++++++++-----
mod.php | 4 +-
stylesheets/style.css | 15 ++++---
templates/mod/ban_list.html | 74 +++++++++++++++++++++++++++++++
templates/mod/new_pm.html | 4 +-
templates/mod/pm.html | 41 +++++++++++++++++
7 files changed, 247 insertions(+), 37 deletions(-)
create mode 100644 templates/mod/ban_list.html
create mode 100644 templates/mod/pm.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
index 8d86cbcd..e7110edf 100644
--- a/inc/mod/ban.php
+++ b/inc/mod/ban.php
@@ -16,44 +16,45 @@ function parse_time($str) {
if (($time = @strtotime($str)) !== false)
return $time;
- if (!preg_match('/^((\d+)\s*ye?a?r?s?)?\s*+((\d+)\s*mon?t?h?s?)?\s*((\d+)\s*we?e?k?s?)?\s*((\d+)\s*da?y?s?)?((\d+)\s*ho?u?r?s?)?\s*((\d+)\s*mi?n?u?t?e?s?)?\s*+((\d+)\s*se?c?o?n?d?s?)?$/', $str, $matches))
+ if (!preg_match('/^((\d+)\s?ye?a?r?s?)?\s?+((\d+)\s?mon?t?h?s?)?\s?+((\d+)\s?we?e?k?s?)?\s?+((\d+)\s?da?y?s?)?((\d+)\s?ho?u?r?s?)?\s?+((\d+)\s?mi?n?u?t?e?s?)?\s?+((\d+)\s?se?c?o?n?d?s?)?$/', $str, $matches))
return false;
- $expire = time();
- if (isset($m[2])) {
+ $expire = 0;
+
+ if (isset($matches[2])) {
// Years
- $expire += $m[2]*60*60*24*365;
+ $expire += $matches[2]*60*60*24*365;
}
- if (isset($m[4])) {
+ if (isset($matches[4])) {
// Months
- $expire += $m[4]*60*60*24*30;
+ $expire += $matches[4]*60*60*24*30;
}
- if (isset($m[6])) {
+ if (isset($matches[6])) {
// Weeks
- $expire += $m[6]*60*60*24*7;
+ $expire += $matches[6]*60*60*24*7;
}
- if (isset($m[8])) {
+ if (isset($matches[8])) {
// Days
- $expire += $m[8]*60*60*24;
+ $expire += $matches[8]*60*60*24;
}
- if (isset($m[10])) {
+ if (isset($matches[10])) {
// Hours
- $expire += $m[10]*60*60;
+ $expire += $matches[10]*60*60;
}
- if (isset($m[12])) {
+ if (isset($matches[12])) {
// Minutes
- $expire += $m[12]*60;
+ $expire += $matches[12]*60;
}
- if (isset($m[14])) {
+ if (isset($matches[14])) {
// Seconds
- $expire += $m[14];
+ $expire += $matches[14];
}
- return $expire;
+ return time() + $expire;
}
function ban($mask, $reason, $length, $board) {
- global $mod;
+ global $mod, $pdo;
// TODO: permissions
@@ -78,6 +79,8 @@ function ban($mask, $reason, $length, $board) {
$query->bindValue(':board', null, PDO::PARAM_NULL);
$query->execute() or error(db_error($query));
+
+ modLog('Created a new ban (#' . $pdo->lastInsertId() . ') for ' . utf8tohtml($mask) . ' with ' . ($reason ? 'reason: ' . $reason . '' : 'no reason'));
}
function unban($id) {
@@ -86,5 +89,7 @@ function unban($id) {
$query = prepare("DELETE FROM `bans` WHERE `id` = :id");
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
+
+ modLog("Removed ban #{$id}");
}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 7518b9fb..60f101ea 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -39,7 +39,7 @@ function mod_login() {
$args['error'] = $config['error']['invalid'];
} else {
- modLog("Logged in.");
+ modLog('Logged in');
// Login successful
// Set cookies
@@ -101,6 +101,7 @@ function mod_view_board($boardName, $page_no = 1) {
$page['btn'] = getPageButtons($page['pages'], true);
$page['mod'] = true;
$page['config'] = $config;
+
echo Element('index.html', $page);
}
@@ -128,6 +129,8 @@ function mod_ip_remove_note($ip, $id) {
$query->bindValue(':id', $id);
$query->execute() or error(db_error($query));
+ modLog("Removed a note for {$ip}");
+
header('Location: ?/IP/' . $ip, true, $config['redirect_http']);
}
@@ -160,6 +163,8 @@ function mod_page_ip($ip) {
$query->bindValue(':body', $_POST['note']);
$query->execute() or error(db_error($query));
+ modLog("Added a note for {$ip}");
+
header('Location: ?/IP/' . $ip, true, $config['redirect_http']);
return;
}
@@ -177,8 +182,9 @@ function mod_page_ip($ip) {
$query->bindValue(':limit', $config['mod']['ip_recentposts'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
- while ($post = $query->fetch()) {
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
if (!$post['thread']) {
+ // TODO: There is no reason why this should be such a fucking mess.
$po = new Thread(
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'],
$post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
@@ -230,13 +236,6 @@ function mod_ban() {
return;
}
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` WHERE `ip` = :ip");
- $query->bindValue(':ip', $ip);
- $query->execute() or error(db_error($query));
- $args['bans'] = $query->fetchAll(PDO::FETCH_ASSOC);
-
- $ip = $_POST['ip'];
-
require_once 'inc/mod/ban.php';
ban($_POST['ip'], $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']);
@@ -247,6 +246,51 @@ function mod_ban() {
header('Location: ?/', true, $config['redirect_http']);
}
+function mod_bans() {
+ global $config;
+
+ if (!hasPermission($config['mod']['view_banlist']))
+ error($config['error']['noaccess']);
+
+ if (isset($_POST['unban'])) {
+ if (!hasPermission($config['mod']['unban']))
+ error($config['error']['noaccess']);
+
+ $unban = array();
+ foreach ($_POST as $name => $unused) {
+ if (preg_match('/^ban_(\d+)$/', $name, $match))
+ $unban[] = $match[1];
+ }
+
+ query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
+
+ foreach ($unban as $id) {
+ modLog("Removed ban #{$id}");
+ }
+
+ header('Location: ?/bans', true, $config['redirect_http']);
+ }
+
+ if ($config['mod']['view_banexpired']) {
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC");
+ $query->bindValue(':time', time(), PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ } else {
+ // Filter out expired bans
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC");
+ $query->bindValue(':time', time(), PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ }
+ $bans = $query->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($bans as &$ban) {
+ if (filter_var($ban['ip'], FILTER_VALIDATE_IP) !== false)
+ $ban['real_ip'] = true;
+ }
+
+ mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans));
+}
+
function mod_delete($board, $post) {
global $config, $mod;
@@ -290,9 +334,48 @@ function mod_user_promote($uid, $action) {
$query->bindValue(':id', $uid);
$query->execute() or error(db_error($query));
+ modLog(($action == 'promote' ? 'Promoted' : 'Demoted') . " user #{$uid}");
+
header('Location: ?/users', true, $config['redirect_http']);
}
+function mod_pm($id, $reply = false) {
+ global $mod, $config;
+
+ $query = prepare("SELECT `mods`.`username`, `mods_to`.`username` AS `to_username`, `pms`.* FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` LEFT JOIN `mods` AS `mods_to` ON `mods_to`.`id` = `to` WHERE `pms`.`id` = :id");
+ $query->bindValue(':id', $id);
+ $query->execute() or error(db_error($query));
+
+ if ((!$pm = $query->fetch(PDO::FETCH_ASSOC)) || ($pm['to'] != $mod['id'] && !hasPermission($config['mod']['master_pm'])))
+ error($config['error']['404']);
+
+ if (isset($_POST['delete'])) {
+ $query = prepare("DELETE FROM `pms` WHERE `id` = :id");
+ $query->bindValue(':id', $id);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/', true, $config['redirect_http']);
+ return;
+ }
+
+ if ($pm['unread'] && $pm['to'] == $mod['id']) {
+ $query = prepare("UPDATE `pms` SET `unread` = 0 WHERE `id` = :id");
+ $query->bindValue(':id', $id);
+ $query->execute() or error(db_error($query));
+
+ modLog('Read a PM');
+ }
+
+ if ($reply) {
+ if (!$pm['to_username'])
+ error($config['error']['404']); // deleted?
+
+ mod_page("New PM for {$pm['to_username']}", 'mod/new_pm.html', array('username' => $pm['to_username'], 'id' => $pm['to'], 'message' => quote($pm['message'])));
+ } else {
+ mod_page("Private message – #$id", 'mod/pm.html', $pm);
+ }
+}
+
function mod_new_pm($username) {
global $config, $mod;
@@ -323,6 +406,8 @@ function mod_new_pm($username) {
$query->bindValue(':time', time());
$query->execute() or error(db_error($query));
+ modLog('Sent a PM to ' . utf8tohtml($username));
+
header('Location: ?/', true, $config['redirect_http']);
}
@@ -371,7 +456,7 @@ function mod_rebuild() {
}
$query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
- while($post = $query->fetch()) {
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding thread #' . $post['id'];
buildThread($post['id']);
}
diff --git a/mod.php b/mod.php
index f641d371..6fc216f8 100644
--- a/mod.php
+++ b/mod.php
@@ -26,16 +26,18 @@ $pages = array(
'!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work)
'!^/log$!' => 'log', // modlog
'!^/log/(\d+)$!' => 'log', // modlog
-
+
'!^/users$!' => 'users', // manage users
'!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user
'!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
+ '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm
'!^/rebuild$!' => 'rebuild', // rebuild static files
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
'!^/IP/([\w.:]+)/remove_note/(\d+)$!' => 'ip_remove_note', // remove note from ip address
+ '!^/bans$!' => 'bans', // ban list
'!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post
diff --git a/stylesheets/style.css b/stylesheets/style.css
index d77f05b5..edebf0c1 100644
--- a/stylesheets/style.css
+++ b/stylesheets/style.css
@@ -68,15 +68,18 @@ form table input {
}
input[type="text"], input[type="password"], textarea {
border: 1px solid #a9a9a9;
- text-indent: 0px;
+ text-indent: 0;
text-shadow: none;
text-transform: none;
word-spacing: normal;
}
form table tr td {
text-align: left;
- margin: 0px;
- padding: 0px;
+ margin: 0;
+ padding: 0;
+}
+form table.mod tr td {
+ padding: 2px;
}
form table tr th {
text-align: left;
@@ -102,7 +105,7 @@ form table tr td div label {
}
p.fileinfo {
display: block;
- margin: 0px;
+ margin: 0;
padding-right: 7em;
}
div.banner {
@@ -326,7 +329,7 @@ div.pages form input {
hr {
border: none;
border-top: 1px solid #B7C5D9;
- height: 0px;
+ height: 0;
clear: left;
}
div.boardlist {
@@ -349,7 +352,7 @@ table.modlog {
}
table.modlog tr td {
text-align: left;
- margin: 0px;
+ margin: 0;
padding: 4px 15px 0 0;
}
table.modlog tr th {
diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html
new file mode 100644
index 00000000..00b8a0f4
--- /dev/null
+++ b/templates/mod/ban_list.html
@@ -0,0 +1,74 @@
+{% if bans|count == 0 %}
+ (There are no active bans.)
+{% else %}
+
+{% endif %}
diff --git a/templates/mod/new_pm.html b/templates/mod/new_pm.html
index d694bc26..ece1325c 100644
--- a/templates/mod/new_pm.html
+++ b/templates/mod/new_pm.html
@@ -2,7 +2,7 @@
{% set username = 'me' %}
{% endif %}#}
-
--
cgit v1.3
From 41e1a2481b4d2b3217b667063d9bf5115dfec9ab Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 17:28:57 +1000
Subject: report queue
---
inc/mod/pages.php | 121 +++++++++++++++++++++++++++++++++++++++++++++
inc/template.php | 2 +-
mod.php | 2 +
templates/mod/report.html | 26 ++++++++++
templates/mod/reports.html | 5 ++
5 files changed, 155 insertions(+), 1 deletion(-)
create mode 100644 templates/mod/report.html
create mode 100644 templates/mod/reports.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 60f101ea..2532e2e7 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -469,3 +469,124 @@ function mod_rebuild() {
mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards()));
}
+function mod_reports() {
+ global $config, $mod;
+
+ if (!hasPermission($config['mod']['reports']))
+ error($config['error']['noaccess']);
+
+ $query = prepare("SELECT * FROM `reports` ORDER BY `time` DESC LIMIT :limit");
+ $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+ $reports = $query->fetchAll(PDO::FETCH_ASSOC);
+
+ $report_queries = array();
+ foreach ($reports as $report) {
+ if (!isset($report_queries[$report['board']]))
+ $report_queries[$report['board']] = array();
+ $report_queries[$report['board']][] = $report['post'];
+ }
+
+ $report_posts = array();
+ foreach ($report_queries as $board => $posts) {
+ $report_posts[$board] = array();
+
+ $query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error());
+ while ($post = $query->fetch()) {
+ $report_posts[$board][$post['id']] = $post;
+ }
+ }
+
+ $body = '';
+ foreach ($reports as $report) {
+ if (!isset($report_posts[$report['board']][$report['post']])) {
+ // // Invalid report (post has since been deleted)
+ $query = prepare("DELETE FROM `reports` WHERE `post` = :id AND `board` = :board");
+ $query->bindValue(':id', $report['post'], PDO::PARAM_INT);
+ $query->bindValue(':board', $report['board']);
+ $query->execute() or error(db_error($query));
+ continue;
+ }
+
+ openBoard($report['board']);
+
+ $post = &$report_posts[$report['board']][$report['post']];
+
+ if (!$post['thread']) {
+ // Still need to fix this:
+ $po = new Thread(
+ $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'],
+ $post['capcode'], $post['body'], $post['time'], $post['thumb'],
+ $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
+ $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'],
+ $post['locked'], $post['sage'], $post['embed'], '?/', $mod, false
+ );
+ } else {
+ $po = new Post(
+ $post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'],
+ $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
+ $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod
+ );
+ }
+
+ // a little messy and inefficient
+ $append_html = Element('mod/report.html', array('report' => $report, 'config' => $config, 'mod' => $mod));
+
+ // Bug fix for https://github.com/savetheinternet/Tinyboard/issues/21
+ $po->body = truncate($po->body, $po->link(), $config['body_truncate'] - substr_count($append_html, ' '));
+
+ if (mb_strlen($po->body) + mb_strlen($append_html) > $config['body_truncate_char']) {
+ // still too long; temporarily increase limit in the config
+ $__old_body_truncate_char = $config['body_truncate_char'];
+ $config['body_truncate_char'] = mb_strlen($po->body) + mb_strlen($append_html);
+ }
+
+ $po->body .= $append_html;
+
+ $body .= $po->build(true) . ' ';
+
+ if(isset($__old_body_truncate_char))
+ $config['body_truncate_char'] = $__old_body_truncate_char;
+ }
+
+ mod_page("Report queue", 'mod/reports.html', array('reports' => $body));
+}
+
+function mod_report_dismiss($id, $all = false) {
+ global $config;
+
+ $query = prepare("SELECT `post`, `board`, `ip` FROM `reports` WHERE `id` = :id");
+ $query->bindValue(':id', $id);
+ $query->execute() or error(db_error($query));
+ if ($report = $query->fetch(PDO::FETCH_ASSOC)) {
+ $ip = $report['ip'];
+ $board = $report['board'];
+ $post = $report['post'];
+ } else
+ error($config['error']['404']);
+
+ if (!$all && !hasPermission($config['mod']['report_dismiss'], $board))
+ error($config['error']['noaccess']);
+
+ if ($all && !hasPermission($config['mod']['report_dismiss_ip'], $board))
+ error($config['error']['noaccess']);
+
+ if ($all) {
+ $query = prepare("DELETE FROM `reports` WHERE `ip` = :ip");
+ $query->bindValue(':ip', $ip);
+ } else {
+ $query = prepare("DELETE FROM `reports` WHERE `id` = :id");
+ $query->bindValue(':id', $id);
+ }
+ $query->execute() or error(db_error($query));
+
+
+ if ($all)
+ modLog("Dismissed all reports by $ip");
+ else
+ modLog("Dismissed a report for post #{$id}", $board);
+
+ header('Location: ?/reports', true, $config['redirect_http']);
+}
+
+
diff --git a/inc/template.php b/inc/template.php
index 8d679d25..5355e18c 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -39,7 +39,7 @@ function Element($templateFile, array $options) {
if (!$twig)
load_twig();
- if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod']))) {
+ if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) {
$options['pm'] = create_pm_header();
}
diff --git a/mod.php b/mod.php
index 6fc216f8..78205bd3 100644
--- a/mod.php
+++ b/mod.php
@@ -33,6 +33,8 @@ $pages = array(
'!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm
'!^/rebuild$!' => 'rebuild', // rebuild static files
+ '!^/reports$!' => 'reports', // report queue
+ '!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report
'!^/ban$!' => 'ban', // new ban
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
diff --git a/templates/mod/report.html b/templates/mod/report.html
new file mode 100644
index 00000000..c84e3c89
--- /dev/null
+++ b/templates/mod/report.html
@@ -0,0 +1,26 @@
+
+
+ Board: {{ config.board_abbreviation|sprintf(report.board) }}
+
+ Reason: {{ report.reason }}
+
+ Report date: {{ report.time|date(config.post_date) }}
+
+ {% if mod|hasPermission(config.mod.show_ip, report.board) %}
+ Reported by: {{ report.ip }}
+
+ {% endif %}
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) or mod|hasPermission(config.mod.report_dismiss_ip, report.board) %}
+
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %}
+ Dismiss
+ {% endif %}
+ {% if mod|hasPermission(config.mod.report_dismiss_ip, report.board) %}
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %}
+ |
+ {% endif %}
+ Dismiss+
+ {% endif %}
+ {% endif %}
+
+
diff --git a/templates/mod/reports.html b/templates/mod/reports.html
new file mode 100644
index 00000000..37322e35
--- /dev/null
+++ b/templates/mod/reports.html
@@ -0,0 +1,5 @@
+{% if reports %}
+ {{ reports }}
+{% else %}
+ (There are no reports.)
+{% endif %}
--
cgit v1.3
From 7101fa540b86a2d90d50ff1121359f5881b507cd Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 17:33:13 +1000
Subject: rebuilding
---
inc/mod/pages.php | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 2532e2e7..98851c52 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -447,18 +447,24 @@ function mod_rebuild() {
continue;
openBoard($board['uri']);
- $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Creating index pages';
- if (!in_array($config['file_script'], $rebuilt_scripts)) {
+ if (isset($_POST['rebuild_index'])) {
+ buildIndex();
+ $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Creating index pages';
+ }
+
+ if (isset($_POST['rebuild_javascript']) && !in_array($config['file_script'], $rebuilt_scripts)) {
$log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding ' . $config['file_script'] . '';
buildJavascript();
$rebuilt_scripts[] = $config['file_script'];
}
- $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
- while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
- $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding thread #' . $post['id'];
- buildThread($post['id']);
+ if (isset($_POST['rebuild_thread'])) {
+ $query = query(sprintf("SELECT `id` FROM `posts_%s` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
+ while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
+ $log[] = '' . sprintf($config['board_abbreviation'], $board['uri']) . ': Rebuilding thread #' . $post['id'];
+ buildThread($post['id']);
+ }
}
}
--
cgit v1.3
From f0412b08140e256056fd1ea41ea1930fcc321d22 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 19:13:30 +1000
Subject: paginate ban list
---
inc/config.php | 2 ++
inc/mod/pages.php | 20 ++++++++++++--------
mod.php | 1 +
templates/mod/ban_list.html | 9 +++++++++
4 files changed, 24 insertions(+), 8 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/config.php b/inc/config.php
index 0ea25b46..2cbecdc3 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -826,6 +826,8 @@
// How many actions to show per page in the moderation log
$config['mod']['modlog_page'] = 350;
+ // How many bans to show per page in the ban list
+ $config['mod']['banlist_page'] = 350;
// Maximum number of results to display for a search, per board
$config['mod']['search_results'] = 75;
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 98851c52..3c3c08a4 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -246,7 +246,7 @@ function mod_ban() {
header('Location: ?/', true, $config['redirect_http']);
}
-function mod_bans() {
+function mod_bans($page_no = 1) {
global $config;
if (!hasPermission($config['mod']['view_banlist']))
@@ -272,23 +272,27 @@ function mod_bans() {
}
if ($config['mod']['view_banexpired']) {
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC");
- $query->bindValue(':time', time(), PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY (`expires` IS NOT NULL AND `expires` < :time), `set` DESC LIMIT :offset, :limit");
} else {
// Filter out expired bans
- $query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC");
- $query->bindValue(':time', time(), PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ $query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC LIMIT :offset, :limit");
}
+ $query->bindValue(':time', time(), PDO::PARAM_INT);
+ $query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT);
+ $query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
$bans = $query->fetchAll(PDO::FETCH_ASSOC);
+ $query = prepare("SELECT COUNT(*) FROM `bans`");
+ $query->execute() or error(db_error($query));
+ $count = $query->fetchColumn(0);
+
foreach ($bans as &$ban) {
if (filter_var($ban['ip'], FILTER_VALIDATE_IP) !== false)
$ban['real_ip'] = true;
}
- mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans));
+ mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans, 'count' => $count));
}
function mod_delete($board, $post) {
diff --git a/mod.php b/mod.php
index 78205bd3..86169b59 100644
--- a/mod.php
+++ b/mod.php
@@ -40,6 +40,7 @@ $pages = array(
'!^/IP/([\w.:]+)$!' => 'ip', // view ip address
'!^/IP/([\w.:]+)/remove_note/(\d+)$!' => 'ip_remove_note', // remove note from ip address
'!^/bans$!' => 'bans', // ban list
+ '!^/bans/(\d+)$!' => 'bans', // ban list
'!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post
diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html
index 00b8a0f4..66471d6d 100644
--- a/templates/mod/ban_list.html
+++ b/templates/mod/ban_list.html
@@ -72,3 +72,12 @@
{% endif %}
+
+{% if count > bans|count %}
+
+ {% for i in range(0, count / config.mod.modlog_page) %}
+ [{{ i + 1 }}]
+ {% endfor %}
+
+{% endif %}
+
--
cgit v1.3
From cc614e36b4135d5b8ac000bad8ed450df0e61ffe Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 20:11:10 +1000
Subject: multiple improvements
---
inc/mod/ban.php | 2 +-
inc/mod/pages.php | 80 ++++++++++++++++++++++++++++++++++++---
mod.php | 11 +++++-
templates/mod/dashboard.html | 10 +++++
templates/mod/debug/antispam.html | 42 ++++++++++++++++++++
templates/page.html | 2 +-
6 files changed, 138 insertions(+), 9 deletions(-)
create mode 100644 templates/mod/debug/antispam.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/ban.php b/inc/mod/ban.php
index e7110edf..4d73488f 100644
--- a/inc/mod/ban.php
+++ b/inc/mod/ban.php
@@ -80,7 +80,7 @@ function ban($mask, $reason, $length, $board) {
$query->execute() or error(db_error($query));
- modLog('Created a new ban (#' . $pdo->lastInsertId() . ') for ' . utf8tohtml($mask) . ' with ' . ($reason ? 'reason: ' . $reason . '' : 'no reason'));
+ modLog('Created a new ban (#' . $pdo->lastInsertId() . ') for ' . utf8tohtml($mask) . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason'));
}
function unban($id) {
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 3c3c08a4..7e6cddfe 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -15,6 +15,7 @@ function mod_page($title, $template, $args) {
echo Element('page.html', array(
'config' => $config,
'mod' => $mod,
+ 'hide_dashboard_link' => $template == 'mod/dashboard.html',
'title' => $title,
'body' => Element($template,
array_merge(
@@ -262,10 +263,12 @@ function mod_bans($page_no = 1) {
$unban[] = $match[1];
}
- query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
+ if (!empty($unban)) {
+ query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error());
- foreach ($unban as $id) {
- modLog("Removed ban #{$id}");
+ foreach ($unban as $id) {
+ modLog("Removed ban #{$id}");
+ }
}
header('Location: ?/bans', true, $config['redirect_http']);
@@ -278,8 +281,8 @@ function mod_bans($page_no = 1) {
$query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC LIMIT :offset, :limit");
}
$query->bindValue(':time', time(), PDO::PARAM_INT);
- $query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT);
- $query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT);
+ $query->bindValue(':limit', $config['mod']['banlist_page'], PDO::PARAM_INT);
+ $query->bindValue(':offset', ($page_no - 1) * $config['mod']['banlist_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$bans = $query->fetchAll(PDO::FETCH_ASSOC);
@@ -295,6 +298,58 @@ function mod_bans($page_no = 1) {
mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans, 'count' => $count));
}
+
+function mod_lock($board, $unlock, $post) {
+ global $config;
+
+ if (!openBoard($board))
+ error($config['error']['noboard']);
+
+ if (!hasPermission($config['mod']['lock'], $board))
+ error($config['error']['noaccess']);
+
+ $query = prepare(sprintf('UPDATE `posts_%s` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query->bindValue(':id', $post);
+ $query->bindValue(':locked', $unlock ? 0 : 1);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
+}
+
+function mod_sticky($board, $unsticky, $post) {
+ global $config;
+
+ if (!openBoard($board))
+ error($config['error']['noboard']);
+
+ if (!hasPermission($config['mod']['sticky'], $board))
+ error($config['error']['noaccess']);
+
+ $query = prepare(sprintf('UPDATE `posts_%s` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query->bindValue(':id', $post);
+ $query->bindValue(':sticky', $unsticky ? 0 : 1);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
+}
+
+function mod_bumplock($board, $unbumplock, $post) {
+ global $config;
+
+ if (!openBoard($board))
+ error($config['error']['noboard']);
+
+ if (!hasPermission($config['mod']['bumplock'], $board))
+ error($config['error']['noaccess']);
+
+ $query = prepare(sprintf('UPDATE `posts_%s` SET `sage` = :bumplock WHERE `id` = :id AND `thread` IS NULL', $board));
+ $query->bindValue(':id', $post);
+ $query->bindValue(':bumplock', $unbumplock ? 0 : 1);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
+}
+
function mod_delete($board, $post) {
global $config, $mod;
@@ -599,4 +654,19 @@ function mod_report_dismiss($id, $all = false) {
header('Location: ?/reports', true, $config['redirect_http']);
}
+function mod_debug_antispam() {
+ $args = array();
+
+ $query = query('SELECT COUNT(*) FROM `antispam`') or error(db_error());
+ $args['total'] = number_format($query->fetchColumn(0));
+
+ $query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL') or error(db_error());
+ $args['expiring'] = number_format($query->fetchColumn(0));
+
+ $query = query('SELECT * FROM `antispam` /* WHERE `passed` > 0 */ ORDER BY `passed` DESC LIMIT 25') or error(db_error());
+ $args['top'] = $query->fetchAll(PDO::FETCH_ASSOC);
+
+ mod_page("Debug: Anti-spam", 'mod/debug/antispam.html', $args);
+}
+
diff --git a/mod.php b/mod.php
index 86169b59..8af74a7b 100644
--- a/mod.php
+++ b/mod.php
@@ -43,10 +43,17 @@ $pages = array(
'!^/bans/(\d+)$!' => 'bans', // ban list
'!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post
+ '!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread
+ '!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread
+ '!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread
+
+ // these pages aren't listed in the dashboard without $config['debug']
+ '!^/debug/antispam$!' => 'debug_antispam',
// This should always be at the end:
- '!^/(\w+)/' . preg_quote($config['file_index'], '!') . '?$!' => 'view_board',
- '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_board',
+ '!^/(\w+)/$!' => 'view_board',
+ '!^/(\w+)/' . preg_quote($config['file_index'], '!') . '$!' => 'view_board',
+ '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_board',
'!^/(\w+)/' . preg_quote($config['dir']['res'], '!') .
str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_thread',
);
diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html
index 2a90d709..e9290e12 100644
--- a/templates/mod/dashboard.html
+++ b/templates/mod/dashboard.html
@@ -79,3 +79,13 @@
{# TODO #}
+
+{% if config.debug %}
+
+{% endif %}
+
diff --git a/templates/mod/debug/antispam.html b/templates/mod/debug/antispam.html
new file mode 100644
index 00000000..af5354ed
--- /dev/null
+++ b/templates/mod/debug/antispam.html
@@ -0,0 +1,42 @@
+
+ Most used (in active):
+
+
+
+ | Board |
+ Thread |
+ Hash (CRC32) |
+ Created |
+ Expires |
+ Passed |
+
+ {% for hash in top %}
+
+ | {{ config.board_abbreviation|sprintf(hash.board) }} |
+
+ {% if hash.thread %}
+ {{ hash.thread }}
+ {% else %}
+ -
+ {% endif %} |
+ {{ hash.hash }} |
+
+ {{ hash.created|ago }} ago
+ |
+
+ {% if hash.expires %}
+
+ {{ hash.expires|until }}
+
+ {% else %}
+ -
+ {% endif %}
+ |
+ {{ hash.passed }} |
+
+ {% endfor %}
+
+
+ Total: {{ total }} ({{ expiring }} set to expire)
+
+
diff --git a/templates/page.html b/templates/page.html
index 39d73bbd..0c0264d1 100644
--- a/templates/page.html
+++ b/templates/page.html
@@ -17,7 +17,7 @@
{% if subtitle %}
{{ subtitle }}
{% endif %}
- {% if mod %}{% trans %}Return to dashboard{% endtrans %} {% endif %}
+ {% if mod and not hide_dashboard_link %}{% trans %}Return to dashboard{% endtrans %} {% endif %}
{{ body }}
--
cgit v1.3
From 93553303b28d21cd2c55aaffc5a5831b6ccaf5c0 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 20:14:57 +1000
Subject: rebuild after sticky, lock, etc.
---
inc/mod/pages.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 7e6cddfe..31c78528 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -312,6 +312,10 @@ function mod_lock($board, $unlock, $post) {
$query->bindValue(':id', $post);
$query->bindValue(':locked', $unlock ? 0 : 1);
$query->execute() or error(db_error($query));
+ if($query->rowCount()) {
+ buildThread($post);
+ buildIndex();
+ }
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
@@ -329,6 +333,10 @@ function mod_sticky($board, $unsticky, $post) {
$query->bindValue(':id', $post);
$query->bindValue(':sticky', $unsticky ? 0 : 1);
$query->execute() or error(db_error($query));
+ if($query->rowCount()) {
+ buildThread($post);
+ buildIndex();
+ }
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
@@ -346,6 +354,10 @@ function mod_bumplock($board, $unbumplock, $post) {
$query->bindValue(':id', $post);
$query->bindValue(':bumplock', $unbumplock ? 0 : 1);
$query->execute() or error(db_error($query));
+ if($query->rowCount()) {
+ buildThread($post);
+ buildIndex();
+ }
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
--
cgit v1.3
From a340c5b6eec89d0e023fc606081ec857f44a0b3d Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Mon, 16 Apr 2012 23:18:07 +1000
Subject: edit users
---
inc/lib/Twig/Extensions/Extension/Tinyboard.php | 2 +-
inc/mod/pages.php | 82 ++++++++++++++++++++++
mod.php | 1 +
templates/mod/log.html | 2 +-
templates/mod/user.html | 93 +++++++++++++++++++++++++
5 files changed, 178 insertions(+), 2 deletions(-)
create mode 100644 templates/mod/user.html
(limited to 'inc/mod/pages.php')
diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
index 2691cc55..df652444 100644
--- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php
+++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php
@@ -76,7 +76,7 @@ function twig_date_filter($date, $format) {
return strftime($format, $date);
}
-function twig_hasPermission_filter($mod, $permission, $board = false) {
+function twig_hasPermission_filter($mod, $permission, $board = null) {
return hasPermission($permission, $board, $mod);
}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 31c78528..e388c509 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -313,6 +313,7 @@ function mod_lock($board, $unlock, $post) {
$query->bindValue(':locked', $unlock ? 0 : 1);
$query->execute() or error(db_error($query));
if($query->rowCount()) {
+ modLog(($unlock ? 'Unlocked' : 'Locked') . " thread #{$post}");
buildThread($post);
buildIndex();
}
@@ -334,6 +335,7 @@ function mod_sticky($board, $unsticky, $post) {
$query->bindValue(':sticky', $unsticky ? 0 : 1);
$query->execute() or error(db_error($query));
if($query->rowCount()) {
+ modLog(($unlock ? 'Unstickied' : 'Stickied') . " thread #{$post}");
buildThread($post);
buildIndex();
}
@@ -355,6 +357,7 @@ function mod_bumplock($board, $unbumplock, $post) {
$query->bindValue(':bumplock', $unbumplock ? 0 : 1);
$query->execute() or error(db_error($query));
if($query->rowCount()) {
+ modLog(($unlock ? 'Unbumplocked' : 'Bumplocked') . " thread #{$post}");
buildThread($post);
buildIndex();
}
@@ -382,6 +385,85 @@ function mod_delete($board, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
+function mod_user($uid) {
+ global $config, $mod;
+
+ if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id']))
+ error($config['error']['noaccess']);
+
+ $query = prepare('SELECT * FROM `mods` WHERE `id` = :id');
+ $query->bindValue(':id', $uid);
+ $query->execute() or error(db_error($query));
+ if (!$user = $query->fetch(PDO::FETCH_ASSOC))
+ error($config['error']['404']);
+
+ if (hasPermission($config['mod']['editusers']) && isset($_POST['username'], $_POST['password'])) {
+ if (isset($_POST['allboards'])) {
+ $boards = array('*');
+ } else {
+ $_boards = listBoards();
+ foreach ($_boards as &$board) {
+ $board = $board['uri'];
+ }
+
+ $boards = array();
+ foreach ($_POST as $name => $value) {
+ if (preg_match('/^board_(\w+)$/', $name, $matches) && in_array($matches[1], $_boards))
+ $boards[] = $matches[1];
+ }
+ }
+
+ $query = prepare('UPDATE `mods` SET `username` = :username, `boards` = :boards WHERE `id` = :id');
+ $query->bindValue(':id', $uid);
+ $query->bindValue(':username', $_POST['username']);
+ $query->bindValue(':boards', implode(',', $boards));
+ $query->execute() or error(db_error($query));
+
+ if ($_POST['password'] != '') {
+ $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id');
+ $query->bindValue(':id', $uid);
+ $query->bindValue(':password', $_POST['password']);
+ $query->execute() or error(db_error($query));
+
+ if ($uid == $mod['id']) {
+ login($_POST['username'], $_POST['password']);
+ setCookies();
+ }
+ }
+
+ header('Location: ?/users', true, $config['redirect_http']);
+ return;
+ }
+
+ if (hasPermission($config['mod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) {
+ if ($_POST['password'] != '') {
+ $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id');
+ $query->bindValue(':id', $uid);
+ $query->bindValue(':password', $_POST['password']);
+ $query->execute() or error(db_error($query));
+
+ login($_POST['username'], $_POST['password']);
+ setCookies();
+ }
+
+ header('Location: ?/users', true, $config['redirect_http']);
+ return;
+ }
+
+ if (hasPermission($config['mod']['modlog'])) {
+ $query = prepare('SELECT * FROM `modlogs` WHERE `mod` = :id ORDER BY `time` DESC LIMIT 5');
+ $query->bindValue(':id', $uid);
+ $query->execute() or error(db_error($query));
+ $log = $query->fetchAll(PDO::FETCH_ASSOC);
+ } else {
+ $log = array();
+ }
+
+ $user['boards'] = explode(',', $user['boards']);
+
+ mod_page('Edit user', 'mod/user.html', array('user' => $user, 'logs' => $log, 'boards' => listBoards()));
+}
+
function mod_users() {
global $config;
diff --git a/mod.php b/mod.php
index 8af74a7b..85d10c6c 100644
--- a/mod.php
+++ b/mod.php
@@ -28,6 +28,7 @@ $pages = array(
'!^/log/(\d+)$!' => 'log', // modlog
'!^/users$!' => 'users', // manage users
+ '!^/users/(\d+)$!' => 'user', // edit user
'!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user
'!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
'!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm
diff --git a/templates/mod/log.html b/templates/mod/log.html
index 61243202..19924b1d 100644
--- a/templates/mod/log.html
+++ b/templates/mod/log.html
@@ -2,7 +2,7 @@
| Staff |
IP address |
- Ago |
+ Time |
Board |
Action |
diff --git a/templates/mod/user.html b/templates/mod/user.html
new file mode 100644
index 00000000..87a57d92
--- /dev/null
+++ b/templates/mod/user.html
@@ -0,0 +1,93 @@
+
+
+{% if logs|count > 0 %}
+
+{% endif %}
--
cgit v1.3
From 4891eae24eac73328ecdc9eb9c5c8a4ab1e9c346 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Thu, 19 Apr 2012 22:40:11 +1000
Subject: added filter/purge controls to ?/debug/antispam
---
inc/mod/pages.php | 27 +++++++++++++++++++++++----
templates/mod/debug/antispam.html | 25 ++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 5 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index e388c509..541a7c23 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -435,7 +435,7 @@ function mod_user($uid) {
return;
}
- if (hasPermission($config['mod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) {
+ if (hasPermission($config['dmod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) {
if ($_POST['password'] != '') {
$query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id');
$query->bindValue(':id', $uid);
@@ -749,15 +749,34 @@ function mod_report_dismiss($id, $all = false) {
}
function mod_debug_antispam() {
+ global $pdo, $config;
+
$args = array();
- $query = query('SELECT COUNT(*) FROM `antispam`') or error(db_error());
+ if (isset($_POST['board'], $_POST['thread'])) {
+ $where = '`board` = ' . $pdo->quote($_POST['board']);
+ if($_POST['thread'] != '')
+ $where .= ' AND `thread` = ' . $pdo->quote($_POST['thread']);
+
+ if (isset($_POST['purge'])) {
+ $query = prepare('UPDATE `antispam` SET `expires` = UNIX_TIMESTAMP() + :expires WHERE' . $where);
+ $query->bindValue(':expires', $config['spam']['hidden_inputs_expire']);
+ $query->execute() or error(db_error());
+ }
+
+ $args['board'] = $_POST['board'];
+ $args['thread'] = $_POST['thread'];
+ } else {
+ $where = '';
+ }
+
+ $query = query('SELECT COUNT(*) FROM `antispam`' . ($where ? " WHERE $where" : '')) or error(db_error());
$args['total'] = number_format($query->fetchColumn(0));
- $query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL') or error(db_error());
+ $query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL' . ($where ? " AND $where" : '')) or error(db_error());
$args['expiring'] = number_format($query->fetchColumn(0));
- $query = query('SELECT * FROM `antispam` /* WHERE `passed` > 0 */ ORDER BY `passed` DESC LIMIT 25') or error(db_error());
+ $query = query('SELECT * FROM `antispam` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `passed` DESC LIMIT 40') or error(db_error());
$args['top'] = $query->fetchAll(PDO::FETCH_ASSOC);
mod_page("Debug: Anti-spam", 'mod/debug/antispam.html', $args);
diff --git a/templates/mod/debug/antispam.html b/templates/mod/debug/antispam.html
index c3e70859..99331ed3 100644
--- a/templates/mod/debug/antispam.html
+++ b/templates/mod/debug/antispam.html
@@ -19,7 +19,9 @@
{% else %}
-
{% endif %} |
- {{ hash.hash }} |
+
+ {{ hash.hash|upper }}
+ |
{{ hash.created|ago }} ago
|
@@ -40,3 +42,24 @@
Total: {{ total }} ({{ expiring }} set to expire)
+
--
cgit v1.3
From 4fcf9c2c916140f8dc95fc975b4ff61cfb98c6cf Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 20 Apr 2012 19:47:55 +1000
Subject: Starting on ?/ban/
---
inc/mod/pages.php | 18 ++++++++++++++++++
mod.php | 1 +
2 files changed, 19 insertions(+)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 541a7c23..7bc970b0 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -365,6 +365,24 @@ function mod_bumplock($board, $unbumplock, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
}
+function mod_ban_post($board, $delete, $post) {
+ global $config, $mod;
+
+ if (!openBoard($board))
+ error($config['error']['noboard']);
+
+ if (!hasPermission($config['mod']['delete'], $board))
+ error($config['error']['noaccess']);
+
+ $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $board));
+ $query->bindValue(':id', $post);
+ $query->execute() or error(db_error($query));
+ if(!$ip = $query->fetchColumn(0))
+ error($config['error']['404']);
+
+ mod_page("New ban", 'mod/ban_form.html', array());
+}
+
function mod_delete($board, $post) {
global $config, $mod;
diff --git a/mod.php b/mod.php
index 85d10c6c..57967da5 100644
--- a/mod.php
+++ b/mod.php
@@ -44,6 +44,7 @@ $pages = array(
'!^/bans/(\d+)$!' => 'bans', // ban list
'!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post
+ '!^/(\w+)/ban/(&delete/)?(\d+)$!' => 'ban_post', // ban poster
'!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread
'!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread
'!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread
--
cgit v1.3
From de84ca6f755347b2c3fcf87165704a2d9e899d77 Mon Sep 17 00:00:00 2001
From: Michael Save
Date: Fri, 20 Apr 2012 21:37:48 +1000
Subject: Multiple improvements: ?/ban/ & ?/ban&delete/
---
inc/mod/pages.php | 47 ++++++++++++++++++++++++++++++++++++++++++---
mod.php | 2 +-
templates/mod/ban_form.html | 36 ++++++++++++++++++++++++++++++++--
3 files changed, 79 insertions(+), 6 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 7bc970b0..78f560ec 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -374,13 +374,54 @@ function mod_ban_post($board, $delete, $post) {
if (!hasPermission($config['mod']['delete'], $board))
error($config['error']['noaccess']);
- $query = prepare(sprintf('SELECT `ip` FROM `posts_%s` WHERE `id` = :id', $board));
+ $query = prepare(sprintf('SELECT `ip`, `thread` FROM `posts_%s` WHERE `id` = :id', $board));
$query->bindValue(':id', $post);
$query->execute() or error(db_error($query));
- if(!$ip = $query->fetchColumn(0))
+ if(!$_post = $query->fetch(PDO::FETCH_ASSOC))
error($config['error']['404']);
- mod_page("New ban", 'mod/ban_form.html', array());
+ $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'];
+
+ ban($ip, $_POST['reason'], parse_time($_POST['length']), $_POST['board'] == '*' ? false : $_POST['board']);
+
+ if (isset($_POST['public_message'], $_POST['message'])) {
+ // public ban message
+ $query = prepare(sprintf('UPDATE `posts_%s` SET `body` = CONCAT(`body`, :body) WHERE `id` = :id', $board));
+ $query->bindValue(':id', $post);
+ $query->bindValue(':body', sprintf($config['mod']['ban_message'], utf8tohtml($_POST['message'])));
+ $query->execute() or error(db_error($query));
+
+ modLog("Attached a public ban message to post #{$post}: " . utf8tohtml($_POST['message']));
+ buildThread($thread ? $thread : $post);
+ buildIndex();
+ } elseif (isset($_POST['delete'])) {
+ // Delete post
+ deletePost($post);
+ modLog("Deleted post #{$post}");
+ // Rebuild board
+ buildIndex();
+ }
+
+ 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()
+ );
+
+ mod_page("New ban", 'mod/ban_form.html', $args);
}
function mod_delete($board, $post) {
diff --git a/mod.php b/mod.php
index 57967da5..b5edd255 100644
--- a/mod.php
+++ b/mod.php
@@ -44,7 +44,7 @@ $pages = array(
'!^/bans/(\d+)$!' => 'bans', // ban list
'!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post
- '!^/(\w+)/ban/(&delete/)?(\d+)$!' => 'ban_post', // ban poster
+ '!^/(\w+)/ban(&delete)?/(\d+)$!' => 'ban_post', // ban poster
'!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread
'!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread
'!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread
diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html
index 1b94e725..9d4d6728 100644
--- a/templates/mod/ban_form.html
+++ b/templates/mod/ban_form.html
@@ -1,15 +1,29 @@
-