Jump to content

CKEditor and Rel = nofollow


Pete
 Share

Recommended Posts

Hi guys

I've been trying to allow rel=nofollow in links when editing the source of a page in CKEditor but it strips them out when the page is saved. CKEditor version is 4.2.0 (older version of the module but not too old I don't think).

I can get it to work if I turn off the HTMLPurifier option in the field's Input tab but would rather not do that.

I thought perhaps something like a[rel](*) in the Extra Allowed Content field might work but it doesn't.

Any suggestions? I'm sure it will be something simple.

Link to comment
Share on other sites

The module docs say:
To specify custom settings to HTML Purifier, perform set() calls before calling purify().

So I guess something like this should work, if placed on top of your templates before you output your fields.

$purifier = wire('modules')->get('MarkupHTMLPurifier');
$purifier->set('Attr.AllowedRel', array('nofollow'));

I did not try this myself. If this doesn't work when placed in your template files I would try placing it in the admin.php in your templates folder.

  • Like 2
Link to comment
Share on other sites

Looking at the sources you seem to be right. The value gets saved already purified.

But it should work when you place the snippet in admin.php in your templates folder

An alternative way would be to edit InputfieldCKEditor.module in site/modules. Around line 262 the purifier is used and configured.

  • Like 1
Link to comment
Share on other sites

Thanks for the input guys - it didn't seem to work in the admin.php template and, yes, the actual frontend template would be too late.

For now, I edited the MarkupHTMLPurifier module and changed the purify() function around line 108 to this:

public function purify($html) {
    $this->set('Attr.AllowedRel', array('nofollow'));
    return $this->getPurifier()->purify($html);
}

That works a treat :)

I think it would be a relatively trivial task to make it so we can have config options with this module, so I might have a look into that over the weekend unless someone beats me to it!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...