public function activate()
    {
        global $db, $cache;
        require_once MYBB_ROOT . "inc/adminfunctions_templates.php";
        $templates = array();
        $templates["myprofile_comments_content"] = '{$comments_form}
{$comment_form_script}
{$comments_table}';
        $templates["myprofile_comments_form"] = '<form action="misc.php" method="post" name="comments-form" id="comments-form">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="action" value="comments-add" />
<input type="hidden" name="memberuid" value="{$memprofile[\'uid\']}" />
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_add_comment}</strong></td>
</tr>
{$status}
<tr>
<td class="trow2">
<textarea id="message" name="message" rows="10" cols="70" tabindex="2"></textarea>
{$codebuttons}
</td>
</tr>
<tr>
<td class="trow2">
<input id="submit_comment" type="submit" class="button" name="submit" value="{$lang->mp_profile_comments_add_comment}" tabindex="3" />
<span id="spinner_span"></span>
</td>
</tr>
{$modoptions}
</table>
</form>';
        $templates["myprofile_comments_form_modoptions"] = '<tr>
<td class="trow2">
<span><strong>{$lang->mp_comments_moderation} : </strong></span>
<button type="button" class="button comment-action comments-delete-all">{$lang->mp_comments_action_delete_all_comments}</button>
<span class="spinner_delete_all_span"></span>
</td>
</tr>';
        $templates["myprofile_comments_stats"] = '<tr>
<td class="trow2"><strong>{$lang->mp_profile_comments_comments}</strong></td>
<td class="trow2">{$stats_total} ({$stats_sent} {$lang->mp_comments_stats_sent} | {$stats_received} {$lang->mp_comments_stats_received})</td>
</tr>';
        $templates["myprofile_comments_form_script"] = '<script>
lang.mp_comments_comment_wrong_length = "{$lang->mp_comments_comment_wrong_length}";
lang.mp_comments_confirm_delete = "{$lang->mp_comments_confirm_delete}";
lang.mp_comments_confirm_delete_all = "{$lang->mp_comments_confirm_delete_all}";
lang.mp_comments_comment_approved_successfully = "{$lang->mp_comments_comment_approved_successfully}";
lang.mp_comments_comment_added_successfully = "{$lang->mp_comments_comment_added_successfully}";
lang.mp_comments_comment_deleted_successfully = "{$lang->mp_comments_comment_deleted_successfully}";
lang.mp_comments_comments_deleted_successfully = "{$lang->mp_comments_comments_deleted_successfully}";
lang.mp_comments_comment_edited_successfully = "{$lang->mp_comments_comment_edited_successfully}";

MyProfile.memberUid = {$comments_memberuid};
MyProfile.ajax = {$comments_ajax};
MyProfile.commentsMinLength = {$comments_minlength};
MyProfile.commentsMaxLength = {$comments_maxlength};
MyProfile.commentsSCEditor = {$comments_sceditor};
MyProfile.commentsPage = {$comments_page};
</script>';
        $templates["myprofile_comments_form_status"] = '<tr>
<td class="trow1">
<span>{$lang->mp_comments_comment_status} : </span>
<select class="{$status_select_class}" name="isprivate">
<option value="0" {$comment_public_selected}>{$lang->mp_comments_comment_public}</option>
<option value="1" {$comment_private_selected}>{$lang->mp_comments_comment_private}</option>
</select>
</td>
</tr>';
        $templates["myprofile_comments_table"] = '{$comments_separator}
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_comments} ({$lang->mp_profile_comments_total} <span id="comments-total">{$comments_total}</span>{$useroptions})</strong></td>
</tr>
<tr class="comments-pagination">
<td colspan="2" {$comments_pagination_style}>{$comments_pagination}</td>
</tr>
<tbody class="comments-content">
{$comments_content}
</tbody>
<tr class="comments-pagination">
<td colspan="2" {$comments_pagination_style}>{$comments_pagination}</td>
</tr>
</table>
<br />';
        $templates["myprofile_comments_comment"] = '<tr width="100%" data-cid="{$comment[\'cid\']}">
<td class="trow2 {$trow_class}" rowspan="2" style="text-align: center; vertical-align: top;" data-cid="{$comment[\'cid\']}">
<img src="{$avatar_src}" {$avatar_width_height} alt />
</td>
<td style="height: 20px;" class="trow1 {$trow_class}" width="100%" data-cid="{$comment[\'cid\']}">
{$profile_link} <small style="font-size: 10px;">({$date} - {$time}) <em>{$comment_private}</em></small><br />
<span style="font-size: 10px;" data-cid="{$comment[\'cid\']}">
{$comments_approve}
{$comments_reply}
{$comments_edit}
{$comments_delete}
{$comments_report}
</span>
</td>
</tr>
<tr>
<td class="trow2 comment_message scaleimages {$trow_class}" style="max-width: 400px; overflow: hidden;" data-cid="{$comment[\'cid\']}">
{$message}
</td>
</tr>';
        $templates["myprofile_comments_no_comment"] = '<tr width="100%">
