managefeeds.php 5.24 KB
Newer Older
1
<?php
2
3
// This file is part of Moodle - http://moodle.org/
//
4
5
6
7
8
9
10
11
12
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
13
//
14
15
16
17
18
19
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Script to let a user manage their RSS feeds.
 *
20
 * @package   block_rss_client
21
22
23
24
 * @copyright 2009 Tim Hunt
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

25
require_once(__DIR__ . '/../../config.php');
26
27
28
29
30
require_once($CFG->libdir . '/tablelib.php');

require_login();

$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
31
32
$courseid = optional_param('courseid', 0, PARAM_INT);
$deleterssid = optional_param('deleterssid', 0, PARAM_INT);
33
34
35
36
37

if ($courseid == SITEID) {
    $courseid = 0;
}
if ($courseid) {
38
    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
39
40
41
    $PAGE->set_course($course);
    $context = $PAGE->context;
} else {
42
    $context = context_system::instance();
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    $PAGE->set_context($context);
}

$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
if (!$managesharedfeeds) {
    require_capability('block/rss_client:manageownfeeds', $context);
}

$urlparams = array();
$extraparams = '';
if ($courseid) {
    $urlparams['courseid'] = $courseid;
    $extraparams = '&courseid=' . $courseid;
}
if ($returnurl) {
    $urlparams['returnurl'] = $returnurl;
    $extraparams = '&returnurl=' . $returnurl;
}
61
62
$baseurl = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
$PAGE->set_url($baseurl);
63
64
65

// Process any actions
if ($deleterssid && confirm_sesskey()) {
66
    $DB->delete_records('block_rss_client', array('id'=>$deleterssid));
67
68
69
70
71
72
73
74
75
76
77
78
79
80

    redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
}

// Display the list of feeds.
if ($managesharedfeeds) {
    $select = '(userid = ' . $USER->id . ' OR shared = 1)';
} else {
    $select = 'userid = ' . $USER->id;
}
$feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));

$strmanage = get_string('managefeeds', 'block_rss_client');

81
$PAGE->set_pagelayout('standard');
82
83
84
$PAGE->set_title($strmanage);
$PAGE->set_heading($strmanage);

85
$managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
86
$PAGE->navbar->add(get_string('blocks'));
87
$PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
88
$PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
89
echo $OUTPUT->header();
90
91
92
93
94

$table = new flexible_table('rss-display-feeds');

$table->define_columns(array('feed', 'actions'));
$table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
95
$table->define_baseurl($baseurl);
96
97
98
99
100
101
102
103
104
105
106

$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'rssfeeds');
$table->set_attribute('class', 'generaltable generalbox');
$table->column_class('feed', 'feed');
$table->column_class('actions', 'actions');

$table->setup();

foreach($feeds as $feed) {
    if (!empty($feed->preferredtitle)) {
107
        $feedtitle = s($feed->preferredtitle);
108
    } else {
109
        $feedtitle =  s($feed->title);
110
111
    }

112
    $viewlink = html_writer::link($CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams, $feedtitle);
113

114
115
    $feedinfo = '<div class="title">' . $viewlink . '</div>' .
        '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
116
        '<div class="description">' . $feed->description . '</div>';
117
118
119
120
121
122
123
    if ($feed->skipuntil) {
        $skipuntil = userdate($feed->skipuntil, get_string('strftimedatetime', 'langconfig'));
        $skipmsg = get_string('failedfeed', 'block_rss_client', $skipuntil);
        $notification = new \core\output\notification($skipmsg, 'error');
        $notification->set_show_closebutton(false);
        $feedinfo .= $OUTPUT->render($notification);
    }
124

Petr Skoda's avatar
Petr Skoda committed
125
126
    $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
    $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
127

Petr Skoda's avatar
Petr Skoda committed
128
129
130
    $deleteurl = new moodle_url('/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams);
    $deleteicon = new pix_icon('t/delete', get_string('delete'));
    $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletefeedconfirm', 'block_rss_client')));
131
132

    $feedicons = $editaction . ' ' . $deleteaction;
133
134
135
136
137
138

    $table->add_data(array($feedinfo, $feedicons));
}

$table->print_html();

139
140
$url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
echo '<div class="actionbuttons">' . $OUTPUT->single_button($url, get_string('addnewfeed', 'block_rss_client'), 'get') . '</div>';
141
142
143


if ($returnurl) {
144
    echo '<div class="backlink">' . html_writer::link($returnurl, get_string('back')) . '</div>';
145
146
147
}

echo $OUTPUT->footer();