Add JSON API to Ukko Overboard Theme

This commit is contained in:
Benjamin Southall 2016-12-10 18:15:11 +09:00
parent fa01d816b3
commit bd3cc25981

View File

@ -15,6 +15,10 @@
if ($action == 'delete') {
file_unlink($settings['uri'] . '/index.html');
if ($config['api']['enabled']) {
$jsonFilename = $settings['uri'] . '/0.json';
file_unlink($jsonFilename);
}
}
elseif ($action == 'rebuild') {
file_write($settings['uri'] . '/index.html', $ukko->build());
@ -48,6 +52,9 @@
$count = 0;
$threads = array();
if ($config['api']['enabled']) {
$apithreads = array();
}
while($post = $query->fetch()) {
if(!isset($threads[$post['board']])) {
@ -89,6 +96,9 @@
$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) {
@ -103,6 +113,14 @@
$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);
}
return Element('index.html', array(
'config' => $config,
'board' => $board,