I believe I have developed a fix for excluding Fckeditor from specific textareas. The problem originally was that Fckeditor would only check for element['#id'], which would usually appear as simply "edit-body" or somesuch in the form.

To resolve this so that we can exclude specific textareas precisely, I've modified the function fckeditor_process_textarea() to add "-$nid" (the $node->nid or node id #) to the end of the results of element['#id']. This also gives administrators the ability to exclude fckeditor from entire nodes.

This code can (and should) be further refined to exclude entire site sections such as "admin," "user," etc. This would probably be accomplished by tying it to paths instead of node id's. I'll work to add this instead and post the updated code here--any help / suggestions appreciated.

I'd also like to know how to create a patch (I'm on a Windows platform) to make it easier for everyone to apply. Any help with that would be appreciated. I'm usually on one of the #drupal IRC channels as "JoshuaL". Thanks to dfletcher and chx for providing coding help and direction.

/**
 * This function create the HTML objects required for the FCKeditor
 *
 * @param $element
 *   A fully populated form elment to add the editor to
 * @return
 *   The same $element with extra FCKeditor markup and initialization
 */
function fckeditor_process_textarea($element) {

/** Added to include '-$nid' to $element['#id'] so fckeditor can properly 
catch specific textareas. Will change id of both textarea and textarea label. */
if (arg(0)=='node' && arg(2)=='edit') $nid = arg(1);
$element['#id'] = $element['#id'] . '-' . $nid;

$exclude = preg_split("/[\s,]+/", strip_tags(variable_get("fckeditor_exclude", '')));
CommentFileSizeAuthor
#2 fckeditor.patch685 bytesJoshLangner

Comments

JoshLangner’s picture

Status: Needs work » Active
JoshLangner’s picture

StatusFileSize
new685 bytes

Here's my first patch ever. Suggestions / recommendations would be helpful!

ontwerpwerk’s picture

I like the idea, and it might be usefull in real life situations too, so I'll see if I can include it as soon as I fix the next problem...

Which is that the interface for enabling or disabling that textarea is so far away... all over in administer >> settings >> fckeditor

JoshLangner’s picture

What approach are you taking for that? My thought would be to add a checkbox to enable / disable the editor directly on the edit-node page under the textarea. Could even tie in some JS to make it dynamically appear / disappear. A global textarea exclusion (in fckeditor >> settings) should override the appearance of the checkbox option for specified nodes (nid), sections (admin/*), textarea id's, or textarea types (i.e. 5 lines or less). I think this would easily tie in to the code I submitted above.

JoshLangner’s picture

I've updated my patch code to append the URL of the page to the textarea and textarea label ID's, so that you can disallow per page and per textarea. This makes wildcard excludes more fun. Here are some examples:

  • *edit-log-*node-21-* Excludes fckeditor from displaying ONLY on the log textarea of node 21
  • *node-21-* Excludes fckeditor from displaying on the entire page of node 21
  • *admin-* Excludes fckeditor from displaying on ANY admin page

You just need to paste the following code at the top of the fckeditor_process_textarea function in fckeditor.module.

function fckeditor_process_textarea($element) {

/** Added to include PAGE URL to $element['#id'] so fckeditor can properly 
catch either / both specific textareas and specific pages. Will change id of
both textarea and textarea label. */
$fckpageurl = str_replace('/', '-', request_uri());
$element['#id'] = $element['#id'] . $fckpageurl;

It could probably still use some tweaks. Help is always welcome.

ontwerpwerk’s picture

wouldn't

<?php
$fckpageurl = str_replace('/', '-', $_GET['q']);
?>

be better?

JoshLangner’s picture

Yes, this would be a slightly faster method. I added a '-' to the front of $fckpageurl in the second line, since using $_GET['q'] does not start with the beginning slash like requesturi() did. Here's the updated code:

/** Added to include PAGE URL to $element['#id'] so fckeditor can properly 
catch either / both specific textareas and specific pages. Will change id of
both textarea and textarea label. */
$fckpageurl = str_replace('/', '-', $_GET['q']);
$element['#id'] = $element['#id'] . '-' . $fckpageurl;
lias’s picture

Title: Complete Fix for Exclusion + New Exclusion Control Ability » Exclusion + New Exclusion Control Ability Fix work for 5.0

Thank you, thank you Joshua Langner , this works great on my install of 5.0. I was having the worst time trying to get adsense to work in a block but now all is good.

ontwerpwerk’s picture

Status: Active » Fixed

an option to work with paths is in the current development release

Anonymous’s picture

Status: Fixed » Closed (fixed)