3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
20 * List of external blogs for current user.
24 * @copyright 2009 Nicolas Connault
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once('../config.php');
29 require_once('lib.php');
32 $context = get_context_instance(CONTEXT_SYSTEM
);
33 $PAGE->set_context($context);
34 $PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
35 require_capability('moodle/blog:manageexternal', $context);
37 $delete = optional_param('delete', null, PARAM_INT
);
39 $strexternalblogs = get_string('externalblogs','blog');
40 $straddnewexternalblog = get_string('addnewexternalblog','blog');
41 $strblogs = get_string('blogs','blog');
44 if ($delete && confirm_sesskey()) {
45 $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
46 if ($externalbloguserid == $USER->id
) {
47 // Delete the external blog
48 $DB->delete_records('blog_external', array('id' => $delete));
50 // Delete the external blog's posts
51 $deletewhere = 'module = :module
53 AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
54 AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
55 $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external', 'userid' => $USER->id
, 'delete' => $delete));
57 $message = get_string('externalblogdeleted', 'blog');
61 $blogs = $DB->get_records('blog_external', array('userid' => $USER->id
));
63 $PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname
);
64 $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
65 $PAGE->set_pagelayout('standard');
67 echo $OUTPUT->header();
68 echo $OUTPUT->heading($strexternalblogs, 2);
70 if (!empty($message)) {
71 echo $OUTPUT->notification($message);
74 echo $OUTPUT->box_start('generalbox boxaligncenter');
77 $table = new html_table();
78 $table->cellpadding
= 4;
79 $table->attributes
['class'] = 'generaltable boxaligncenter';
80 $table->head
= array(get_string('name'), get_string('url'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions'));
82 foreach ($blogs as $blog) {
83 if ($blog->failedlastsync
) {
84 $validicon = $OUTPUT->pix_icon('i/cross_red_big', get_string('feedisinvalid', 'blog'));
86 $validicon = $OUTPUT->pix_icon('i/tick_green_big', get_string('feedisvalid', 'blog'));
89 $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id
));
90 $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
92 $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id
, 'sesskey'=>sesskey()));
93 $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
95 $table->data
[] = new html_table_row(array($blog->name
, $blog->url
, userdate($blog->timefetched
), $validicon, $editicon . ' '. $deleteicon));
97 echo html_writer
::table($table);
100 $newexternalurl = new moodle_url('/blog/external_blog_edit.php');
101 echo html_writer
::link($newexternalurl, $straddnewexternalblog);
102 echo $OUTPUT->box_end();
103 echo $OUTPUT->footer();