diff options
| author | Appleman1234 <applemansigloo@gmail.com> | 2016-12-15 18:25:42 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-15 18:25:42 +0900 |
| commit | cae526e65a20f3da2d8884c4d8e8978c54120000 (patch) | |
| tree | 2954153dd49f616f5018490058ff4bfbd17300d3 /templates/themes/rss | |
| parent | b58fab98147a92c8e6d22f15d23684508b6bb811 (diff) | |
| parent | 5feae402cb55d49963bfd2c6f5a33d10690ecbc1 (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/rss')
| -rwxr-xr-x | templates/themes/rss/info.php | 75 | ||||
| -rw-r--r-- | templates/themes/rss/rss.xml | 28 | ||||
| -rwxr-xr-x | templates/themes/rss/theme.php | 127 |
3 files changed, 230 insertions, 0 deletions
diff --git a/templates/themes/rss/info.php b/templates/themes/rss/info.php new file mode 100755 index 00000000..4da43bf0 --- /dev/null +++ b/templates/themes/rss/info.php @@ -0,0 +1,75 @@ +<?php + $theme = Array(); + + // Theme name + $theme['name'] = 'RSS'; + // Description (you can use Tinyboard markup here) + $theme['description'] = 'Show recent posts and images as a RSS'; + $theme['version'] = 'v0.1'; + + // Theme configuration + $theme['config'] = Array(); + + $theme['config'][] = Array( + 'title' => 'Title', + 'name' => 'title', + 'type' => 'text', + 'default' => 'Recent Posts RSS' + ); + + $theme['config'][] = Array( + 'title' => 'Excluded boards', + 'name' => 'exclude', + 'type' => 'text', + 'comment' => '(space seperated)' + ); + + $theme['config'][] = Array( + 'title' => '# of recent posts', + 'name' => 'limit_posts', + 'type' => 'text', + 'default' => '30', + 'comment' => '(maximum posts to display)' + ); + + $theme['config'][] = Array( + 'title' => 'XML file', + 'name' => 'xml', + 'type' => 'text', + 'default' => 'recent.xml', + 'comment' => '(eg. "recent.xml")' + ); + + $theme['config'][] = Array( + 'title' => 'Base URL', + 'name' => 'base_url', + 'type' => 'text', + 'default' => 'http://test.com', + 'comment' => '(eg. "http://test.com")' + ); + + $theme['config'][] = Array( + 'title' => 'Show Threads Only', + 'name' => 'show_threads_only', + 'type' => 'text', + 'default' => 'false', + ); + + $theme['config'][] = Array( + 'title' => 'Enable Per Board', + 'name' => 'enable_per_board', + 'type' => 'text', + 'default' => 'false', + ); + + // Unique function name for building everything + $theme['build_function'] = 'rss_recentposts_build'; + $theme['install_callback'] = 'rss_recentposts_install'; + + if (!function_exists('rss_recentposts_install')) { + function rss_recentposts_install($settings) { + if (!is_numeric($settings['limit_posts']) || $settings['limit_posts'] < 0) + return Array(false, '<strong>' . utf8tohtml($settings['limit_posts']) . '</strong> is not a non-negative integer.'); + } + } + diff --git a/templates/themes/rss/rss.xml b/templates/themes/rss/rss.xml new file mode 100644 index 00000000..6bf34113 --- /dev/null +++ b/templates/themes/rss/rss.xml @@ -0,0 +1,28 @@ +{% filter remove_whitespace %} +<?xml version="1.0" encoding="utf-8"?> +<rss xmlns:dc="http://purl.org/dc/elements/1.1/" + version="2.0"> + <channel> + <description> + <![CDATA[{{ settings.subtitle }}]]> + </description> + <title>{{ settings.title }}</title> + <generator>Tinyboard {{ config.version }}</generator> + <link>{{ settings.base_url }}{{ config.root }}{{ settings.html }}</link> + {% for post in recent_posts %} + <item> + <title><![CDATA[ {{ post.board_name }} ]]></title> + <description> + <![CDATA[ + <a href="{{ settings.base_url }}{{ post.link }}"> + {{ post.snippet }} + </a> + ]]> + </description> + <link>{{ settings.base_url }}{{ post.link }}</link> + <guid>{{ settings.base_url }}{{ post.link }}</guid> + </item> + {% endfor %} + </channel> +</rss> +{% endfilter %} diff --git a/templates/themes/rss/theme.php b/templates/themes/rss/theme.php new file mode 100755 index 00000000..eb833ec8 --- /dev/null +++ b/templates/themes/rss/theme.php @@ -0,0 +1,127 @@ +<?php + require 'info.php'; + + function rss_recentposts_build($action, $settings, $board) { + // Possible values for $action: + // - all (rebuild everything, initialization) + // - news (news has been updated) + // - boards (board list changed) + // - post (a post has been made) + // - post-thread (a thread has been made) + + $b = new RSSRecentPosts(); + $b->build($action, $settings); + } + + // Wrap functions in a class so they don't interfere with normal Tinyboard operations + class RSSRecentPosts { + public function build($action, $settings) { + global $config, $_theme,$board; + + + $this->excluded = explode(' ', $settings['exclude']); + if ($settings['show_threads_only'] == 'true'){ + if ($action == 'all' || $action == 'post-thread' || $action == 'post-delete') + file_write($config['dir']['home'] . $settings['xml'], $this->site_rsspage($settings)); + } + else { + if ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete') + file_write($config['dir']['home'] . $settings['xml'], $this->site_rsspage($settings)); + } + + if ($settings['enable_per_board'] == 'true'){ + $boards = listBoards(); + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) + continue; + + openBoard($_board['uri']); + if ($settings['show_threads_only'] == 'true'){ + if ($action == 'all' || $action == 'post-thread' || $action == 'post-delete') + file_write($config['dir']['home'] . $board['dir'] . $settings['xml'], $this->board_rsspage($settings,$_board)); + } + else { + if ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete') + file_write($config['dir']['home'] . $board['dir'] . $settings['xml'], $this->board_rsspage($settings,$_board)); + } + } + + } + } + + // Build news page + public function site_rsspage($settings) { + global $config, $board; + + $recent_posts = Array(); + + $boards = listBoards(); + + $query = ''; + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) + continue; + if ($settings['show_threads_only'] == 'true'){ + $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` is null UNION ALL ", $_board['uri'], $_board['uri']); + } + else { + $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']); + } + } + $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query); + $query = query($query) or error(db_error()); + + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + openBoard($post['board']); + + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + $post['snippet'] = pm_snippet($post['body'], 30); + $post['board_name'] = $board['name']; + + $recent_posts[] = $post; + } + + + return Element('themes/rss/rss.xml', Array( + 'settings' => $settings, + 'config' => $config, + 'recent_posts' => $recent_posts, + )); + } + + // Build news page + public function board_rsspage($settings,$_board) { + global $config, $board; + + $recent_posts = Array(); + + $query = ''; + if ($settings['show_threads_only'] == 'true'){ + $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` is null UNION ALL ", $_board['uri'], $_board['uri']); + } + else { + $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` UNION ALL ", $_board['uri'], $_board['uri']); + } + $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query); + $query = query($query) or error(db_error()); + + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + openBoard($post['board']); + + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + $post['snippet'] = pm_snippet($post['body'], 30); + $post['board_name'] = $board['name']; + + $recent_posts[] = $post; + } + + + return Element('themes/rss/rss.xml', Array( + 'settings' => $settings, + 'config' => $config, + 'recent_posts' => $recent_posts, + )); + } + }; + +?> |
