Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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.
  13  //
  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/>.
  16  
  17  /**
  18   * The comments block
  19   *
  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
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  // Obviously required
  28  require_once($CFG->dirroot . '/comment/lib.php');
  29  
  30  class block_comments extends block_base {
  31  
  32      function init() {
  33          $this->title = get_string('pluginname', 'block_comments');
  34      }
  35  
  36      function specialization() {
  37          // require js for commenting
  38          comment::init();
  39      }
  40      function applicable_formats() {
  41          return array('all' => true);
  42      }
  43  
  44      function instance_allow_multiple() {
  45          return false;
  46      }
  47  
  48      function get_content() {
  49          global $CFG;
  50          if ($this->content !== NULL) {
  51              return $this->content;
  52          }
  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');
  58              }
  59              return $this->content;
  60          }
  61          $this->content = new stdClass();
  62          $this->content->footer = '';
  63          $this->content->text = '';
  64          if (empty($this->instance)) {
  65              return $this->content;
  66          }
  67          list($context, $course, $cm) = get_context_info_array($this->page->context->id);
  68  
  69          $args = new stdClass;
  70          $args->context   = $this->page->context;
  71          $args->course    = $course;
  72          $args->area      = 'page_comments';
  73          $args->itemid    = 0;
  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();
  82  
  83          $this->content = new stdClass();
  84          $this->content->text = $comment->output(true);
  85          $this->content->footer = '';
  86          return $this->content;
  87      }
  88  }