The version of vichan running on lainchan.org
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

163 líneas
5.3KB

  1. <?php
  2. require 'info.php';
  3. function ukko_build($action, $settings) {
  4. global $config;
  5. $ukko = new ukko();
  6. $ukko->settings = $settings;
  7. if (! ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete')) {
  8. return;
  9. }
  10. $action = generation_strategy('sb_ukko', array());
  11. if ($action == 'delete') {
  12. file_unlink($settings['uri'] . '/index.html');
  13. if ($config['api']['enabled']) {
  14. $jsonFilename = $settings['uri'] . '/0.json';
  15. file_unlink($jsonFilename);
  16. $jsonFilename = $settings['uri'] . '/catalog.json';
  17. file_unlink($jsonFilename);
  18. $jsonFilename = $settings['uri'] . '/threads.json';
  19. file_unlink($jsonFilename);
  20. }
  21. }
  22. elseif ($action == 'rebuild') {
  23. file_write($settings['uri'] . '/index.html', $ukko->build());
  24. }
  25. }
  26. class ukko {
  27. public $settings;
  28. public function build($mod = false) {
  29. global $config;
  30. $boards = listBoards();
  31. $body = '';
  32. $overflow = array();
  33. $board = array(
  34. 'dir' => $this->settings['uri'] . "/",
  35. 'url' => $this->settings['uri'],
  36. 'uri' => $this->settings['uri'],
  37. 'name' => $this->settings['title'],
  38. 'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
  39. );
  40. $boardsforukko = array();
  41. $query = '';
  42. foreach($boards as &$_board) {
  43. if(in_array($_board['uri'], explode(' ', $this->settings['exclude'])))
  44. continue;
  45. $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
  46. array_push($boardsforukko,$_board);
  47. }
  48. $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
  49. $query = query($query) or error(db_error());
  50. $count = 0;
  51. $threads = array();
  52. if ($config['api']['enabled']) {
  53. $apithreads = array();
  54. }
  55. while($post = $query->fetch()) {
  56. if(!isset($threads[$post['board']])) {
  57. $threads[$post['board']] = 1;
  58. } else {
  59. $threads[$post['board']] += 1;
  60. }
  61. if($count < $this->settings['thread_limit']) {
  62. openBoard($post['board']);
  63. $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
  64. $posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `sticky` DESC, `id` DESC LIMIT :limit", $post['board']));
  65. $posts->bindValue(':id', $post['id']);
  66. $posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
  67. $posts->execute() or error(db_error($posts));
  68. $num_images = 0;
  69. while ($po = $posts->fetch()) {
  70. if ($po['files'])
  71. $num_images++;
  72. $post2 = new Post($po, $mod ? '?/' : $config['root'], $mod);
  73. $thread->add($post2);
  74. }
  75. if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
  76. $ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
  77. $ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
  78. $ct->execute() or error(db_error($count));
  79. $c = $ct->fetch();
  80. $thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
  81. $c = $ct->fetch();
  82. $thread->omitted_images = $c['num'] - $num_images;
  83. }
  84. $thread->posts = array_reverse($thread->posts);
  85. $body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
  86. $body .= $thread->build(true);
  87. if ($config['api']['enabled']) {
  88. array_push($apithreads,$thread);
  89. }
  90. } else {
  91. $page = 'index';
  92. if(floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
  93. $page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
  94. }
  95. $overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
  96. }
  97. $count += 1;
  98. }
  99. $body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
  100. $body .= '<script type="text/javascript" src="/'.$this->settings['uri'].'/ukko.js"></script>';
  101. // json api
  102. if ($config['api']['enabled']) {
  103. require_once __DIR__. '/../../../inc/api.php';
  104. $api = new Api();
  105. $jsonFilename = $board['dir'] . '0.json';
  106. $json = json_encode($api->translatePage($apithreads));
  107. file_write($jsonFilename, $json);
  108. $catalog = array();
  109. $catalog[0] = $apithreads;
  110. $json = json_encode($api->translateCatalog($catalog));
  111. $jsonFilename = $board['dir'] . 'catalog.json';
  112. file_write($jsonFilename, $json);
  113. $json = json_encode($api->translateCatalog($catalog, true));
  114. $jsonFilename = $board['dir'] . 'threads.json';
  115. file_write($jsonFilename, $json);
  116. }
  117. $antibot = null;
  118. if (!$antibot) {
  119. $antibot = create_antibot($board['uri']);
  120. }
  121. $antibot->reset();
  122. return Element('index.html', array(
  123. 'config' => $config,
  124. 'board' => $board,
  125. 'no_post_form' => $config['overboard_post_form'] ? false : true,
  126. 'body' => $body,
  127. 'mod' => $mod,
  128. 'boardlist' => createBoardlist($mod),
  129. 'boards' => $boardsforukko,
  130. 'antibot' => $antibot )
  131. );
  132. }
  133. };
  134. ?>