SpamSpan prevents Extlink mailto image

zac - April 29, 2009 - 15:47
Project:External Links
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I am using both External Links and SpamSpan (http://drupal.org/project/spamspan). Both work great. However, since SpamSpan uses Javascript to render the mailto links, External Links doesn't detect this to place the little envelope icon beside it.

Just a little inconvenience that would be nice if it still worked!

#1

quicksketch - April 29, 2009 - 19:06
Title:External Links + SpamSpan = Broken» SpamSpan prevents Extlink mailto image
Category:bug report» feature request

Thanks, I'm not really sure what can be done to fix this problem, since making the e-mail links on the page hard to find is what SpamSpan is intended to do. If SpamSpan adds a specific class to replacements (I believe it's actually a setting) then ExtLink could in theory try to target those elements as well. But at the same time, since you already have a specific class, there's no reason why your own theme's CSS couldn't place the icon.

#2

Dane Powell - June 1, 2009 - 01:36

Actually SpamSpan does add the "spamspan" class to all generated links - this is not a user-configurable option, so we can count on it being there. Thus, I propose the following simple patch - let me know if this works for you. It seems to work perfectly on my site.

To do this really properly, I suppose we should test for the SpamSpan module first, but I'm not sure how to do that in conjunction with the CSS file, and it seems like overkill for such a trivial CSS modification.

AttachmentSize
extlink-448588-2.patch 342 bytes

#3

der_tisch - June 1, 2009 - 13:06

Maybe it is just a matter of the order in which the corresponding javascript functions are called.
Spamspan should be first. Extlink should be second.
Unfortunately I do not know how to control that, because I am quite new to Drupal.

#4

Dane Powell - June 1, 2009 - 13:21
Status:active» needs review

I could be wrong - I am fairly new to JS in Drupal as well - but I think what you are looking for is a way to define your script's "weight". Unfortunately, I don't think that feature exists in the D6 API (though it will in D7). (see http://api.drupal.org/api/function/drupal_add_js)

That's why I think tweaking the CSS is the next-best solution.

#5

Dane Powell - June 10, 2009 - 20:35

Is anybody able to test this patch and verify that it works (or provide alternate solutions?) It works fine on my site, and is pretty foolproof IMHO.

#6

Dane Powell - June 14, 2009 - 21:06
Version:6.x-1.7» 6.x-1.x-dev

#7

Dane Powell - June 24, 2009 - 20:09

@quicksketch: Will you please either commit this and mark as fixed or let me know if more work needs to be done, so I can get it out of my queue. Thank you.

#8

quicksketch - June 30, 2009 - 03:19
Status:needs review» needs work

Hey Dane, this patch will affect mail links even if the option to add the "mail" icon next to mailto addresses is disabled. I think a better approach would be to have the JavaScript add an extra "mailto" class to all spamspan links if that option is enabled.

#9

Dane Powell - July 1, 2009 - 16:29

Ah, good point. I don't know why I didn't think of that problem. I'll look into getting the necessary JS in place.

#10

Dane Powell - July 1, 2009 - 22:51

JS and jQuery are not really my forte; I tried adding the following code in extlink.js at line 57, but it breaks the script - "this" is undefined. Can you tell me what I'm doing wrong?

$("span", context).each(function(el) {
  try {
    var url = this.className.toLowerCase();
    if (url.indexOf('spamspan') == 0) {
      mailto_links.push(this);
    }
  }
  catch(error) {
    return false;
  }
});

#11

Dane Powell - July 2, 2009 - 20:42
Status:needs work» needs review

Nevermind - that code seems to work fine now. Maybe I just forgot to clear my cache or something. See attached patch.

AttachmentSize
extlink-448588-11.patch 564 bytes

#12

quicksketch - July 4, 2009 - 00:43
Status:needs review» needs work

So I installed SpamSpan today to test this out, and I realized we're going about it in a strange manner. SpamSpan should work automatically with External Links as long as the two following things are true:

1) SpamSpan uses Drupal.behaviors like it's supposed to: #361440: Breaks on ajax view filters
2) External Links runs *after* SpamSpan (so the the mailto: links are in place). This can be done by setting the External Links weight to 1 in the system table.

So we need some collaboration here. Extlink needs to make a .install file an set its weight to 1, SpamSpan needs to apply that patch to use Drupal.behaviors.

#13

Dane Powell - July 25, 2009 - 17:00

Actually this problem seems to be fixed on my site just by installing spamspan-6.x-1.x-dev . Can anyone confirm this? (I'm afraid it could just be a fluke from caches not getting flushed properly)

#14

quicksketch - July 25, 2009 - 22:21

I can't confirm that it works out-of-box for me. But with #361440: Breaks on ajax view filters fixed on the SpamSpan side, it's fairly easy to get it working for External Links. Just setting the weight of the module to 1 makes everything work for me.

UPDATE system SET weight=1 WHERE name = 'extlink';
TRUNCATE cache;

So now I think a extlink.install file is necessary to actually set the module weight on install/update, then everything should be good.

#15

Dane Powell - November 9, 2009 - 23:37
Status:needs work» needs review

Yep, that fixes it! I've never had to make an install file before, does this look good? (You'll have to remove the .txt extension, obviously - d.o wasn't happy about the .install extension)

AttachmentSize
extlink.install.txt 248 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.