Browse Source

smart_build for buildIndex

pull/40/head
czaks 9 years ago
parent
commit
55277ce383
  1. 25
      inc/functions.php

25
inc/functions.php

@ -1488,6 +1488,7 @@ function checkMute() {
function buildIndex($global_api = "yes") {
global $board, $config, $build_pages;
if (!$config['smart_build']) {
$pages = getPages();
if (!$config['try_smarter'])
$antibot = create_antibot($board['uri']);
@ -1496,13 +1497,17 @@ function buildIndex($global_api = "yes") {
$api = new Api();
$catalog = array();
}
}
for ($page = 1; $page <= $config['max_pages']; $page++) {
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages)
&& !empty($build_pages) && !in_array($page, $build_pages) )
if ((!$config['api']['enabled'] || $global_api == "skip" || $config['smart_build']) && $config['try_smarter']
&& isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) )
continue;
if (!$config['smart_build']) {
$content = index($page);
if (!$content)
break;
@ -1511,7 +1516,6 @@ function buildIndex($global_api = "yes") {
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;
@ -1533,8 +1537,13 @@ function buildIndex($global_api = "yes") {
file_write($filename, Element('index.html', $content));
}
else {
file_unlink($filename);
file_unlink($jsonFilename);
}
}
if ($page < $config['max_pages']) {
if (!$config['smart_build'] && $page < $config['max_pages']) {
for (;$page<=$config['max_pages'];$page++) {
$filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page));
file_unlink($filename);
@ -1548,6 +1557,13 @@ function buildIndex($global_api = "yes") {
// json api catalog
if ($config['api']['enabled'] && $global_api != "skip") {
if ($config['smart_build']) {
$jsonFilename = $board['dir'] . 'catalog.json';
file_unlink($jsonFilename);
$jsonFilename = $board['dir'] . 'threads.json';
file_unlink($jsonFilename);
}
else {
$json = json_encode($api->translateCatalog($catalog));
$jsonFilename = $board['dir'] . 'catalog.json';
file_write($jsonFilename, $json);
@ -1556,6 +1572,7 @@ function buildIndex($global_api = "yes") {
$jsonFilename = $board['dir'] . 'threads.json';
file_write($jsonFilename, $json);
}
}
if ($config['try_smarter'])
$build_pages = array();

Loading…
Cancel
Save