<td class="trow2">{$lang->mp_comments_no_comment_to_display}</td>
</tr>';
        $templates["myprofile_comments_comment_approve"] = '<form action="misc.php" method="post" style="display: inline;">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="action" value="comments-approve" />
<input type="hidden" name="cid" value="{$comment[\'cid\']}" />
<input type="hidden" name="memberuid" value="{$comment[\'userid\']}" />
<button class="comments-approve comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_approve}</button>
</form>';
        $templates["myprofile_comments_comment_reply"] = '<form action="{$mybb->settings[\'bburl\']}/member.php" method="get" style="display: inline;">
<input type="hidden" name="action" value="profile" />
<input type="hidden" name="uid" value="{$commentor_uid}" />
<button style="font-size: 11px;">{$lang->mp_comments_action_reply}</button>
</form>';
        $templates["myprofile_comments_comment_edit"] = '<button class="comments-edit comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_edit}</button>';
        $templates["myprofile_comments_comment_delete"] = '<form action="misc.php" method="post" style="display: inline;">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="action" value="comments-delete" />
<input type="hidden" name="cid" value="{$comment[\'cid\']}" />
<input type="hidden" name="memberuid" value="{$comment[\'userid\']}" />
<button class="comments-delete comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_delete}</button>
</form>';
        $templates["myprofile_comments_comment_report"] = '<button class="comments-report comments-action button" style="font-size: 11px;">{$lang->mp_comments_action_report}</button>';
        $templates["myprofile_comments_report_reasons"] = '<tr>
<td class="trow1" align="left" style="width: 25%"><span class="smalltext"><strong>{$lang->report_reason}</strong></span></td>
<td class="trow1" align="left">
<select name="reason" id="report_reason">
<option value="rules">{$lang->report_reason_rules}</option>
<option value="bad">{$lang->report_reason_bad}</option>
<option value="spam">{$lang->report_reason_spam}</option>
<option value="other">{$lang->report_reason_other}</option>
</select>
</td>
</tr>
<tr id="reason">
<td class="trow2">&nbsp;</td>
<td class="trow2" align="left">
<div>{$lang->report_reason_other_description}</div>
<input type="text" class="textbox" name="comment" size="40" maxlength="250" />
</td>
</tr>
<tr>
	<td colspan="2" class="tfoot"><input type="submit" class="button" value="{$report_title}" /></td>
</tr>';
        $templates["myprofile_comments_usercp"] = '<legend><strong>{$lang->mp_my_profile}</strong></legend>
<table cellspacing="0" cellpadding="2">
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentsopen" id="mpcommentsopen" value="1" {$mpcommentsopen} /></td>
<td><span class="smalltext"><label for="mpcommentsopen">{$lang->mp_comments_open}</label></span></td>
</tr>
<tr>
<td colspan="2"><span class="smalltext">{$lang->mp_who_can_leave_comments}</span></td>
</tr>
<tr>
<td colspan="2">
<select name="mpwhocancomment" id="mpwhocancomment">
<option value="0" {$nobodycanleavecomments}>{$lang->mp_nobody_can_leave_comments}</option>
<option value="1" {$friendlistcanleavecomment}>{$lang->mp_friendlist_can_leave_comments}</option>
<option value="2" {$anyonecanleavecomments}>{$lang->mp_anyone_can_leave_comments}</option>
</td>
</tr>
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentsapprove" id="mpcommentsapprove" value="1" {$mpcommentsapprove} /></td>
<td><span class="smalltext"><label for="mpcommentsapprove">{$lang->mp_comments_approve}</label></span></td>
</tr>
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="mpcommentnotification" id="mpcommentnotification" value="1" {$mpcommentnotification} /></td>
<td><span class="smalltext"><label for="mpcommentnotification">{$lang->mp_comments_notification}</label></span></td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="trow2">';
        $templates["myprofile_modcp_nav_comments"] = '<tr><td class="trow1 smalltext"><a href="modcp.php?action=myprofilecomments" class="modcp_nav_item modcp_nav_ipsearch">{$lang->mp_myprofile_comments}</a></td></tr>';
        $templates["myprofile_comments_edit"] = '
