weekly release 3.7.1+
[moodle.git] / mod / chat / renderer.php
blob4469fc12d6b8d87f6b88cbaf645bb229a9ab61fc
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.
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/>.
17 /**
18 * Chat module rendering methods
20 * @package mod_chat
21 * @copyright 2012 Andrew Davis
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * Chat module renderer class
30 * @copyright 2012 Andrew Davis
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class mod_chat_renderer extends plugin_renderer_base {
35 /**
36 * Render and event_message instance
38 * @param event_message $eventmessage The event_message instance to render
39 * @return string HTML representing the event_message instance
41 protected function render_event_message(event_message $eventmessage) {
42 global $CFG;
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');
48 $patterns = array();
49 $patterns[] = '___senderprofile___';
50 $patterns[] = '___sender___';
51 $patterns[] = '___time___';
52 $patterns[] = '___event___';
54 $replacements = array();
55 $replacements[] = $eventmessage->senderprofile;
56 $replacements[] = $eventmessage->sendername;
57 $replacements[] = $eventmessage->time;
58 $replacements[] = $eventmessage->event;
60 return str_replace($patterns, $replacements, $chattheme_cfg->event_message);
63 /**
64 * Render a user message
66 * @param user_message $usermessage the user message to display
67 * @return string html representation of a user_message instance
69 protected function render_user_message(user_message $usermessage) {
70 global $CFG;
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');
76 $patterns = array();
77 $patterns[] = '___avatar___';
78 $patterns[] = '___sender___';
79 $patterns[] = '___senderprofile___';
80 $patterns[] = '___time___';
81 $patterns[] = '___message___';
82 $patterns[] = '___mymessageclass___';
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;
92 $output = null;
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);
100 } else {
101 $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message);
104 return $output;