The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

109 lignes
2.7KB

  1. <?php
  2. // This file contains the controller part of vichan
  3. // don't bother with that unless you use smart build or advanced build
  4. // you can use those parts for your own implementations though :^)
  5. defined('TINYBOARD') or exit;
  6. function sb_board($b, $page = 1) { global $config, $build_pages; $page = (int)$page;
  7. if ($page < 1) return false;
  8. if (!openBoard($b)) return false;
  9. if ($page > $config['max_pages']) return false;
  10. $config['try_smarter'] = true;
  11. $build_pages = array($page);
  12. buildIndex("skip");
  13. return true;
  14. }
  15. function sb_api_board($b, $page = 0) { $page = (int)$page;
  16. return sb_board($b, $page + 1);
  17. }
  18. function sb_thread($b, $thread, $slugcheck = false) { global $config; $thread = (int)$thread;
  19. if ($thread < 1) return false;
  20. if (!preg_match('/^'.$config['board_regex'].'$/u', $b)) return false;
  21. if (Cache::get("thread_exists_".$b."_".$thread) == "no") return false;
  22. $query = prepare(sprintf("SELECT MAX(`id`) AS `max` FROM ``posts_%s``", $b));
  23. if (!$query->execute()) return false;
  24. $s = $query->fetch(PDO::FETCH_ASSOC);
  25. $max = $s['max'];
  26. if ($thread > $max) return false;
  27. $query = prepare(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL", $b));
  28. $query->bindValue(':id', $thread);
  29. if (!$query->execute() || !$query->fetch(PDO::FETCH_ASSOC) ) {
  30. Cache::set("thread_exists_".$b."_".$thread, "no", 3600);
  31. return false;
  32. }
  33. if ($slugcheck && $config['slugify']) {
  34. global $request;
  35. $link = link_for(array("id" => $thread), $slugcheck === 50, array("uri" => $b));
  36. $link = "/".$b."/".$config['dir']['res'].$link;
  37. if ($link != $request) {
  38. header("Location: $link", true, 301);
  39. die();
  40. }
  41. }
  42. if ($slugcheck == 50) { // Should we really generate +50 page? Maybe there are not enough posts anyway
  43. global $request;
  44. $r = str_replace("+50", "", $request);
  45. $r = substr($r, 1); // Cut the slash
  46. if (file_exists($r)) return false;
  47. }
  48. if (!openBoard($b)) return false;
  49. buildThread($thread);
  50. return true;
  51. }
  52. function sb_thread_slugcheck($b, $thread) {
  53. return sb_thread($b, $thread, true);
  54. }
  55. function sb_thread_slugcheck50($b, $thread) {
  56. return sb_thread($b, $thread, 50);
  57. }
  58. function sb_api($b) { global $config, $build_pages;
  59. if (!openBoard($b)) return false;
  60. $config['try_smarter'] = true;
  61. $build_pages = array(-1);
  62. buildIndex();
  63. return true;
  64. }
  65. function sb_ukko() {
  66. rebuildTheme("ukko", "post-thread");
  67. return true;
  68. }
  69. function sb_catalog($b) {
  70. if (!openBoard($b)) return false;
  71. rebuildTheme("catalog", "post-thread", $b);
  72. return true;
  73. }
  74. function sb_recent() {
  75. rebuildTheme("recent", "post-thread");
  76. return true;
  77. }
  78. function sb_sitemap() {
  79. rebuildTheme("sitemap", "all");
  80. return true;
  81. }