3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Chat module rendering methods
22 * @copyright 2012 Andrew Davis
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
29 * Chat module renderer class
31 * @copyright 2012 Andrew Davis
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class mod_chat_renderer
extends plugin_renderer_base
{
37 * Render and event_message instance
39 * @param event_message $eventmessage The event_message instance to render
40 * @return string HTML representing the event_message instance
42 protected function render_event_message(event_message
$eventmessage) {
45 if (file_exists($CFG->dirroot
. '/mod/chat/gui_ajax/theme/'.$eventmessage->theme
.'/config.php')) {
46 include($CFG->dirroot
. '/mod/chat/gui_ajax/theme/'.$eventmessage->theme
.'/config.php');
50 $patterns[] = '___senderprofile___';
51 $patterns[] = '___sender___';
52 $patterns[] = '___time___';
53 $patterns[] = '___event___';
55 $replacements = array();
56 $replacements[] = $eventmessage->senderprofile
;
57 $replacements[] = $eventmessage->sendername
;
58 $replacements[] = $eventmessage->time
;
59 $replacements[] = $eventmessage->event
;
61 return str_replace($patterns, $replacements, $chattheme_cfg->event_message
);
65 * Render a user message
67 * @param user_message $usermessage the user message to display
68 * @return string html representation of a user_message instance
70 protected function render_user_message(user_message
$usermessage) {
73 if (file_exists($CFG->dirroot
. '/mod/chat/gui_ajax/theme/'.$usermessage->theme
.'/config.php')) {
74 include($CFG->dirroot
. '/mod/chat/gui_ajax/theme/'.$usermessage->theme
.'/config.php');
78 $patterns[] = '___avatar___';
79 $patterns[] = '___sender___';
80 $patterns[] = '___senderprofile___';
81 $patterns[] = '___time___';
82 $patterns[] = '___message___';
83 $patterns[] = '___mymessageclass___';
85 $replacements = array();
86 $replacements[] = $usermessage->avatar
;
87 $replacements[] = $usermessage->sendername
;
88 $replacements[] = $usermessage->senderprofile
;
89 $replacements[] = $usermessage->time
;
90 $replacements[] = $usermessage->message
;
91 $replacements[] = $usermessage->mymessageclass
;
95 if (!empty($chattheme_cfg->avatar
) and !empty($chattheme_cfg->align
)) {
96 if (!empty($usermessage->mymessageclass
)) {
97 $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_right
);
99 $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_left
);
102 $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message
);