Textboxer 2.0 integration
Tutorial on how to implement the Textboxer 2.0 on a single plugin page
The Textboxer 2.0 used in Plugins
The Textboxer 2.0 system is not as complicated as you think. Ok you can find a piece here and there on the forums, but never a complete topic about how it works and how to add it in you own costum made plugin.
I will try to write here some lines about how to configure a textboxerfield in you plugin and let you parse it to the mysql databse.
So let me first explain the idea behind the textboxer.
The Textboxer Idea
TheTextboxer is a easy and secure way to format font in posts, pages and other plugins. The Textboxer uses the BBCode function. The BBcodes have the idea to easy format text without knowing HTML or CSS. The other reason for the Textboxer is to not get HTML or PHP Code in the Pages to get a secure way to add formatting to the text.
Ok so much for the Textboxer function from my Point of view.
(please note: this tut isn�t very PHP-unknown compatible, so make sure you know at least a bit of PHP to master the textboxer)
The needed Items
First is to make clear what we need to add the Textboxerfield to your Plugin.
1. The Textboxer Configuration File (textboxer.php)
2. The Function for an var for displaying the <textarea>
3. the possibility to parse the field to an Tag
4. the right method to insert the textarea input in the DB
5. the right method to get it the hell out of the DB
1. The configuration File
Kod:
/* ====================
Seditio - Website engine
Copyright Neocrome
http://www.neocrome.net
[BEGIN_SED]
File=plugins/yourplugin/ yourplugin.tb.php
Version=101
Updated=2006-mar-15
Type=Plugin
Author=Arkkimaagi
Description=
[END_SED]
==================== */
if (!defined('SED_CODE')) { die('Wrong URL.'); }
require_once("plugins/textboxer2/inc/textboxer2.lang.php");
require_once("plugins/textboxer2/inc/textboxer2.inc.php");
$tb2Buttons = array(
'tb_ieOnlyStart',
2,
'copy',
'cut',
'paste',
'}',
'tb_ieOnlyEnd',
'bold',
'underline',
'italic',
3,
'left',
'center',
'right',
'}',
4,
'quote',
'code',
'list',
'hr',
'spacer',
'ac',
'p',
'}',
5,
'image',
'thumb',
'colleft',
'colright',
'}',
6,
'url',
// 'urlp',
'email',
// 'emailp',
'}',
7,
'black',
'grey',
'sea',
'blue',
'sky',
'green',
'yellow',
'orange',
'red',
'white',
'pink',
'purple',
'}',
8,
'page',
// 'pagep',
'user',
// 'link',
// 'linkp',
'flag',
'pfs',
'topic',
'post',
'pm',
'}',
1,
'smilies',
'}',
//'more',
'title',
'preview'
);
$tb2DropdownIcons = array(-1,49,1,7,10,15,19,23,35);
$tb2MaxSmilieDropdownHeight = 300; // Height in px for smilie dropdown
$tb2InitialSmilieLimit = 20; // Smilies loaded by default to dropdown
$tb2TextareaRows = 10; // Rows of the textarea
// Do not edit below this line !
$tb2ParseBBcodes = $cfg['parsebbcodepages'];
$tb2ParseSmilies = $cfg['parsesmiliespages'];
$tb2ParseBR = TRUE;
ş>
]
This is the Configuration file. Here you can set up what fields should be visible on the Textboxerfield in your Plugin. You just have to delete the relevant part of the entries and the icons for adding smillies, for example, are not showing of again.
Here are a example part what I cutted out:
Kod:
1,
'smilies',
'}',
//'more',
'title',
'preview'
);
I thought the smillies are not so good in a professional plugin so I decide to not use them.
You can cut out the only a specific part of the config file to not let the user access the url function, for example. Its up to you.
So this file is quite important for your plugin so save it in you plugin folder.
Most likely you would use a name like �yourplug.tb.inc.php� or something like that.
Configuration
Second step the setup in your plugin. To use the textboxer field you have to add first a �require� in the plugin. The require function of PHP is to include a external file with a higher priority (correct me if iam wrong). So for now add this to you plugin
Kod:
$textboxer = sed_textboxer2('tb_add', 'add', $cont, $tb2TextareaRows, $tb2TextareaCols, 'add', $tb2ParseBBcodes,$tb2ParseSmilies, $tb2ParseBR, $tb2Buttons, $tb2DropdownIcons, $tb2MaxSmilieDropdownHeight, $tb2InitialSmilieLimit);
here is the creation function. It works pretty easy but now for the explanation.
First important is to save the function in a variable, mine is $textboxer.
So the important part is this �sed_textboxer2('tb_add', � here you can see the tb_add, it�s the name of the text area field what gets generated. �<textarea name=�tb_add��.
The other two vars are for identify the name if the form, for security reasons again (I know I stole this). Now another important thing is the variable here: �sed_textboxer2('tb_add', 'add', $cont, $tb2TextareaRows� the var �$cont� is like the value=�� part of the input field from html or correct on the <textarea system �<textarea>$cont</textarea>� would be the more accurate way to show where it get inserted.
Ok so much for the function itself, just add it to you plugin in a proper way.
The Tags
Now comes a important part. Here are possibly the phases where the most mistakes come to the light.
Lets start with a standart t-parse of a plugin:
Kod:
$t-> assign(array(
"YOURPLUGIN_TEXTBOXERFIELD" => $ textboxer,
));
$t->parse("MAIN.ADD");
now with this function we are adding the textboxer to a plugin template file where are the template code �add� has been defined
<!�BEGIN: ADD -->
now there is a other way to do this:
Kod:
$t-> assign(array(
"YOURPLUGIN_TEXTBOXERFIELD" => $ textboxer,
));
with this method its directly parsed to the template assigned to the plugin. OR to the hook where you insert. page.tags for example.
So. Now our file should have these lines in it:
Kod:
$cont = �Lorem ipsum dolor sit amet��;
$textboxer = sed_textboxer2('tb_add', 'add', $cont, $tb2TextareaRows, $tb2TextareaCols, 'add', $tb2ParseBBcodes,$tb2ParseSmilies, $tb2ParseBR, $tb2Buttons, $tb2DropdownIcons, $tb2MaxSmilieDropdownHeight, $tb2InitialSmilieLimit);
$t-> assign(array(
"YOURPLUGIN_TEXTBOXERFIELD" => $ textboxer,
));
i just added the var $cont that we have something inside the textboxer field. This can be replaced by a $row[�username�] or something else.
How to add the vars to the DB
Now! A part that took me some time to understand. But no worries its quite simple, you just have to look for these two functions from seditio:
Kod:
sed_cc($yourvar);
and
Kod:
sed_parse($yourvar,1,1,1),
the first function is to add the textboxer to your DB without converting it to HTML or other junk we don�t need/want.
The second function is to convert the BBCODE to HTML code.
In short the SQL function would look something like this:
Kod:
$sql = sed_sql_query("INSERT INTO `sed_yourdatabase` (
`cont`
)
VALUES (
'".sed_cc($_POST['cont'])."'
)");
Display the input on a Page
If you want to display the right formatted output on a page you don�t have to worry!
It�s the easiest thing:
Kod:
sed_parse($row['cont'],1,1,1),
this function is the important one (above)
Kod:
$t-> assign(array(
"NOTEBOOK_FRM_CONT" => sed_parse($row['cont'],1,1,1),
));
and here its included in the t-parse and get assigned as an tag. (above)
here we get the input directly from the databse trough �$row[�cont�]�.
we just have to let it outputted with the sed_parse function to let it formatted correctly.