To integrating YII and CKEditor I used editme extension. You can download it from YII Extensions directory. I found installing and using editme extension is easier than the other CKEditor extension that I ever used. Here the link of editme extension: http://www.yiiframework.com/extension/editme/
Then, here came the hard question for me, about how to integrating kcfinder into existing application. For you that want to know what kcfinder is, then you may go to the project website here in http://kcfinder.sunhater.com/.
And because the limitation of my English, I will show you how I integrating kcfinder with YII in code and avoiding too much technique discussion about it .
First, I create yii.php and saved it in integration folder of kcfinder. That is kcfinder/integration/yii.php
<?php
/**
* set with your webroot application (this is not YII framework path)
*/
$yii_app = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..';
// -- main logic
$current_cwd = getcwd();
// we need ability to share SESSION between kcfinder and YII ?
chdir($yii_app);
// get current after change directory ...
$curr = getcwd();
// set $yii and $config path value
// THIS IS YII Framework directory, relative with your application.
// For easier purpose, I just copy paste my code in index.php
// ---
$yii=$curr.'/../yii/framework/yii.php';
if(!($_SERVER['HTTP_HOST']=='localhost')) {
// change the following paths if necessary
$yii=$curr.'/yii/framework/yii.php';
$config=$curr.'/protected/config/production.php';
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
} else {
$config=$curr.'/protected/config/main.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
}
require_once($yii);
Yii::createWebApplication($config);
/**
* SET WITH YOUR VALUE ------------------------
* decide your own PATH here
* for description then you need to read kcfinder manual
*/
$uploadURL = Yii::app()->baseUrl
.'/..'
.Yii::app()->params['fileDownloadPath'];
$uploadDir = dirname(__FILE__).DIRECTORY_SEPARATOR
.'..'.DIRECTORY_SEPARATOR // out of integration
.'..' // out of kcfinder
.Yii::app()->params['fileDownloadPath'];
$session = new CHttpSession;
$session->setSavePath(Yii::app()->session->savePath);
$session->open();
$session['KCFINDER'] = array();
$session['KCFINDER'] = array(
'disabled'=> !UserIdentity::canBrowseServer(),
'uploadURL'=> $uploadURL,
'uploadDir'=>$uploadDir,
);
// then back to our path
chdir($current_cwd);
spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register('__autoload');
spl_autoload_register(array('YiiBase','autoload'));
?>
After that I change kcfinder/core/autoload.php, I add yii as the another CMS integration into kcfinder. Yes I know it’s not true because YII is not a CMS. But currently, change too much core code will cause a headache next time when we decide to upgrade kcfinder with the new version.
In my code it is about line number 40, change it into code like this.
// CMS INTEGRATION
if (isset($_GET['cms'])) {
switch ($_GET['cms']) {
case "drupal": require "integration/drupal.php"; break;
case "yii": require "integration/yii.php"; break;
}
}
And then we need to change kcfinder/core/uploader.php too.
About line 118 we need to add yii, here I show you my code …
// SET CMS INTEGRATION ATTRIBUTE
if (isset($this->get['cms']) &&
(
in_array($this->get['cms'], array("drupal", "yii"))
)
)
$this->cms = $this->get['cms'];
And then in the same file about line 140, when kcfinder set the SESSION; we don’t want kcfinder execute session_start() because we already did that with integration code previously. I change it into this …
switch ($this->cms) {
case "drupal": break;
case "yii": break;
default: session_start(); break;
}
And finally, to used it with editme extension I code it like this:
$this->widget('application.extensions.editme.ExtEditMe', array(
'model'=>$model,
'height'=>$height,
'attribute'=>$the_attribute,
'toolbar'=>$btoolbar,
'filebrowserImageBrowseUrl'=> Yii::app()->baseUrl.'/kcfinder/browse.php?type=images&cms=yii',
'filebrowserImageBrowseLinkUrl'=>Yii::app()->baseUrl.'/kcfinder/browse.php?type=images&cms=yii',
'filebrowserImageUploadUrl'=>Yii::app()->baseUrl.'/kcfinder/upload.php?type=images&cms=yii',
));
As an info, in my application kcfinder installed in webroot and not inside protected directory; and Of course PHP safe_mode value must be off.