Page 1 of 3

[SOLVED] Cloaking Email Addresses

Posted: Fri Oct 22, 2021 11:19 am
by NorfolkGreg
It's been my practice over a number of years to use this snippet of JavaScript to cloak email address links on the web sites I produce, using this code:

Code: Select all

<script type="text/javascript">
	<!-- Begin
		who = "user";
		where = "mydomain.com";
		document.write('<a href=\"mailto:' + who + '@' + where + '\">');
		document.write('Email Me' + '<\/a>');
	// End -->
</script>
All was going well until I installed Summernote!

Now every time I edit the page I get multiple copies of the email link with the additional ones as standard mail link code

Code: Select all

<a href="mailto:user@mydomain.com">Email Me</a>
Is there a way to escape the Javascript so Summernote does not both leave the code on the page and produce its rendering of it. Editing the code direct through Summernote does not do it!

Re: Cloaking Email Addresses

Posted: Sat Oct 23, 2021 8:49 am
by NorfolkGreg
Still more tragic things happen when I use this code in my footer:

Code: Select all

<p>&copy; 2008
	<script>
	new Date().getFullYear()>2008&&document.
	write("-"+new Date().getFullYear());
	</script>
	Organisation Name
</p>
to generate a line: "© 2008 -2021 Organisation Name"

The entire page disappears leaving me with just

-2021

on the screen!

Re: Cloaking Email Addresses

Posted: Thu Nov 04, 2021 9:56 am
by OneManLaptop
Yeah, had a bizarre thing a few days ago. Edited the source of one site online and all the prices in my food menu vanished. The CMS definitely needs some TLC.

Re: Cloaking Email Addresses

Posted: Thu Nov 04, 2021 10:18 am
by NorfolkGreg
Normally, I say it was probably a minor mis-keying that did that, but having looked at your Irish Pub site I know you have the skills to avoid any obvious mistypings. More likely you're right and it was a bug in Summernote.

I confess I hate what the Summernote editor does to one's carefully crafted and neatly indented code, but that's pretty standard for WYSIWYG code editors and, I guess, has to be tolerated, so one's users don't have to be intimidated into learning how to wrap content in a few simple HTML tags. I haven't checked but I strongly suspect that if I removed Summernote I could retain my JavaScript and keep email addresses cloaked.

Re: Cloaking Email Addresses

Posted: Thu Nov 04, 2021 11:30 am
by OneManLaptop
NorfolkGreg wrote: Thu Nov 04, 2021 10:18 am Normally, I say it was probably a minor mis-keying that did that, but having looked at your Irish Pub site I know you have the skills to avoid any obvious mistypings. More likely you're right and it was a bug in Summernote.

I confess I hate what the Summernote editor does to one's carefully crafted and neatly indented code, but that's pretty standard for WYSIWYG code editors and, I guess, has to be tolerated, so one's users don't have to be intimidated into learning how to wrap content in a few simple HTML tags. I haven't checked but I strongly suspect that if I removed Summernote I could retain my JavaScript and keep email addresses cloaked.
Well that's very kind of you to say so. :)

A lot of Wonder CMS's development is tied up in Summernote, which makes things tricky for Wiz and co. I edited the site the other day using it and it all worked like a dream, but I won't be poking around in the source code without making a full backup!

My main concern right now is the image handling, every other week I have to run behind a client and edit the images they upload, because there's no resizing / resaving happening, so clients are uploading huge images to their site and obviously it kills performance.

I'm also changing my mind about having the save be automatic. I had a client do half an edit on their site, delete a load of things and then he was called away, but of course all his edits up to that point had been saved and were active on the live site so it was a huge mess and I had to quickly upload an old version, so I think that will need changing to force the user to explicitly save their updates. Be handy if they could store their edits in a temp file so they get the best of both worlds.

Only so many hours in the day, I wish I knew more about PHP / JSON so I could help them out.

Re: Cloaking Email Addresses

Posted: Thu Nov 04, 2021 3:31 pm
by NorfolkGreg
To avoid topic drift I've opening two new topics Image Handling and Auto Save Issues.

Re: Cloaking Email Addresses

Posted: Mon Nov 08, 2021 4:52 pm
by NorfolkGreg
I think this topic got marked [SOLVED] in error. My fault! We seem to have spawned a couple of additional issues.

I still wonder if there's a way to stop Summernote processing my JavaScript code to cloak email addresses. And here I must remind others my own understanding of JavaScript is extremely limited, so I need very basic instructions.

For example, could I simply include in my theme calls to external JavaScript files to generate the email addresses. Would having them outside the database stop Summernote processing them?

Re: Cloaking Email Addresses

Posted: Thu Feb 03, 2022 6:03 pm
by NorfolkGreg
I now realise that it's not Summernote that process the JavaScript. I have removed it from my site and I still find that the uncloaked email address appears in the code after the page is saved. :-(

Has anyone a suggestion on how to include email links in WCMS?

Re: Cloaking Email Addresses

Posted: Fri Feb 04, 2022 12:03 am
by wiz
I don't think this is easily solvable, as document.write will always write the additional content each time you edit it. There's currently no way to disable JS parsing without probably breaking some WonderCMS websites that utilize it in some way.

You can also do some tricks with CSS: https://www.labnol.org/internet/hide-em ... ges/28364/
Or manually input the script somewhere in your theme.php to display it anywhere you want.

Re: Cloaking Email Addresses

Posted: Fri Feb 04, 2022 12:23 am
by NorfolkGreg
Thanks for the thoughts and the link.!
I hadn't encountered the CSS hiding technique previously. I'll investigate that further.
I had wondered whether one could avoid the JS parsing by including the JavaScript in an external PHP include file, but that's probably naive and demonstrates how little I know about both JavaScript and PHP!