From 4a69c62df33fdf8832e9e18ac272a30c4139a61f Mon Sep 17 00:00:00 2001 From: Pietro Carrara Date: Sun, 4 Jul 2021 19:33:31 -0300 Subject: [PATCH 1/2] Load board config while generating json --- inc/api.php | 21 +++++++++++++++------ status.php | 15 ++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/inc/api.php b/inc/api.php index 9175ede2..f5d19561 100644 --- a/inc/api.php +++ b/inc/api.php @@ -108,13 +108,17 @@ class Api { $apiPost['file_path'] = $config['uri_img'] . $file->file; // Pick the correct thumbnail - if (!isset ($file->thumb) || $file->thumb === 'file') { - $thumbFile = $config['file_icons']['default']; - if (isset($file->extension) && isset($config['file_icons'][$file->extension])) { - $thumbFile = $config['file_icons'][$file->extension]; - } + if (isset($file->thumb)) { + if ($file->thumb === 'spoiler') { + $apiPost['thumb_path'] = $config['root'] . $config['spoiler_image']; + } else if ($file->thumb === 'file') { + $thumbFile = $config['file_icons']['default']; + if (isset($file->extension) && isset($config['file_icons'][$file->extension])) { + $thumbFile = $config['file_icons'][$file->extension]; + } - $apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile); + $apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile); + } } else { $apiPost['thumb_path'] = $config['uri_thumb'] . $file->thumb; } @@ -129,6 +133,11 @@ class Api { if (isset($config['poster_ids']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']); if ($threadsPage) return $apiPost; + // Load board info + if (isset($post->board)) { + openBoard($post->board); + } + // Handle special fields if (isset($post->body_nomarkup) && ($this->config['country_flags'] || $this->config['user_flag'])) { $modifiers = extract_modifiers($post->body_nomarkup); diff --git a/status.php b/status.php index b02a650b..30bb116c 100644 --- a/status.php +++ b/status.php @@ -3,6 +3,11 @@ require_once 'inc/functions.php'; require_once 'templates/themes/overboards/overboards.php'; +// Boards that are nsfw +$nsfw_boards = ['b', 'overboard']; +// Boards where posts are not allowed to be created +$readonly_boards = []; + // Allowed boards $whitelist = []; foreach ($config['boards'] as $boards) { @@ -12,15 +17,9 @@ foreach ($config['boards'] as $boards) { } foreach ($overboards_config as $board) { $whitelist[] = $board['uri']; + $readonly_boards[] = $board['uri']; } -// 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 @@ -33,7 +32,6 @@ foreach ($overboards_config as $overboard) { * - code: The board code ('b', 'tech', ...) * - name: The board user-readable name ('Siberia', ...) * - sfw: Is this board sfw? - * - alternate_spoilers: Does this board use the alunya spoiler? * - posting_enabled: Can new posts be created belonging to this board? */ $boards = []; @@ -47,7 +45,6 @@ foreach ($board_list as $board) { '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), ]; } From ddb7c92bdb83c9ec93076dda9a9aeded1b6162c1 Mon Sep 17 00:00:00 2001 From: Pietro Carrara Date: Sun, 4 Jul 2021 19:42:45 -0300 Subject: [PATCH 2/2] Check if file fields are set on the API --- inc/api.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/inc/api.php b/inc/api.php index f5d19561..a60d9b41 100644 --- a/inc/api.php +++ b/inc/api.php @@ -108,18 +108,19 @@ class Api { $apiPost['file_path'] = $config['uri_img'] . $file->file; // Pick the correct thumbnail - if (isset($file->thumb)) { - if ($file->thumb === 'spoiler') { - $apiPost['thumb_path'] = $config['root'] . $config['spoiler_image']; - } else if ($file->thumb === 'file') { - $thumbFile = $config['file_icons']['default']; - if (isset($file->extension) && isset($config['file_icons'][$file->extension])) { - $thumbFile = $config['file_icons'][$file->extension]; - } - - $apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile); + if (isset($file->thumb) && $file->thumb === 'spoiler') { + // Spoiler + $apiPost['thumb_path'] = $config['root'] . $config['spoiler_image']; + } else if (!isset($file->thumb) || $file->thumb === 'file') { + // Default file format image + $thumbFile = $config['file_icons']['default']; + if (isset($file->extension) && isset($config['file_icons'][$file->extension])) { + $thumbFile = $config['file_icons'][$file->extension]; } + + $apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile); } else { + // The file's own thumbnail $apiPost['thumb_path'] = $config['uri_thumb'] . $file->thumb; } }