Automatic Email Address Protection PHP / JavaScript

Date: 27th October 2008 at 7:44 pm | Filed under: development, scripts | Author: Sam Burdge

It is important to protect email addresses on websites from being harvested by spambots.

"Email spambots collect e-mail addresses from the Internet in order to build mailing lists for sending unsolicited e-mail, also known as spam. Such spambots are web crawlers that can gather e-mail addresses from Web sites, newsgroups, special-interest group (SIG) postings, and chat-room conversations. Because e-mail addresses have a distinctive format, spambots are easy to write. A number of legislators in the U.S. are reported to be devising laws that would outlaw the spambot." – Wikipedia

This is my method for automatically detecting email addresses and replacing them with a javascript that will disguise them from spambots. The script works in two stages one in javascript and the other in php.

First the javascript function that outputs the mailto link:

function sb_email(user,site){
document.write('<a href=\"mailto:' + user + '@' + site + '\">');
document.write(user + '@' + site + '<\/a>');
}

The function has 2 parameters "user" and "site", which are the two parts of the email address either side of the "@". This function can be called like so:

sb_email('joe','bloggs.com');

The second part is the php functions that recognise email addresses and replace them with the javascript function to disguise them:

//function to output the js
function create_js ($matches){
$parts = explode ('@', substr ($matches[0], 1));
if(substr($parts[1],-1)=='.'){$parts[1]=substr($parts[1],0,-1); $parts[2]='.';}
$str = $matches[1].'<script language="JavaScript" type="text/javascript">';
$str .= 'sb_email("'.$parts[0].'", "'.$parts[1].'");';
$str .= '</script>'.$parts[2];
return $str;
}
$js_callback = "create_js ";
 
//function to recognise emails
function email_protect($text){
global $js_callback;
$replace = '/([> ])[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}/i';
$output = preg_replace_callback($replace, $js_callback, $text);
return $output;
}

The email_protect php function can be called on any text string like so:

echo email_protect($text);

It will automatically replace any email addresses in the text with the javascript, therefore hiding them from spambots.

Leave a Comment

Control Arms Flash Viral Game

Date: 22nd October 2008 at 8:09 pm | Filed under: flash, portfolio | Author: Sam Burdge

This viral game built for controlarms.org is my most recent Flash project. The game has been translated into 4 other languages – French, Spanish, Potugese and Arabic. The object of the game is to catch as many bombs in the dustbin as you can before 5 drop. Once completed you can follow the "Take Action" link to lobby your MP in the form of an email.

Check it out: www.controlarms.org/en/games/catch-bombs

Leave a Comment

Time delay loading for swf files and images

Date: 26th March 2008 at 11:54 pm | Filed under: actionscript, development, flash, scripts | Author: Sam Burdge

Q. How can I make an image or swf file load after a specified number of seconds?

A. Use the simple but effective flash_timer.swf file by Sam Burdge. Whoopeee!

Ever wanted a particular Flash movie or image to load up / start playing after the rest of your page has loaded, or after a set amount of time? This tutorial, and the support files provided with it will make it very easy indeed. The flash_timer.swf file will load a swf or image into your page after a number of seconds that you specify.

Example:

Check out this basic example to see a swf (called test.swf) load after a 10 second delay: Example 1
You can view the source code of the example to see how it works.

Usage:

  1. Download the source files using the link below, and unzip the archive.
  2. Embed the swf file 'flash_timer.swf' into your webpage. In my example I have used the swfObject method to embed the file, but you can use whichever method you prefer. For more information about this you can check this useful tutorial by Jeroen Wijering.
  3. Set the height, width & background colour of the swf according to those of the file you want to load in.
  4. Pass the two variables that the file requires to work: myswf – the file that will be loaded & mysecs – the number of seconds delay before the file is loaded. You can pass the variables in the url string, for example:

flash_timer.swf?myswf=my_movie.swf&mysecs=5

(This will load the movie 'my_movie.swf' after a 5 second delay.)

You can also pass the variables as flashvars, for example:

flashvars="myswf=example.jpg&mysecs=10"

(This will load the image 'example.jpg' after a 10 second delay.)

I hope you find this useful, if you do or if you have any questions, please feel free to leave a comment on this page (no emails please, I won't reply unless you are offering me hard cash!!). The flash_timer.swf file is only 1kb, so it will not effect the overall loading time of your page, it can be embedded at any height/width dimensions and works from flash player 7 upwards.

Download Source:

The download contains the all important flash_timer.swf plus a working example (index.html). The size of the zip is 6kb. Enjoy!!


4 Responses to “Time delay loading for swf files and images”

  • Comment by Bob Stone
    Date: May 12th, 2008 at 1:32 pm

    Excellent, excellent, excellent! spectacular! stupendous!

    Was exactly what I was looking for.
    And does exactly what you said it would do!
    Can’t say that about many other things I’ve downloaded - including stuff I’ve paid for!

    Good show!

  • Comment by Wayne Moran
    Date: June 21st, 2008 at 1:40 am

    Great tool - well done. One issue however: how can I prevent my video from repeating / looping continuiously. I have tried setting &loop=false as part of passing the swf filename and I have set it in the calling code as well but it ignores them. See the code below:

  • Comment by Nathan
    Date: September 10th, 2008 at 10:14 pm

    I have the same problem as Wayne Moran. I would like the flash to run only once, as the constant repeating would detract from the sight and prevent the point of the flash from being made.

  • Comment by dave.com
    Date: September 19th, 2008 at 5:57 pm

    Works perfectly… Amazingly simple…see http://www.hotmix.org

Leave a Comment

WordPress - Change Default Email Address Plugin

Date: 20th February 2008 at 12:04 am | Filed under: development, plugins, wordpress | Author: Sam Burdge

This WordPress plugin changes the default email address that all notifications sent from your blog are addressed from. The default address for all emails sent by your blog is currently wordpress@ yoursite.com.

I had seen some tutorials / forum entries previously where people suggested editing the core WordPress file 'pluggable.php' to overide this default. This method does work, however you would have to repeat the hack every time you upgrade to a new version of WordPress so it is not an ideal solution.

Faced with this problem for a site I was working on recently, I wrote this basic plugin which allows you to configure your own email address in the format: Your Name <yourname@yoursite.com>.

Installation:

  1. Upload the file wp_change_default_email.php to your wp-content/plugins folder
  2. Activate the plugin from the Plugins page in WordPress

Usage:

  1. In the Plugins page in WordPress click the edit button next to the plugin in the list.
  2. Scroll down until you see a note saying 'Configure it'
  3. Enter your name and email as shown
  4. If you don't enter a new address the default 'wordpress@' will remain

Download:


5 Responses to “WordPress - Change Default Email Address Plugin”

  • Comment by Shane
    Date: February 29th, 2008 at 8:33 am

    Works great - thank you!

  • Comment by Change Default Email Address » Wordpress Plugins
    Date: July 9th, 2008 at 6:56 am

    [...] Version: 0.1 - License: n/a - Author: Sam Burge - Plugin Page - » Download [...]

  • Comment by Shane
    Date: August 25th, 2008 at 10:27 pm

    Is there a newer version than 0.1? I upgraded to WordPress 2.6.1 and the Plugins area is telling me that there is a new version, but the new version links to:
    GALLERY LIGHTBOX PLUGIN
    http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/

    Also, just an FYI, version 0.1 now conflicts with the Subscribe2 plugin.

  • Comment by Greg
    Date: September 17th, 2008 at 8:06 pm

    Very handy little plug-in, works like a charm, thanks.

    I’m experiencing a little weirdness, though. I downloaded it from your site. When I install it, it works fine but I get an alert telling me there’s a new version 1.3 (the code says “Version 0.1″) and the link to get the new version points at http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/ which is clearly wrong. The “Upgrade automatically” option doesn’t work either, with the error mentioning wp-25-gallery.

    Since it works, the only reason I care is I don’t want the little orange flag over “Plugins” in my dashboard, but seems like something you’d want to know.

  • Comment by huski
    Date: October 23rd, 2008 at 10:19 am

    wordpress 2.5
    not working for me, i made the two changes , name and email to the php file, verified the changes were saved in the php file, but it continues to send wordpress and wordpress@domain

    ????

Leave a Comment

WP Instructions Plugin

Date: 19th February 2008 at 10:07 pm | Filed under: development, plugins, wordpress | Author: Sam Burdge

As someone who regularly sets up WordPress sites for clients, often with bespoke themes and various plugins installed, I find it useful and helpful to include basic instructions for them. I used to send a text document to them by email when I handed the site over, but more recently have been including an instructions page as a tab in WordPress.

This plugin allows you to create a custom instructions page for a wordpress blog. Especially useful for those setting up WordPress sites for other people. You can use it to provide instructions for use of specific plugins etc.

Installation:

  1. Upload the wp_instructions folder to your wp-content/plugins folder.
  2. Activate the plugin from the Plugins page.

Usage:

To create your custom instructions simply edit the instructions.txt file in the wp_instructions folder. You can use html if you want. Numbered lists are a good format for giving step-by -step instructions.

Handy Tip:

As pointed out by David A (See comments for this post) you can use WordPress to create an instructions page and save it as private. You can then copy and paste the code from the code view of the WP text editor into the plugin's instructions.txt file, thus creating an html formatted instructions page without having to write any html yourself.

Download:


20 Responses to “WP Instructions Plugin”

  • Comment by Sam Burdge
    Date: March 2nd, 2008 at 5:19 pm

    Hi all,
    Just a quick note to users of this plugin - the plugin is currently set so that all user levels are able to view the instructions. If you wish to change this so that only users of a certain level (i.e Authors or administrators) are able to view the instructions you can change the following line in the plugin's code:

    add_menu_page('WP Instructions', 'Instructions', 1, __FILE__, 'wp_instructions_page');

    Replace the number 1 with the number that relates to the user level you want. For more info about user levels please visit this page on the wordpress site Levels and Users for WordPress.

    Also for non-english users you can always replace the word 'Instructions' with the translation in your own language.

    I hope these tips come in handy.

    Sam

  • Comment by Ken savage
    Date: March 4th, 2008 at 3:58 pm

    Hey Sam, nice plugins. thx for sharing.

    Woould you be willing to share the instruction you give out for new people accessing wordpress? I'm turning over a new site to another group in my company and this would save me a few hours of writing and creating screen shots.

  • Comment by David
    Date: March 4th, 2008 at 10:58 pm

    The download is an empty file!?!?

  • Comment by Sam Burdge
    Date: March 9th, 2008 at 1:54 pm

    Hi Ken,
    All of the instructions I have written are generally to do with using specific plugins like Podpress or ANIga. They would probably not be that useful to you. You could always take some of the instructions from the wordpress.org site and summarise them.
    Sam

  • Comment by Sam Burdge
    Date: March 10th, 2008 at 10:01 pm

    Hi David
    This problem (in IE only) should be solved now. Appologies for the inconvenience.
    Sam

  • Comment by David A
    Date: March 18th, 2008 at 3:18 pm

    Hi, nice idea! However, I'm wondering if it can be modified to pull a specific page from Wordpress instead of using a text file. That way you could use WP's page editor to edit up your instructions with formatting.

    So far, it appears that if you were to create a page template with no header, sidebar, footer- just the page content code, then create a page in WP, make it private, and use that blank page template, it should work fine as a replacement for Instructions.txt under your plugin (provided the path is changed in the plugin).

    You'd probably need to use pretty permalinks to keep the path stable, or provide a selector within the plugin page to pick the right page, but otherwise it should work fine? Does this sound workable/useful, or have I strayed too far from the path (again) ? :)

  • Comment by Sam Burdge
    Date: March 19th, 2008 at 7:31 pm

    Hi David,
    Thats an interesting thought. I will think about integrating such a feature for a future release of the plugin.
    Sam

  • Comment by David A
    Date: March 20th, 2008 at 3:59 pm

    Hi again, I discovered that by using WP to create a Private page of instructions, you can copy and paste from the Code view into the Instructions.txt, and it displays perfectly.

    You will still likely need to upload the text file into the plugin folder (your server directories, like mine, are probably not writeable for security reasons), but at least you can use WP to write and maintain the instructions.

    Thanks again for such a great idea, and donation incoming!

    David
    p.s. The captcha system is giving me a headache, three tries and no luck so far. I'm triplechecking before submitting, and it sure LOOKS right…

  • Comment by Sam Burdge
    Date: March 23rd, 2008 at 5:35 pm

    Hi David
    Thanks. I'm glad you found it so useful.
    Sam

  • Comment by Weathervane
    Date: March 25th, 2008 at 10:01 pm

    I can't find a download link for any of your plugins. Am I missing something?

  • Comment by Sam Burdge
    Date: March 26th, 2008 at 10:57 pm

    @Weathervane: Hi, erm… the big button that says 'download file' under the heading 'Download:' at the bottom of each plugin post!

  • Comment by Kevin
    Date: April 8th, 2008 at 12:46 pm

    The plugin doesn't work op wp 2.5 :(

  • Comment by Sam Burdge
    Date: April 12th, 2008 at 10:48 pm

    @Kevin: I have tested it on WP 2.5 and it works fine for me. Have you tried re-installing the plugin?

  • Comment by Leon
    Date: April 14th, 2008 at 1:07 pm

    Hi Sam

    Nice plugin. Was looking for something like this. The WP admin plugin manager states that there is a 1.0 version, but the HTML link refers to your flash clock plugin. Maybe you can fix this?

  • Comment by Christopher
    Date: April 15th, 2008 at 2:44 pm

    Just installed it and I think it is a great little plugin - really useful, many thanks for your hard work.

    It did not seem to like it that I have not installed WordPress in the root (blog homepage is in different directory from where WordPress is installed), so had to edit the plugin to point it at the right directory for the text file.

    I also just noticed that WordPress is suggesting an update but linking to wp-digi-clock-plugin-01beta

  • Comment by Christopher
    Date: April 15th, 2008 at 2:50 pm

    Sorry, could have been more useful if I had included my edit.

    Changed get_bloginfo(’url’) for get_bloginfo(’wpurl’)

  • Comment by Casey
    Date: May 30th, 2008 at 5:49 pm

    I keep downloading and upgrading, but it keeps telling me that a new version is available. The zip I download produces a folder name wp_instructions_01, with another wp_instructions folder within. No matter which folder I put up there, the plugins page says there’s a newer version available.

    could you please check to see if the package is correct? I’m using 2.5.1. I read that your plugin was compatible with 2.5x…. please advise if this isn’t true, thanks!

  • Comment by WP Help : Pressing Pixels | A Wordpress Magazine
    Date: June 4th, 2008 at 10:10 pm

    [...] I came across a plugin that did this but is was not easily updatable and had some issues with a couple of installations. So I’ve improved on it and here is WP Help inspired by Sam Burdge’s wp-instructions. [...]

  • Comment by Laran Evans
    Date: July 19th, 2008 at 5:21 am

    Hey Sam. Neat plugin.

    I did run into some issues due to the use of the fopen function.

    I wrote a plugin that generates a table of contents for content.

    Someone contacted me today saying that they wanted to integrate the table of contents with your instructions plugin. So I did. I also fixed the fopen bug.

    So, here’s a link to the integrated code (just the .php file, not instructions.txt) along with two screenshots. One screenshot is when my table of contents plugin is activated. The other is when it’s de-activated.

    http://tinyurl.com/5n3qj6

    Now I’m going to go check out the WP Help plugin :)

    Enjoy!

  • Comment by Laran Evans
    Date: July 19th, 2008 at 5:23 am

    I forgot to give the url of my plugin. Here it is:

    http://wordpress.org/extend/plugins/wordpress-table-of-contents/

Leave a Comment