[eluser]Stefano G[/eluser]
flyer, first of all thanks for this very useful way to integrate FCK/CI: I recently needed to extend the basic functionalities of the FCK helper so I had to slightly modify the helper and the configuration file.
I hope you don't mind if I share my solution (based on your hard work) with the community.
My need was to add my custom
fckconfig.js file for defining a new toolbar and to override some FCK properties.
So I slightly modified your
form_helper.php class and added one line to the
application/config/config.php file with a new entry that points to my FCK custom config file.
application/config/config.php (excerpt)
Code:
/*
|--------------------------------------------------------------------------
| FCKeditor Custom config file
|--------------------------------------------------------------------------
|
| This is the link to a custom configuration file that can be used to
| override the properties in the main fckconfig.js file
|
|
*/
$config['fckeditor_custom_configurations_path'] = "/same dir of fckconfig.js/fckconfig_custom.js";
application/helpers/form_helper.php (excerpt)
Code:
if( $fckeditor->IsCompatible() )
{
...
/* NEW */
if( $fckeditor_custom_configurations_path = $CI->config->item('fckeditor_custom_configurations_path'))
$fckeditor->Config['CustomConfigurationsPath'] = $fckeditor_custom_configurations_path;
/* NEW */
if( is_array($data) )
{
BTW this is an excerpt of my
fckconfig_custom.js:
Code:
FCKConfig.ToolbarSets["Stefano"] = [
['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField']
] ;
FCKConfig.EnterMode = 'br' ; // p | div | br <- this one to get rid of the extra breaks added by FCK!!!
FCKConfig.ShiftEnterMode = 'br' ; // p | div | br
Going one step further
The second modification I did to the
form_helper.php class was to allow a generic view/controller to override the config items.
Generally speaking
ALL the values in the
fckconfig.js:
Code:
eg. FCKConfig.EnterMode = 'p';
can be set from a PHP script this way:
Code:
$fckeditor->Config['EnterMode'] = 'p';
So I did another little modification in the
form_helper.php class to allow the script (a view in the following example) to set his own properties:
Code:
myview.php
...
$data = array(
'name' => 'editor',
'id' => 'editor',
'toolbarset' => 'Default',
'width' => '800',
'height' => '600',
'value' => '',
'properties' => array(
'EnterMode' => 'div',
'AutoDetectLanguage' => false,
'DefaultLanguage' => 'hu'
)
);
echo form_fckeditor($data);
...
NOTE: I decided not to put the properties in the
$extra third argument of the
form_fckeditor() function to avoid problems in case the editor should be rendered as a textarea.
This is the second modification into the
form_helper.php just before the
return statement (excerpt)
Code:
...
if (isset($data['properties']) && is_array($data['properties'])) {
foreach($data['properties'] as $k=>$v) {
$fckeditor->Config[$k] = $v;
}
}
return $fckeditor->CreateHtml();
The loop simply reads and sets the properties from the input data.
I hope that I was clear enough (this is a sort of english language exam to me
) and that someone else will find my post useful.
Again I'd like to thanks
flyer for his brilliant work without whom I couldn't easily integrate FCKeditor (that really lacks some good docs!) into my CI powered apps!
Stefano