From 62fe8571e2d7c6477f0f6d9c51be5f1eeec50624 Mon Sep 17 00:00:00 2001 From: czaks Date: Sat, 28 Dec 2013 18:03:49 +0100 Subject: [PATCH] json api: fix building of catalog.json (NB: this puts extra load on server; we can try to make it lighter) --- inc/functions.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 4616a0db..676b6554 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1365,13 +1365,27 @@ function buildIndex() { for ($page = 1; $page <= $config['max_pages']; $page++) { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); - if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages) + if (!$config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) && is_file($filename)) continue; $content = index($page); if (!$content) break; + // json api + if ($config['api']['enabled']) { + $threads = $content['threads']; + $json = json_encode($api->translatePage($threads)); + $jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0 + file_write($jsonFilename, $json); + + $catalog[$page-1] = $threads; + } + + if ($config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) + && !in_array($page, $build_pages) && is_file($filename)) + continue; + if ($config['try_smarter']) { $antibot = create_antibot($board['uri'], 0 - $page); $content['current_page'] = $page; @@ -1383,16 +1397,6 @@ function buildIndex() { $content['antibot'] = $antibot; file_write($filename, Element('index.html', $content)); - - // json api - if ($config['api']['enabled']) { - $threads = $content['threads']; - $json = json_encode($api->translatePage($threads)); - $jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0 - file_write($jsonFilename, $json); - - $catalog[$page-1] = $threads; - } } if ($page < $config['max_pages']) {