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
/**
18
 * Script to let a user manage their RSS feeds.
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 . '/tablelib.php');
27
 
28
require_login();
29
 
30
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
31
$courseid = optional_param('courseid', 0, PARAM_INT);
32
$deleterssid = optional_param('deleterssid', 0, 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
 
46
$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
47
if (!$managesharedfeeds) {
48
    require_capability('block/rss_client:manageownfeeds', $context);
49
}
50
 
51
$urlparams = array();
52
$extraparams = '';
53
if ($courseid) {
54
    $urlparams['courseid'] = $courseid;
55
    $extraparams = '&courseid=' . $courseid;
56
}
57
if ($returnurl) {
58
    $urlparams['returnurl'] = $returnurl;
59
    $extraparams = '&returnurl=' . $returnurl;
60
}
61
$baseurl = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
62
$PAGE->set_url($baseurl);
63
 
1441 ariadna 64
if ($managesharedfeeds) {
65
    $select = '(userid = :userid OR shared = 1)';
66
} else {
67
    $select = 'userid = :userid';
68
}
69
 
1 efrain 70
// Process any actions
71
if ($deleterssid && confirm_sesskey()) {
72
 
1441 ariadna 73
    $deleterssid = $DB->get_field_select('block_rss_client', 'id', "id = :id AND {$select}", [
74
        'id' => $deleterssid,
75
        'userid' => $USER->id
76
    ], MUST_EXIST);
77
 
78
    $DB->delete_records('block_rss_client', ['id' => $deleterssid]);
79
 
1 efrain 80
    redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
81
}
82
 
83
// Display the list of feeds.
1441 ariadna 84
$feeds = $DB->get_records_select('block_rss_client', $select, ['userid' => $USER->id], $DB->sql_order_by_text('title'));
1 efrain 85
 
86
$strmanage = get_string('managefeeds', 'block_rss_client');
87
 
88
$PAGE->set_pagelayout('standard');
89
$PAGE->set_title($strmanage);
90
$PAGE->set_heading($strmanage);
91
 
92
$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
93
$PAGE->navbar->add(get_string('blocks'));
94
$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
95
$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
96
echo $OUTPUT->header();
97
 
98
$table = new flexible_table('rss-display-feeds');
99
 
100
$table->define_columns(array('feed', 'actions'));
101
$table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
102
$table->define_baseurl($baseurl);
103
 
104
$table->set_attribute('cellspacing', '0');
105
$table->set_attribute('id', 'rssfeeds');
106
$table->set_attribute('class', 'generaltable generalbox');
107
$table->column_class('feed', 'feed');
108
$table->column_class('actions', 'actions');
109
 
110
$table->setup();
111
 
112
foreach($feeds as $feed) {
113
    if (!empty($feed->preferredtitle)) {
114
        $feedtitle = s($feed->preferredtitle);
115
    } else {
116
        $feedtitle = $feed->title;
117
    }
118
 
119
    $viewlink = html_writer::link($CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams, $feedtitle);
120
 
121
    $feedinfo = '<div class="title">' . $viewlink . '</div>' .
122
        '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
123
        '<div class="description">' . $feed->description . '</div>';
124
    if ($feed->skipuntil) {
125
        $skipuntil = userdate($feed->skipuntil, get_string('strftimedatetime', 'langconfig'));
126
        $skipmsg = get_string('failedfeed', 'block_rss_client', $skipuntil);
127
        $notification = new \core\output\notification($skipmsg, 'error');
128
        $notification->set_show_closebutton(false);
129
        $feedinfo .= $OUTPUT->render($notification);
130
    }
131
 
132
    $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
133
    $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
134
 
135
    $deleteurl = new moodle_url('/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams);
136
    $deleteicon = new pix_icon('t/delete', get_string('delete'));
137
    $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletefeedconfirm', 'block_rss_client')));
138
 
139
    $feedicons = $editaction . ' ' . $deleteaction;
140
 
141
    $table->add_data(array($feedinfo, $feedicons));
142
}
143
 
144
$table->print_html();
145
 
146
$url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
147
echo '<div class="actionbuttons">' . $OUTPUT->single_button($url, get_string('addnewfeed', 'block_rss_client'), 'get') . '</div>';
148
 
149
 
150
if ($returnurl) {
151
    echo '<div class="backlink">' . html_writer::link($returnurl, get_string('back')) . '</div>';
152
}
153
 
154
echo $OUTPUT->footer();