summaryrefslogtreecommitdiff
path: root/templates/themes/catalog
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2016-12-15 18:25:42 +0900
committerGitHub <noreply@github.com>2016-12-15 18:25:42 +0900
commitcae526e65a20f3da2d8884c4d8e8978c54120000 (patch)
tree2954153dd49f616f5018490058ff4bfbd17300d3 /templates/themes/catalog
parentb58fab98147a92c8e6d22f15d23684508b6bb811 (diff)
parent5feae402cb55d49963bfd2c6f5a33d10690ecbc1 (diff)
Merge pull request #79 from lainchan/clean_prod_vichan_update
Merge vichan changes from upstream and changes directly applied to the site.
Diffstat (limited to 'templates/themes/catalog')
-rw-r--r--templates/themes/catalog/catalog.html31
-rw-r--r--templates/themes/catalog/index.rss19
-rw-r--r--templates/themes/catalog/info.php7
-rw-r--r--templates/themes/catalog/theme.php98
4 files changed, 125 insertions, 30 deletions
diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html
index f23298bf..ac19a90e 100644
--- a/templates/themes/catalog/catalog.html
+++ b/templates/themes/catalog/catalog.html
@@ -4,12 +4,13 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script type='text/javascript'>
- active_page = "catalog";
+ var active_page = "catalog"
+ , board_name = "{{ board }}";
</script>
+ <title>{{ settings.title }} ( /{{ board }}/ )</title>
{% include 'header.html' %}
- <title>{{ settings.title }} (/{{ board }}/)</title>
</head>
-<body class="theme-catalog board-{{ board }}">
+<body class="8chan vichan {% if mod %}is-moderator{% else %}is-not-moderator{% endif %} theme-catalog active-catalog" data-stylesheet="{% if config.default_stylesheet.1 != '' %}{{ config.default_stylesheet.1 }}{% else %}default{% endif %}">
<div class="top bar topbar">
{{ boardlist.top }}
</div>
@@ -41,15 +42,17 @@
<option value="large">{% trans 'Large' %}</option>
</select>
</div>
-
- <div class="threads">
- <ul id="Grid">
- {% for post in recent_posts %}
- <li class="mix"
+ <br></br>
+ <div class="threads">
+ <div id="Grid">
+ {% for post in recent_posts %}
+ <div class="mix"
data-reply="{{ post.reply_count }}"
- data-bump="{{ post.bump }}"
- data-time="{{ post.time }}"
- data-board="{{ post.board }}"
+ data-bump="{{ post.bump }}"
+ data-time="{{ post.time }}"
+ data-id="{{ post.id }}"
+ data-sticky="{% if post.sticky %}true{% else %}false{% endif %}"
+ data-locked="{% if post.locked %}true{% else %}false{% endif %}"
>
<div class="thread grid-li grid-size-small">
<a href="{{post.link}}">
@@ -61,7 +64,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')}}">
</a>
<div class="replies">
- <strong>R: {{ post.reply_count }} / I: {{ post.image_count }}</strong>
+ <strong>R: {{ post.reply_count }} / I: {{ post.image_count }}{% if post.sticky %} (sticky){% endif %}</strong>
{% if post.subject %}
<p class="intro">
<span class="subject">
@@ -75,9 +78,9 @@
{{ post.body }}
</div>
</div>
- </li>
+ </div>
{% endfor %}
- </ul>
+ </div>
</div>
<hr/>
diff --git a/templates/themes/catalog/index.rss b/templates/themes/catalog/index.rss
new file mode 100644
index 00000000..e6576ffc
--- /dev/null
+++ b/templates/themes/catalog/index.rss
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
+<channel>
+ <title>/{{ board.uri }}/ - {{ board.title|e }}</title>
+ <link>{{ config.root }}{{ board.uri }}/</link>
+ <description>Live feed of new threads on the board /{{ board.uri }}/ - {{ board.title|e }}.</description>
+ <atom:link href="{{ config.root }}{{ board.uri }}/index.rss" rel="self" type="application/rss+xml"/>
+ {% for post in recent_posts %}
+ <item>
+ <title>{% if post.subject %}{{ post.subject|e }}{% else %}{{ post.body_nomarkup[:256]|remove_modifiers|e }}{% endif %}</title>
+ <link>{{ config.root }}{{ board.uri }}/res/{{ post.id }}.html</link>
+ <guid>{{ config.root }}{{ board.uri }}/res/{{ post.id }}.html</guid>
+ <comments>{{ config.root }}{{ board.uri }}/res/{{ post.id }}.html</comments>
+ <pubDate>{{ post.pubdate }}</pubDate>
+ <description><![CDATA[ <a href='{{ config.root }}{{ board.uri }}/res/{{ post.id }}.html' target=_blank><img style='float:left;margin:8px' border=0 src='{% if not config.uri_thumb %}{{ config.root }}{% endif %}{{ post.file }}'></a> {{ post.body }} ]]></description>
+ </item>
+ {% endfor %}
+</channel>
+</rss>
diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php
index e2b13307..66c45082 100644
--- a/templates/themes/catalog/info.php
+++ b/templates/themes/catalog/info.php
@@ -47,6 +47,13 @@
);
$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',
'type' => 'checkbox',
diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php
index 9ecdb9d1..3ef974c3 100644
--- a/templates/themes/catalog/theme.php
+++ b/templates/themes/catalog/theme.php
@@ -15,23 +15,30 @@
// - post-thread (a thread has been made)
if ($action === 'all') {
foreach ($boards as $board) {
- if ($config['smart_build']) {
+ $b = new Catalog($settings);
+
+ $action = generation_strategy("sb_catalog", array($board));
+ if ($action == 'delete') {
file_unlink($config['dir']['home'] . $board . '/catalog.html');
- } else {
- $b->build($board);
+ file_unlink($config['dir']['home'] . $board . '/index.rss');
+ }
+ elseif ($action == 'rebuild') {
+ $b->build($settings, $board);
}
}
- } elseif (in_array($board, $boards) &&
- $action == 'post-thread' ||
- ($settings['update_on_posts'] && $action == 'post') ||
- ($settings['update_on_posts'] && $action == 'post-delete'))
- {
- if ($config['smart_build']) {
+ } elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') && in_array($board, $boards)) {
+ $b = new Catalog($settings);
+
+ $action = generation_strategy("sb_catalog", array($board));
+ if ($action == 'delete') {
file_unlink($config['dir']['home'] . $board . '/catalog.html');
- } else {
- $b->build($board);
+ file_unlink($config['dir']['home'] . $board . '/index.rss');
}
- }
+ elseif ($action == 'rebuild') {
+ $b->build($settings, $board);
+ }
+
+ }
// FIXME: Check that Ukko is actually enabled
if ($settings['enable_ukko'] && (
@@ -40,6 +47,14 @@
{
$b->buildUkko();
}
+
+ // FIXME: Check that Rand is actually enabled
+ if ($settings['enable_rand'] && (
+ $action === 'all' || $action === 'post' ||
+ $action === 'post-thread' || $action === 'post-delete'))
+ {
+ $b->buildRand();
+ }
}
// Wrap functions in a class so they don't interfere with normal Tinyboard operations
@@ -90,14 +105,56 @@
$this->saveForBoard($ukkoSettings['uri'], $recent_posts,
$config['root'] . $ukkoSettings['uri']);
}
+
+ /**
+ * Build and save the HTML of the catalog for the Rand theme
+ */
+ public function buildRand() {
+ global $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));
+ }
+
+ // Sort in bump order
+ usort($threads, function($a, $b) {
+ return strcmp($b['bump'], $a['bump']);
+ });
+ // Generate data for the template
+ $recent_posts = $this->generateRecentPosts($threads);
+
+ $this->saveForBoard($randSettings['uri'], $recent_posts,
+ $config['root'] . $randSettings['uri']);
+ }
/**
* Build and save the HTML of the catalog for the given board
*/
- public function build($board_name) {
- if (!openBoard($board_name)) {
- error(sprintf(_("Board %s doesn't exist"), $post['board']));
- }
+ public function build($settings, $board_name) {
+ global $config, $board;
+ if ($board['uri'] != $board_name) {
+ if (!openBoard($board_name)) {
+ error(sprintf(_("Board %s doesn't exist"), $board_name));
+ }
+ }
if (array_key_exists($board_name, $this->threadsCache)) {
$threads = $this->threadsCache[$board_name];
@@ -163,10 +220,13 @@
$post['file'] = $config['uri_thumb'] . $files[0]->thumb;
}
}
+ } else {
+ $post['file'] = $config['root'] . $config['image_deleted'];
}
if (empty($post['image_count']))
$post['image_count'] = 0;
+ $post['pubdate'] = date('r', $post['time']);
$posts[] = $post;
}
@@ -200,5 +260,11 @@
'board' => $board_name,
'link' => $board_link
)));
+
+ file_write($config['dir']['home'] . $board_name . '/index.rss', Element('themes/catalog/index.rss', Array(
+ 'config' => $config,
+ 'recent_posts' => $recent_posts,
+ 'board' => $board
+ )));
}
}