Browse Source

wildcard option ("*") for per-board mods

pull/40/head
Savetheinternet 13 years ago
parent
commit
eadeb6669e
  1. 2
      inc/config.php
  2. 7
      inc/mod.php
  3. 1
      install.php
  4. 4
      install.sql
  5. 94
      mod.php

2
inc/config.php

@ -371,7 +371,7 @@
// What level of administration you need to: // What level of administration you need to:
// Don't worry about per-board moderators. Let all mods moderate any board. // Don't worry about per-board moderators. Let all mods moderate any board.
$config['mod']['skip_per_board'] = true; $config['mod']['skip_per_board'] = true;
/* Post Controls */ /* Post Controls */
// View IP addresses // View IP addresses

7
inc/mod.php

@ -24,8 +24,11 @@
if(isset($action) && $mod['type'] < $action) if(isset($action) && $mod['type'] < $action)
return false; return false;
if(isset($board) && !$config['mod']['skip_per_board'] && !in_array($board, $mod['boards'])) if(!isset($board))
return true;
if(!$config['mod']['skip_per_board'] && !in_array('*', $mod['boards']) && !in_array($board, $mod['boards']))
return false; return false;
return true; return true;

1
install.php

@ -75,6 +75,7 @@
query("ALTER TABLE `theme_settings` DROP INDEX `name`") or error(db_error()); query("ALTER TABLE `theme_settings` DROP INDEX `name`") or error(db_error());
case 'v0.9.3-dev-1': case 'v0.9.3-dev-1':
query("ALTER TABLE `mods` ADD `boards` TEXT NOT NULL") or error(db_error()); query("ALTER TABLE `mods` ADD `boards` TEXT NOT NULL") or error(db_error());
query("UPDATE `mods` SET `boards` = '*'") or error(db_error());
case false: case false:
// Update version number // Update version number
file_write($config['has_installed'], VERSION); file_write($config['has_installed'], VERSION);

4
install.sql

