An open source alternative to CKfinder

http://kcfinder.sunhater.com/#overview

Will this work with CKeditor ?

Comments

mephir’s picture

Status: Active » Fixed

Yes. You should extract archive, for an example into sites/all/libraries/kcfinder and then go through with instruction.
Configuration setting can be set into ckeditor.config.js or Advanced javascript configuration in profile settings.
Configuration for an example should look:

   config.filebrowserBrowseUrl = '/sites/all/libraries/kcfinder/browse.php?type=files';
   config.filebrowserImageBrowseUrl = '/sites/all/libraries/kcfinder/browse.php?type=images';
   config.filebrowserFlashBrowseUrl = '/sites/all/libraries/kcfinder/browse.php?type=flash';
   config.filebrowserUploadUrl = '/sites/all/libraries/kcfinder/upload.php?type=files';
   config.filebrowserImageUploadUrl = '/sites/all/libraries/kcfinder/upload.php?type=images';
   config.filebrowserFlashUploadUrl = '/sites/all/libraries/kcfinder/upload.php?type=flash';

If you have any lack of clarity about issue, feel free to reopen it. I don't think so if we provide closer solution for kcfinder, this is 3rd part project, i don't have so much time to test it for security issues.

mephir’s picture

Category: feature » support
gooddesignusa’s picture

sub

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ikeigenwijs’s picture

sub

laogui’s picture

subscribe.
kcfinder is opensource.
ckfinder is commercial.

Mamoun’s picture

Subscribe

Maroli’s picture

Version: 6.x-1.1 » 7.x-1.0

Anyone got thsi working on drupal 7? I Urgently need it. I did all of the above, without any result. Searched the website of KCfinder with no result.

Anyone?

xandeadx’s picture

+1 for kcfinder

kondrat’s picture

Se my blog http://code201.net/blog/ckeditor.html
I use KCFinder with CKEditor

espirates’s picture

Your site doesn't even load.

Se my blog http://code201.net/blog/ckeditor.html
I use KCFinder with CKEditor

Niremizov’s picture

Look like there is a way of useing KCFinder with Ckeditor in Drupal, but probably it isn't the best.

1. Make changes like in #1 was told.

2. Go inside KCFinder/core and edit autoload.php.
Add before function __autoload($class) this: spl_autoload_register('__autoload');

3. Go inside KCFinder folder and edit browse.php and upload.php by inserting this line first:

require '../modules/ckeditor/includes/filemanager.config.php';

Well, actually you just need to require filemanager.config.php inside includes folder in CKEditor module.

4. Now go inside CKEditor/includes folder and make some changes in filemanager.config.php:

After $authenticated = user_access('allow CKFinder file uploads');

Place something like that:

	$_SESSION['KCFINDER'] = array();
	$_SESSION['KCFINDER']['disabled'] = false;
	$_SESSION['KCFINDER']['uploadURL'] = "";
	$_SESSION['KCFINDER']['uploadDir'] = "";

Surely it is better to change uploadDir to $_SESSION['ckeditor']['UserFilesPath']."/kcfinder" but there is some security issue that i do not understand for now.

danyalejandro’s picture

(My case is: Drupal 7 + WYSIWG module + CKeditor installed)

You can create a small module with the "wysiwyg_editor_settings_alter" hook; that's where you configure the settings that the WYSIWYG module uses for ckEditor. In the module, you can use the following:

<?php
function drupal_kc_wysiwyg_editor_settings_alter(&$settings, &$context) {
	$kcfinderRoute = url('sites/all/libraries/kcfinder/');
	if ($context['profile']->editor == 'ckeditor') {
		$settings['filebrowserImageBrowseUrl'] = $kcfinderRoute . 'browse.php?type=images';
		$settings['filebrowserBrowseUrl'] = $kcfinderRoute . 'browse.php?type=files';
		$settings['filebrowserFlashBrowseUrl'] = $kcfinderRoute . 'browse.php?type=flash';
		$settings['filebrowserUploadUrl'] = $kcfinderRoute . 'upload.php?type=files';
		$settings['filebrowserImageUploadUrl'] = $kcfinderRoute . 'upload.php?type=images';
		$settings['filebrowserFlashUploadUrl'] = $kcfinderRoute . 'upload.php?type=flash';
	}
}

