Jul 05, 2009, 09:33 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2   Go Down
  Print  
Author Topic: [Plugin] Email Link Obfuscator  (Read 11182 times)
0 Members and 1 Guest are viewing this topic.
cyberk
Jr. Member
*
Posts: 44

Andrew Berkowitz


WWW
« on: Jan 26, 2006, 01:51 AM »

First day playing with MODx and very impressed.

Here's a little plugin to obfuscate email links with Javascript.

It basically scours the page for mailto: email links, and if it finds one it obfuscates it before sending the result to the browser. Yes, this is kind of a brute force method, but for our clients we find it's MUCH easier to just let them enter email addresses as normal and to obfuscate them on-the-fly than making them remember to enter one via some sort of snippet code. I suppose this could easily be re-written as a Snippet to let you choose which bits of content you wanted to scour for obfuscation, but as a plug-in it's set it and forget it for the entire site.

To install:

1. Create a new Plugin named whatever you want (i.e. Email Obfuscator).

2. Under System Events, check the OnWebPagePrerender event.

3. Save and enjoy.

Assuming everything works right, all the regular email links on every page on your site should be obfuscated with Javascript. No guarantees as to the spambot-proofness of the actual obfuscation, and please note that it does NOT obfuscate email addresses that are written outside a mailto: link.

And with all that said, here's the plugin:

Code:
function replaceEntities($str) {

       $str=html_entity_decode($str);

for ($i = 0 ; $i < strlen($str) ; $i++) {
$strreplaced = $strreplaced . "&#" . ord($str{$i}) . ";";
}
return $strreplaced;
}

function emailaddress($matches) {

$strNewAddress = replaceEntities($matches[1]);

$strText = replaceEntities($matches[2]);

$arrEmail = explode("&#64;",$strNewAddress);

$strTag = "<script language='Javascript' type='text/javascript'>" . "\r";
$strTag = $strTag . "<!--" . "\r";
$strTag = $strTag . "document.write('<a href=\"mai');" . "\r";
$strTag = $strTag . "document.write('lto');" . "\r";
$strTag = $strTag . "document.write(':" . $arrEmail[0] . "');" . "\r";
$strTag = $strTag . "document.write('@');" . "\r";
$strTag = $strTag . "document.write('" . $arrEmail[1] . "\">');" . "\r";
$strTag = $strTag . "document.write('" . $strText . "<\/a>');" . "\r";
$strTag = $strTag . "// -->" . "\r";
$strTag = $strTag . "</script><noscript>" . $arrEmail[0] . " at " . "\r";
$strTag = $strTag . str_replace("&#46;"," dot ",$arrEmail[1]) . "</noscript>";

return $strTag;

}


$modx->documentOutput=preg_replace_callback("#<a[^>]*mailto:([^'\" ]*)['\" ]>([^<]*)</a>#i","emailaddress",$modx->documentOutput);
« Last Edit: Mar 20, 2006, 12:34 PM by cyberk » Logged
Commodore64
Moderators
*
Posts: 93



WWW
« Reply #1 on: Jan 26, 2006, 02:58 AM »

I had to replace the occurrences of "documentContent" with "documentOutput"  Huh

After that, the plugin worked like a charm. Very cool  Grin
Logged
sottwell
Documentation Team
*
Posts: 8,837



WWW
« Reply #2 on: Jan 26, 2006, 03:25 AM »

A plugin on the first day?  Ooooh!  Always very happy to see a professional join the community! (your site is really nice, too!)
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
davidm
MODx evangelist
Marketing & Design Team
*
Posts: 7,026


Software is like sex, it's better when it's free !


WWW
« Reply #3 on: Jan 26, 2006, 03:30 AM »

Yeah, nice one, and on your first day pretty amazing...
Amazing we have two antibot plugins in the same week Tongue

And Susan, thanks for attracting our attention on cyberk's website : indeed very very nice ! Waow... And also : I very much like your approach of webdesign, first class Grin ...glad to have you there !
« Last Edit: Jan 26, 2006, 03:37 AM by davidm » Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez ŕ l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accčs pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.67 - PHP 5.2.8 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
cyberk
Jr. Member
*
Posts: 44

Andrew Berkowitz


