|
2 | 2 |
|
3 | 3 | /* For licensing terms, see /license.txt */ |
4 | 4 |
|
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'; |
7 | 10 |
|
8 | 11 | $plugin = RssPlugin::create(); |
9 | 12 |
|
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; |
14 | 17 |
|
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 | + } |
17 | 22 |
|
18 | 23 | return; |
19 | 24 | } |
20 | 25 |
|
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; |
37 | 28 | } |
| 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(); |
0 commit comments