@ -113,8 +113,8 @@ CREATE TABLE IF NOT EXISTS `mods` (
-- Dumping data for table `mods` -- Dumping data for table `mods`
-- --
INSERT INTO `mods` (`id`, `username`, `password`, `type`) VALUES INSERT INTO `mods` (`id`, `username`, `password`, `type`, `boards`) VALUES
(1, 'admin', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 2); (1, 'admin', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 2, '*');
-- -------------------------------------------------------- -- --------------------------------------------------------

94
mod.php

@ -1008,7 +1008,7 @@
$boards = Array(); $boards = Array();
foreach($_POST as $name => $null) { foreach($_POST as $name => $null) {
if(preg_match('/^board_(\w+)/', $name, $m)) if(preg_match('/^board_(.+)$/', $name, $m))
$boards[] = $m[1]; $boards[] = $m[1];
} }
$boards = implode(',', $boards); $boards = implode(',', $boards);
@ -1021,50 +1021,57 @@
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
modLog('Create a new user: "' . $_POST['username'] . '"'); modLog('Create a new user: "' . $_POST['username'] . '"');
} header('Location: ?/users', true, $config['redirect_http']);
} else {
$__boards = '<ul style="list-style:none;padding:2px 5px">'; $__boards = '<ul style="list-style:none;padding:2px 5px">';
$boards = listBoards(); $boards = array_merge(
foreach($boards as &$_board) { Array(Array('uri' => '*', 'title' => 'All')
$__boards .= '<li>' . ), listBoards());
'<input type="checkbox" name="board_' . $_board['uri'] . '" id="board_' . $_board['uri'] . '"/> ' . foreach($boards as &$_board) {
'<label style="display:inline" for="board_' . $_board['uri'] . '">' . $__boards .= '<li>' .
sprintf($config['board_abbreviation'], $_board['uri']) . '<input type="checkbox" name="board_' . $_board['uri'] . '" id="board_' . $_board['uri'] . '"' .
' - ' . $_board['title'] . '<label style="display:inline" for="board_' . $_board['uri'] . '">' .
'</label>' . ($_board['uri'] == '*' ?
'</li>'; '<em>"*"</em>'
} :
$__boards .= '</ul>'; sprintf($config['board_abbreviation'], $_board['uri'])
) .
' - ' . $_board['title'] .
'</label>' .
'</li>';
}
$body = '<fieldset><legend>New user</legend>' . $body = '<fieldset><legend>New user</legend>' .
// Begin form // Begin form
'<form style="text-align:center" action="" method="post">' . '<form style="text-align:center" action="" method="post">' .
'<table>' . '<table>' .
'<tr><th>Username</th><td><input size="20" maxlength="30" type="text" name="username" value="" autocomplete="off" /></td></tr>' . '<tr><th>Username</th><td><input size="20" maxlength="30" type="text" name="username" value="" autocomplete="off" /></td></tr>' .
'<tr><th>Password</th><td><input size="20" maxlength="30" type="password" name="password" value="" autocomplete="off" /></td></tr>' . '<tr><th>Password</th><td><input size="20" maxlength="30" type="password" name="password" value="" autocomplete="off" /></td></tr>' .
'<tr><th>Type</th><td>' . '<tr><th>Type</th><td>' .
'<div><label for="janitor">Janitor</label> <input type="radio" id="janitor" name="type" value="' . JANITOR . '" /></div>' . '<div><label for="janitor">Janitor</label> <input type="radio" id="janitor" name="type" value="' . JANITOR . '" /></div>' .
'<div><label for="mod">Mod</label> <input type="radio" id="mod" name="type" value="' . MOD . '" /></div>' . '<div><label for="mod">Mod</label> <input type="radio" id="mod" name="type" value="' . MOD . '" /></div>' .
'<div><label for="admin">Admin</label> <input type="radio" id="admin" name="type" value="' . ADMIN . '" /></div>' . '<div><label for="admin">Admin</label> <input type="radio" id="admin" name="type" value="' . ADMIN . '" /></div>' .
'</td></tr>' . '</td></tr>' .
'<tr><th>Boards</th><td>' . $__boards . '</td></tr>' . '<tr><th>Boards</th><td>' . $__boards . '</td></tr>' .
'</table>' . '</table>' .
'<input style="margin-top:10px" type="submit" value="Create user" />' . '<input style="margin-top:10px" type="submit" value="Create user" />' .
// End form // End form
'</form></fieldset>'; '</form></fieldset>';
echo Element('page.html', Array( echo Element('page.html', Array(
'config'=>$config, 'config'=>$config,
'title'=>'New user', 'title'=>'New user',
'body'=>$body 'body'=>$body
,'mod'=>true ,'mod'=>true
) )
); );
}
} elseif(preg_match('/^\/users\/(\d+)(\/(promote|demote|delete))?$/', $query, $matches)) { } elseif(preg_match('/^\/users\/(\d+)(\/(promote|demote|delete))?$/', $query, $matches)) {
$modID = &$matches[1]; $modID = &$matches[1];
@ -1112,7 +1119,7 @@
if(!isset($change_password_only)) { if(!isset($change_password_only)) {
$boards = Array(); $boards = Array();
foreach($_POST as $name => $null) { foreach($_POST as $name => $null) {
if(preg_match('/^board_(\w+)/', $name, $m)) if(preg_match('/^board_(.+)$/', $name, $m))
$boards[] = $m[1]; $boards[] = $m[1];
} }
$boards = implode(',', $boards); $boards = implode(',', $boards);
@ -1149,7 +1156,10 @@
} }
$__boards = '<ul style="list-style:none;padding:2px 5px">'; $__boards = '<ul style="list-style:none;padding:2px 5px">';
$boards = listBoards(); $boards = array_merge(
Array(Array('uri' => '*', 'title' => 'All')
), listBoards());
$_mod['boards'] = explode(',', $_mod['boards']); $_mod['boards'] = explode(',', $_mod['boards']);
foreach($boards as &$_board) { foreach($boards as &$_board) {
$__boards .= '<li>' . $__boards .= '<li>' .
@ -1159,7 +1169,11 @@
: '') . : '') .
'/> ' . '/> ' .
'<label style="display:inline" for="board_' . $_board['uri'] . '">' . '<label style="display:inline" for="board_' . $_board['uri'] . '">' .
sprintf($config['board_abbreviation'], $_board['uri']) . ($_board['uri'] == '*' ?
'<em>"*"</em>'
:
sprintf($config['board_abbreviation'], $_board['uri'])
) .
' - ' . $_board['title'] . ' - ' . $_board['title'] .
'</label>' . '</label>' .
'</li>'; '</li>';

Loading…
Cancel
Save