[eluser]daniel ispas[/eluser]
This is the helper file I use to integrate CK.
Code:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* CKEditor helper for CodeIgniter
*
* @author Samuel Sanchez <[email protected]> - http://www.kromack.com/
* @package CodeIgniter
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
* @tutorial http://www.kromack.com/codeigniter/ckeditor-helper-for-codeigniter
* @see http://ellislab.com/forums/viewthread/127374/
*
************************************************
* CKFinder Integration *
************************************************
* Improvements by Carlos Alcala from UAR Software
* [email protected]
*/
function display_ckeditor($data)
{
$return = '[removed][removed]';
$return .= '[removed][removed]';
//Adding styles values
if(isset($data['styles'])) {
$return .= "[removed]CKEDITOR.addStylesSet( 'my_styles', [";
foreach($data['styles'] as $k=>$v) {
$return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { ";
if(isset($v['styles'])) {
foreach($v['styles'] as $k2=>$v2) {
$return .= "'" . $k2 . "' : '" . $v2 . "'";
if($k2 !== end(array_keys($v['styles']))) {
$return .= ",";
}
}
}
$return .= '} }';
if($k !== end(array_keys($data['styles']))) {
$return .= ',';
}
}
$return .= ']);[removed]';
}
//Building Ckeditor
$return .= "[removed]
CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';
CKEDITOR.replace('" . $data['id'] . "', {";
//Adding config values
if(isset($data['config'])) {
foreach($data['config'] as $k=>$v) {
$return .= $k . " : '" . $v . "'";
if($k !== end(array_keys($data['config']))) {
$return .= ",";
}
}
}
$return .= '});';
$return .= "CKEDITOR.config.stylesCombo_stylesSet = 'my_styles';";
//CKFINDER INTEGRATION
$return .= "CKFinder.SetupCKEditor( null, { BasePath : '" .base_url(). $data['ckfinder']['path']."', RememberLastFolder : false } ) ;";
$return .= "if (CKEDITOR.instances['" . $data['id'] . "']) {CKEDITOR.remove(CKEDITOR.instances['" . $data['id'] . "']);}";
//FINISH SCRIPT
$return .= "[removed]";
return $return;
}
In controller you should have:
Code:
$this->load->helper('ckeditor');
//Ckeditor's configuration
$this->editor['ckeditor'] = array(
//ID of the textarea that will be replaced
'id' => 'content', // Must match the textarea's id
'path' => 'js/ckeditor', // Path to the ckeditor folder relative to index.php
//Ckfinder's configuration
'ckfinder' => array(
'path' => 'js/ckfinder', // Path to the ckeditor folder relative to index.php
),
//Optionnal values
'config' => array(
'toolbar' => "Full", //Using the Full toolbar
'width' => "810px", //Setting a custom width
'height' => '200px', //Setting a custom height
),
);
In view:
Code:
<?php echo display_ckeditor($ckeditor); ?>
This goes after the textarea.
If upload doesn't work make sure you have set $baseurl and $baseDir in CKFinder-> config.php