Add ckfinder to Drupal FCKeditor module

This note was taken on Drupal-5.7, fckeditor-5.x-2.1 (module), fckeditor-2.5.1, and ckfinder-1.1.

  1. Locate the file named settings.php inside your drupal directory (usually sites/default/settings.php) and set $cookie_domain variable to the appropiate domain (remember to uncomment that line). If you do not do this, FCKeditor will claim that file browser is disabled.
  2. Download ckfinder and put it inside the directory of fckeditor module, after which you will see something like below:

    % ls
    CHANGELOG.txt             fckeditor.info          filemanager.config.php
    ckfinder                          fckeditor.install      img_assist_fckeditor.js
    ckfinder_php_1.1.tar.gz  fckeditor.module     LICENSE.txt
    fckeditor                         plugins                   FCKeditor_2.5.1.tar.gz
    fckeditor.popup.html      po                           fckeditor.config.js     
    fckeditor.popup.js           fckeditor.css            fckeditor.utils.js     
    README.txt

  3. Edit the fckconfig.js file in the FCKeditor directory and modify the following settings:

    FCKConfig.LinkBrowserURL = '/ckfinder/ckfinder.html' ;
    FCKConfig.ImageBrowserURL = '/ckfinder/ckfinder.html?type=Images' ;
    FCKConfig.FlashBrowserURL = '/ckfinder/ckfinder.html?type=Flash' ;
    FCKConfig.LinkUploadURL = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files' ;
    FCKConfig.ImageUploadURL = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images' ;
    FCKConfig.FlashUploadURL = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash' ;

  4. Edit fckconfig.modulefckeditor.module, and replace the lines

    if ($advanced_uploads) {
        $element['#suffix'] .= $js_id .".Config['LinkBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Connector=". $connector_path ."&ServerPath=". $files_path ."\";
      ". $js_id .".Config['ImageBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=". $connector_path ."&ServerPath=". $files_path ."\";
      ". $js_id .".Config['FlashBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=". $connector_path ."&ServerPath=". $files_path ."\";\n";
    }

    with the following:

    if ($advanced_uploads) {
      $element['#suffix'] .= $js_id.".Config['LinkBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html';
            ".$js_id.".Config['ImageBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html?type=Images';
            ".$js_id.".Config['FlashBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html?type=Flash';\n";
    }

  5. Open file ckfinder/config.php, and replace the empty function CheckAuthentication() with the following code:

     function CheckAuthentication()
    {
      static $authenticated;
     
      if (!isset($authenticated)) {
        $drupal_path = "../../../";
        if(!file_exists($drupal_path . "/includes/bootstrap.inc")) {
          $drupal_path = "../..";
          do {
            $drupal_path .= "/..";
            $depth = substr_count($drupal_path, "..");
          }
          while(!($bootstrapFileFound = file_exists($drupal_path . "/includes/bootstrap.inc")) && $depth<10);
        }
        if (!isset($bootstrapFileFound) || $bootstrapFileFound) {
          $cwd = getcwd();
          chdir($drupal_path);
          require_once "./includes/bootstrap.inc";
          drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
          $authenticated = user_access("allow fckeditor file uploads");
          chdir($cwd);
        }
      }
     
      return $authenticated;
    }
    $Config['Enabled'] = CheckAuthentication();
    $baseUrl = '/' . file_directory_path() . '/';

    Please note that you must call this function right after declaration, otherwise the "session_start()" function call inside bootstrap.inc will cause error.

 

Comments

thanks for this information

thankss..
it really works fine!

Cannot find fckconfig.module

Hi Daisy,

Thanks for the ckfinder stuff. I have searched the directory structure of my Drupal fckeditor install and cannot find fckconfig.module.

Can you give me a clue as to where it should be?

Regards
Martin Fuggle

It should be "fckeditor.module"

Sorry for my bad typo. I have fixed it above.

Thanks

Many thanks for your reply...

Regards -- Martin Fuggle

Still having trouble

Hi Daisy,

I am sorry to be a bother but I am still having trouble. I have checked all the releases to make sure that they are the same as you have used and they are except that I am using Drupal-5.5. That should not have an impact on my issue.

I cannot located the following text string in the file fckeditor_module. Is there some way that I have the wrong version of the Drupal fckeditor module?

As I say I am sorry to trouble you but I would like to use ckfinder if poss...

Cheers
Martin

if ($advanced_uploads) {
$element['#suffix'] .= $js_id .".Config['LinkBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Connector=". $connector_path ."&ServerPath=". $files_path ."\";
". $js_id .".Config['ImageBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=". $connector_path ."&ServerPath=". $files_path ."\";
". $js_id .".Config['FlashBrowserURL'] = \"". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=". $connector_path ."&ServerPath=". $files_path ."\";\n";
}

Found the text!

Hi Daisy,

I found the stuff in fckeditor.module. Initially I used a text searh function in the editor I use and for some reason (no doubt user error) it didn't find it.

Cheers
Martin

Glad to know it worked

And thank you for telling me, Martin.

Set $baseUrl

I had to do one more step: $baseUrl = '/' . file_directory_path() . '/'; in the file ckfinder/config.php

You are right.

I checked my diff in ckfinder/config.php. Sure enough, I also had this line patched. Thank you for pointing it out.

Daisy

Response 200, T_Static error

Parse error: syntax error, unexpected T_STATIC in /..**../modules/fckeditor/ckfinder/config.php on line 23 ...

Can you help on that?

Trying to integrate with 6.2 It is almost there. I am not sure where to go from here.

It's a php error. I guess,

It's a php error.

I guess, you may try to remove your line 23 and see if the error persists. If it does, then it would be somewhere above this line that has problem.

Good luck.

Daisy

Non default baseUrl, baseDir

First thaks a lot for great text... As I am not using the default location for baseUrl and baseDir (different per use using tokens) - here is my changed code:

function CheckAuthentication()
{
static $authenticated;

if (!isset($authenticated)) {
$drupal_path = "../../../";
if(!file_exists($drupal_path . "/includes/bootstrap.inc")) {
$drupal_path = "../..";
do {
$drupal_path .= "/..";
$depth = substr_count($drupal_path, "..");
}
while(!($bootstrapFileFound = file_exists($drupal_path . "/includes/bootstrap.inc")) && $depth<10);
}
if (!isset($bootstrapFileFound) || $bootstrapFileFound) {
$cwd = getcwd();
chdir($drupal_path);
require_once "./includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$authenticated = user_access("allow fckeditor file uploads");
//cdmaslo A
if (isset($_SESSION['FCKeditor']['UserFilesPath'], $_SESSION['FCKeditor']['UserFilesAbsolutePath'])) {
$GLOBALS['fck_user_files_path'] = $_SESSION['FCKeditor']['UserFilesPath'];
$GLOBALS['fck_user_files_absolute_path'] = $_SESSION['FCKeditor']['UserFilesAbsolutePath'];
}
//cdmaslo Z
chdir($cwd);
}
}

return $authenticated;
}
$Config['Enabled'] = CheckAuthentication();
//cdmaslo A
if (!empty($fck_user_files_path)) {
$baseUrl = $fck_user_files_path;
$baseDir = $fck_user_files_absolute_path;
}
else {
// Nothing in session? Shouldn't happen... anyway let's try to upload it in the (almost) right place
// Path to user files relative to the document root.
$baseUrl = '/' . file_directory_path() . '/'; // cdmaslo original
$baseDir = resolveUrl($baseUrl);// cdmaslo original
}
// cdmaslo Z

See comments with cdmaslo for changes

Thank you for sharing. Daisy

Thank you for sharing.

Daisy

works out great for me very

works out great for me very nice. yahoo

V 2.6.3 ?

Thanks for these detailed instructions. One question: Has anyone successfully enabled this in v2.6.3? I can't seem to find any reference to 'advanceduploads' in the file. It looks like the if() has been re-written as a switch, and there are several new parameters in the file. Can't seem to get it to work.

Thanks for any help.

Not yet

I am sorry but we haven't looked into V2.6.3 yet.

drupal 6.4+fckeditor module 6.x

Hello all thanks for this great tutorial.
Now I'm using Drupal 6.4 + FCKed module for 6.x and the last FCKeditor.
The n.4 step is totally differnt in 6.x release and I don't know what to do/change.
Please If someone knows how,I would be very grateful!

thanks in advance

jM.

I found the solution for the new version!

With a bit of trial and error, I managed to find what you have to change in this new version :)

In the steep #4, when you have to edit the fckeditor.module file, look for the following lines:

$js .= $js_id .".Config['LinkBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Connector=". $connector_path ."&ServerPath=". $files_path ."';\n";
$js .= $js_id .".Config['ImageBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=". $connector_path ."&ServerPath=". $files_path ."';\n";
$js .= $js_id .".Config['FlashBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=". $connector_path ."&ServerPath=". $files_path ."';\n";

Then replace these previous lines for the following ones:

$js .= $js_id .".Config['LinkBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html';\n";
$js .= $js_id .".Config['ImageBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html?type=Images';\n";
$js .= $js_id .".Config['FlashBrowserURL'] = '".$module_full_path."/ckfinder/ckfinder.html?type=Flash';\n";

The other steeps are the same.

I hope I have helped!

Best regards,
Tiago Paolini

Is disabled?

Hi,i have installed ckfinder in drupal with this solution, but when i go to browse the images, appear a message like "This program was disabled for security reason... Please contact the administrator", i don't know what i have to do to enable ckfinder...

No two \n"

It seems that the two \n" at end of the second and third lines should be removed. --Bob

Thanks!

This is awesome. Thank you!