<div class="modal" id="modal-edit-comments">
<div style="overflow-y: auto; max-height: 400px;" class="modal_2">
<form action="misc.php" method="post" id="comments-edit-form" name="comments-edit-form">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="action" value="comments-do-edit" />
<input type="hidden" name="memberuid" value="{$memprofile[\'uid\']}" />
<input type="hidden" name="no_modal" value="1" />
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
	<td class="thead" colspan="2"><strong>{$lang->mp_profile_comments_edit_comment}</strong></td>
</tr>
{$status}
<tr>
<td class="trow2">
<textarea id="message_edit" name="message_edit" rows="10" cols="70" tabindex="2"></textarea>
</td>
</tr>
<tr>
<td class="trow2">
<input type="submit" class="comments-edit-submit button" name="submit" value="{$lang->mp_profile_comments_edit_comment}" tabindex="3" data-cid="{$cid}" />
</td>
</tr>
</table>
</form>
<script>
$(function() {
var original_text = {$original_text};
var instance = {};
//Problem with SCEditor in new object
//if(MyProfile.commentsSCEditor) {
//$("#message_edit").sceditor(opt_editor);
//instance = $("#message_edit").sceditor(\'instance\');
//}
//else {
instance = $("#message_edit");
//}
instance.val(original_text.message);
});
</script>
</div>
</div>';
        $templates["myprofile_comments_alertbar"] = '<div class="pm_alert" id="mp_comments_notice">
