protected function render_user_message(user_message $usermessage) {
        global $CFG;

        if (file_exists($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$usermessage->theme.'/config.php')) {
            include($CFG->dirroot . '/mod/chat/gui_ajax/theme/'.$usermessage->theme.'/config.php');
        }

        $patterns = array();
        $patterns[] = '___avatar___';
        $patterns[] = '___sender___';
        $patterns[] = '___senderprofile___';
        $patterns[] = '___time___';
        $patterns[] = '___message___';
        $patterns[] = '___mymessageclass___';

        $replacements = array();
        $replacements[] = $usermessage->avatar;
        $replacements[] = $usermessage->sendername;
        $replacements[] = $usermessage->senderprofile;
        $replacements[] = $usermessage->time;
        $replacements[] = $usermessage->message;
        $replacements[] = $usermessage->mymessageclass;

        $output = null;

        if (!empty($chattheme_cfg->avatar) and !empty($chattheme_cfg->align)) {
            if (!empty($usermessage->mymessageclass)) {
                $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_right);
            } else {
                $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message_left);
            }
        } else {
            $output = str_replace($patterns, $replacements, $chattheme_cfg->user_message);
        }

        return $output;
    }