summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-02-22 17:38:38 +1100
committerSavetheinternet <savetheinternet@n0v4.com>2011-02-22 17:38:38 +1100
commita1f300cc8f2627c815b6fd054e8d6f3a88eb5ed9 (patch)
tree525cc0ffb81a265b874f2d4cb0eed6c80292f28f
parent23f67abb0eae540a404836a11fdd924715729580 (diff)
Manage boards
-rw-r--r--inc/config.php4
-rw-r--r--inc/functions.php16
-rw-r--r--inc/mod.php2
-rw-r--r--mod.php82
4 files changed, 104 insertions, 0 deletions
diff --git a/inc/config.php b/inc/config.php
index 5bd8eb97..d19af058 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -295,6 +295,10 @@
$config['mod']['view_ban'] = $config['mod']['view_banlist'];
// Create a new board
$config['mod']['newboard'] = ADMIN;
+ // Manage existing boards (change title, etc)
+ $config['mod']['manageboards'] = ADMIN;
+ // Delete a board
+ $config['mod']['deleteboard'] = ADMIN;
// Mod links (full HTML)
// Correspond to above permission directives
diff --git a/inc/functions.php b/inc/functions.php
index 0fa20fc3..dabdbb64 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -988,6 +988,22 @@
@file_put_contents($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body) or error("Couldn't write to file.");
}
+ function rrmdir($dir) {
+ if (is_dir($dir)) {
+ $objects = scandir($dir);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($dir."/".$object) == "dir")
+ rrmdir($dir."/".$object);
+ else
+ unlink($dir."/".$object);
+ }
+ }
+ reset($objects);
+ rmdir($dir);
+ }
+ }
+
function generate_tripcode ( $name, $length = 10 ) {
global $config;
$name = stripslashes ( $name );
diff --git a/inc/mod.php b/inc/mod.php
index 89ab8d35..51ff7785 100644
--- a/inc/mod.php
+++ b/inc/mod.php
@@ -112,6 +112,8 @@
'</a> - ' .
$b['title'] .
(isset($b['subtitle']) ? '<span class="unimportant"> — ' . $b['subtitle'] . '</span>' : '') .
+ ($mod['type'] >= $config['mod']['manageboards'] ?
+ ' <a href="?/board/' . $b['uri'] . '" class="unimportant">[manage]</a>' : '') .
'</li>';
}
diff --git a/mod.php b/mod.php
index 0dfb8262..d438cd9d 100644
--- a/mod.php
+++ b/mod.php
@@ -194,6 +194,84 @@
header('Location: ' . $_SERVER['HTTP_REFERER'], true, $config['redirect_http']);
else
header('Location: ?/reports', true, $config['redirect_http']);
+ } elseif(preg_match('/^\/board\/(\w+)(\/delete)?$/', $query, $matches)) {
+ if($mod['type'] < $config['mod']['manageboards']) error($config['error']['noaccess']);
+
+ if(!openBoard($matches[1]))
+ error($config['error']['noboard']);
+
+ if(isset($matches[2]) && $matches[2] == '/delete') {
+ if($mod['type'] < $config['mod']['deleteboard']) error($config['error']['noaccess']);
+ // Delete board
+
+ // Delete entire board directory
+ rrmdir($board['uri'] . '/');
+
+ // Delete posting table
+ $query = query(sprintf("DROP TABLE IF EXISTS `posts_%s`", $board['uri'])) or error(db_error());
+
+ // Clear reports
+ $query = prepare("DELETE FROM `reports` WHERE `board` = :id");
+ $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ // Delete from table
+ $query = prepare("DELETE FROM `boards` WHERE `id` = :id");
+ $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ header('Location: ?/', true, $config['redirect_http']);
+ } elseif(isset($_POST['title']) && isset($_POST['subtitle'])) {
+ $query = prepare("UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `id` = :id");
+ $query->bindValue(':title', utf8tohtml($_POST['title'], true));
+
+ if(!empty($_POST['subtitle']))
+ $query->bindValue(':subtitle', utf8tohtml($_POST['subtitle'], true));
+ else
+ $query->bindValue(':subtitle', null, PDO::PARAM_NULL);
+
+ $query->bindValue(':id', $board['id'], PDO::PARAM_INT);
+ $query->execute() or error(db_error($query));
+
+ openBoard($board['uri']);
+ }
+
+ $body =
+ '<fieldset><legend><a href="?/' .
+ $board['uri'] . '/' . $config['file_index'] . '">' .
+ sprintf($config['board_abbreviation'], $board['uri']) . '</a>' .
+ ' - ' . $board['name'] . '</legend>' .
+
+ // Begin form
+ '<form style="text-align:center" action="" method="post">' .
+
+ '<table>' .
+
+ '<tr><th>URI</th><td>' . $board['uri'] . '</td>' .
+ '<tr><th>Title</th><td><input size="20" maxlength="20" type="text" name="title" value="' . $board['name'] . '" /></td></tr>' .
+ '<tr><th>Subtitle</th><td><input size="20" maxlength="40" type="text" name="subtitle" value="' .
+ (isset($board['title']) ? $board['title'] : '') . '" /></td></tr>' .
+
+ '</table>' .
+
+ '<input type="submit" value="Update" />' .
+
+ // End form
+ '</form> ' .
+
+ // Delete button
+ ($mod['type'] >= $config['mod']['deleteboard'] ?
+ '<p style="text-align:center"><a href="?/board/' . $board['uri'] . '/delete">Delete board</a></p>'
+ :'') .
+
+ '</fieldset>';
+
+ echo Element('page.html', Array(
+ 'index'=>$config['root'],
+ 'title'=>'Manage – ' . sprintf($config['board_abbreviation'], $board['uri']),
+ 'body'=>$body,
+ 'mod'=>true
+ ));
} elseif(preg_match('/^\/bans$/', $query)) {
if($mod['type'] < $config['mod']['view_banlist']) error($config['error']['noaccess']);
@@ -368,6 +446,10 @@
'subtitle' => $_POST['subtitle']
);
+ // HTML characters
+ $b['title'] = utf8tohtml($b['title'], true);
+ $b['subtitle'] = utf8tohtml($b['subtitle'], true);
+
// Check required fields
if(empty($b['uri']))
error(sprintf($config['error']['required'], 'URI'));