MDL-65788 tool_policy: Prevent two modals rendering for guests.
[moodle.git] / blocks / rss_client / viewfeed.php
CommitLineData
f1a34d8f 1<?php
4ca6cfbf
PS
2// This file is part of Moodle - http://moodle.org/
3//
f1a34d8f 4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
4ca6cfbf 13//
f1a34d8f 14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Script to let a user edit the properties of a particular RSS feed.
19 *
f25a6839 20 * @package block_rss_client
f1a34d8f 21 * @copyright 2009 Tim Hunt
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
1fcf0ca8 25require_once(__DIR__ . '/../../config.php');
0864a083 26require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
f1a34d8f 27
28require_login();
4cdb8d70 29if (isguestuser()) {
1b62c87d 30 print_error('guestsarenotallowed');
f1a34d8f 31}
32
33$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
1e12c120
RT
34$courseid = optional_param('courseid', 0, PARAM_INT);
35$rssid = required_param('rssid', PARAM_INT);
f1a34d8f 36
37if ($courseid = SITEID) {
38 $courseid = 0;
39}
40if ($courseid) {
74df2951 41 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
f1a34d8f 42 $PAGE->set_course($course);
43 $context = $PAGE->context;
44} else {
fe2fdd11 45 $context = context_system::instance();
f1a34d8f 46 $PAGE->set_context($context);
47}
48
49$urlparams = array('rssid' => $rssid);
f1a34d8f 50if ($courseid) {
51 $urlparams['courseid'] = $courseid;
f1a34d8f 52}
53if ($returnurl) {
54 $urlparams['returnurl'] = $returnurl;
f1a34d8f 55}
a6855934 56$PAGE->set_url('/blocks/rss_client/viewfeed.php', $urlparams);
78946b9b 57$PAGE->set_pagelayout('popup');
f1a34d8f 58
59$rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
60
0864a083 61$rss = new moodle_simplepie($rssrecord->url);
f1a34d8f 62
0864a083 63if ($rss->error()) {
64 debugging($rss->error());
f1a34d8f 65 print_error('errorfetchingrssfeed');
66}
67
68$strviewfeed = get_string('viewfeed', 'block_rss_client');
69
70$PAGE->set_title($strviewfeed);
71$PAGE->set_heading($strviewfeed);
72
a6855934 73$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
7d2a0492 74$PAGE->navbar->add(get_string('blocks'));
cdc018ad
RW
75$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
76$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
7d2a0492 77$PAGE->navbar->add($strviewfeed);
78echo $OUTPUT->header();
f1a34d8f 79
80if (!empty($rssrecord->preferredtitle)) {
81 $feedtitle = $rssrecord->preferredtitle;
82} else {
0864a083 83 $feedtitle = $rss->get_title();
f1a34d8f 84}
85echo '<table align="center" width="50%" cellspacing="1">'."\n";
4925b9e8 86echo '<tr><td colspan="2"><strong>'. s($feedtitle) .'</strong></td></tr>'."\n";
0864a083 87foreach ($rss->get_items() as $item) {
f1a34d8f 88 echo '<tr><td valign="middle">'."\n";
4925b9e8
DP
89 echo '<a href="'.$item->get_link().'" target="_blank"><strong>';
90 echo s($item->get_title());
f1a34d8f 91 echo '</strong></a>'."\n";
92 echo '</td>'."\n";
93 echo '</tr>'."\n";
94 echo '<tr><td colspan="2"><small>';
4925b9e8 95 echo format_text($item->get_description(), FORMAT_HTML) .'</small></td></tr>'."\n";
f1a34d8f 96}
97echo '</table>'."\n";
98
99echo $OUTPUT->footer();