MDL-50874 block: basic tests for tag-related blocks
[moodle.git] / blog / external_blogs.php
blob4b0d408cbce158775cf926cce26c3830e9d0ca0f
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.
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/>.
18 /**
19 * List of external blogs for current user.
21 * @package moodlecore
22 * @subpackage blog
23 * @copyright 2009 Nicolas Connault
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once('lib.php');
30 require_login();
31 $context = context_system::instance();
32 $PAGE->set_context(context_user::instance($USER->id));
33 $PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
34 require_capability('moodle/blog:manageexternal', $context);
36 $delete = optional_param('delete', null, PARAM_INT);
38 $strexternalblogs = get_string('externalblogs', 'blog');
39 $straddnewexternalblog = get_string('addnewexternalblog', 'blog');
40 $strblogs = get_string('blogs', 'blog');
41 $message = null;
43 if ($delete && confirm_sesskey()) {
44 $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
45 if ($externalbloguserid == $USER->id) {
46 // Delete the external blog.
47 $DB->delete_records('blog_external', array('id' => $delete));
49 // Delete the external blog's posts.
50 $deletewhere = 'module = :module
51 AND userid = :userid
52 AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
53 AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
54 $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external',
55 'userid' => $USER->id,
56 'delete' => $delete));
58 $message = get_string('externalblogdeleted', 'blog');
62 $blogs = $DB->get_records('blog_external', array('userid' => $USER->id));
64 $PAGE->set_heading(fullname($USER));
65 $PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
66 $PAGE->set_pagelayout('standard');
68 echo $OUTPUT->header();
69 echo $OUTPUT->heading($strexternalblogs, 2);
71 if (!empty($message)) {
72 echo $OUTPUT->notification($message);
75 echo $OUTPUT->box_start('generalbox boxaligncenter');
77 if (!empty($blogs)) {
78 $table = new html_table();
79 $table->cellpadding = 4;
80 $table->attributes['class'] = 'generaltable boxaligncenter';
81 $table->head = array(get_string('name'),
82 get_string('url', 'blog'),
83 get_string('timefetched', 'blog'),
84 get_string('valid', 'blog'),
85 get_string('actions'));
87 foreach ($blogs as $blog) {
88 if ($blog->failedlastsync) {
89 $validicon = $OUTPUT->pix_icon('i/invalid', get_string('feedisinvalid', 'blog'));
90 } else {
91 $validicon = $OUTPUT->pix_icon('i/valid', get_string('feedisvalid', 'blog'));
94 $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
95 $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
97 $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey()));
98 $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
100 $table->data[] = new html_table_row(array($blog->name,
101 $blog->url,
102 userdate($blog->timefetched),
103 $validicon,
104 $editicon . '&nbsp'. $deleteicon));
106 echo html_writer::table($table);
109 $newexternalurl = new moodle_url('/blog/external_blog_edit.php');
110 echo html_writer::link($newexternalurl, $straddnewexternalblog);
111 echo $OUTPUT->box_end();
112 echo $OUTPUT->footer();