Updated - July 7, 2012

This is a long overdue update to my original post. Some things change, some things remain the same. Some of the original post is here, most of it is gone.

Background -- Aug 20, 2010

Having attempted to scale that learning curve called Mount Drupal without ropes (and having failed), I am now working my way through the book Using Drupal by Angela Byron et. al. By the end of chapter 2, the casual reader has learned of the WYSIWYG, FCKeditor, and the IMCE modules.

The intrepid reader may have successfully installed Drupal and downloaded the code examples from the O'Reilly website, and noted that the Drupal core modules, the contributed modules, and even the directory tree from the O'Reilly site are really out of date. The determined reader will have rearranged the directory tree and updated the core modules and the recommended contributor modules referenced by the book; and maybe even downloaded the new CKeditor and something called CKFinder. The frustrated reader may have managed to get CKEditor and CKFinder working together - sort of. At this point there are ckeditor amd ckfinder subdirectories in the sites/all/modules/ckeditor directory.

There are now over 1100 files and 285 folders in the /modules/ckeditor/ directory!

Then a new twist..

So I decided to enable the WYSIWYG and the IMCE modules. The WYSIWYG module informs me that the CKEditor library needs to be in a sites/all/libraries directory.

So I created a sites/all/libraries directory and then extract the CKEditor library into a directory called ckeditor. The WYSIWYG module is now happy. Then I delete the sites/all/modules/ckeditor/ckeditor directory. Everything works properly again after I do a Drupal update. This is all quite amazing.
But the same procedure the CKFinder library fails. So like a damn fool, the I set out to find out why?

There is a point to all of this...

I would like to share the insights learned in this process and eventually become a Drupal contributor. This will be my first attempt. What follows is a tutorial on getting all of the modules listed in the title line working together. Over the next few days I will add, edit and clarify this post according to any feedback received here.

Where to begin?

This tutorial assumes that you may have already done the following according to the current instructions in the README.txt file in the ckeditor module.

  • installed the ckeditor module in sites/all/modules/ckeditor
  • installed the CKEditor library in a sites/all/modules/ckeditor/ckeditor directory
  • installed the CKFinder library in a sites/all/modules/ckeditor/ckfinder directory

< ---- A really big SNIP occurred here ---- >

The Update - July 7, 2012

I gave up on ckeditor for a while. It was made clear to me that I had it all wrong; that the ckeditor module and the wysiwyg module are incompatible, like oil and water. It was never meant to be. Then Drupal 7 came along and it was a long, long, time before any D7 version of the ckeditor module was ready.

I tried out the rival wysiwyg module with the ckeditor library (and without the ckeditor module enabled). The wysiwyg module has some excellent code contained within -- there is much to learn from it. They even disable the rival ckeditor module if it happens to be enabled. I think the name of that function should be Dont_fuck_with_me_bro() but that's just me..

But in the end, I found the wysiywyg module to be like that 27 function swiss army knife that is just too big to carry around camping. In addition, a special effort was needed to get the ckfinder library functioning. It required a bridge module from a sandbox project.

But what really irritated me with all the different module/library configurations was that there was no way to control the size of the edit box that appeared. I figured out how to adjust that size, but then every ckeditor widget that appeared was the same height, whether it was for adding a full page rant (like this) or a simple comment.

Why are the simplest things in Drupal so damn difficult?

I gave the latest ckeditor module another go recently, with some success.

Configuring the D7 ckeditor module and the CKEditor/CKFinder libraries

The good news is that it is now possible, with the latest versions of the ckeditor module, to locate the CKEditor and CKFinder libraries in /site/all/libraries rather than in subdirectories under the /sites/all/modules/ckeditor directory. I believe this is the case for both D6 & D7 versions of ckeditor.

The bad news is that the instructions for configuring ckfinder in the README file (and the accompanying code) are just as bad as they were 2 years ago, which is why I made the original post. You can read the original version if you want, even if I can't change the title of this post. Sigh.

Get to the point!

OK - kindly disregard most of the information in the ckeditor/README.txt file with respect to installing ckfinder.