Notice how my module was called "drupal_kc". No other code was required (just to see it work; remember to set your settings according to the SESSION stuff or everyone will be able to use kcfinder!!)

Just in case, my .info file was like this:

; $Id $
name = Drupal KCFinder
description = Integrates KCFinder into Drupal 7 (CKEditor trough WYSIWYG).
package = User interface
;dependencies[] = wysiwyg
core = 7.x

now... I wonder how to make this SECURE...

Niremizov’s picture

danyalejandro<

I wonder how to make this SECURE...

I just don’t really understood< how did you want to set SESSION vars... and transport them to KCFinder?

By the way, there is a better way then #12.
You still need to put kcfinder folder inside ckeditor module's folder.(Code written below was tested if KCF folder was there)
It is possible to use #13 after what you should place to the end of core/autoload.php:

function CheckAuthentication() {
    static $authenticated;

    if (!isset($authenticated)) {
        if (!empty($_SERVER['SCRIPT_FILENAME'])) {
            $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
            if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
                $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
                $depth = 2;
                do {
                    $drupal_path = dirname($drupal_path);
                    $depth++;
                } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
            }
        }

        if (!isset($bootstrap_file_found) || !$bootstrap_file_found) {
            $drupal_path = '../../../../..';
            if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
                $drupal_path = '../..';
                do {
                    $drupal_path .= '/..';
                    $depth = substr_count($drupal_path, '..');
                } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
            }
        }
        if (!isset($bootstrap_file_found) || $bootstrap_file_found) {
            $current_cwd = getcwd();
            if (!defined('DRUPAL_ROOT')){
                define('DRUPAL_ROOT', $drupal_path);
            }
            require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
            drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
            
            if ($authenticated = user_access('allow CKFinder file uploads')){
                if (!$_SESSION['KCFINDER']) { 
                	global $user;
                	$_SESSION['KCFINDER']= array(); 
                	$_SESSION['KCFINDER']['disabled'] = false;
                	$_SESSION['KCFINDER']['uploadURL'] = $_SESSION['ckeditor']['UserFilesPath']."kcfinder/".$user->uid;
                	$_SESSION['KCFINDER']['uploadDir'] = "../../../../default/files/kcfinder/".$user->uid;
                }  
            }

        }
    }

}
CheckAuthentication();

and to the beginning of core/autoload.php

spl_autoload_register('__autoload');

Be careful when useing $_SESSION['KCFINDER']['uploadURL'] or uploadDir... you should not to forget to create folder like kcfinder inside /sites/default/files/ ..... of course if only you will use this variable like written above...

Also, if you will use code above, there is no need to change any ini_session vars and you should also comment line 66 inside core/uploader.php for not getting any notices...

And that is all... i suppose now it is SECURE, or not? Such function is used by CkFinder...

danyalejandro’s picture

