2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
20 * @package block_comments
21 * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 require_once($CFG->dirroot
. '/comment/lib.php');
30 class block_comments
extends block_base
{
33 $this->title
= get_string('pluginname', 'block_comments');
36 function specialization() {
37 // require js for commenting
40 function applicable_formats() {
41 return array('all' => true);
44 function instance_allow_multiple() {
48 function get_content() {
50 if ($this->content
!== NULL) {
51 return $this->content
;
53 if (!$CFG->usecomments
) {
54 $this->content
= new stdClass();
55 $this->content
->text
= '';
56 if ($this->page
->user_is_editing()) {
57 $this->content
->text
= get_string('disabledcomments');
59 return $this->content
;
61 $this->content
= new stdClass();
62 $this->content
->footer
= '';
63 $this->content
->text
= '';
64 if (empty($this->instance
)) {
65 return $this->content
;
67 list($context, $course, $cm) = get_context_info_array($this->page
->context
->id
);
70 $args->context
= $this->page
->context
;
71 $args->course
= $course;
72 $args->area
= 'page_comments';
74 $args->component
= 'block_comments';
75 $args->linktext
= get_string('showcomments');
76 $args->notoggle
= true;
77 $args->autostart
= true;
78 $args->displaycancel
= false;
79 $comment = new comment($args);
80 $comment->set_view_permission(true);
81 $comment->set_fullwidth();
83 $this->content
= new stdClass();
84 $this->content
->text
= $comment->output(true);
85 $this->content
->footer
= '';
86 return $this->content
;