Integrating the CKFinder library with the CKEditor library can be handled with the simple addition of a Drupal ckfinder configuration file -- drupal.config.inc-- to the /sites/all/libraries/ckfinder directory. It is intended as a replacement for the filemanager.config.php file found in the /sites/all/modules/ckeditor/includes/ directory.

/*
 * @file
 * A Drupal include file for adding ckfinder to a ckeditor instance vis-a-vis 
 * the drupal ckeditor module.  Copy this file to the root directory of
 * the ckfinder library and reference it with an include statement in the 
 * ckfinder file 'config.php'.
 *
 * The code sets ckeditor variables $baseUrl and $baseDir.  It replaces 
 * the ckeditor defaults, or the default values found in config.php.   
 */

/** 
 * Drupal bootstrap -- start_session() invoked -- allows drupal calls.
 *
 * Do a backward search through the directory tree for a signature file and then 
 * execute an appropriate drupal bootstrap. Return to the starting dir and 
 * resume loading.
 */
function _init_drupal_CKFinder() {
  global $baseUrl, $baseDir;

  $start_cwd = getcwd();
  $path = $start_cwd;

  // Cheater code to save time -- optimized for /sites/all/libraries/ckfinder config.
  // Comment out next line if it does not work.
  chdir('../../../../../..'); $path = getcwd();

  // single steps back thru each parent on the dir tree looking for drupal
  while(strlen($path) > 3) {
    $path = dirname($path);
    if( file_exists($path . '/includes/bootstrap.inc')) 
      break; 
  };
  chdir($path);
  
  require_once './includes/bootstrap.inc';
  define('DRUPAL_ROOT', getcwd());
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
  
  // Get back, get back, get back to where you once belonged. Beatles - Get Back (1968).
  chdir($start_cwd);
  //drupal_set_message("connector.php path was $start_cwd");

  // we should now have a $_SESSION array and other info -- set the ckfinder globals.
  if (isset($_GET['id'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath'], $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath'])){
    $_SESSION['ckeditor']['UserFilesPath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesPath'];
    $_SESSION['ckeditor']['UserFilesAbsolutePath'] = $_SESSION['ckeditor'][$_GET['id']]['UserFilesAbsolutePath'];
    $baseUrl = $_SESSION['ckeditor']['UserFilesPath'];
    $baseDir = $_SESSION['ckeditor']['UserFilesAbsolutePath'];
  } 
}

// Drupal bootstrap
_init_drupal_CKFinder();

/**
 * Replaces the CheckAuthentication() function in config.php.  The CKfinder
 * library invokes this function communication to the server in connector.php.
 * Note that user_access() is a drupal function.
 */
function CheckAuthentication() {
  return user_access('allow CKFinder file uploads');
}

There are two functions. The first does a drupal bootstrap and gets info from the Drupal server. The second function, CheckAuthentication() is called by ckfinder functions and replaces the CheckAuthentication() found in /ckfinder/config.php.

The key assignment here is to set two variables $baseUrl and $baseDir. These variables are referenced by the ckfinder library functions. The file config.php is the ckfinder hook to these variables.

A simple two step dance

Step 1 - After you have copied and pasted the above to drupal.config.inc in the root directory of the ckfinder library, edit the config.php file to include this file after the final reference to either $baseUrl or $baseDir. i.e.

$baseDir = resolveUrl($baseUrl);
include 'drupal.config.inc';

Step 2 - Comment out or remove the CheckAuthentication() function in config.php.

The drupal.config.inc will replace whatever $baseUrl and $baseDir have been set to if everything works properly.

If you comment out this include statement, then ckeditor/ckfinder work together like the standalone out-of-the-box product. This mode of operation is a great way to learn how ckeditor and ckfinder work together (see the demo files) and to get file and directory permissions sorted out. Add the include statement back in, and it's back into drupal mode of operation.

Edit those ckeditor profiles

