Add aditional overboard themes that are similar to ukko but only include certain boards instead of excluding certain boards. In order for them to work ['overboards'] needs to be configured correctly.

This commit is contained in:
Benjamin Southall 2017-04-25 00:49:34 +09:00
parent a16122329f
commit f453fa1ee3
8 changed files with 652 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
$theme = array();
// Theme name
$theme['name'] = 'Overboard (Ukko2)';
// Description (you can use Tinyboard markup here)
$theme['description'] = 'Board with threads and messages from all boards';
$theme['version'] = 'v0.2';
// Theme configuration
$theme['config'] = array();
$theme['config'][] = array(
'title' => 'Board name',
'name' => 'title',
'type' => 'text',
'default' => 'Ukko'
);
$theme['config'][] = array(
'title' => 'Board URI',
'name' => 'uri',
'type' => 'text',
'default' => '*',
'comment' => '(ukko for example)'
);
$theme['config'][] = array(
'title' => 'Subtitle',
'name' => 'subtitle',
'type' => 'text',
'comment' => '(%s = thread limit. for example "%s freshly bumped threads")'
);
$theme['config'][] = array(
'title' => 'included boards',
'name' => 'include',
'type' => 'text',
'comment' => '(space seperated)'
);
$theme['config'][] = array(
'title' => 'Number of threads',
'name' => 'thread_limit',
'type' => 'text',
'default' => '15',
);
// Unique function name for building everything
$theme['build_function'] = 'ukko2_build';
$theme['install_callback'] = 'ukko2_install';
if(!function_exists('ukko2_install')) {
function ukko2_install($settings) {
if (!file_exists($settings['uri']))
@mkdir($settings['uri'], 0777) or error("Couldn't create " . $settings['uri'] . ". Check permissions.", true);
file_write($settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array()));
}
}

View File

