Merge pull request #135 from PietroCarrara/overboard-api
Build overboard json
This commit is contained in:
commit
0eb4059a7c
|
@ -35,11 +35,13 @@ class Api {
|
||||||
'cycle' => 'cyclical',
|
'cycle' => 'cyclical',
|
||||||
'bump' => 'last_modified',
|
'bump' => 'last_modified',
|
||||||
'embed' => 'embed',
|
'embed' => 'embed',
|
||||||
|
'board' => 'board',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->threadsPageFields = array(
|
$this->threadsPageFields = array(
|
||||||
'id' => 'no',
|
'id' => 'no',
|
||||||
'bump' => 'last_modified'
|
'bump' => 'last_modified',
|
||||||
|
'board' => 'board',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->fileFields = array(
|
$this->fileFields = array(
|
||||||
|
|
|
@ -1322,7 +1322,7 @@ function index($page, $mod=false, $brief = false) {
|
||||||
$body = '';
|
$body = '';
|
||||||
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset,:threads_per_page", $board['uri']));
|
$query = prepare(sprintf("SELECT *,'%s' as board FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset,:threads_per_page", $board['uri'], $board['uri']));
|
||||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
|
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
@ -2292,7 +2292,7 @@ function buildThread($id, $return = false, $mod = false) {
|
||||||
$action = generation_strategy('sb_thread', array($board['uri'], $id));
|
$action = generation_strategy('sb_thread', array($board['uri'], $id));
|
||||||
|
|
||||||
if ($action == 'rebuild' || $return || $mod) {
|
if ($action == 'rebuild' || $return || $mod) {
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri']));
|
$query = prepare(sprintf("SELECT *,'%s' as board FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri'],$board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<div id="Grid">
|
<div id="Grid">
|
||||||
{% for post in recent_posts %}
|
{% for post in recent_posts %}
|
||||||
<div class="mix"
|
<div class="mix"
|
||||||
data-reply="{{ post.reply_count }}"
|
data-reply="{{ post.replies }}"
|
||||||
data-bump="{{ post.bump }}"
|
data-bump="{{ post.bump }}"
|
||||||
data-time="{{ post.time }}"
|
data-time="{{ post.time }}"
|
||||||
data-id="{{ post.id }}"
|
data-id="{{ post.id }}"
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
id="img-{{ post.id }}" data-subject="{% if post.subject %}{{ post.subject|e }}{% endif %}" data-name="{{ post.name|e }}" data-muhdifference="{{ post.muhdifference }}" class="{{post.board}} thread-image" title="{{post.bump|date('%b %d %H:%M')}}">
|
id="img-{{ post.id }}" data-subject="{% if post.subject %}{{ post.subject|e }}{% endif %}" data-name="{{ post.name|e }}" data-muhdifference="{{ post.muhdifference }}" class="{{post.board}} thread-image" title="{{post.bump|date('%b %d %H:%M')}}">
|
||||||
</a>
|
</a>
|
||||||
<div class="replies">
|
<div class="replies">
|
||||||
<strong>R: {{ post.reply_count }} / I: {{ post.image_count }}{% if post.sticky %} (sticky){% endif %}{% if post.locked %} <span class="fa fa-lock"> </span>{% endif %}</strong>
|
<strong>R: {{ post.replies }} / I: {{ post.images }}{% if post.sticky %} (sticky){% endif %}{% if post.locked %} <span class="fa fa-lock"> </span>{% endif %}</strong>
|
||||||
{% if post.subject %}
|
{% if post.subject %}
|
||||||
<p class="intro">
|
<p class="intro">
|
||||||
<span class="subject">
|
<span class="subject">
|
||||||
|
|
|
@ -337,8 +337,8 @@
|
||||||
|
|
||||||
private function buildThreadsQuery($board) {
|
private function buildThreadsQuery($board) {
|
||||||
$sql = "SELECT *, `id` AS `thread_id`, " .
|
$sql = "SELECT *, `id` AS `thread_id`, " .
|
||||||
"(SELECT COUNT(`id`) FROM ``posts_$board`` WHERE `thread` = `thread_id`) AS `reply_count`, " .
|
"(SELECT COUNT(`id`) FROM ``posts_$board`` WHERE `thread` = `thread_id`) AS `replies`, " .
|
||||||
"(SELECT SUM(`num_files`) FROM ``posts_$board`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `image_count`, " .
|
"(SELECT SUM(`num_files`) FROM ``posts_$board`` WHERE `thread` = `thread_id` AND `num_files` IS NOT NULL) AS `images`, " .
|
||||||
"'$board' AS `board` FROM ``posts_$board`` WHERE `thread` IS NULL";
|
"'$board' AS `board` FROM ``posts_$board`` WHERE `thread` IS NULL";
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
|
@ -348,6 +348,8 @@
|
||||||
* Build and save the HTML of the catalog for the overboard
|
* Build and save the HTML of the catalog for the overboard
|
||||||
*/
|
*/
|
||||||
public function buildOverboardCatalog($settings, $boards) {
|
public function buildOverboardCatalog($settings, $boards) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
$board_name = $settings['overboard_location'];
|
$board_name = $settings['overboard_location'];
|
||||||
|
|
||||||
if (array_key_exists($board_name, $this->threadsCache)) {
|
if (array_key_exists($board_name, $this->threadsCache)) {
|
||||||
|
@ -371,6 +373,33 @@
|
||||||
$recent_posts = $this->generateRecentPosts($threads);
|
$recent_posts = $this->generateRecentPosts($threads);
|
||||||
|
|
||||||
$this->saveForBoard($board_name, $recent_posts, '/' . $settings['overboard_location']);
|
$this->saveForBoard($board_name, $recent_posts, '/' . $settings['overboard_location']);
|
||||||
|
|
||||||
|
// Build the overboard JSON outputs
|
||||||
|
if ($config['api']['enabled']) {
|
||||||
|
$api = new Api();
|
||||||
|
|
||||||
|
// Separate the threads into pages
|
||||||
|
$pages = array(array());
|
||||||
|
$totalThreads = count($recent_posts);
|
||||||
|
$page = 0;
|
||||||
|
for ($i = 1; $i <= $totalThreads; $i++) {
|
||||||
|
$pages[$page][] = new Thread($recent_posts[$i-1]);
|
||||||
|
|
||||||
|
// If we have not yet visited all threads,
|
||||||
|
// and we hit the limit on the current page,
|
||||||
|
// skip to the next page
|
||||||
|
if ($i < $totalThreads && ($i % $config['threads_per_page'] == 0)) {
|
||||||
|
$page++;
|
||||||
|
$pages[$page] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = json_encode($api->translateCatalog($pages));
|
||||||
|
file_write($config['dir']['home'] . $board_name . '/catalog.json', $json);
|
||||||
|
|
||||||
|
$json = json_encode($api->translateCatalog($pages, true));
|
||||||
|
file_write($config['dir']['home'] . $board_name . '/threads.json', $json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateRecentPosts($threads) {
|
private function generateRecentPosts($threads) {
|
||||||
|
@ -416,8 +445,8 @@
|
||||||
$post['file'] = $config['root'] . $config['image_deleted'];
|
$post['file'] = $config['root'] . $config['image_deleted'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($post['image_count']))
|
if (empty($post['images']))
|
||||||
$post['image_count'] = 0;
|
$post['images'] = 0;
|
||||||
$post['pubdate'] = date('r', $post['time']);
|
$post['pubdate'] = date('r', $post['time']);
|
||||||
|
|
||||||
$posts[] = $post;
|
$posts[] = $post;
|
||||||
|
@ -457,6 +486,6 @@
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'recent_posts' => $recent_posts,
|
'recent_posts' => $recent_posts,
|
||||||
'board' => $board
|
'board' => $board
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue