1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-11 15:26:08 +01:00
vichan/templates/themes/catalog/theme.php

59 lines
2.0 KiB
PHP
Raw Normal View History

2013-07-18 17:30:00 +02:00
<?php
require 'info.php';
function catalog_build($action, $settings, $board) {
global $config;
2013-07-18 17:30:00 +02:00
// Possible values for $action:
// - all (rebuild everything, initialization)
// - news (news has been updated)
// - boards (board list changed)
// - post (a reply has been made)
// - post-thread (a thread has been made)
2013-07-18 17:30:00 +02:00
$boards = explode(' ', $settings['boards']);
if ($action == 'all') {
2013-07-18 17:30:00 +02:00
foreach ($boards as $board) {
$b = new Catalog();
$b->build($settings, $board);
2013-07-18 17:30:00 +02:00
}
} elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') && in_array($board, $boards)) {
$b = new Catalog();
$b->build($settings, $board);
2013-07-18 17:30:00 +02:00
}
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
class Catalog {
public function build($settings, $board_name) {
2013-07-18 17:30:00 +02:00
global $config, $board;
openBoard($board_name);
2013-07-18 17:30:00 +02:00
$recent_images = array();
$recent_posts = array();
$stats = array();
$query = query(sprintf("SELECT *, `id` AS `thread_id`, (SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count`, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `bump` DESC", $board_name, $board_name, $board_name)) or error(db_error());
2013-07-18 17:30:00 +02:00
2013-08-01 02:51:43 +02:00
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
2013-07-18 17:30:00 +02:00
$post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id']));
$post['board_name'] = $board['name'];
$post['file'] = $config['uri_thumb'] . $post['thumb'];
$recent_posts[] = $post;
}
file_write($config['dir']['home'] . $board_name . '/catalog.html', Element('themes/catalog/catalog.html', Array(
2013-07-18 17:30:00 +02:00
'settings' => $settings,
'config' => $config,
'boardlist' => createBoardlist(),
'recent_images' => $recent_images,
'recent_posts' => $recent_posts,
'stats' => $stats,
'board' => $board_name,
'link' => $config['root'] . $board['dir']
)));
2013-07-18 17:30:00 +02:00
}
};