Browse Source

Add catalog support for rand and ukko themes

main
Benjamin Southall 8 years ago
committed by -
parent
commit
8266c29f3f
  1. 7
      templates/themes/catalog/info.php
  2. 69
      templates/themes/catalog/theme.php
  3. 1
      templates/themes/rand/theme.php
  4. 1
      templates/themes/semirand/theme.php
  5. 1
      templates/themes/ukko/theme.php

7
templates/themes/catalog/info.php

@ -46,6 +46,13 @@
'comment' => 'Enable catalog for the Ukko theme. This requires the Ukko theme to be enabled.'
);
$theme['config'][] = Array(
'title' => 'Enable Rand catalog',
'name' => 'enable_rand',
'type' => 'checkbox',
'default' => false,
'comment' => 'Enable catalog for the Rand theme. This requires the Rand theme to be enabled.'
);
$theme['config'][] = Array(
'title' => 'Use tooltipster',
'name' => 'use_tooltipster',

69
templates/themes/catalog/theme.php

@ -15,8 +15,6 @@
// - post-thread (a thread has been made)
if ($action === 'all') {
foreach ($boards as $board) {
$b = new Catalog($settings);
$action = generation_strategy("sb_catalog", array($board));
if ($action == 'delete') {
file_unlink($config['dir']['home'] . $board . '/catalog.html');
@ -42,10 +40,18 @@
// FIXME: Check that Ukko is actually enabled
if ($settings['enable_ukko'] && (
$action === 'all' || $action === 'post' ||
$action === 'post-thread' || $action === 'post-delete'))
$action === 'post-thread' || $action === 'post-delete' || $action === 'rebuild'))
{
$b->buildUkko();
}
// FIXME: Check that Rand is actually enabled
if ($settings['enable_rand'] && (
$action === 'all' || $action === 'post' ||
$action === 'post-thread' || $action === 'post-delete' || $action === 'rebuild'))
{
$b->buildRand();
}
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
@ -62,7 +68,7 @@
* Build and save the HTML of the catalog for the Ukko theme
*/
public function buildUkko() {
global $config;
global $board, $config;
$ukkoSettings = themeSettings('ukko');
$queries = array();
@ -93,8 +99,63 @@
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
// Generate board data for building
$board_original = $board;
$board = [];
$board['uri'] = $ukkoSettings['uri'];
$board['title'] = $ukkoSettings['title'];
$board['subtitle'] = $ukkoSettings['subtitle'];
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
$config['root'] . $ukkoSettings['uri']);
$board = $board_original;
}
/**
* Build and save the HTML of the catalog for the Rand theme
*/
public function buildRand() {
global $board, $config;
$randSettings = themeSettings('rand');
$queries = array();
$threads = array();
$exclusions = explode(' ', $randSettings['exclude']);
$boards = array_diff(listBoards(true), $exclusions);
foreach ($boards as $b) {
if (array_key_exists($b, $this->threadsCache)) {
$threads = array_merge($threads, $this->threadsCache[$b]);
} else {
$queries[] = $this->buildThreadsQuery($b);
}
}
// Fetch threads from boards that haven't beenp processed yet
if (!empty($queries)) {
$sql = implode(' UNION ALL ', $queries);
$res = query($sql) or error(db_error());
$threads = array_merge($threads, $res->fetchAll(PDO::FETCH_ASSOC));
}
// Randomize order
shuffle($threads);
// Generate data for the template
$recent_posts = $this->generateRecentPosts($threads);
// Generate board data for building
$board_original = $board;
$board = [];
$board['uri'] = $randSettings['uri'];
$board['title'] = $randSettings['title'];
$board['subtitle'] = $randSettings['subtitle'];
$this->saveForBoard($randSettings['uri'], $recent_posts,
$config['root'] . $randSettings['uri']);
$board = $board_original;
}
/**

1
templates/themes/rand/theme.php

@ -18,6 +18,7 @@
$body = '';
$overflow = array();
$board = array(
'dir' => $this->settings['uri'] . "/",
'url' => $this->settings['uri'],
'name' => $this->settings['title'],
'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])

1
templates/themes/semirand/theme.php

@ -225,6 +225,7 @@
return Element('index.html', array(
'config' => $config,
'board' => array(
'dir' => $this->settings['uri'] . "/",
'url' => $this->settings['uri'],
'title' => $this->settings['title'],
'subtitle' => str_replace('%s', $this->settings['thread_limit'],

1
templates/themes/ukko/theme.php

@ -32,6 +32,7 @@
$board = array(
'uri' => $this->settings['uri'],
'url' => $this->settings['uri'],
'dir' => $this->settings['uri'] . "/",
'title' => $this->settings['title'],
'subtitle' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
);

Loading…
Cancel
Save