Merge pull request #295 from PietroCarrara/config
Dynamic boards, API changes
This commit is contained in:
commit
72d61b6bac
44
inc/api.php
44
inc/api.php
|
@ -45,8 +45,9 @@ class Api {
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->fileFields = array(
|
$this->fileFields = array(
|
||||||
'thumbheight' => 'tn_h',
|
'file_id' => 'id',
|
||||||
'thumbwidth' => 'tn_w',
|
'type' => 'mime',
|
||||||
|
'extension' => 'ext',
|
||||||
'height' => 'h',
|
'height' => 'h',
|
||||||
'width' => 'w',
|
'width' => 'w',
|
||||||
'size' => 'fsize',
|
'size' => 'fsize',
|
||||||
|
@ -90,13 +91,12 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translateFile($file, $post, &$apiPost) {
|
private function translateFile($file, $post, &$apiPost) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
$this->translateFields($this->fileFields, $file, $apiPost);
|
$this->translateFields($this->fileFields, $file, $apiPost);
|
||||||
$apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.'));
|
$apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.'));
|
||||||
$dotPos = strrpos($file->file, '.');
|
|
||||||
$apiPost['ext'] = substr($file->file, $dotPos);
|
|
||||||
$apiPost['tim'] = substr($file->file, 0, $dotPos);
|
|
||||||
if (isset ($file->thumb) && $file->thumb) {
|
if (isset ($file->thumb) && $file->thumb) {
|
||||||
$apiPost['spoiler'] = $file->thumb === 'spoiler' ? 1 : 0;
|
$apiPost['spoiler'] = $file->thumb === 'spoiler';
|
||||||
}
|
}
|
||||||
if (isset ($file->hash) && $file->hash) {
|
if (isset ($file->hash) && $file->hash) {
|
||||||
$apiPost['md5'] = base64_encode(hex2bin($file->hash));
|
$apiPost['md5'] = base64_encode(hex2bin($file->hash));
|
||||||
|
@ -104,6 +104,20 @@ class Api {
|
||||||
else if (isset ($post->filehash) && $post->filehash) {
|
else if (isset ($post->filehash) && $post->filehash) {
|
||||||
$apiPost['md5'] = base64_encode(hex2bin($post->filehash));
|
$apiPost['md5'] = base64_encode(hex2bin($post->filehash));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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];
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiPost['thumb_path'] = $config['root'] . sprintf($config['file_thumb'], $thumbFile);
|
||||||
|
} else {
|
||||||
|
$apiPost['thumb_path'] = $config['uri_thumb'] . $file->thumb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function translatePost($post, $threadsPage = false) {
|
private function translatePost($post, $threadsPage = false) {
|
||||||
|
@ -138,21 +152,13 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle files
|
// Handle files
|
||||||
// Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API.
|
|
||||||
if (isset($post->files) && $post->files && !$threadsPage) {
|
if (isset($post->files) && $post->files && !$threadsPage) {
|
||||||
$file = $post->files[0];
|
$apiPost['files'] = [];
|
||||||
$this->translateFile($file, $post, $apiPost);
|
foreach ($post->files as $f) {
|
||||||
if (sizeof($post->files) > 1) {
|
$file = array();
|
||||||
$extra_files = array();
|
$this->translateFile($f, $post, $file);
|
||||||
foreach ($post->files as $i => $f) {
|
|
||||||
if ($i == 0) continue;
|
|
||||||
|
|
||||||
$extra_file = array();
|
$apiPost['files'][] = $file;
|
||||||
$this->translateFile($f, $post, $extra_file);
|
|
||||||
|
|
||||||
$extra_files[] = $extra_file;
|
|
||||||
}
|
|
||||||
$apiPost['extra_files'] = $extra_files;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
status.php
26
status.php
|
@ -1,13 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'inc/functions.php';
|
require_once 'inc/functions.php';
|
||||||
|
require_once 'templates/themes/overboards/overboards.php';
|
||||||
|
|
||||||
function endsWith( $haystack, $needle ) {
|
// Allowed boards
|
||||||
$length = strlen( $needle );
|
$whitelist = [];
|
||||||
if( !$length ) {
|
foreach ($config['boards'] as $boards) {
|
||||||
return true;
|
foreach ($boards as $board) {
|
||||||
|
$whitelist[] = $board;
|
||||||
}
|
}
|
||||||
return substr( $haystack, -$length ) === $needle;
|
}
|
||||||
|
foreach ($overboards_config as $board) {
|
||||||
|
$whitelist[] = $board['uri'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boards that are nsfw
|
// Boards that are nsfw
|
||||||
|
@ -20,22 +24,22 @@ $readonly_boards = ['overboard', 'sfw', 'alt'];
|
||||||
$board_list = listBoards();
|
$board_list = listBoards();
|
||||||
|
|
||||||
// Add objects that are not boards but are treated as such
|
// Add objects that are not boards but are treated as such
|
||||||
$board_list[] = ['uri' => 'overboard', 'title' => 'Overboard'];
|
foreach ($overboards_config as $overboard) {
|
||||||
$board_list[] = ['uri' => 'sfw', 'title' => 'SFW Overboard'];
|
$board_list[] = $overboard;
|
||||||
$board_list[] = ['uri' => 'alt', 'title' => 'Alternate Overboard'];
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allowed fields for the board object:
|
* Allowed fields for the board object:
|
||||||
* - code<string>: The board code ('b', 'tech', ...)
|
* - code<string>: The board code ('b', 'tech', ...)
|
||||||
* - name<string>: The board user-readable name ('Siberia', ...)
|
* - name<string>: The board user-readable name ('Siberia', ...)
|
||||||
* - description<string>: The board description ('Leftist Politically Incorrect', ...)
|
|
||||||
* - sfw<boolean>: Is this board sfw?
|
* - sfw<boolean>: Is this board sfw?
|
||||||
* - alternate_spoilers<boolean>: Does this board use the alunya spoiler?
|
* - alternate_spoilers<boolean>: Does this board use the alunya spoiler?
|
||||||
|
* - posting_enabled<boolean>: Can new posts be created belonging to this board?
|
||||||
*/
|
*/
|
||||||
$boards = [];
|
$boards = [];
|
||||||
foreach ($board_list as $board) {
|
foreach ($board_list as $board) {
|
||||||
// Skip archives
|
// Skip non-whitelisted boards
|
||||||
if (endsWith($board['uri'], '_archive')) {
|
if (!in_array($board['uri'], $whitelist)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue