<?php
/*
Plugin Name: Digg Protector
Plugin URI: http://hansengel.wordpress.com/wordpress/plugins/digg-protector/
Description: Protects images from the Digg effect. If the viewer of your page was referred via Digg, an alternate image from a remote host is used, instead of the default locally hosted image.
Version: 1.0
Author: Hans Engel
Author URI: http://engel.uk.to
*/
/*  Copyright 2007  engel  (email : engel@engel.uk.to)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


function digg_protect($content) {
	if (stristr($_SERVER["HTTP_REFERER"], "digg.com")) {
		$content = preg_replace('/\<img(.+?)src="(.+?)"(.+?)protect="(.+?)"(.+?)\/>/', '<img$1src="$4"$5/>', $content);
	} else {
		$content = preg_replace('/\<img(.+?)src="(.+?)"(.+?)protect="(.+?)"(.+?)\/>/', '<img$1src="$2"$3$5/>', $content);
	}
	return $content;
}

add_filter("the_content", "digg_protect");

?>
