From bea631d3f5e7d533185187e284cd392da73de325 Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Tue, 25 Apr 2017 00:09:35 +0900 Subject: [PATCH] Changes to add recent news to the Recent Posts Theme for the front page --- templates/themes/recent/info.php | 9 +++++++++ templates/themes/recent/recent.css | 2 +- templates/themes/recent/recent.html | 20 +++++++++++++++++++- templates/themes/recent/theme.php | 6 +++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/templates/themes/recent/info.php b/templates/themes/recent/info.php index 58448b3d..bea3513c 100644 --- a/templates/themes/recent/info.php +++ b/templates/themes/recent/info.php @@ -64,12 +64,21 @@ 'comment' => '(eg. "recent.css" - see templates/themes/recent for details)' ); + $theme['config'][] = Array( + 'title' => '# of recent news', + 'name' => 'limit_news', + 'type' => 'text', + 'default' => '1', + 'comment' => '(maximum news to display)' + ); // Unique function name for building everything $theme['build_function'] = 'recentposts_build'; $theme['install_callback'] = 'recentposts_install'; if (!function_exists('recentposts_install')) { function recentposts_install($settings) { + if (!is_numeric($settings['limit_news']) || $settings['limit_news'] < 0) + return Array(false, '' . utf8tohtml($settings['limit_news']) . ' is not a non-negative integer.'); if (!is_numeric($settings['limit_images']) || $settings['limit_images'] < 0) return Array(false, '' . utf8tohtml($settings['limit_images']) . ' is not a non-negative integer.'); if (!is_numeric($settings['limit_posts']) || $settings['limit_posts'] < 0) diff --git a/templates/themes/recent/recent.css b/templates/themes/recent/recent.css index 2559bcc3..0bc6efa7 100644 --- a/templates/themes/recent/recent.css +++ b/templates/themes/recent/recent.css @@ -51,7 +51,7 @@ body color: #7fdd57; border: 0px solid #006; float: right; - width: 50%; + width: 40%; } .box h2 { diff --git a/templates/themes/recent/recent.html b/templates/themes/recent/recent.html index c7802aaf..7ae8f5c2 100644 --- a/templates/themes/recent/recent.html +++ b/templates/themes/recent/recent.html @@ -33,7 +33,24 @@

CYBERPUNK IS DUCK

Pour out the Soykaf, lurk, and read the rules before posting!
mascot

- +
+

Latest News

+ {% if recent_news|count == 0 %} +

(No news to show.)

+ {% else %} + {% for entry in recent_news %} +

+ {% if entry.subject %} + {{ entry.subject }} + {% else %} + no subject + {% endif %} + — by {{ entry.name }} at {{ entry.time|date(config.post_date, config.timezone) }} +

+

{{ entry.body }}

+ {% endfor %} + {% endif %} +

Recent Images

@@ -59,6 +76,7 @@ {% endfor %} +

Stats

diff --git a/templates/themes/recent/theme.php b/templates/themes/recent/theme.php index d4d4e9b8..7081346b 100644 --- a/templates/themes/recent/theme.php +++ b/templates/themes/recent/theme.php @@ -147,13 +147,17 @@ $stats['active_content'] += array_sum($matches[1]); } + $query = query("SELECT * FROM ``news`` ORDER BY `time` DESC" . ($settings['limit_news'] ? ' LIMIT ' . $settings['limit_news'] : '')) or error(db_error()); + $recent_news = $query->fetchAll(PDO::FETCH_ASSOC); + return Element('themes/recent/recent.html', Array( 'settings' => $settings, 'config' => $config, 'boardlist' => createBoardlist(), 'recent_images' => $recent_images, 'recent_posts' => $recent_posts, - 'stats' => $stats + 'stats' => $stats, + 'recent_news' => $recent_news, )); } };