From bd3cc259810fa664abd09de0d94e4d0dc70648e8 Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Sat, 10 Dec 2016 18:15:11 +0900 Subject: [PATCH] Add JSON API to Ukko Overboard Theme --- templates/themes/ukko/theme.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/templates/themes/ukko/theme.php b/templates/themes/ukko/theme.php index ee2707bf..a3f30dd4 100644 --- a/templates/themes/ukko/theme.php +++ b/templates/themes/ukko/theme.php @@ -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 .= '

/' . $post['board'] . '/

'; $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) { @@ -102,7 +112,15 @@ $body .= ''; $body .= ''; - + + // 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,