Adding Editor to your Mods
I've seen many posts here from coders asking details on how they can add vB's editor in their hack. Unfortunatelly (as it happen to my question too) all posts have 0 replies. Finally I succeeded to find a way to add the editor in my mod, so I felt obligue to write the way here, for those who are interesting on it.
Step by step instructions:
1.-
In your product-name.xml file
a) In table structure add a field:
Code:
`message` mediumtext,
Bug or my mistype in variable name, when I tried with different field name it didn't worked.
b) In Plugins section (below the templates and before phrases) add:
Code:
<plugin active="1">
<title>Get Editor</title>
<hookname>editor_toolbar_start</hookname>
<phpcode><![CDATA[if ($forumid == '
Your_Module_Name')
{
global $setting;
$setting['allow_bbcode'] = '1';
$show['img_bbcode'] = $setting['allow_imgcode'];
$toolbartype = $setting['allow_bbcode'] ? is_wysiwyg_compatible(-1, $editor_type) : 0;
$show['wysiwyg_compatible'] = (is_wysiwyg_compatible(2, $editor_type) == 2);
$show['editor_toolbar'] = ($toolbartype > 0);
$editor_template_name = ($toolbartype ? 'editor_toolbar_on' : 'editor_toolbar_off');
}]]></phpcode>
</plugin>
2.-
In your PHP file
a] In your Add New Form Procedure add:
Code:
require_once(DIR . '/includes/functions_editor.php');
$show['wysiwyg'] = ($setting['allow_bbcode'] ? is_wysiwyg_compatible() : 0);
$istyles_js = construct_editor_styles_js();
$show['qr_require_click'] = 0;
$editorid = construct_edit_toolbar('', 0, '
Your_Module_Name', ($setting['allow_smilies'] ? 1 : 0), 1, false, 'qr');
$messagearea = "
<script type=\"text/javascript\">
<!--
var require_click = false;
var threaded_mode = 1;
var is_last_page = false;
// -->
</script>
$messagearea
";
b] In your Save New Form Procedure
Code:
require_once('./includes/functions_wysiwyg.php');
$message= convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message']);
$message = $vbulletin->db->escape_string($message);
and of course don't forget to include field message in your Insert code
c] In your Edit Form Procedure
Code:
require_once(DIR . '/includes/functions_editor.php');
$show['wysiwyg'] = ($setting['allow_bbcode'] ? is_wysiwyg_compatible() : 0);
$istyles_js = construct_editor_styles_js();
$show['qr_require_click'] = 0;
$editorid = construct_edit_toolbar(
$article[message], 0, '
Your_Module_Name', ($setting['allow_smilies'] ? 1 : 0), 1, false, 'qr');
$messagearea = "
<script type=\"text/javascript\">
<!--
var require_click = false;
var threaded_mode = 1;
var is_last_page = false;
// -->
</script>
$messagearea
";
$article[message] is the name of your field variable. Be carefull on it to replace with the right one.
d] In your Save Edited Form procedure:
Code:
require_once('./includes/functions_wysiwyg.php');
$message= convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message']);
$message = $vbulletin->db->escape_string($message);
Also here, don't forget to include field message in your Update
3.- Again in you
product-name.xml file in the templates section, in any form that you want to use the Editor, you must add:
Code:
<form enctype="multipart/form-data" action="Your_PHP_File" name="vbform" method="post"
<if condition="!is_browser('webtv')"> onsubmit="return vB_Editor['$editorid'].prepare_submit(0, $vboptions[postminchars])"</if>>
and at the part of the template where you want to add the editor, add:
$messagearea