The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7KB

  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. if ($config['smart_build']) {
  11. file_unlink($settings['uri'] . '/index.html');
  12. }
  13. else {
  14. file_write($settings['uri'] . '/index.html', $ukko->build());
  15. }
  16. }
  17. class ukko {
  18. public $settings;
  19. public function build($mod = false) {
  20. global $config;
  21. $boards = listBoards();
  22. $body = '';
  23. $overflow = array();
  24. $board = array(
  25. 'url' => $this->settings['uri'],
  26. 'uri' => $this->settings['uri'],
  27. 'name' => $this->settings['title'],
  28. 'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
  29. );
  30. $query = '';
  31. foreach($boards as &$_board) {
  32. if(in_array($_board['uri'], explode(' ', $this->settings['exclude'])))
  33. continue;
  34. $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
  35. }
  36. $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
  37. $query = query($query) or error(db_error());
  38. $count = 0;
  39. $threads = array();
  40. while($post = $query->fetch()) {
  41. if(!isset($threads[$post['board']])) {
  42. $threads[$post['board']] = 1;
  43. } else {
  44. $threads[$post['board']] += 1;
  45. }
  46. if($count < $this->settings['thread_limit']) {
  47. openBoard($post['board']);
  48. $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
  49. $posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
  50. $posts->bindValue(':id', $post['id']);
  51. $posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
  52. $posts->execute() or error(db_error($posts));
  53. $num_images = 0;
  54. while ($po = $posts->fetch()) {
  55. if ($po['files'])
  56. $num_images++;
  57. $thread->add(new Post($po, $mod ? '?/' : $config['root'], $mod));
  58. }
  59. if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
  60. $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']));
  61. $ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
  62. $ct->execute() or error(db_error($count));
  63. $c = $ct->fetch();
  64. $thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
  65. $c = $ct->fetch();
  66. $thread->omitted_images = $c['num'] - $num_images;
  67. }
  68. $thread->posts = array_reverse($thread->posts);
  69. $body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
  70. $body .= $thread->build(true);
  71. } else {
  72. $page = 'index';
  73. if(floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
  74. $page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
  75. }
  76. $overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
  77. }
  78. $count += 1;
  79. }
  80. $body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
  81. $body .= '<script type="text/javascript" src="/'.$this->settings['uri'].'/ukko.js"></script>';
  82. return Element('index.html', array(
  83. 'config' => $config,
  84. 'board' => $board,
  85. 'no_post_form' => true,
  86. 'body' => $body,
  87. 'mod' => $mod,
  88. 'boardlist' => createBoardlist($mod),
  89. ));
  90. }
  91. };
  92. ?>