After installing the ckfinder library and drupal.config.inc, it will be necessary to configure each ckeditor profile so that ckfinder is enabled. The first step is to add a file widget (like image) to the toolbar, the second step is to enable ckfinder under the File Browser settings. It's possible to give each user their own upload directory. Use the %u/ token (note the trailing slash), not %n, because if the user name changes, they can't see their previous uploads.

About that status report...

You can get everything working here but there remains one problem: The status report (/admin/reports/status) will report a ckeditor error -- it will ask you to review the file that I just asked you to disregard.

To eliminate this error, simply add the following 3 lines to libraries/ckfinder/config.php. If the require_once line in between /* */ markers, the error goes away.

/*
require_once '../../../includes/filemanager.config.php';
*/

Good luck and success with this if you try it. CKfinder/CKEditor are a couple of great apps once you get them working together.

-Dio

P.S. -ignore the patch below - I can't change or get rid of that either.

Comments

mjohnq3’s picture

Great tutorial! As someone who just went through most of this (I used IMCE instead of CKFinder) I'm sure many people will find this a very useful time-saver. Hopefully, this will be moved to the Handbooks section of Drupal.

Diogenes’s picture

Title: Configuring ckeditor and the CKEditor & CKFinder libraries - a tutorial » Getting the ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries working together - a tutorial
Version: 7.x-1.x-dev » 6.x-1.1
Status: Closed (fixed) » Needs review
StatusFileSize
new6.52 KB

@mjohnq3 - Thank you!

I have now figured out that you can't edit an original post if it's an issue. DOH!

9/26/2012 UPDATE - yes you can!

Diogenes’s picture

Title: Getting the ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries working together - a tutorial » Configuring ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries - a tutorial
Version: 6.x-1.1 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new7.45 KB

Attached is the same patch for 6.x-1.x-dev version of the ckeditor module.

Diogenes’s picture

Title: Getting the ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries working together - a tutorial » Configuring ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries - a tutorial
Version: 6.x-1.1 » 6.x-1.x-dev
StatusFileSize
new10.04 KB
new2.09 KB

<SNIP> - irrelevant now.

Diogenes’s picture

Issue summary: View changes

Added section to eliminate Status Report error

wwalc’s picture

We'll check the attached patches, but I don't quite understand why to use Wysiwyg module and CKEditor module at the same time (I assume that you were a little bit confused by the existence of two modules that provide the same editor - CKEditor).

Just to be sure - is it the final verison of a patch and filemanager.config.php or did you perhaps updated something later?

davepotts’s picture

"If all goes well then the next time you refresh the CKFinder Samples page, everything will work and you will have an Empty Folder to play with."

What if it doesn't? I can't seem to get past this step, even with an absolute URL to my userfile directory. Permissions are set correctly. Any ideas?

Diogenes’s picture

@davepotts

Need more info - current directory config, and any messages that may have appeared under "status report".

Have you applied the correct patch and are you using the new config files? Do the CKEditor user permissions look complete (with CKFinder) and correct (enabled for the right roles)?

You should be able to test out the CKFinder sample pages and they should work on their own. Then configure the drupal settings.

When I originally posted, I did not realize that one could not edit an original post. I made some mistakes in the OP (of course) and now I can't do much about that, except by posting addendums here.

I also developing on a windoze XP box (ugh!) which makes it a bit more challenging to create patches.

Also I have re-jigged my personal config so you can send me a message. I am better at responding when I know somebody has asked a question.

Cheers
-Dio

Compel’s picture

Two questions:

1. With all this coding gymnastics, does the final product work with Acquia Fusion themes? That's where the problem in displaying in IE7/8 browsers appears to be.

2. Is CKEditor really worth all this trouble? Would it make sense to just use an editor that works out of the box instead?

technobrarygeek’s picture

I have been working on this for DAYS, and, so far, NONE of them "works out of the box" It sucks.

CKeditor has the issues listed here and a problem displaying all the tools

FCKeditor is by and large deprecated to CKeditor besides it has issues with some themes and inline image uploading.

TinyMCE has decided it is smarter than we are when it comes to allowable html code so, without a series of arcane hacks it strips out <style> and <iframe> tags. Good luck getting 3rd party widgets to work.

