| 1 | 
           efrain | 
           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 | 
            */
  | 
        
        
           | 1441 | 
           ariadna | 
           24 | 
           class block_comments extends block_base {
  | 
        
        
           | 1 | 
           efrain | 
           25 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           26 | 
               function init() {
  | 
        
        
           | 1 | 
           efrain | 
           27 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
                   require_once($CFG->dirroot . '/comment/lib.php');
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
                   $this->title = get_string('pluginname', 'block_comments');
  | 
        
        
            | 
            | 
           32 | 
               }
  | 
        
        
            | 
            | 
           33 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           34 | 
               function specialization() {
  | 
        
        
            | 
            | 
           35 | 
                   // require js for commenting
  | 
        
        
           | 122 | 
           ariadna | 
           36 | 
                   comment::init();
  | 
        
        
           | 1 | 
           efrain | 
           37 | 
               }
  | 
        
        
           | 1441 | 
           ariadna | 
           38 | 
               function applicable_formats() {
  | 
        
        
           | 127 | 
           ariadna | 
           39 | 
                   return array('all' => true);
  | 
        
        
           | 115 | 
           ariadna | 
           40 | 
               }
  | 
        
        
           | 1 | 
           efrain | 
           41 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           42 | 
               function instance_allow_multiple() {
  | 
        
        
           | 1 | 
           efrain | 
           43 | 
                   return false;
  | 
        
        
            | 
            | 
           44 | 
               }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           46 | 
               function get_content() {
  | 
        
        
           | 1 | 
           efrain | 
           47 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           48 | 
              | 
        
        
            | 
            | 
           49 | 
                   if ($this->content !== NULL) {
  | 
        
        
            | 
            | 
           50 | 
                       return $this->content;
  | 
        
        
            | 
            | 
           51 | 
                   }
  | 
        
        
            | 
            | 
           52 | 
                   if (!$CFG->usecomments) {
  | 
        
        
            | 
            | 
           53 | 
                       $this->content = new stdClass();
  | 
        
        
            | 
            | 
           54 | 
                       $this->content->text = '';
  | 
        
        
            | 
            | 
           55 | 
                       if ($this->page->user_is_editing()) {
  | 
        
        
            | 
            | 
           56 | 
                           $this->content->text = get_string('disabledcomments');
  | 
        
        
            | 
            | 
           57 | 
                       }
  | 
        
        
            | 
            | 
           58 | 
                       return $this->content;
  | 
        
        
            | 
            | 
           59 | 
                   }
  | 
        
        
            | 
            | 
           60 | 
                   $this->content = new stdClass();
  | 
        
        
            | 
            | 
           61 | 
                   $this->content->footer = '';
  | 
        
        
            | 
            | 
           62 | 
                   $this->content->text = '';
  | 
        
        
            | 
            | 
           63 | 
                   if (empty($this->instance)) {
  | 
        
        
            | 
            | 
           64 | 
                       return $this->content;
  | 
        
        
            | 
            | 
           65 | 
                   }
  | 
        
        
            | 
            | 
           66 | 
                   list($context, $course, $cm) = get_context_info_array($this->page->context->id);
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
                   $args = new stdClass;
  | 
        
        
            | 
            | 
           69 | 
                   $args->context   = $this->page->context;
  | 
        
        
            | 
            | 
           70 | 
                   $args->course    = $course;
  | 
        
        
            | 
            | 
           71 | 
                   $args->area      = 'page_comments';
  | 
        
        
            | 
            | 
           72 | 
                   $args->itemid    = 0;
  | 
        
        
            | 
            | 
           73 | 
                   $args->component = 'block_comments';
  | 
        
        
            | 
            | 
           74 | 
                   $args->linktext  = get_string('showcomments');
  | 
        
        
            | 
            | 
           75 | 
                   $args->notoggle  = true;
  | 
        
        
            | 
            | 
           76 | 
                   $args->autostart = true;
  | 
        
        
            | 
            | 
           77 | 
                   $args->displaycancel = false;
  | 
        
        
            | 
            | 
           78 | 
                   $comment = new comment($args);
  | 
        
        
            | 
            | 
           79 | 
                   $comment->set_view_permission(true);
  | 
        
        
            | 
            | 
           80 | 
                   $comment->set_fullwidth();
  | 
        
        
            | 
            | 
           81 | 
              | 
        
        
            | 
            | 
           82 | 
                   $this->content = new stdClass();
  | 
        
        
            | 
            | 
           83 | 
                   $this->content->text = $comment->output(true);
  | 
        
        
            | 
            | 
           84 | 
                   $this->content->footer = '';
  | 
        
        
            | 
            | 
           85 | 
                   return $this->content;
  | 
        
        
            | 
            | 
           86 | 
               }
  | 
        
        
            | 
            | 
           87 | 
              | 
        
        
            | 
            | 
           88 | 
               /**
  | 
        
        
            | 
            | 
           89 | 
                * This block shouldn't be added to a page if the comments advanced feature is disabled.
  | 
        
        
            | 
            | 
           90 | 
                *
  | 
        
        
            | 
            | 
           91 | 
                * @param moodle_page $page
  | 
        
        
            | 
            | 
           92 | 
                * @return bool
  | 
        
        
            | 
            | 
           93 | 
                */
  | 
        
        
           | 1441 | 
           ariadna | 
           94 | 
               public function can_block_be_added(moodle_page $page): bool {
  | 
        
        
           | 1 | 
           efrain | 
           95 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           96 | 
              | 
        
        
            | 
            | 
           97 | 
                   return $CFG->usecomments;
  | 
        
        
            | 
            | 
           98 | 
               }
  | 
        
        
            | 
            | 
           99 | 
           }
  |