Skip to content

Commit 76206b1

Browse files
Merge pull request #8476 from christianbeeznest/fixes-plugin-rss01
Plugin: Improve Rss plugin region integration
2 parents 30192a1 + 65a161b commit 76206b1

7 files changed

Lines changed: 444 additions & 48 deletions

File tree

public/main/admin/settings.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ function getStablePluginAllowList(): array
334334
'MigrationMoodle',
335335
'EmbedRegistry',
336336
'SearchCourse',
337+
'Rss',
337338
];
338339
}
339340

public/plugin/Rss/index.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,40 @@
22

33
/* For licensing terms, see /license.txt */
44

5-
use Zend\Feed\Reader\Feed\FeedInterface;
6-
use Zend\Feed\Reader\Reader;
5+
if (!function_exists('api_get_path')) {
6+
require_once __DIR__.'/../../main/inc/global.inc.php';
7+
}
8+
9+
require_once __DIR__.'/lib/rss_plugin.class.php';
710

811
$plugin = RssPlugin::create();
912

10-
$url = $plugin->get_rss();
11-
$title = $plugin->get_block_title();
12-
$title = $title ? "<h4>$title</h4>" : '';
13-
$css = $plugin->get_css();
13+
$isDirectRequest = isset($_SERVER['SCRIPT_FILENAME'])
14+
&& realpath((string) $_SERVER['SCRIPT_FILENAME']) === realpath(__FILE__);
15+
16+
$isRenderingOwnFullPage = defined('RSS_FULL_PAGE_RENDERING') && RSS_FULL_PAGE_RENDERING;
1417

15-
if (empty($url)) {
16-
echo Display::return_message(get_lang('NoRSSItem'), 'warning');
18+
if (!$plugin->isEnabled()) {
19+
if ($isDirectRequest && !$isRenderingOwnFullPage) {
20+
api_not_allowed(true);
21+
}
1722

1823
return;
1924
}
2025

21-
try {
22-
$channel = Reader::import($url);
23-
if (!empty($channel)) {
24-
/** @var FeedInterface $item */
25-
foreach ($channel as $item) {
26-
$title = $item->getTitle();
27-
$link = $item->getLink();
28-
if (!empty($link)) {
29-
$title = Display::url($title, $link, ['target' => '_blank']);
30-
}
31-
echo Display::panel($item->getDescription(), $title);
32-
}
33-
}
34-
} catch (Exception $e) {
35-
echo Display::return_message($plugin->get_lang('no_valid_rss'), 'warning');
36-
error_log($e->getMessage());
26+
if ($isRenderingOwnFullPage) {
27+
return;
3728
}
29+
30+
if (!$isDirectRequest) {
31+
echo $plugin->renderBlock();
32+
33+
return;
34+
}
35+
36+
define('RSS_FULL_PAGE_RENDERING', true);
37+
38+
$template = new Template($plugin->get_title());
39+
$template->assign('header', $plugin->get_title());
40+
$template->assign('content', $plugin->renderFullPage());
41+
$template->display_one_col_template();

public/plugin/Rss/lang/en_US.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
$strings['plugin_title'] = 'RSS';
99
$strings['plugin_comment'] = 'Display RSS content.';
1010

11-
$strings['rss'] = 'RSS';
11+
$strings['rss'] = 'RSS URL';
12+
$strings['rss_help'] = 'Public HTTP or HTTPS URL of the RSS/Atom feed to display.';
1213
$strings['block_title'] = 'Block title';
14+
$strings['block_title_help'] = 'Optional title displayed above the feed items.';
1315

1416
$strings['title'] = 'Title';
15-
$strings['no_rss'] = 'There is no RSS configured. Please add a RSS';
16-
$strings['no_valid_rss'] = 'Please check if the URL contains a valid RSS URL';
17+
$strings['Feed'] = 'Feed';
18+
$strings['no_rss'] = 'There is no RSS URL configured. Please add a valid RSS or Atom feed URL.';
19+
$strings['no_valid_rss'] = 'Please check if the URL contains a valid RSS or Atom feed.';
20+
$strings['invalid_rss_url'] = 'The RSS URL must be a valid public HTTP or HTTPS URL.';
21+
$strings['no_items'] = 'No RSS items were found.';

public/plugin/Rss/lang/es.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
$strings['plugin_title'] = 'RSS';
99
$strings['plugin_comment'] = 'Muestra contenido RSS.';
1010

11-
$strings['rss'] = 'RSS';
11+
$strings['rss'] = 'URL RSS';
12+
$strings['rss_help'] = 'URL pública HTTP o HTTPS del feed RSS/Atom que se mostrará.';
1213
$strings['block_title'] = 'Título del bloque';
14+
$strings['block_title_help'] = 'Título opcional mostrado encima de los elementos del feed.';
1315

1416
$strings['title'] = 'Título';
15-
$strings['no_rss'] = 'RSS no está configurado. Favor de agregar una fuente RSS';
16-
$strings['no_valid_rss'] = 'Por favor, verifica si la URL contiene una URL RSS válida';
17+
$strings['Feed'] = 'Feed';
18+
$strings['no_rss'] = 'RSS no está configurado. Agrega una URL RSS o Atom válida.';
19+
$strings['no_valid_rss'] = 'Verifica si la URL contiene un feed RSS o Atom válido.';
20+
$strings['invalid_rss_url'] = 'La URL RSS debe ser una URL pública HTTP o HTTPS válida.';
21+
$strings['no_items'] = 'No se encontraron elementos RSS.';

0 commit comments

Comments
 (0)