Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
1441 ariadna 18
 * Script to let a user view the output of a particular RSS feed.
1 efrain 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
 
25
require_once(__DIR__ . '/../../config.php');
26
require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
27
 
28
require_login();
29
 
30
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
31
$courseid = optional_param('courseid', 0, PARAM_INT);
32
$rssid = required_param('rssid', PARAM_INT);
33
 
34
if ($courseid = SITEID) {
35
    $courseid = 0;
36
}
37
if ($courseid) {
38
    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
39
    $PAGE->set_course($course);
40
    $context = $PAGE->context;
41
} else {
42
    $context = context_system::instance();
43
    $PAGE->set_context($context);
44
}
45
 
1441 ariadna 46
$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
47
if (!$managesharedfeeds) {
48
    require_capability('block/rss_client:manageownfeeds', $context);
49
}
50
 
1 efrain 51
$urlparams = array('rssid' => $rssid);
52
if ($courseid) {
53
    $urlparams['courseid'] = $courseid;
54
}
55
if ($returnurl) {
56
    $urlparams['returnurl'] = $returnurl;
57
}
58
$PAGE->set_url('/blocks/rss_client/viewfeed.php', $urlparams);
59
$PAGE->set_pagelayout('popup');
60
 
1441 ariadna 61
if ($managesharedfeeds) {
62
    $select = 'id = :id AND (userid = :userid OR shared = 1)';
63
} else {
64
    $select = 'id = :id AND userid = :userid';
65
}
1 efrain 66
 
1441 ariadna 67
$rssrecord = $DB->get_record_select('block_rss_client', $select, [
68
    'id' => $rssid,
69
    'userid' => $USER->id,
70
], '*', MUST_EXIST);
71
 
1 efrain 72
$rss = new moodle_simplepie($rssrecord->url);
73
if ($rss->error()) {
74
    debugging($rss->error());
75
    throw new \moodle_exception('errorfetchingrssfeed');
76
}
77
 
78
$strviewfeed = get_string('viewfeed', 'block_rss_client');
79
 
80
$PAGE->set_title($strviewfeed);
81
$PAGE->set_heading($strviewfeed);
82
 
83
$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
84
$PAGE->navbar->add(get_string('blocks'));
85
$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
86
$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
87
$PAGE->navbar->add($strviewfeed);
88
echo $OUTPUT->header();
89
 
90
if (!empty($rssrecord->preferredtitle)) {
91
    $feedtitle = $rssrecord->preferredtitle;
92
} else {
93
    $feedtitle =  $rss->get_title();
94
}
95
echo '<table align="center" width="50%" cellspacing="1">'."\n";
96
echo '<tr><td colspan="2"><strong>'. s($feedtitle) .'</strong></td></tr>'."\n";
97
foreach ($rss->get_items() as $item) {
98
    echo '<tr><td valign="middle">'."\n";
99
    echo '<a href="'.$item->get_link().'" target="_blank"><strong>';
100
    echo s($item->get_title());
101
    echo '</strong></a>'."\n";
102
    echo '</td>'."\n";
103
    echo '</tr>'."\n";
104
    echo '<tr><td colspan="2"><small>';
105
    echo format_text($item->get_description(), FORMAT_HTML) .'</small></td></tr>'."\n";
106
}
107
echo '</table>'."\n";
108
 
109
echo $OUTPUT->footer();