Just my 2¢ worth on out of the box editors.

mjohnq3’s picture

@Compel

None of them works 'out of the box', you have to tinker with all of them.

You posted another issue about compatibility with Fusion themes. I haven't had any problems related specifically to Fusion. There's something about your installation/configuration that's likely causing the problem. Perhaps, a compatibility problem with other modules, especially any using jscript or jquery.

Compel’s picture

@mjohnq3

Thanks for the reply. I have indeed discovered you have to tinker with all of them. I was able to get CKEditor to behave, albeit with some additional tweaking needed (all of which is noted in the ReadMe.

The problem as noted elsewhere was related to CSS. Set CSS Optimization on and the problem of invisible CKEditor goes away. It's definitely a learning curve :-)

beren’s picture

I was looking at trying to go thru this on Drupal 7, but I wonder what is the advantage of CKFinder over IMCE. Is there anything in CKFinder that is a dramatic benefit over IMCE?

I looked at some of the samples and demos although it looks a bit nicer, I didn't see much else besides that.

jrsinclair’s picture

I've created a bridging module for WYSIWYG, CKEditor and CKFinder, to make this whole process a little easier. We'd love people to try it out and let us know how it goes-- just make sure that you read the installation instructions carefully.

PacketPaul’s picture

With regards to step 5, the required_once statement should go below the $baseDir line NOT below the $baseUrl line as specified in the instructions.

The config.php file should look as follows:

------------
$baseDir = resolveUrl($baseUrl);

require_once '../../../../includes/filemanager.config.php';
------------

The reason you place it below the $baseDir line is because filemanager.config.php sets the $baseUrl and $baseDir variables thus overriding the default values found in config.php.

agileware’s picture

@jrsinclair:

Any chance of posting the module on drupal.org?
In a sandbox instead of a project if you prefer at this stage.

iancu35’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

a brilliant module; any chance to be ported to drupal 7 on github or drupal.org; thanks

jrsinclair’s picture

@Agileware and @iancu35 - Thanks for the encouragement. A port to D7 and move into a d.o sandbox is in progress. Will post here when it's up.

jrsinclair’s picture

The sandbox module is now available at:

http://drupal.org/sandbox/jrsinclair/1348830

It has been updated to work for D7.

Diogenes’s picture

Issue summary: View changes

Update to reflect current D7 versions available.

Diogenes’s picture

Issue summary: View changes

PS message added

Diogenes’s picture

Title: Configuring ckeditor, WYSIWYG, IMCE modules and CKEditor & CKFinder libraries - a tutorial » Configuring ckeditor and the CKEditor & CKFinder libraries - a tutorial

Changed title of original post and its content.

I suppose this is a feature request to replace the filemanager.config.php file and related instructions with something a little easier to understand and debug.

Advantages:

  1. drupal.config.inc is an independant file that is not overwritten with a ckfinder library update.
  2. locating it in the ckfinder library root eliminates the clumsy and mysterious code constructs:
    require_once '../../../../includes/filemanager.config.php';
    or
    require_once '../../../includes/filemanager.config.php';
    and all dependence on the location of the ckfinder library.
Diogenes’s picture

Issue summary: View changes

Minor edits and removed someting that was incorrect.

jrsinclair’s picture

For anyone who's still reading this far down the thread, the Sandbox module mentioned in #18 now has a 1.0 release on drupal.org. You can find it at http://drupal.org/project/WYSIWYG-CKFinder and has an admin interface for entering licence keys and specifying file locations).

Many thanks to Carl Hinton (http://drupal.org/user/461094) and OPC IT (http://www.opc.com.au) for making this possible.

Diogenes’s picture

@jrsinclair - congratulations on getting that sandbox promoted to a project. I know that is not easy.

Thought I should mention that your module is for the WYSIWYG project and not this project (CKEditor - WYSIWYG HTML Editor). The two are quite incompatible.

kendouglass’s picture

Diogenes, I think you are really complicating everything. I recommend that people simply follow the instructions included with this module.

Diogenes’s picture

I recommend that people simply follow the instructions included with this module

What module are you speaking of? With all due respect, I think YOU may be in the wrong thread.

http://drupal.org/project/ckeditor

or

http://drupal.org/project/wysiwyg

???

THIS thread is about the first link; post #20 was referring to the latter.

The two modules are INCOMPATIBLE. The WYSIWYG project page makes no mention of this BUT IT SHOULD. That was the source of confusion 2 years ago when I made the original post.

Want proof of this? An excerpt of code from wysiwyg/wysiwyg.install file (line 87)

/**
 * Implementation of hook_enable().
 */
function wysiwyg_enable() {
  // Disable conflicting, obsolete editor integration modules whenever this
  // module is enabled. This is crude, but the only way to ensure no conflicts.
  module_disable(array(
    'ckeditor',
    'editarea',
    'editonpro',
    'editor',
    'fckeditor',
    'freerte',
    'htmlarea',
    'htmlbox',
    'jwysiwyg',
    'markitup',
    'nicedit',
    'openwysiwyg',
    'pegoeditor',
    'quicktext',
    'tinymce',
    'tinymce_autoconf',
    'tinytinymce',
    'whizzywig',
    'widgeditor',
    'wymeditor',
    'xstandard',
    'yui_editor',
  ));
}

@kendouglass - go look up module_disable() -- hey whadda know -- the wysiwyg module disables the ckeditor module. No warnings, nothing in the documentation, nothing on the drupal wysiwyg project page about this.

The above snippet of code, in the absence of all else, qualifies as a STUPID PROGRAMMING TRICK in my book. Go talk about it on Letterman someday. It has no place in a proper drupal module.

UPDATE: Sept 24 '12
My apologies about those oblique references -- "STUPID PROGRAMMING TRICK" and "Go talk about it on Letterman someday." I'm a foreigner and forget that some culture is not everywhere :-)

A long time ago on "Late Night With David Letterman" (a popular American TV talk show), one of the feature segments was "Stupid Pet Tricks". People would bring their pets on the show and have them perform a stupid trick. There, now you know the context.

On a final note, it appears that is a fix to the above issue is in the works. Should anyone be interested on how conflicts with other modules should be handled, please read the patch and discussion here:

wysiwyg Issues - Improve documentation about usage with other editor modules

dczepierga’s picture

@Diogenes, yes we know that WYSIWYG disable our module and we also know that they do that without any warning/info - i don't want to discuss here about that is correct way or not, because this thread is not for that... - this is their module and they can do everything what they want there.
In our module we also have this option, but we make it by warning where user can click and then disable incompatible module - this is our way...

Also pls don't write here about other modules and they way of doing sth - this issue was created as tutorial for users who search help in configuration of CKFinder and CKEditor module, so everyone should write here only about that...

Greetings

Diogenes’s picture

Status: Needs review » Closed (fixed)

@dczepierga - I understand your position (I think). Since I was the one that originally opened this issue, I hope you don't mind if I close it now. No use flogging a dead horse (another idiom).

The original post was intended to help others by sharing what I had discovered to make things work. But it was explained to me elsewhere on drupal.org that I had my head up my ass. There was no point or advantage of having both ckeditor and wysiwyg enabled. It's not supposed to work that way!

Then about a month after that (back in 2010), 'ckeditor' was added the list of modules disabled. IMHO, this was just lazy programming; there are better ways of doing this and the link in my previous post is a discussion on how. I think it could be the basis for a Drupal standard.

You are right, doing a code review here of another module is absurd. A better system is needed, like the one they have in place for newbies. But at present, it is sometimes necessary to Taser others into action. I don't like being thought of as an asshole, though many here probably think I am. Please think of me as an unhappy customer who is having serious thoughts about switching brands.

I'll close on this note -- there are some serious issues with quality control on some contributed modules.

Your team (ckeditor) is doing a pretty good job. I use your module (with a couple of tweaks) and I quite like it. You managed to handle the 3rd party library issue gracefully without requiring another module for that. The team is good at responding to issues too.

I wish that were the norm. It's NOT.

Status: Needs review » Closed (fixed)