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.
   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 helper functions and callbacks
  19   *
  20   * @package   block_comments
  21   * @copyright 2011 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  /**
  28   * Validate comment parameter before perform other comments actions
  29   *
  30   * @package  block_comments
  31   * @category comment
  32   *
  33   * @param stdClass $comment_param {
  34   *              context  => context the context object
  35   *              courseid => int course id
  36   *              cm       => stdClass course module object
  37   *              commentarea => string comment area
  38   *              itemid      => int itemid
  39   * }
  40   * @return boolean
  41   */
  42  function block_comments_comment_validate($comment_param) {
  43      if ($comment_param->commentarea != 'page_comments') {
  44          throw new comment_exception('invalidcommentarea');
  45      }
  46      if ($comment_param->itemid != 0) {
  47          throw new comment_exception('invalidcommentitemid');
  48      }
  49      return true;
  50  }
  51  
  52  /**
  53   * Running addtional permission check on plugins
  54   *
  55   * @package  block_comments
  56   * @category comment
  57   *
  58   * @param stdClass $args
  59   * @return array
  60   */
  61  function block_comments_comment_permissions($args) {
  62      return array('post'=>true, 'view'=>true);
  63  }
  64  
  65  /**
  66   * Validate comment data before displaying comments
  67   *
  68   * @package  block_comments
  69   * @category comment
  70   *
  71   * @param stdClass $comment
  72   * @param stdClass $args
  73   * @return boolean
  74   */
  75  function block_comments_comment_display($comments, $args) {
  76      if ($args->commentarea != 'page_comments') {
  77          throw new comment_exception('invalidcommentarea');
  78      }
  79      if ($args->itemid != 0) {
  80          throw new comment_exception('invalidcommentitemid');
  81      }
  82      return $comments;
  83  }