 |
[eluser]flyer[/eluser]
Hi,
Thought someone might find this useful. Some of the other FCKEditor/CodeIgniter integrations seem to want to add it as a library or otherwise. The way I see it, its basically a fancy text area, and should be treated as such. Hence integration into the form helper.
It has 3 basic steps:
Step 1.
Download and unzip the FCKEditor application into a directory of your choice.
I prefer either the /system/plugins/fckeditor/ or /system/application/plugins/fckeditor/ or my choice - external/fckeditor/
Step 2.
Add following FCKEditor settings to the system/application/config/config.php file:
Code: /*
|--------------------------------------------------------------------------
| FCKEditor Basepath
|--------------------------------------------------------------------------
|
| The path from your site's root in which the fckeditor folder is. Note
| this is from the site's root, not the file system root. Also note the
| required slashes at start and finish.
|
| e.g. /fckeditor/ or /system/plugins/fckeditor/ etc...
|
*/
$config['fckeditor_basepath'] = "/system/plugins/fckeditor/";
/*
|--------------------------------------------------------------------------
| FCKEditor Toolbar Set Default
|--------------------------------------------------------------------------
|
| The default Toolbar set to be used for FCKEditor across your site. Leave
| as empty string or comment out if your happy enough with the standard
| default.
|
*/
$config['fckeditor_toolbarset_default'] = 'Default';
Step 3.
Finally the new helper class. The following code should be placed in a file named:
/system/application/helpers/form_helper.php
Note this will override /system/helpers/form_helper.php but all functions are imported from here anyway, so no clash or reduced functionality should occur.
Code: <!--****** FILE /system/application/helpers/form_helper.php code ********-->
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once( BASEPATH . '/helpers/form_helper'.EXT);
function form_fckeditor($data = '', $value = '', $extra = '')
{
$CI =& get_instance();
$fckeditor_basepath = $CI->config->item('fckeditor_basepath');
require_once( $_SERVER["DOCUMENT_ROOT"] . $fckeditor_basepath. 'fckeditor.php' );
$instanceName = ( is_array($data) && isset($data['name']) ) ? $data['name'] : $data;
$fckeditor = new FCKeditor($instanceName);
if( $fckeditor->IsCompatible() )
{
$fckeditor->Value = html_entity_decode($value);
$fckeditor->BasePath = $fckeditor_basepath;
if( $fckeditor_toolbarset = $CI->config->item('fckeditor_toolbarset_default'))
$fckeditor->ToolbarSet = $fckeditor_toolbarset;
if( is_array($data) )
{
if( isset($data['value']) )
$fckeditor->Value = html_entity_decode($data['value']);
if( isset($data['basepath']) )
$fckeditor->BasePath = $data['basepath'];
if( isset($data['toolbarset']) )
$fckeditor->ToolbarSet = $data['toolbarset'];
if( isset($data['width']) )
$fckeditor->Width = $data['width'];
if( isset($data['height']) )
$fckeditor->Height = $data['height'];
}
return $fckeditor->CreateHtml();
}
else
{
return form_textarea( $data, $value, $extra );
}
}
?>
form_fckeditor() Usage
This function is identical in nearly all respects to the form_textarea() function above except that it generates a FCKEditor editor instead of a textarea and it takes some additional $data fields. So please read the Form Helper section of the Code Igniter User Guide!
However, the FCKEditor takes $data fields- 'name' 'basepath', 'toolbarset', 'width', 'height' which are passed on to the FCKEditor.php class from the FCKEditor application download. These $data fields control the settings for the editor, rather than any that you would normally pass to form_textarea() e.g. 'rows' or 'cols'.
Code: ***** USAGE ******
// e.g. 1
echo form_fckeditor('textareaName', $value );
// e.g. 2
$data = array(
'name' => 'textareaName2',
'id' => 'textareaName2',
'toolbarset' => 'Advanced',
'basepath' => '/fckeditor/',
'width' => '100%',
'height' => '200'
);
echo form_fckeditor( $data );
It is important to know the regular $data fields that you would normal supply to the form_textarea() should also be provided if you wish to alter the defaults. This is because if the user's browser is not compatible with FCKEditor e.g. no javascript, the form_fckeditor() falls back to form_textarea().
Also, the 3rd parameter of the function, $extra, is discarded unless the function falls back to form_textarea().
Note that this helper technique requires zero modification of the FCKEditor source files, so when it comes to updates to FCKEditor, then your not going to have to remember where you've changed. Personally, I highly value keeping plugin code as independent as possible.
Any other changes to customize FCKEditor can be done exactly as per the FCKEditor documentation on its website.
Let me know what u think. Hopefully fairly easy to see what I've done!
Eddie
PS. Please don't ask about customizing FCKEditor. All customisation other than that above occurs within the FCKEditor source directory and better left for the FCKEditor support site
|