@ -0,0 +1,155 @@
<?php
require 'info.php';
function ukko2_build($action, $settings) {
global $config;
$ukko2 = new ukko2();
$ukko2->settings = $settings;
if (! ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete')) {
return;
}
$action = generation_strategy('sb_ukko2', array());
if ($action == 'delete') {
file_unlink($settings['uri'] . '/index.html');
if ($config['api']['enabled']) {
$jsonFilename = $settings['uri'] . '/0.json';
file_unlink($jsonFilename);
$jsonFilename = $settings['uri'] . '/catalog.json';
file_unlink($jsonFilename);
$jsonFilename = $settings['uri'] . '/threads.json';
file_unlink($jsonFilename);
}
}
elseif ($action == 'rebuild') {
file_write($settings['uri'] . '/index.html', $ukko2->build());
}
}
class ukko2 {
public $settings;
public function build($mod = false) {
global $config;
$boards = listBoards();
$body = '';
$overflow = array();
$board = array(
'dir' => $this->settings['uri'] . "/",
'url' => $this->settings['uri'],
'uri' => $this->settings['uri'],
'name' => $this->settings['title'],
'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
);
$boardsforukko2 = array();
$query = '';
foreach($boards as &$_board) {
if(in_array($_board['uri'], explode(' ', $this->settings['include']))){
$query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
array_push($boardsforukko2,$_board);
}
}
$query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
$query = query($query) or error(db_error());
$count = 0;
$threads = array();
if ($config['api']['enabled']) {
$apithreads = array();
}
while($post = $query->fetch()) {
if(!isset($threads[$post['board']])) {
$threads[$post['board']] = 1;
} else {
$threads[$post['board']] += 1;
}
if($count < $this->settings['thread_limit']) {
openBoard($post['board']);
$thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
$posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
$posts->bindValue(':id', $post['id']);
$posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
$posts->execute() or error(db_error($posts));
$num_images = 0;
while ($po = $posts->fetch()) {
if ($po['files'])
$num_images++;
$post2 = new Post($po, $mod ? '?/' : $config['root'], $mod);
$thread->add($post2);
}
if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
$ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
$ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
$ct->execute() or error(db_error($count));
$c = $ct->fetch();
$thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
$c = $ct->fetch();
$thread->omitted_images = $c['num'] - $num_images;
}
$thread->posts = array_reverse($thread->posts);
$body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
$body .= $thread->build(true);
if ($config['api']['enabled']) {
array_push($apithreads,$thread);
}
} else {
$page = 'index';
if(floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
$page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
}
$overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
}
$count += 1;
}
$body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
$body .= '<script type="text/javascript" src="/'.$this->settings['uri'].'/ukko.js"></script>';
// json api
if ($config['api']['enabled']) {
require_once __DIR__. '/../../../inc/api.php';
$api = new Api();
$jsonFilename = $board['dir'] . '0.json';
$json = json_encode($api->translatePage($apithreads));
file_write($jsonFilename, $json);
$catalog = array();
$catalog[0] = $apithreads;
$json = json_encode($api->translateCatalog($catalog));
$jsonFilename = $board['dir'] . 'catalog.json';
file_write($jsonFilename, $json);
$json = json_encode($api->translateCatalog($catalog, true));
$jsonFilename = $board['dir'] . 'threads.json';
file_write($jsonFilename, $json);
}
return Element('index.html', array(
'config' => $config,
'board' => $board,
'no_post_form' => $config['overboard_post_form'] ? false : true,
'body' => $body,
'mod' => $mod,
'boardlist' => createBoardlist($mod),
'boards' => $boardsforukko2 )
);
}
};
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,116 @@
(function(){
var cache = new Array(),
thread = false,
loading = false,
ukkotimer = false;
if (localStorage.hiddenboards === undefined) {
localStorage.hiddenboards = "{}";
}
// Load data from HTML5 localStorage
var hiddenboards = JSON.parse(localStorage.hiddenboards);
var storeboards = function() {
localStorage.hiddenboards = JSON.stringify(hiddenboards);
};
$(document).ready(function() {
var addukkohide = function() {
var ukkohide = $('<a href="javascript:void(0);" class="unimportant ukkohide"></a>');
var board = $(this).next().data("board");
var hr = $("<hr />");
$(this).append(ukkohide);
$(this).append(hr);
if (hiddenboards[board] !== true) {
ukkohide.html(_("(hide threads from this board)"));
hr.hide();
}
else {
ukkohide.html(_("(show threads from this board)"));
$(this).next().hide();
}
ukkohide.click(function() {
hiddenboards[board] = (hiddenboards[board] !== true);
if (hiddenboards[board] !== true) {
$('[data-board="'+board+'"]:not([data-cached="yes"])').show().prev().
find('.ukkohide').html(_("(hide threads from this board)")).
parent().find('hr').hide();
}
else {
$('[data-board="'+board+'"]:not([data-cached="yes"])').hide().prev().
find('.ukkohide').html(_("(show threads from this board)"))
.parent().find('hr').show();
}
storeboards();
return false;
});
};
$("h2").each(addukkohide);
$('.pages').hide();
var loadnext = function() {
if (overflow.length == 0) {
$('.pages').show().html(_("No more threads to display"));
}
while($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading && overflow.length > 0) {
var page = modRoot + overflow[0].board + '/' + overflow[0].page;
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present
overflow.shift();
continue;
}
var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>');
if($.inArray(page, cache) != -1) {
if (thread.length > 0) {
$('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
boardheader.insertBefore(thread);
addukkohide.call(boardheader);
$(document).trigger('new_post', thread);
}
overflow.shift();
} else {
loading = true;
$('.pages').show().html(_("Loading..."));
$.get(page, function(data) {
cache.push(page);
$(data).find('div[id*="thread_"]').each(function() {
var checkout = $(this).attr('id').replace('thread_', '');
if ($('div#thread_' + checkout + '[data-board="' + overflow[0].board + '"]').length == 0) {
$('form[name="postcontrols"]').prepend($(this).css('display', 'block').attr("data-cached", "yes").attr('data-board', overflow[0].board));
}
});
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"][data-cached="yes"]');
if(thread.length > 0) {
$('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
boardheader.insertBefore(thread);
addukkohide.call(boardheader);
$(document).trigger('new_post', thread);
}
overflow.shift();
loading = false;
$('.pages').hide().html("");
});
break;
}
}
clearTimeout(ukkotimer);
ukkotimer = setTimeout(loadnext, 1000);
};
$(window).on('scroll', loadnext);
ukkotimer = setTimeout(loadnext, 1000);
});
})();

View File

@ -0,0 +1,55 @@
<?php
$theme = array();
// Theme name
$theme['name'] = 'Overboard (Ukko3)';
// Description (you can use Tinyboard markup here)
$theme['description'] = 'Board with threads and messages from all boards';
$theme['version'] = 'v0.2';
// Theme configuration
$theme['config'] = array();
$theme['config'][] = array(
'title' => 'Board name',
'name' => 'title',
'type' => 'text',
'default' => 'Ukko'
);
$theme['config'][] = array(
'title' => 'Board URI',
'name' => 'uri',
'type' => 'text',
'default' => '*',
'comment' => '(ukko for example)'
);
$theme['config'][] = array(
'title' => 'Subtitle',
'name' => 'subtitle',
'type' => 'text',
'comment' => '(%s = thread limit. for example "%s freshly bumped threads")'
);
$theme['config'][] = array(
'title' => 'included boards',
'name' => 'include',
'type' => 'text',
'comment' => '(space seperated)'
);
$theme['config'][] = array(
'title' => 'Number of threads',
'name' => 'thread_limit',
'type' => 'text',
'default' => '15',
);
// Unique function name for building everything
$theme['build_function'] = 'ukko3_build';
$theme['install_callback'] = 'ukko3_install';
if(!function_exists('ukko3_install')) {
function ukko3_install($settings) {
if (!file_exists($settings['uri']))
@mkdir($settings['uri'], 0777) or error("Couldn't create " . $settings['uri'] . ". Check permissions.", true);
file_write($settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array()));
}
}

