MDL-19683 MDL-20300 MDL-20219 Interface for external blogs
[moodle.git] / blog / external_blogs.php
CommitLineData
b57d3959
NC
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18
19/**
20 * List of external blogs for current user.
21 *
22 * @package moodlecore
23 * @subpackage blog
24 * @copyright 2009 Nicolas Connault
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28require_once('../config.php');
29require_once('lib.php');
30
31require_login();
32
33$PAGE->set_url('/blog/external_blogs.php');
34require_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM));
35
36$delete = optional_param('delete', null, PARAM_INT);
37
38$strexternalblogs = get_string('externalblogs','blog');
39$straddnewexternalblog = get_string('addnewexternalblog','blog');
40$strblogs = get_string('blogs','blog');
41$message = null;
42
43if ($delete && confirm_sesskey()) {
44 $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
45 if ($externalbloguserid == $USER->id) {
46 $DB->delete_records('blog_external', array('id' => $delete));
47 $message = get_string('externalblogdeleted', 'blog');
48 }
49}
50
51$blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
52
53$PAGE->navbar->add(fullname($USER), new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$USER->id)));
54$PAGE->navbar->add($strblogs, new moodle_url($CFG->wwwroot.'/blog/index.php', array('userid'=>$USER->id)));
55$PAGE->navbar->add($strexternalblogs);
56$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
57$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
58
59echo $OUTPUT->header();
60echo $OUTPUT->heading($strexternalblogs, 2);
61
62if (!empty($message)) {
63 echo $OUTPUT->notification($message);
64}
65
66echo $OUTPUT->box_start('generalbox boxaligncenter');
67
68if (!empty($blogs)) {
69 $table = new html_table();
70 $table->cellpadding = 4;
71 $table->add_class('generaltable boxaligncenter');
72 $table->head = array(get_string('name'), get_string('url'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions'));
73
74 foreach ($blogs as $blog) {
75 $validicon = html_image::make($OUTPUT->old_icon_url('i/tick_green_big'));
76 $validicon->alt = get_string('feedisvalid', 'blog');
77 $validicon->title = get_string('feedisvalid', 'blog');
78
79 if ($blog->failedlastsync) {
80 $validicon->src = $OUTPUT->old_icon_url('i/cross_red_big');
81 $validicon->alt = get_string('feedisinvalid', 'blog');
82 $validicon->title = get_string('feedisinvalid', 'blog');
83 }
84
85 $editicon = new moodle_action_icon;
86 $editicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php', array('id' => $blog->id));
87 $editicon->link->title = get_string('editexternalblog', 'blog');
88 $editicon->image->src = $OUTPUT->old_icon_url('t/edit');
89 $editicon->image->alt = get_string('editexternalblog', 'blog');
90
91 $deleteicon = new moodle_action_icon;
92 $deleteicon->link->url = new moodle_url($CFG->wwwroot.'/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey()));
93 $deleteicon->link->title = get_string('deleteexternalblog', 'blog');
94 $deleteicon->image->src = $OUTPUT->old_icon_url('t/delete');
95 $deleteicon->image->alt = get_string('deleteexternalblog', 'blog');
96 $deleteicon->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
97 $icons = $OUTPUT->action_icon($editicon) . $OUTPUT->action_icon($deleteicon);
98 $table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $OUTPUT->image($validicon), $icons));
99 }
100 echo $OUTPUT->table($table);
101}
102
103$newexternalurl = new moodle_url($CFG->wwwroot.'/blog/external_blog_edit.php');
104echo $OUTPUT->link(html_link::make($newexternalurl, $straddnewexternalblog));
105echo $OUTPUT->box_end();
106echo $OUTPUT->footer();