summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-04-14 22:28:21 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-04-14 22:28:21 +1000
commit87281687ed3ed06fd76d7bbb6c29404bb883418a (patch)
treeb343c1751d8f351ba87d2337d83014865a84f80e
parent1437a121f759731db35ea8c35c7f2ebbb2a42f5d (diff)
promote/demote users, started on rebuild
-rw-r--r--inc/mod/pages.php67
-rw-r--r--inc/template.php2
-rw-r--r--mod.php3
-rw-r--r--templates/mod/rebuild.html71
-rw-r--r--templates/mod/users.html6
5 files changed, 136 insertions, 13 deletions
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 @@
+<form style="width:200px;margin:auto" action="?/rebuild" method="post">
+ <ul id="rebuild">
+ <li style="margin-bottom:8px">
+ <input type="checkbox" name="rebuild_all" id="rebuild_all" onchange="toggleall(this.checked)">
+ <label for="rebuild_all"><strong>Toggle all</strong></label>
+ <script>
+ function toggleall(val) {
+ /* TODO: something more suitable for all browsers? */
+ var elements = document.getElementById('rebuild').querySelectorAll('input');
+ for (i in elements) {
+ elements[i].checked = val;
+ }
+ }
+ </script>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_cache" id="rebuild_cache" checked>
+ <label for="rebuild_cache">Flush cache</label>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_javascript" id="rebuild_javascript" checked>
+ <label for="rebuild_javascript">Rebuild Javascript</label>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_index" id="rebuild_index" checked>
+ <label for="rebuild_index">Rebuild index pages</label>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_thread" id="rebuild_thread" checked>
+ <label for="rebuild_thread">Rebuild thread pages</label>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_themes" id="rebuild_themes" checked>
+ <label for="rebuild_themes">Rebuild themes</label>
+ </li>
+ <li>
+ <input type="checkbox" name="rebuild_posts" id="rebuild_posts">
+ <label for="rebuild_posts">Rebuild replies</label>
+ </li>
+ </ul>
+
+ <hr>
+
+ <ul id="boards">
+ <li style="margin-bottom:8px">
+ <input type="checkbox" name="boards_all" id="boards_all" onchange="toggleallboards(this.checked)" checked>
+ <label for="boards_all"><strong>All boards</strong></label>
+ <script>
+ function toggleallboards(val) {
+ /* TODO: something more suitable for all browsers? */
+ var elements = document.getElementById('boards').querySelectorAll('input');
+ for (i in elements) {
+ elements[i].checked = val;
+ }
+ }
+ </script>
+ </li>
+ {% for board in boards %}
+ <li>
+ <input type="checkbox" name="board_{{ board.uri }}" id="board-{{ board.uri }}" checked>
+ <label for="board-{{ board.uri }}">
+ {{ config.board_abbreviation|sprintf(board.uri) }} - {{ board.title }}
+ </label>
+ </li>
+ {% endfor %}
+ </ul>
+
+ <p style="text-align:center">
+ <input type="submit" value="Rebuild">
+ </p>
+</form>
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 @@
</td>
<td>
{% if mod|hasPermission(config.mod.modlog) %}
- <span title="{{ user.action|e }}">{{ user.last|ago }}</span>
+ {% if user.last %}
+ <span title="{{ user.action|e }}">{{ user.last|ago }}</span>
+ {% else %}
+ <em>never</em>
+ {% endif %}
{% else %}
&ndash;
{% endif %}