Files
moodle/blocks/comments/block_comments.php
T
Petr Skoda 3588897512 MDL-22054 startinging blocks to pluginname
AMOS START
 CPY [comments,core],[pluginname,block_comments]
AMOS END
2010-04-11 11:14:03 +00:00

61 lines
1.8 KiB
PHP

<?php
require_once($CFG->dirroot . '/comment/lib.php');
class block_comments extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_comments');
$this->version = 2009072000;
}
function specialization() {
// require js for commenting
comment::init();
}
function applicable_formats() {
return array('all' => true);
}
function instance_allow_multiple() {
return false;
}
function get_content() {
global $CFG;
if (!$CFG->usecomments) {
$this->content->text = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('disabledcomments');
}
return $this->content;
}
if ($this->content !== NULL) {
return $this->content;
}
if (empty($this->instance)) {
return null;
}
$this->content->footer = '';
$this->content->text = '';
//TODO: guest and not-logged-in shoudl be able to read comments, right?
if (isloggedin() && !isguestuser()) { // Show the block
list($context, $course, $cm) = get_context_info_array($this->context->id);
$cmt = new stdclass;
$cmt->context = $context;
$cmt->course = $course;
$cmt->area = 'block_comments';
$cmt->itemid = $this->instance->id;
// this is a hack to adjust commenting UI in block_comments
$cmt->env = 'block_comments';
$cmt->linktext = get_string('showcomments');
$comment = new comment($cmt);
$this->content = new stdClass;
$this->content->text = $comment->output(true);
$this->content->footer = '';
}
return $this->content;
}
}