<div class="float_right"><a href="#" id="mp_comments_notice_url" title="{$lang->mp_comments_dismiss_notice}"><img src="{$theme[\'imgdir\']}/dismiss_notice.png" alt="{$lang->mp_comments_dismiss_notice}" title="{$lang->mp_comments_dismiss_notice}"></a></div>
<div>{$comments_text}</div>
</div>
<script>
$(document).ready(function() {
	$(document).on("click", "a#mp_comments_notice_url", myprofile_dismiss_alertbar);
	
	function myprofile_dismiss_alertbar() {
		$.ajax({
			"url": rootpath + "/xmlhttp.php",
			"data": {
				"action" : "comments-dismiss",
				"my_post_key" : my_post_key
			},
			"type": "POST"
		});
		$("#mp_comments_notice").remove();
	}
});
</script>';
        /* - next version
            $templates["myprofile_comments_modcp_start"] = '<html>
            <head>
            <title>{$mybb->settings[\'bbname\']} - {$lang->warning_logs}</title>
            {$headerinclude}
            </head>
            <body>
            {$header}
            <table width="100%" border="0" align="center">
            <tr>
            {$modcp_nav}
            <td valign="top">
            <form action="modcp.php" method="get">
            <input type="hidden" name="action" value="warninglogs" />
            <table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
            <tr>
            <td class="thead" colspan="2"><strong>{$lang->filter_warning_logs}</strong></td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->filter_warned_user}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[username]" id="username" value="{$mybb->input[\'filter\'][\'username\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow2" width="25%"><strong>{$lang->filter_issued_by}</strong></td>
            <td class="trow2" width="75%"><input type="text" name="filter[mod_username]" value="{$mybb->input[\'filter\'][\'mod_username\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->filter_reason}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[reason]" value="{$mybb->input[\'filter\'][\'reason\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow2" width="25%"><strong>{$lang->sort_by}</strong></td>
            <td class="trow2" width="75%">
            <select name="filter[sortby]">
            <option value="username"{$sortbysel[\'username\']}>{$lang->username}</option>
            <option value="issuedby"{$sortbysel[\'issuedby\']}>{$lang->issued_by}</option>
            <option value="dateline"{$sortbysel[\'dateline\']}>{$lang->issued_date}</option>
            <option value="expires"{$sortbysel[\'expires\']}>{$lang->expiry_date}</option>
            </select>
            {$lang->in}
            <select name="filter[order]">
            <option value="asc"{$ordersel[\'asc\']}>{$lang->asc}</option>
            <option value="desc"{$ordersel[\'desc\']}>{$lang->desc}</option>
            </select>
            {$lang->order}
            </td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->per_page}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[per_page]" value="{$per_page}" class="textbox" /></td>
            </tr>
            </table>
            <br />
            <div align="center">
            <input type="submit" class="button" value="{$lang->filter_warning_logs}" />
            </div>
            </form>
            {$multipage}
            <br />
            <form action="modcp.php" method="get">
            <input type="hidden" name="action" value="warninglogs" />
            <table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
            <tr>
            <td class="thead" colspan="2"><strong>{$lang->filter_warning_logs}</strong></td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->filter_warned_user}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[username]" id="username" value="{$mybb->input[\'filter\'][\'username\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow2" width="25%"><strong>{$lang->filter_issued_by}</strong></td>
            <td class="trow2" width="75%"><input type="text" name="filter[mod_username]" value="{$mybb->input[\'filter\'][\'mod_username\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->filter_reason}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[reason]" value="{$mybb->input[\'filter\'][\'reason\']}" class="textbox" /></td>
            </tr>
            <tr>
            <td class="trow2" width="25%"><strong>{$lang->sort_by}</strong></td>
            <td class="trow2" width="75%">
            <select name="filter[sortby]">
            <option value="username"{$sortbysel[\'username\']}>{$lang->username}</option>
            <option value="issuedby"{$sortbysel[\'issuedby\']}>{$lang->issued_by}</option>
            <option value="dateline"{$sortbysel[\'dateline\']}>{$lang->issued_date}</option>
            <option value="expires"{$sortbysel[\'expires\']}>{$lang->expiry_date}</option>
            </select>
            {$lang->in}
            <select name="filter[order]">
            <option value="asc"{$ordersel[\'asc\']}>{$lang->asc}</option>
            <option value="desc"{$ordersel[\'desc\']}>{$lang->desc}</option>
            </select>
            {$lang->order}
            </td>
            </tr>
            <tr>
            <td class="trow1" width="25%"><strong>{$lang->per_page}</strong></td>
            <td class="trow1" width="75%"><input type="text" name="filter[per_page]" value="{$per_page}" class="textbox" /></td>
            </tr>
            </table>
            <br />
            <div align="center">
            <input type="submit" class="button" value="{$lang->filter_warning_logs}" />
            </div>
            </form>
            </td>
            </tr>
            </table>
            {$footer}
            <link rel="stylesheet" href="{$mybb->asset_url}/jscripts/select2/select2.css">
            <script type="text/javascript" src="{$mybb->asset_url}/jscripts/select2/select2.min.js"></script>
            <script type="text/javascript">
            <!--
            if(use_xmlhttprequest == "1")
            {
            MyBB.select2();
            $("#username").select2({
            placeholder: "{$lang->search_user}",
            minimumInputLength: 3,
            maximumSelectionSize: 3,
            multiple: false,
            ajax: { // instead of writing the function to execute the request we use Select2\'s convenient helper
            url: "xmlhttp.php?action=get_users",
            dataType: \'json\',
            data: function (term, page) {
            return {
            query: term, // search term
            };
            },
            results: function (data, page) { // parse the results into the format expected by Select2.
            // since we are using custom formatting functions we do not need to alter remote JSON data
            return {results: data};
            }
            },
            initSelection: function(element, callback) {
            var value = $(element).val();
            if (value !== "") {
            callback({
            id: value,
            text: value
            });
            }
            },
            });
            }
            // -->
            </script>
            </body>
            </html>';
           */
        MyProfileUtils::insert_templates($templates);
        find_replace_templatesets("usercp_options", '#' . preg_quote('<legend><strong>{$lang->date_time_options}</strong></legend>') . '#i', '{$myprofile_comments_usercp}<legend><strong>{$lang->date_time_options}</strong></legend>');
        find_replace_templatesets("modcp_nav_users", "#" . preg_quote('{$nav_editprofile}') . "#i", '{$nav_editprofile}{$nav_myprofilecomments}');
        find_replace_templatesets("member_profile", "#" . preg_quote('{$modoptions}') . "#i", '{$modoptions}{$myprofile_comments}');
        find_replace_templatesets("member_profile", "#" . preg_quote('{$warning_level}') . "#i", '{$warning_level}{$myprofile_comments_stats}');
        find_replace_templatesets('header', "#" . preg_quote('{$unreadreports}') . "#i", '{$unreadreports}{$myprofile_alertbar}');
        /* let's integrate with MyAlerts 2.0 if it's not already the case */
        if (MyProfileUtils::myalerts_exists()) {
            if (MyProfileComments::myalerts_can_integrate()) {
                $alertTypeManager = MybbStuff_MyAlerts_AlertTypeManager::createInstance($db, $cache);
                $alertType = new MybbStuff_MyAlerts_Entity_AlertType();
                $alertType->setCode(MyProfileCommentsMyAlertsFormatter::alert_type_code());
                $alertType->setEnabled(true);
                $alertTypeManager->add($alertType);
            }
        }
    }