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 @@ ' - ' . $b['title'] . (isset($b['subtitle']) ? ' — ' . $b['subtitle'] . '' : '') . + ($mod['type'] >= $config['mod']['manageboards'] ? + ' [manage]' : '') . ''; } 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 = + '
' . + sprintf($config['board_abbreviation'], $board['uri']) . '' . + ' - ' . $board['name'] . '' . + + // Begin form + '
' . + + '' . + + '' . + '' . + '' . + + '
URI' . $board['uri'] . '
Title
Subtitle
' . + + '' . + + // End form + '
' . + + // Delete button + ($mod['type'] >= $config['mod']['deleteboard'] ? + '

Delete board

' + :'') . + + '
'; + + 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'));