forked from leftypol/leftypol
Use whitelist on boards
This commit is contained in:
parent
6797d447f2
commit
186e122b42
1 changed files with 12 additions and 55 deletions
67
status.php
67
status.php
|
@ -3,11 +3,16 @@
|
||||||
require_once 'inc/functions.php';
|
require_once 'inc/functions.php';
|
||||||
require_once 'templates/themes/overboards/overboards.php';
|
require_once 'templates/themes/overboards/overboards.php';
|
||||||
|
|
||||||
// List of regexes that blacklist boards
|
// Allowed boards
|
||||||
$blacklist = [
|
$whitelist = [];
|
||||||
'/^.*_archive$/', // b_archive, leftypol_archive, ...
|
foreach ($config['boards'] as $boards) {
|
||||||
'/^b_.*$/', // b_anime, b_leftypol, ...
|
foreach ($boards as $board) {
|
||||||
];
|
$whitelist[] = $board;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($overboards_config as $board) {
|
||||||
|
$whitelist[] = $board['uri'];
|
||||||
|
}
|
||||||
|
|
||||||
// Boards that are nsfw
|
// Boards that are nsfw
|
||||||
$nsfw_boards = ['b', 'overboard'];
|
$nsfw_boards = ['b', 'overboard'];
|
||||||
|
@ -33,56 +38,8 @@ foreach ($overboards_config as $overboard) {
|
||||||
*/
|
*/
|
||||||
$boards = [];
|
$boards = [];
|
||||||
foreach ($board_list as $board) {
|
foreach ($board_list as $board) {
|
||||||
// Skip blacklisted boards
|
// Skip non-whitelisted boards
|
||||||
foreach ($blacklist as $regex) {
|
if (!in_array($board['uri'], $whitelist)) {
|
||||||
if (preg_match($regex, $board['uri'])) {
|
|
||||||
continue 2; // Skip to the next board
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$boards[] = [
|
|
||||||
'code' => $board['uri'],
|
|
||||||
'name' => $board['title'],
|
|
||||||
'sfw' => !in_array($board['uri'], $nsfw_boards),
|
|
||||||
'alternate_spoilers' => in_array($board['uri'], $alunya_spoiler),
|
|
||||||
'posting_enabled' => !in_array($board['uri'], $readonly_boards),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function endsWith( $haystack, $needle ) {
|
|
||||||
$length = strlen( $needle );
|
|
||||||
if( !$length ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return substr( $haystack, -$length ) === $needle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Boards that are nsfw
|
|
||||||
$nsfw_boards = ['b', 'overboard'];
|
|
||||||
// Boards that use spoiler_alunya.png as their spoiler
|
|
||||||
$alunya_spoiler = ['leftypol', 'anime'];
|
|
||||||
// Boards where posts are not allowed to be created
|
|
||||||
$readonly_boards = ['overboard', 'sfw', 'alt'];
|
|
||||||
|
|
||||||
$board_list = listBoards();
|
|
||||||
|
|
||||||
// Add objects that are not boards but are treated as such
|
|
||||||
$board_list[] = ['uri' => 'overboard', 'title' => 'Overboard'];
|
|
||||||
$board_list[] = ['uri' => 'sfw', 'title' => 'SFW Overboard'];
|
|
||||||
$board_list[] = ['uri' => 'alt', 'title' => 'Alternate Overboard'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allowed fields for the board object:
|
|
||||||
* - code<string>: The board code ('b', 'tech', ...)
|
|
||||||
* - name<string>: The board user-readable name ('Siberia', ...)
|
|
||||||
* - description<string>: The board description ('Leftist Politically Incorrect', ...)
|
|
||||||
* - sfw<boolean>: Is this board sfw?
|
|
||||||
* - alternate_spoilers<boolean>: Does this board use the alunya spoiler?
|
|
||||||
*/
|
|
||||||
$boards = [];
|
|
||||||
foreach ($board_list as $board) {
|
|
||||||
// Skip archives
|
|
||||||
if (endsWith($board['uri'], '_archive')) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue