summaryrefslogtreecommitdiff
path: root/templates/themes
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-05-26 18:03:20 -0400
committerczaks <marcin@6irc.net>2013-05-26 18:03:20 -0400
commit9c29cec6598331589a9020e5be627260e659e977 (patch)
tree7730fd53c3f183fa65a5ab1f9c52945ddeb97e77 /templates/themes
parent9b8326473555d2419c1c62f957893eb97e6082eb (diff)
Moved ukko to a proper location
Diffstat (limited to 'templates/themes')
-rw-r--r--templates/themes/ukko/info.php53
-rw-r--r--templates/themes/ukko/theme.php111
-rw-r--r--templates/themes/ukko/thumb.pngbin0 -> 15123 bytes
-rw-r--r--templates/themes/ukko/ukko.js37
4 files changed, 201 insertions, 0 deletions
diff --git a/templates/themes/ukko/info.php b/templates/themes/ukko/info.php
new file mode 100644
index 00000000..34d59d4e
--- /dev/null
+++ b/templates/themes/ukko/info.php
@@ -0,0 +1,53 @@
+<?php
+ $theme = Array();
+
+ // Theme name
+ $theme['name'] = 'Ukko';
+ // Description (you can use Tinyboard markup here)
+ $theme['description'] = 'Board with threads and messages from all boards';
+ $theme['version'] = 'v0.1';
+
+ // Theme configuration
+ $theme['config'] = Array();
+
+ $theme['config'][] = Array(
+ 'title' => 'Board name',
+ 'name' => 'title',
+ 'type' => 'text',
+ 'default' => 'Ukko'
+ );
+ $theme['config'][] = Array(
+ 'title' => 'Board URI',
+ 'name' => 'uri',
+ 'type' => 'text',
+ 'comment' => '(ukko for example)'
+ );
+ $theme['config'][] = Array(
+ 'title' => 'Subtitle',
+ 'name' => 'subtitle',
+ 'type' => 'text',
+ 'comment' => '(%s = thread limit. for example "%s freshly bumped threads")'
+ );
+ $theme['config'][] = Array(
+ 'title' => 'Excluded boards',
+ 'name' => 'exclude',
+ 'type' => 'text',
+ 'comment' => '(space seperated)'
+ );
+ $theme['config'][] = Array(
+ 'title' => 'Number of threads',
+ 'name' => 'thread_limit',
+ 'type' => 'text',
+ 'default' => '15',
+ );
+ // Unique function name for building everything
+ $theme['build_function'] = 'ukko_build';
+ $theme['install_callback'] = 'ukko_install';
+
+ if(!function_exists('ukko_install')) {
+ function ukko_install($settings) {
+ if (!file_exists($settings['uri']))
+ @mkdir($settings['uri'], 0777) or error("Couldn't create " . $settings['uri'] . ". Check permissions.", true);
+ }
+ }
+
diff --git a/templates/themes/ukko/theme.php b/templates/themes/ukko/theme.php
new file mode 100644
index 00000000..6fa5fa7e
--- /dev/null
+++ b/templates/themes/ukko/theme.php
@@ -0,0 +1,111 @@
+<?php
+ require 'info.php';
+
+ function ukko_build($action, $settings) {
+ $ukko = new ukko();
+ $ukko->settings = $settings;
+ $ukko->build();
+ }
+
+ class ukko {
+ public $settings;
+ public function build($mod = false) {
+ global $config;
+ $boards = listBoards();
+
+ $body = '';
+ $overflow = array();
+ $board = array(
+ 'url' => $this->settings['uri'],
+ 'name' => $this->settings['title'],
+ 'title' => sprintf($this->settings['subtitle'], $this->settings['thread_limit'])
+ );
+
+ $query = '';
+ foreach($boards as &$_board) {
+ if(in_array($_board['uri'], explode(' ', $this->settings['exclude'])))
+ continue;
+ $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
+ }
+ $query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
+ $query = query($query) or error(db_error());
+
+ $count = 0;
+ $threads = array();
+ while($post = $query->fetch()) {
+
+ if(!isset($threads[$post['board']])) {
+ $threads[$post['board']] = 1;
+ } else {
+ $threads[$post['board']] += 1;
+ }
+
+ if($count < $this->settings['thread_limit']) {
+ openBoard($post['board']);
+ $thread = new Thread(
+ $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'],
+ $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'],
+ $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod
+ );
+
+ $posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
+ $posts->bindValue(':id', $post['id']);
+ $posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
+ $posts->execute() or error(db_error($posts));
+
+ $num_images = 0;
+ while ($po = $posts->fetch()) {
+ if ($po['file'])
+ $num_images++;
+
+ $thread->add(new Post(
+ $po['id'], $post['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'],
+ $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'],
+ $po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod)
+ );
+
+ }
+ if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
+ $ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
+ $ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
+ $ct->execute() or error(db_error($count));
+
+ $c = $ct->fetch();
+ $thread->omitted = $c['num'] - ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
+
+ $c = $ct->fetch();
+ $thread->omitted_images = $c['num'] - $num_images;
+ }
+
+
+ $thread->posts = array_reverse($thread->posts);
+ $body .= '<h2><a href="' . $config['root'] . $post['board'] . '">/' . $post['board'] . '/</a></h2>';
+ $body .= $thread->build(true);
+ } else {
+ $page = 'index';
+ if(floor($threads[$post['board']] / $config['threads_per_page']) > 0) {
+ $page = floor($threads[$post['board']] / $config['threads_per_page']) + 1;
+ }
+ $overflow[] = array('id' => $post['id'], 'board' => $post['board'], 'page' => $page . '.html');
+ }
+
+ $count += 1;
+ }
+
+ $body .= '<script> var overflow = ' . json_encode($overflow) . '</script>';
+ $body .= '<script type="text/javascript" src="ukko.js"></script>';
+
+ file_write($this->settings['uri'] . '/index.html', Element('index.html', array(
+ 'config' => $config,
+ 'board' => $board,
+ 'no_post_form' => true,
+ 'body' => $body,
+ 'boardlist' => createBoardlist($mod)
+ )));
+
+ file_write($this->settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array()));
+ }
+
+ };
+
+?>
diff --git a/templates/themes/ukko/thumb.png b/templates/themes/ukko/thumb.png
new file mode 100644
index 00000000..49c4237b
--- /dev/null
+++ b/templates/themes/ukko/thumb.png
Binary files differ
diff --git a/templates/themes/ukko/ukko.js b/templates/themes/ukko/ukko.js
new file mode 100644
index 00000000..baf0f78d
--- /dev/null
+++ b/templates/themes/ukko/ukko.js
@@ -0,0 +1,37 @@
+var cache = new Array(),
+ thread = false,
+ loading = false;
+$(document).ready(function() {
+ $(window).on('scroll', function() {
+ if($(window).scrollTop() + $(window).height() + 100 > $(document).height() && !loading && overflow.length > 0) {
+ var page = '../' + overflow[0].board + '/' + overflow[0].page;
+ if($.inArray(page, cache) != -1) {
+ thread = $('div#thread_' + overflow[0].id);
+ if(thread.length > 0) {
+ thread.prepend('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a></h2>');
+ $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block'));
+ overflow.shift();
+ }
+ } else {
+ loading = true;
+ $.get(page, function(data) {
+ cache.push(page);
+
+ $(data).find('div[id*="thread_"]').each(function() {
+ $('body').prepend($(this).css('display', 'none').attr('data-board', overflow[0].board));
+ });
+
+ thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
+ if(thread.length > 0) {
+ thread.prepend('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a></h2>');
+ $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block'));
+ overflow.shift();
+ }
+
+ loading = false;
+ });
+ }
+ }
+ });
+
+}); \ No newline at end of file