Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is 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   * Chat module rendering methods
  19   *
  20   * @package    mod_chat
  21   * @copyright  2012 Andrew Davis
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Chat module renderer class
  29   *
  30   * @copyright 2012 Andrew Davis
  31   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class mod_chat_renderer extends plugin_renderer_base {
  34  
  35      /**
  36       * Render and event_message instance
  37       *
  38       * @param event_message $eventmessage The event_message instance to render
  39       * @return string HTML representing the event_message instance
  40       */
  41      protected function render_event_message(event_message $eventmessage) {
  42          global $CFG;
  43  
  44          if (file_exists($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$eventmessage->theme.'/config.php')) {
  45              include($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$eventmessage->theme.'/config.php');
  46          }
  47  
  48          $patterns = array();
  49          $patterns[] = '___senderprofile___';
  50          $patterns[] = '___sender___';
  51          $patterns[] = '___time___';
  52          $patterns[] = '___event___';
  53  
  54          $replacements = array();
  55          $replacements[] = $eventmessage->senderprofile;
  56          $replacements[] = $eventmessage->sendername;
  57          $replacements[] = $eventmessage->time;
  58          $replacements[] = $eventmessage->event;
  59  
  60          return str_replace($patterns, $replacements, $chattheme_cfg->event_message);
  61      }
  62  
  63      /**
  64       * Render a user message
  65       *
  66       * @param user_message $usermessage the user message to display
  67       * @return string html representation of a user_message instance
  68       */
  69      protected function render_user_message(user_message $usermessage) {
  70          global $CFG;
  71  
  72          if (file_exists($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$usermessage->theme.'/config.php')) {
  73              include($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$usermessage->theme.'/config.php');
  74          }
  75  
  76          $patterns = array();
  77          $patterns[] = '___avatar___';
  78          $patterns[] = '___sender___';
  79          $patterns[] = '___senderprofile___';
  80          $patterns[] = '___time___';
  81          $patterns[] = '___message___';
  82          $patterns[] = '___mymessageclass___';
  83  
  84          $replacements = array();
  85          $replacements[] = $usermessage->avatar;
  86          $replacements[] = $usermessage->sendername;
  87          $replacements[] = $usermessage->senderprofile;
  88          $replacements[] = $usermessage->time;
  89          $replacements[] = $usermessage->message;
  90          $replacements[] = $usermessage->mymessageclass;
  91  
  92          $output = null;
  93  
  94          if (!empty($chattheme_cfg->avatar) and !empty($chattheme_cfg->align)) {
  95              if (!empty($usermessage->mymessageclass)) {
  96                  $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_right);
  97              } else {
  98                  $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_left);
  99              }
 100          } else {
 101              $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message);
 102          }
 103  
 104          return $output;
 105      }
 106  }