diff --git a/controller/rss.php b/controller/rss.php
index f67b6ab..241f74f 100644
--- a/controller/rss.php
+++ b/controller/rss.php
@@ -10,6 +10,7 @@
namespace phpbbmodders\feedlinks\controller;
+use phpbb\exception\http_exception;
use phpbb\feed\feed_interface;
use phpbbmodders\feedlinks\atom_to_rss;
use Symfony\Component\HttpFoundation\Response;
@@ -45,12 +46,22 @@ public function set_converter(atom_to_rss $converter)
*
* @param feed_interface $feed
* @return Response
+ * @throws http_exception When phpBB's feed can't be converted
*/
protected function send_feed_do(feed_interface $feed)
{
$response = parent::send_feed_do($feed);
- $response->setContent($this->converter->convert($response->getContent()));
+ try
+ {
+ $response->setContent($this->converter->convert($response->getContent()));
+ }
+ catch (\RuntimeException $e)
+ {
+ $this->language->add_lang('feedlinks', 'phpbbmodders/feedlinks');
+ throw new http_exception(Response::HTTP_INTERNAL_SERVER_ERROR, 'FEEDLINKS_RSS_ERROR', [], $e);
+ }
+
$response->headers->set('Content-Type', 'application/rss+xml; charset=UTF-8');
return $response;
diff --git a/docs/events/forumlist_body_forum_desc_after.txt b/docs/events/forumlist_body_forum_desc_after.txt
index bc9cdf7..868ca4e 100644
--- a/docs/events/forumlist_body_forum_desc_after.txt
+++ b/docs/events/forumlist_body_forum_desc_after.txt
@@ -40,8 +40,8 @@ not the forum has a description, moderators or subforums.
USE CASE
========
phpbbmodders/feedlinks shows a forum's Atom and RSS feed links below its
-description ("Subscribe to the feed: Atom or RSS"), as phpBB.com does by
-hand in its forum descriptions.
+description ("Subscribe to the feed, available in Atom or RSS format."),
+as phpBB.com does by hand in its forum descriptions.
The existing events in the row do not fit:
- forumlist_body_forum_image_before/prepend/append/after sit before the
diff --git a/event/listener.php b/event/listener.php
index 554599c..576e45b 100644
--- a/event/listener.php
+++ b/event/listener.php
@@ -88,12 +88,14 @@ public static function getSubscribedEvents()
}
/**
- * Tell the page head whether to add RSS links for the board-wide feeds
+ * Tell the page head whether to add RSS links for the board-wide feeds,
+ * and load the language its RSS links use
*
* @return void
*/
public function add_rss_head_switch()
{
+ $this->load_language();
$this->template->assign_var('S_FEEDLINKS_RSS_HEAD', (bool) $this->config['feedlinks_rss_head']);
}
@@ -101,8 +103,7 @@ public function add_rss_head_switch()
* Add a forum's feed links below its description on forum lists
*
* phpBB has no template event after the description of a forum row (see
- * docs/events/), so the rendered links are appended to FORUM_DESC. The
- * URLs are also given to the row for styles that place them elsewhere.
+ * docs/events/), so the rendered links are appended to FORUM_DESC.
*
* @param data $event
* @return void
@@ -117,8 +118,6 @@ public function add_forumlist_links(data $event)
}
$forum_row = $event['forum_row'];
- $forum_row['U_FEEDLINKS_ATOM'] = $urls['atom'];
- $forum_row['U_FEEDLINKS_RSS'] = $urls['rss'];
$forum_row['FORUM_DESC'] .= $this->render_links($urls, $event['row']['forum_name'], true, $forum_row['FORUM_DESC'] !== '');
$event['forum_row'] = $forum_row;
}
@@ -139,7 +138,6 @@ public function add_viewforum_links(data $event)
}
$this->template->assign_vars([
- 'U_FEEDLINKS_ATOM' => $urls['atom'],
'U_FEEDLINKS_RSS' => $urls['rss'],
'FEEDLINKS_FORUM_LINKS' => $this->render_links($urls, $event['forum_data']['forum_name'], false),
]);
@@ -193,7 +191,7 @@ public function acp_forum_initialise(data $event)
if ($event['action'] === 'add' && !$event['update'])
{
$forum_data = $event['forum_data'];
- $forum_data['forum_feedlinks'] = 0;
+ $forum_data['forum_feedlinks'] = links::NONE;
$event['forum_data'] = $forum_data;
}
}
@@ -208,9 +206,9 @@ public function acp_forum_display(data $event)
{
$this->language->add_lang('acp_feedlinks', 'phpbbmodders/feedlinks');
- $current = isset($event['forum_data']['forum_feedlinks']) ? (int) $event['forum_data']['forum_feedlinks'] : 0;
+ $current = isset($event['forum_data']['forum_feedlinks']) ? (int) $event['forum_data']['forum_feedlinks'] : links::NONE;
$options = [
- 0 => 'FEEDLINKS_NONE',
+ links::NONE => 'FEEDLINKS_NONE',
links::ATOM => 'FEEDLINKS_ATOM',
links::RSS => 'FEEDLINKS_RSS',
links::BOTH => 'FEEDLINKS_BOTH',
@@ -266,11 +264,7 @@ public function acp_board_feed_settings(data $event)
*/
protected function render_links(array $urls, $forum_name, $in_list, $new_line = false)
{
- if (!$this->language_loaded)
- {
- $this->language->add_lang('feedlinks', 'phpbbmodders/feedlinks');
- $this->language_loaded = true;
- }
+ $this->load_language();
return $this->twig->render(self::LINKS_TEMPLATE, [
'U_ATOM' => $urls['atom'],
@@ -280,4 +274,18 @@ protected function render_links(array $urls, $forum_name, $in_list, $new_line =
'S_NEW_LINE' => $new_line,
]);
}
+
+ /**
+ * Load the front-end language file once
+ *
+ * @return void
+ */
+ protected function load_language()
+ {
+ if (!$this->language_loaded)
+ {
+ $this->language->add_lang('feedlinks', 'phpbbmodders/feedlinks');
+ $this->language_loaded = true;
+ }
+ }
}
diff --git a/language/en/feedlinks.php b/language/en/feedlinks.php
index 7c77285..85367ea 100644
--- a/language/en/feedlinks.php
+++ b/language/en/feedlinks.php
@@ -29,4 +29,5 @@
'FEEDLINKS_RSS' => 'RSS',
'FEEDLINKS_ATOM_TITLE' => 'Atom feed - %s',
'FEEDLINKS_RSS_TITLE' => 'RSS feed - %s',
+ 'FEEDLINKS_RSS_ERROR' => 'The RSS feed could not be created.',
]);
diff --git a/links.php b/links.php
index c6d888f..27b8668 100644
--- a/links.php
+++ b/links.php
@@ -19,6 +19,9 @@
*/
class links
{
+ /** Forum setting: show no links */
+ const NONE = 0;
+
/** Forum setting bit: show the Atom link */
const ATOM = 1;
@@ -59,11 +62,11 @@ public function __construct(auth $auth, config $config, helper $helper)
*
* @param array $forum Forum row with forum_id, forum_type, forum_options,
* forum_password and forum_feedlinks
- * @return int Bits of self::ATOM and self::RSS; 0 for no links
+ * @return int Bits of self::ATOM and self::RSS; self::NONE for no links
*/
public function get_formats(array $forum)
{
- $formats = isset($forum['forum_feedlinks']) ? ((int) $forum['forum_feedlinks'] & self::BOTH) : 0;
+ $formats = isset($forum['forum_feedlinks']) ? ((int) $forum['forum_feedlinks'] & self::BOTH) : self::NONE;
if (!$formats
|| !$this->config['feed_enable']
@@ -73,7 +76,7 @@ public function get_formats(array $forum)
|| !empty($forum['forum_password'])
|| !$this->auth->acl_get('f_read', (int) $forum['forum_id']))
{
- return 0;
+ return self::NONE;
}
return $formats;
diff --git a/styles/all/template/event/overall_header_feeds.html b/styles/all/template/event/overall_header_feeds.html
index b6c8f67..f7b3597 100644
--- a/styles/all/template/event/overall_header_feeds.html
+++ b/styles/all/template/event/overall_header_feeds.html
@@ -1,9 +1,9 @@
{% if S_FEEDLINKS_RSS_HEAD %}
- {% if S_ENABLE_FEEDS_OVERALL %}{% endif %}
- {% if S_ENABLE_FEEDS_NEWS %}{% endif %}
- {% if S_ENABLE_FEEDS_FORUMS %}{% endif %}
- {% if S_ENABLE_FEEDS_TOPICS %}{% endif %}
- {% if S_ENABLE_FEEDS_TOPICS_ACTIVE %}{% endif %}
+ {% if S_ENABLE_FEEDS_OVERALL %}{% endif %}
+ {% if S_ENABLE_FEEDS_NEWS %}{% endif %}
+ {% if S_ENABLE_FEEDS_FORUMS %}{% endif %}
+ {% if S_ENABLE_FEEDS_TOPICS %}{% endif %}
+ {% if S_ENABLE_FEEDS_TOPICS_ACTIVE %}{% endif %}
{% endif %}
-{% if U_FEEDLINKS_RSS %}{% endif %}
-{% if U_FEEDLINKS_RSS_TOPIC_HEAD %}{% endif %}
+{% if U_FEEDLINKS_RSS %}{% endif %}
+{% if U_FEEDLINKS_RSS_TOPIC_HEAD %}{% endif %}
diff --git a/styles/all/template/feedlinks_links.html b/styles/all/template/feedlinks_links.html
index 92b5963..5a312ca 100644
--- a/styles/all/template/feedlinks_links.html
+++ b/styles/all/template/feedlinks_links.html
@@ -3,8 +3,8 @@
links follow the description inline, after a line break (S_NEW_LINE) when there is one, as the moderators
and subforums lines do. #}
{% set feedlinks_icon %}{% endset %}
-{% set feedlinks_atom %}{% if U_ATOM %}{{ feedlinks_icon }}{{ lang('FEEDLINKS_ATOM') }} – {{ FORUM_NAME }}{% endif %}{% endset %}
-{% set feedlinks_rss %}{% if U_RSS %}{{ feedlinks_icon }}{{ lang('FEEDLINKS_RSS') }} – {{ FORUM_NAME }}{% endif %}{% endset %}
+{% set feedlinks_atom %}{% if U_ATOM %}{{ feedlinks_icon }}{{ lang('FEEDLINKS_ATOM') }} – {{ FORUM_NAME }}{% endif %}{% endset %}
+{% set feedlinks_rss %}{% if U_RSS %}{{ feedlinks_icon }}{{ lang('FEEDLINKS_RSS') }} – {{ FORUM_NAME }}{% endif %}{% endset %}
{% if S_NEW_LINE %}
{% endif %}
{%- if U_ATOM and U_RSS -%}
{{ lang('FEEDLINKS_AVAILABLE_BOTH', feedlinks_atom, feedlinks_rss) }}
diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php
index 0e1616f..717e9d5 100644
--- a/tests/event/listener_test.php
+++ b/tests/event/listener_test.php
@@ -121,11 +121,7 @@ public function test_forumlist_links()
]);
$this->get_listener()->add_forumlist_links($event);
- $this->assertSame([
- 'FORUM_DESC' => 'Description',
- 'U_FEEDLINKS_ATOM' => 'atom-url',
- 'U_FEEDLINKS_RSS' => '',
- ], $event['forum_row']);
+ $this->assertSame(['FORUM_DESC' => 'Description'], $event['forum_row']);
}
public function test_forumlist_without_links()