Giter Site home page Giter Site logo

craft-emailobfuscate's Introduction

EmailObfuscate plugin for Craft CMS

A plugin to obfuscate email addresses in strings. Specifically intended to parse rich text field output in templates, find, and replace mailto links with obfuscated gobbledygook.

Super-basic usage. It's just a filter so use like so:

{{ entry.body|emailObfuscate }}

The method of obfuscation is borrowed directly from a person.

Credit

Thanks to Matt Stauffer since I took some notes from his Twig LinkHelpers plugin and to Barrel Strength Design's Sprout Encode Email plugin which I would have used instead of writing EmailObfuscate if only it handled searching through RTE output to find/replace mailto links.

craft-emailobfuscate's People

Contributors

jpwdesigns avatar

Stargazers

Oleg Tishkin avatar Mario Pizzinini avatar Branden Garrett avatar superflausch avatar  avatar

Watchers

James Cloos avatar Greg Hayes avatar  avatar

Forkers

zachshallbetter

craft-emailobfuscate's Issues

Auto convert address to mailto link as well

My content editors are lazy or unaware about mailto links, so I'd like the ability for it to search for email addresses patterns not mailto links. Then to obfuscate them and then wrap the mailto code around it. Is this an option you could help with?

I'm used to having this feature from ExpressionEngine and it's Auto Linker plugin.

Error if empty

I have a text field where|emailObfuscate which returns a error when the field is empty:

DOMDocument::loadHTML(): Empty string supplied as input

/craft/plugins/emailobfuscate/twigextensions/EmailObfuscateTwigExtension.php(54)

42      * @param string $string
43      * @return string 
44      *
45      */ 
46     public function emailObfuscate($string)
47     {
48         // Start the dom object
49         $dom = new DOMDocument();
50         $dom->recover = true;
51         $dom->substituteEntities = true;
52 
53         // Feed the content to the dom object
54         $dom->loadHTML($string);
55 
56         // Check each link
57         foreach ($dom->getElementsByTagName('a') as $anchor) {
58 
59             // Get the href
60             $href = $anchor->getAttribute('href');
61 
62             // // Check if it's a mailto link
63             if (substr($href, 0, 7) == 'mailto:') {
64 
65                 $anchor = $dom->saveHTML($anchor);
66                 $encoded = $this->js_rot13_encode($anchor);

It is preventable by wraping the field in a conditional. But it would be neat if the filter recognices a empty field.

PHP Warning when passing in an HTML string with certain HTML5 elements.

The loadHTML function in EmailObfuscateTwigExtension:emailObfuscate() doesn't recognize certain HTML5 elements, such as figure, which is inserted by another Craft plugin that we are using for image alignment. We got around this by calling this before the loadHTML function:
libxml_use_internal_errors(true);

And this after:
libxml_use_internal_errors(false);

See this article for more information:
http://stackoverflow.com/questions/9149180/domdocumentloadhtml-error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.