forked from ctrlcctrlv/infinity
-
Notifications
You must be signed in to change notification settings - Fork 8
/
boards.php
136 lines (106 loc) · 4.07 KB
/
boards.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
include "inc/functions.php";
$admin = isset($mod["type"]) && $mod["type"]<=30;
$founding_date = "October 23, 2013";
if (php_sapi_name() == 'fpm-fcgi' && !$admin && count($_GET) == 0) {
error('Cannot be run directly.');
}
/* Build parameters for page */
$searchJson = include "board-search.php";
$boards = array();
$tags = array();
if (count($searchJson)) {
if (isset($searchJson['boards'])) {
$boards = $searchJson['boards'];
}
if (isset($searchJson['tagWeight'])) {
$tags = $searchJson['tagWeight'];
}
}
$boardQuery = prepare("SELECT COUNT(1) AS 'boards_total', SUM(indexed) AS 'boards_public', SUM(posts_total) AS 'posts_total' FROM ``boards``");
$boardQuery->execute() or error(db_error($tagQuery));
$boardResult = $boardQuery->fetchAll(PDO::FETCH_ASSOC)[0];
$boards_total = number_format( $boardResult['boards_total'], 0 );
$boards_public = number_format( $boardResult['boards_public'], 0 );
$boards_hidden = number_format( $boardResult['boards_total'] - $boardResult['boards_public'], 0 );
$boards_omitted = (int) $searchJson['omitted'];
$posts_hour = number_format( fetchBoardActivity(), 0 );
$posts_total = number_format( $boardResult['posts_total'], 0 );
// This incredibly stupid looking chunk of code builds a query string using existing information.
// It's used to make clickable tags for users without JavaScript for graceful degredation.
// Because of how it orders tags, what you end up with is a prefix that always ends in tags=x+
// ?tags= or ?sfw=1&tags= or ?title=foo&tags=bar+ - etc
$tagQueryGet = $_GET;
$tagQueryTags = isset($tagQueryGet['tags']) ? $tagQueryGet['tags'] : "";
unset($tagQueryGet['tags']);
$tagQueryGet['tags'] = $tagQueryTags;
$tag_query = "/boards.php?" . http_build_query( $tagQueryGet ) . ($tagQueryTags != "" ? "+" : "");
/* Create and distribute page */
// buildJavascript();
$boardsHTML = Element("8chan/boards-table.html", array(
"config" => $config,
"boards" => $boards,
"tag_query" => $tag_query,
)
);
$tagsHTML = Element("8chan/boards-tags.html", array(
"config" => $config,
"tags" => $tags,
"tag_query" => $tag_query,
)
);
$query = query('SELECT np.* FROM newsplus np INNER JOIN `posts_n` p ON np.thread=p.id WHERE np.dead IS FALSE ORDER BY p.bump DESC');
if ($query) {
$newsplus = $query->fetchAll(PDO::FETCH_ASSOC);
} else {
$newsplus = [];
}
$searchArray = array(
"config" => $config,
"boards" => $boards,
"tags" => $tags,
"search" => $searchJson['search'],
"languages" => $config['languages'],
"boards_total" => $boards_total,
"boards_public" => $boards_public,
"boards_hidden" => $boards_hidden,
"boards_omitted" => $boards_omitted,
"posts_hour" => $posts_hour,
"posts_total" => $posts_total,
"founding_date" => $founding_date,
"page_updated" => date('r'),
"html_boards" => $boardsHTML,
"html_tags" => $tagsHTML,
"newsplus" => $newsplus
);
$searchHTML = Element("8chan/boards-index.html", $searchArray);
$pageHTML = Element("page.html", array(
"title" => $config['site_slogan'],
"config" => $config,
"body" => $searchHTML,
)
);
$searchHTML2 = Element("8chan/boards-search.html", $searchArray);
$pageHTML2 = Element("page.html", array(
"title" => "Boards on ".$config['site_name'],
"config" => $config,
"body" => $searchHTML2,
)
);
// We only want to cache if this is not a dynamic form request.
// Otherwise, our information will be skewed by the search criteria.
if (php_sapi_name() == 'cli') {
// Preserves the JSON output format of [{board},{board}].
$nonAssociativeBoardList = array_values($response['boardsFull']);
file_write("index.html", $pageHTML);
file_write("boards.html", $pageHTML2);
file_write("boards.json", json_encode($nonAssociativeBoardList));
$topbar = array();
foreach ($boards as $i => $b) {
if (is_array($config['no_top_bar_boards']) && !in_array($b['uri'], $config['no_top_bar_boards'])) {
$topbar[] = $b;
}
}
file_write("boards-top20.json", json_encode(array_splice($topbar, 0, 48)));
}
echo $pageHTML;