WWW
« Reply #4 on: Jan 26, 2006, 10:10 AM »

Thanks, all!

Can someone explain the difference between documentContent and documentOutput? Both seem to work equally well for me here?
Logged
OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,814


damn accurate caricatures...


WWW
« Reply #5 on: Jan 26, 2006, 10:29 AM »

$modx->documentContent is used internally by the parser to store the output of a document, and can be retrieved dynamically from the DB or from the cache, depending on certain settings.  However, the final portion of the parsing process, which is responsible for parsing uncached snippet tags and replacing any remaining placeholders in the content, uses $modx->documentOutput to collect the final bits of uncached page data and merge it into the $modx->documentContent.  Then it checks to see if the $modx->documentContent was generated from the database (vs. retrieved from cache), and if so, it caches the $modx->documentContent while still outputting the $modx->documentOutput.

In other words, $modx->documentContent is the potentially cacheable content for a page, while $modx->documentOutput represents the final output to be delivered following final processing that occurs on all pages, regardless of the cacheability.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa
cyberk
Jr. Member
*
Posts: 44

Andrew Berkowitz


WWW
« Reply #6 on: Jan 26, 2006, 10:31 AM »

Thanks, Jason!

I updated the code above.
Logged
Kunal Kapoor
Full Member
***
Posts: 145


Effective, Functional, Standards Compliant


WWW
« Reply #7 on: Jan 28, 2006, 09:07 AM »

This plugin works a treat. Thanks a lot. This should be added to the REPOSITORY. This is much easier to use than my little snippet.
Logged

Kunal Kapoor
Technical Director
Limesharp Internet Limited - Effective, Functional, Standards Compliant

IRC Nick: KingKoopa
Skype ID: KingKoopa16
Djamoer
Emeritus
******
Posts: 1,495

No one can limit a man other than the man himself.


WWW
« Reply #8 on: Jan 28, 2006, 10:04 AM »

Thanks for bringing this up. Link added. Wink Thanks for the great plugin as well. I'm looking forward to all your new invention with MODx Grin
Logged

dernier_recours
Member
**
Posts: 83



« Reply #9 on: Mar 19, 2006, 11:40 AM »

The plugin does not allow rendering of special characters. For example, <a href="mailto:email@email.com">événement</a> will be shown as a link &eacute;v&eacute;nement.
Logged

at the edge of dawn,
you ask yourself if your shadow did follow you down
all night long
Aikdo
Jr. Member
*
Posts: 43


« Reply #10 on: Mar 20, 2006, 09:36 AM »

AMAZING snippit my only thing would be with any sort of bot would not have Javascript enabled and so your comment about spambot proofness is good in the fact it would only obscure it against your end user... shame really i really like the idea...
Logged
zi
MODx Special Forces /
Administrator
*
Posts: 3,329


May Peace Be On You


WWW
« Reply #11 on: Mar 20, 2006, 10:30 AM »

This plugin is very good!

..and it would be great if someone adds the functionality asked 2 posts up here.

Thanks for sharing.

regards,

zi
Logged

cyberk
Jr. Member
*
Posts: 44

Andrew Berkowitz


WWW
« Reply #12 on: Mar 20, 2006, 12:40 PM »

The plugin does not allow rendering of special characters. For example, <a href="mailto:email@email.com">événement</a> will be shown as a link &eacute;v&eacute;nement.

Great catch. I've fixed the plug-in to handle special characters correctly.

The code in the original post has been fixed. Either replace code with fixed code, or simply add this line:

$str=html_entity_decode($str);

as the first line in the replaceEntities function. That's the only change necessary.

Thanks!
Logged
Colin
Full Member
***
Posts: 188

I love MODx!


« Reply #13 on: Apr 11, 2006, 07:54 PM »

This may be a stupid question, but that's never stopped me before: what happens if the visitor has JS disabled?
Logged
cyberk
Jr. Member
*
Posts: 44

Andrew Berkowitz


WWW
« Reply #14 on: Apr 12, 2006, 09:09 AM »

This may be a stupid question, but that's never stopped me before: what happens if the visitor has JS disabled?

It will display "name at address dot com"

At least, I'm pretty sure that's what it does.
Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!