summaryrefslogtreecommitdiff
path: root/templates/themes/catalog/theme.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-07-18 15:19:03 -0400
committerczaks <marcin@6irc.net>2013-07-18 15:19:03 -0400
commitfa66b96240e9fdf7b179e604833d1c59702f9c39 (patch)
treec7640caebe4294b1bd0eff54ce418fe0a251104c /templates/themes/catalog/theme.php
parent8c72c8a43232f137256fa170c889ba330ebba7af (diff)
parente4bd9a6886af2a812ccc909d8ad957df1bdc5d2b (diff)
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: post.php
Diffstat (limited to 'templates/themes/catalog/theme.php')
-rw-r--r--templates/themes/catalog/theme.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php
new file mode 100644
index 00000000..e585cf17
--- /dev/null
+++ b/templates/themes/catalog/theme.php
@@ -0,0 +1,60 @@
+<?php
+ require 'info.php';
+
+ function catalog_build($action, $settings, $board) {
+ global $config;
+
+ // 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)
+
+ $boards = explode(' ', $settings['boards']);
+
+ if ($action == 'all') {
+ copy('templates/themes/catalog/catalog.css', $config['dir']['home'] . $settings['css']);
+
+ foreach ($boards as $board) {
+ $b = new Catalog();
+ $b->build($settings, $board);
+ }
+ } elseif ($action == 'post-thread' && in_array($board, $boards)) {
+ $b = new Catalog();
+ $b->build($settings, $board);
+ }
+ }
+
+ // Wrap functions in a class so they don't interfere with normal Tinyboard operations
+ class Catalog {
+ public function build($settings, $board_name) {
+ global $config, $board;
+
+ openBoard($board_name);
+
+ $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());
+
+ while ($post = $query->fetch()) {
+ $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(
+ 'settings' => $settings,
+ 'config' => $config,
+ 'boardlist' => createBoardlist(),
+ 'recent_images' => $recent_images,
+ 'recent_posts' => $recent_posts,
+ 'stats' => $stats,
+ 'board' => $board_name,
+ 'link' => $config['root'] . $board['dir']
+ )));
+ }
+ };