View File

@ -0,0 +1,155 @@
<?php
require 'info.php';
function ukko3_build($action, $settings) {
global $config;
$ukko3 = new ukko3();
$ukko3->settings = $settings;
if (! ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete')) {
return;
}
$action = generation_strategy('sb_ukko3', array());
if ($action == 'delete') {
file_unlink($settings['uri'] . '/index.html');
if ($config['api']['enabled']) {
$jsonFilename = $settings['uri'] . '/0.json';
file_unlink($jsonFilename);
$jsonFilename = $settings['uri'] . '/catalog.json';
file_unlink($jsonFilename);
$jsonFilename = $settings['uri'] . '/threads.json';
file_unlink($jsonFilename);
}
}
elseif ($action == 'rebuild') {
file_write($settings['uri'] . '/index.html', $ukko3->build());
}
}
class ukko3 {
public $settings;
public function build($mod = false) {
global $config;
$boards = listBoards();
$body = '';
$overflow = array();
$board = array(
'dir' => $this->settings['uri'] . "/",
'url' => $this->settings['uri'],
'uri' => $this->settings['uri'],
'name' => $this->settings['title'],
'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
);
$boardsforukko3 = array();
$query = '';
foreach($boards as &$_board) {
if(in_array($_board['uri'], explode(' ', $this->settings['include']))){
$query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
array_push($boardsforukko3,$_board);
}
}
$query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
$query = query($query) or error(db_error());
$count = 0;
$threads = array();
if ($config['api']['enabled']) {
$apithreads = array();
}
while($post = $query->fetch()) {
if(!isset($threads[$post['board']])) {
$threads[$post['board']] = 1;
} else {
$threads[$post['board']] += 1;
}
if($count < $this->settings['thread_limit']) {
openBoard($post['board']);
$thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
$posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
$posts->bindValue(':id', $post['id']);
$posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
$posts->execute() or error(db_error($posts));
$num_images = 0;
while ($po = $posts->fetch()) {
if ($po['files'])
$num_images++;
$post2 = new Post($po, $mod ? '?/' : $config['root'], $mod);
$thread->add($post2);
}
if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
$ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
$ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
$ct->execute() or error(db_error($count));
$c = $ct->fetch();
$thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
$c = $ct->fetch();
$thread->omitted_images = $c['num'] - $num_images;
}
$thread->posts = array_reverse($thread->posts);
$body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
$body .= $thread->build(true);
if ($config['api']['enabled']) {
array_push($apithreads,$thread);
}
} else {
$page = 'index';
if(floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
$page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
}
$overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
}
$count += 1;
}
$body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
$body .= '<script type="text/javascript" src="/'.$this->settings['uri'].'/ukko.js"></script>';
// json api
if ($config['api']['enabled']) {
require_once __DIR__. '/../../../inc/api.php';
$api = new Api();
$jsonFilename = $board['dir'] . '0.json';
$json = json_encode($api->translatePage($apithreads));
file_write($jsonFilename, $json);
$catalog = array();
$catalog[0] = $apithreads;
$json = json_encode($api->translateCatalog($catalog));
$jsonFilename = $board['dir'] . 'catalog.json';
file_write($jsonFilename, $json);
$json = json_encode($api->translateCatalog($catalog, true));
$jsonFilename = $board['dir'] . 'threads.json';
file_write($jsonFilename, $json);
}
return Element('index.html', array(
'config' => $config,
'board' => $board,
'no_post_form' => $config['overboard_post_form'] ? false : true,
'body' => $body,
'mod' => $mod,
'boardlist' => createBoardlist($mod),
'boards' => $boardsforukko3 )
);
}
};
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,116 @@
(function(){
var cache = new Array(),
thread = false,
loading = false,
ukkotimer = false;
if (localStorage.hiddenboards === undefined) {
localStorage.hiddenboards = "{}";
}
// Load data from HTML5 localStorage
var hiddenboards = JSON.parse(localStorage.hiddenboards);
var storeboards = function() {
localStorage.hiddenboards = JSON.stringify(hiddenboards);
};
$(document).ready(function() {
var addukkohide = function() {
var ukkohide = $('<a href="javascript:void(0);" class="unimportant ukkohide"></a>');
var board = $(this).next().data("board");
var hr = $("<hr />");
$(this).append(ukkohide);
$(this).append(hr);
if (hiddenboards[board] !== true) {
ukkohide.html(_("(hide threads from this board)"));
hr.hide();
}
else {
ukkohide.html(_("(show threads from this board)"));
$(this).next().hide();
}
ukkohide.click(function() {
hiddenboards[board] = (hiddenboards[board] !== true);
if (hiddenboards[board] !== true) {
$('[data-board="'+board+'"]:not([data-cached="yes"])').show().prev().
find('.ukkohide').html(_("(hide threads from this board)")).
parent().find('hr').hide();
}
else {
$('[data-board="'+board+'"]:not([data-cached="yes"])').hide().prev().
find('.ukkohide').html(_("(show threads from this board)"))
.parent().find('hr').show();
}
storeboards();
return false;
});
};
$("h2").each(addukkohide);
$('.pages').hide();
var loadnext = function() {
if (overflow.length == 0) {
$('.pages').show().html(_("No more threads to display"));
}
while($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading && overflow.length > 0) {
var page = modRoot + overflow[0].board + '/' + overflow[0].page;
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present
overflow.shift();
continue;
}
var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>');
if($.inArray(page, cache) != -1) {
if (thread.length > 0) {
$('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
boardheader.insertBefore(thread);
addukkohide.call(boardheader);
$(document).trigger('new_post', thread);
}
overflow.shift();
} else {
loading = true;
$('.pages').show().html(_("Loading..."));
$.get(page, function(data) {
cache.push(page);
$(data).find('div[id*="thread_"]').each(function() {
var checkout = $(this).attr('id').replace('thread_', '');
if ($('div#thread_' + checkout + '[data-board="' + overflow[0].board + '"]').length == 0) {
$('form[name="postcontrols"]').prepend($(this).css('display', 'block').attr("data-cached", "yes").attr('data-board', overflow[0].board));
}
});
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"][data-cached="yes"]');
if(thread.length > 0) {
$('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
boardheader.insertBefore(thread);
addukkohide.call(boardheader);
$(document).trigger('new_post', thread);
}
overflow.shift();
loading = false;
$('.pages').hide().html("");
});
break;
}
}
clearTimeout(ukkotimer);
ukkotimer = setTimeout(loadnext, 1000);
};
$(window).on('scroll', loadnext);
ukkotimer = setTimeout(loadnext, 1000);
});
})();