Browse Source

Make it possible to disable API, disable it by default

pull/40/head
ctrlcctrlv 11 years ago
parent
commit
a29a9324ea
  1. 9
      inc/config.php
  2. 36
      inc/functions.php

9
inc/config.php

@ -1342,6 +1342,15 @@
// return 'Sorry, you cannot post that!'; // return 'Sorry, you cannot post that!';
// }); // });
/*
* =============
* API settings
* =============
*/
// Whether or not to use the API, disabled by default.
$config['api']['enabled'] = false;
/* /*
* ==================== * ====================
* Other/uncategorized * Other/uncategorized

36
inc/functions.php

@ -1299,8 +1299,10 @@ function buildIndex() {
if (!$config['try_smarter']) if (!$config['try_smarter'])
$antibot = create_antibot($board['uri']); $antibot = create_antibot($board['uri']);
$api = new Api(); if ($config['api']['enabled']) {
$catalog = array(); $api = new Api();
$catalog = array();
}
for ($page = 1; $page <= $config['max_pages']; $page++) { for ($page = 1; $page <= $config['max_pages']; $page++) {
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
@ -1324,12 +1326,14 @@ function buildIndex() {
file_write($filename, Element('index.html', $content)); file_write($filename, Element('index.html', $content));
// json api // json api
$threads = $content['threads']; if ($config['api']['enabled']) {
$json = json_encode($api->translatePage($threads)); $threads = $content['threads'];
$jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0 $json = json_encode($api->translatePage($threads));
file_write($jsonFilename, $json); $jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0
file_write($jsonFilename, $json);
$catalog[$page-1] = $threads; $catalog[$page-1] = $threads;
}
} }
if ($page < $config['max_pages']) { if ($page < $config['max_pages']) {
for (;$page<=$config['max_pages'];$page++) { for (;$page<=$config['max_pages'];$page++) {
@ -1342,9 +1346,11 @@ function buildIndex() {
} }
// json api catalog // json api catalog
$json = json_encode($api->translateCatalog($catalog)); if ($config['api']['enabled']) {
$jsonFilename = $board['dir'] . "catalog.json"; $json = json_encode($api->translateCatalog($catalog));
file_write($jsonFilename, $json); $jsonFilename = $board['dir'] . "catalog.json";
file_write($jsonFilename, $json);
}
} }
function buildJavascript() { function buildJavascript() {
@ -1765,10 +1771,12 @@ function buildThread($id, $return = false, $mod = false) {
$build_pages[] = thread_find_page($id); $build_pages[] = thread_find_page($id);
// json api // json api
$api = new Api(); if ($config['api']['enabled']) {
$json = json_encode($api->translateThread($thread)); $api = new Api();
$jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json"; $json = json_encode($api->translateThread($thread));
file_write($jsonFilename, $json); $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json";
file_write($jsonFilename, $json);
}
if ($return) { if ($return) {
return $body; return $body;

Loading…
Cancel
Save