summaryrefslogtreecommitdiff
path: root/templates/themes/ukko/theme.php
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2016-12-10 18:15:11 +0900
committerBenjamin Southall <applemansigloo@gmail.com>2016-12-10 18:15:11 +0900
commitbd3cc259810fa664abd09de0d94e4d0dc70648e8 (patch)
tree9d88c572eadd85dcda2998cf0fdb4a3ff57fa7eb /templates/themes/ukko/theme.php
parentfa01d816b3b2d9dfb4f6b37435d1a6fd3cbf76f7 (diff)
Add JSON API to Ukko Overboard Theme
Diffstat (limited to 'templates/themes/ukko/theme.php')
-rw-r--r--templates/themes/ukko/theme.php20
1 files changed, 19 insertions, 1 deletions
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 .= '<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) {
@@ -102,7 +112,15 @@
$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,