2009-07-24 02:52:09 +00:00
|
|
|
<?php
|
2011-05-04 17:23:46 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-24 02:52:09 +00:00
|
|
|
|
2011-05-04 17:23:46 +08:00
|
|
|
/**
|
|
|
|
* The comments block
|
|
|
|
*
|
2014-02-13 10:55:46 +13:00
|
|
|
* @package block_comments
|
2011-05-04 17:23:46 +08:00
|
|
|
* @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
|
|
// Obviously required
|
2010-03-15 07:59:28 +00:00
|
|
|
require_once($CFG->dirroot . '/comment/lib.php');
|
2009-07-24 02:52:09 +00:00
|
|
|
|
|
|
|
class block_comments extends block_base {
|
|
|
|
|
|
|
|
function init() {
|
2010-04-11 11:14:03 +00:00
|
|
|
$this->title = get_string('pluginname', 'block_comments');
|
2009-07-24 02:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function specialization() {
|
|
|
|
// require js for commenting
|
2010-03-15 07:59:28 +00:00
|
|
|
comment::init();
|
2009-07-24 02:52:09 +00:00
|
|
|
}
|
|
|
|
function applicable_formats() {
|
|
|
|
return array('all' => true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function instance_allow_multiple() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_content() {
|
2010-04-13 05:39:34 +00:00
|
|
|
global $CFG, $PAGE;
|
2012-01-15 13:37:53 +01:00
|
|
|
if ($this->content !== NULL) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
2009-10-15 01:36:50 +00:00
|
|
|
if (!$CFG->usecomments) {
|
2012-01-15 13:37:53 +01:00
|
|
|
$this->content = new stdClass();
|
2009-10-15 01:36:50 +00:00
|
|
|
$this->content->text = '';
|
|
|
|
if ($this->page->user_is_editing()) {
|
|
|
|
$this->content->text = get_string('disabledcomments');
|
|
|
|
}
|
|
|
|
return $this->content;
|
|
|
|
}
|
2012-01-15 13:37:53 +01:00
|
|
|
$this->content = new stdClass();
|
2009-07-24 02:52:09 +00:00
|
|
|
$this->content->footer = '';
|
|
|
|
$this->content->text = '';
|
2012-01-15 13:37:53 +01:00
|
|
|
if (empty($this->instance)) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
2010-08-25 03:50:19 +00:00
|
|
|
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
|
2011-05-04 17:23:46 +08:00
|
|
|
|
|
|
|
$args = new stdClass;
|
2010-08-25 03:50:19 +00:00
|
|
|
$args->context = $PAGE->context;
|
|
|
|
$args->course = $course;
|
|
|
|
$args->area = 'page_comments';
|
|
|
|
$args->itemid = 0;
|
|
|
|
$args->component = 'block_comments';
|
|
|
|
$args->linktext = get_string('showcomments');
|
2011-03-30 14:51:07 +08:00
|
|
|
$args->notoggle = true;
|
|
|
|
$args->autostart = true;
|
2011-11-22 15:25:09 +08:00
|
|
|
$args->displaycancel = false;
|
2010-08-25 03:50:19 +00:00
|
|
|
$comment = new comment($args);
|
|
|
|
$comment->set_view_permission(true);
|
2014-11-13 11:53:43 +13:00
|
|
|
$comment->set_fullwidth();
|
2010-04-09 09:03:51 +00:00
|
|
|
|
2010-09-21 08:54:01 +00:00
|
|
|
$this->content = new stdClass();
|
2010-08-25 03:50:19 +00:00
|
|
|
$this->content->text = $comment->output(true);
|
|
|
|
$this->content->footer = '';
|
2009-07-24 02:52:09 +00:00
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
}
|