CKEditor – HOWTO replace Xinha with CKEditor using PHP

I was working for a client with a custom CMS written n PHP. Who does that these days, nobody. In any case, one of the problems with the site was that it was broken in IE9 as Xinha is not really compatible with IE9; there is a way to fix this but my thinking is why bother — if it’s not being maintained it doesn’t make sense to keep using it. The two alternatives are TinyMCE and CKEditor, I chose CKEditor. And the replacement was pretty simple. Simply drop that in to some sort of path and then replace the code that intialized Xinha with code that initializes CKEditor usually in the head of the document.

CKEditor provides a class called ‘ckeditor_php5.php’ that automatically writes the code necessary for the editor to replace a css id. Simply require ckeditor_php5.php in your PHP code base and then initialize it:
[php]
$CKEditor = new CKEditor();
$CKEditor->replace(“css-id-tag”,$config);
[/php]

You may also add configurations to the editor using the following:
[php]
//Set formatting options
$config[‘toolbar’] = array(
array( ‘Source’,’-‘,
‘NewPage’,’Preview’,’Templates’,’-‘,
‘Cut’,’Copy’,’Paste’,’PasteText’,’PasteFromWord’,’-‘,
‘Undo’,’Redo’,’-‘,
‘Find’,’Replace’,’-‘,
‘SelectAll’,’RemoveFormat’,’-‘,
‘Maximize’, ‘ShowBlocks’),
‘/’,
array(‘Bold’,’Italic’,’Underline’,’Strike’,’-‘,
‘Subscript’,’Superscript’,’-‘,
‘NumberedList’,’BulletedList’,’-‘,
‘Outdent’,’Indent’,’Blockquote’,’-‘,
‘JustifyLeft’,’JustifyCenter’,’JustifyRight’,’JustifyBlock’,’-‘,
‘Link’,’Unlink’,’Anchor’,’-‘,
‘Image’,’Flash’,’Table’,’HorizontalRule’,’SpecialChar’
),
‘/’,
array(‘Format’,’Font’,’FontSize’,’-‘,
‘TextColor’,’BGColor’)
);
[/php]

Published on: 23 April 2012
Posted by: Sami K.