Niremizov, I did exactly as you said (did #13 and #14, ignored everything else), and it seems like the bootstrap process was succesfull (I can print nodes and stuff). The problem is, it looks like the session isn't being shared between Drupal and ckfinder; just after the bootstrap, if I write:

global $user;
echo $user->uid;

it writes "0", even tough I have a session started as the drupal admin...

btw, my kcfinder/config.php contains the following:

$_CONFIG = array(

    'disabled' => true,
    'readonly' => false,
    'denyZipDownload' => true,

    'theme' => "oxygen",

    'uploadURL' => "../../../../default/files/kcfinder",
    'uploadDir' => "",

    'dirPerms' => 0755,
    'filePerms' => 0644,

    'deniedExts' => "exe com msi bat php cgi pl",

    'types' => array(

        // CKEditor & FCKEditor types
        'files'   =>  "",
        'flash'   =>  "swf",
        'images'  =>  "*img",

        // TinyMCE types
        'file'    =>  "",
        'media'   =>  "swf flv avi mpg mpeg qt mov wmv asf rm",
        'image'   =>  "*img",
    ),

    'mime_magic' => "",

    'maxImageWidth' => 0,
    'maxImageHeight' => 0,

    'thumbWidth' => 100,
    'thumbHeight' => 100,

    'thumbsDir' => ".thumbs",

    'jpegQuality' => 90,

    'cookieDomain' => "",
    'cookiePath' => "",
    'cookiePrefix' => 'KCFINDER_',

    // THE FOLLOWING SETTINGS CANNOT BE OVERRIDED WITH SESSION CONFIGURATION

    '_check4htaccess' => true,
    //'_tinyMCEPath' => "/tiny_mce",

    '_sessionVar' => &$_SESSION['KCFINDER'],
    //'_sessionLifetime' => 200000,
    //'_sessionDir' => "e:/wamp/tmp",

    //'_sessionDomain' => "",
    //'_sessionPath' => "/",
);

maybe kcfinder and drupal can't share the session because of my settings? how could you make it work?

danyalejandro’s picture

Niremizov, I created a file called "sessiontest.php" in my Drupal root folder with the content:

<?php
static $authenticated;

if (!isset($authenticated)) {
	$current_cwd = getcwd();
	if (!defined('DRUPAL_ROOT')){
		define('DRUPAL_ROOT', 'E:/wamp/www/drupal');
	}
	
	require_once(DRUPAL_ROOT . '/includes/bootstrap.inc');
	drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
	
	global $user;
	print_r($user);
}
?>

when I run it, it successfully shows the data of the current user session. So I guess my problem described above has to do with domain names or something like that... what do you think?

danyalejandro’s picture

Finally did it!

Based on your code, I made a version of the function that works out-of-box and you can place the kcfinder folder anywhere you want... I don't really understand much of it tough (I combined stuff from many sources) but at least it works now.

<?php
function CheckAuthentication() {
    static $authenticated;

    if (!isset($authenticated)) {
        if (!empty($_SERVER['SCRIPT_FILENAME'])) {
            $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
            if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
                $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
                $depth = 2;
                do {
                    $drupal_path = dirname($drupal_path);
                    $depth++;
                } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
            }
        }

        if (!isset($bootstrap_file_found) || !$bootstrap_file_found) {
            $drupal_path = '../../../../..';
            if (!file_exists($drupal_path . '/includes/bootstrap.inc')) {
                $drupal_path = '../..';
                do {
                    $drupal_path .= '/..';
                    $depth = substr_count($drupal_path, '..');
                } while (!($bootstrap_file_found = file_exists($drupal_path . '/includes/bootstrap.inc')) && $depth < 10);
            }
        }
		
		if (!isset($bootstrap_file_found) || $bootstrap_file_found) {
			$current_cwd = getcwd();
			if (!defined('DRUPAL_ROOT')){
				define('DRUPAL_ROOT', $drupal_path);
			}
			
			// Simulate being in the drupal root folder so we can share the session
			chdir(DRUPAL_ROOT);
			
			global $base_url;
			$base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
			$base_url = $base_root .= '://'. preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
			
			if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
				$base_path = "/$dir";
				$base_url .= $base_path;
			}
			
			// correct base_url so it points to Drupal root
			$pos = strpos($base_url, '/sites/');
			$base_url = substr($base_url, 0, $pos);
			
			// bootstrap
			require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
			drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
			
			// if user has access permission...
			if ($authenticated = user_access('access kcfinder')){
				if (!$_SESSION['KCFINDER']) {
					global $user;
					$_SESSION['KCFINDER']= array();
					$_SESSION['KCFINDER']['disabled'] = false;
					//$_SESSION['KCFINDER']['uploadURL'] = $_SESSION['ckeditor']['UserFilesPath']."kcfinder/".$user->uid;
					//$_SESSION['KCFINDER']['uploadDir'] = "../../../../default/files/kcfinder/".$user->uid;
				} 
			}
			
			// return to kcfinder folder
			chdir($current_cwd);
		}
    }
}
?>

The only extra configuration required for kcfinder is setting the upload url...

Hey... how about we publish this as a module?

danyalejandro’s picture

I published the module in http://drupal.org/project/kcfinder , the problem is, I've never used GIT before and I want to turn it into a dev relase... oh well.

Could you please take a look in the code? this needs some serious testing...

Niremizov’s picture

Ok. I'am in.

Wolfgang Reszel’s picture

Version: 7.x-1.0 » 7.x-1.6

This issues seems to be fixed, but I still can't select KCFinder in the CKEditor profiles. The linked module is just for the WYSIWYG module only, but not the standalone CKEditor module.

Wolfgang Reszel’s picture

Status: Closed (fixed) » Needs work