1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
13//
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 *
20 * @package   block_rss_client
21 * @copyright 2009 Tim Hunt
22 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once(__DIR__ . '/../../config.php');
26require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
27
28require_login();
29if (isguestuser()) {
30    print_error('guestsarenotallowed');
31}
32
33$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
34$courseid = optional_param('courseid', 0, PARAM_INT);
35$rssid = required_param('rssid', PARAM_INT);
36
37if ($courseid = SITEID) {
38    $courseid = 0;
39}
40if ($courseid) {
41    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
42    $PAGE->set_course($course);
43    $context = $PAGE->context;
44} else {
45    $context = context_system::instance();
46    $PAGE->set_context($context);
47}
48
49$urlparams = array('rssid' => $rssid);
50if ($courseid) {
51    $urlparams['courseid'] = $courseid;
52}
53if ($returnurl) {
54    $urlparams['returnurl'] = $returnurl;
55}
56$PAGE->set_url('/blocks/rss_client/viewfeed.php', $urlparams);
57$PAGE->set_pagelayout('popup');
58
59$rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
60
61$rss = new moodle_simplepie($rssrecord->url);
62
63if ($rss->error()) {
64    debugging($rss->error());
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
73$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
74$PAGE->navbar->add(get_string('blocks'));
75$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
76$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
77$PAGE->navbar->add($strviewfeed);
78echo $OUTPUT->header();
79
80if (!empty($rssrecord->preferredtitle)) {
81    $feedtitle = $rssrecord->preferredtitle;
82} else {
83    $feedtitle =  $rss->get_title();
84}
85echo '<table align="center" width="50%" cellspacing="1">'."\n";
86echo '<tr><td colspan="2"><strong>'. s($feedtitle) .'</strong></td></tr>'."\n";
87foreach ($rss->get_items() as $item) {
88    echo '<tr><td valign="middle">'."\n";
89    echo '<a href="'.$item->get_link().'" target="_blank"><strong>';
90    echo s($item->get_title());
91    echo '</strong></a>'."\n";
92    echo '</td>'."\n";
93    echo '</tr>'."\n";
94    echo '<tr><td colspan="2"><small>';
95    echo format_text($item->get_description(), FORMAT_HTML) .'</small></td></tr>'."\n";
96}
97echo '</table>'."\n";
98
99echo $OUTPUT->footer();
100