function digg_protect($content) {
include("htmlparser.inc"); // Include the class
$parser = new HtmlParser($content); // Create the parser
while($parser->parse()) { // Start parsing the content
if ($parser->iNodeName = "img") { // If this node is an image
if ($parser->iNodeAttributes["src"] && $parser->iNodeAttributes["protect"]) { // If the "protect" and "src" attributes are both declared
if (strstr($_SERVER["HTTP_REFERRER"], "digg.com")) { // If our viewer is visiting from Digg
$alt = "";
$width = "";
$height = "";
if ($parser->iNodeAttributes["alt"]) {
$alt = " alt=\"" . $parser->iNodeAttributes["alt"] . "\"";
}
if ($parser->iNodeAttributes["width"]) {
$width = " width=\"" . $parser->iNodeAttributes["width"] . "\"";
}
if ($parser->iNodeAttributes["height"]) {
$height = " height=\"" . $parser->iNodeAttributes["height"] . "\"";
}
$tag = "
iNodeAttributes["protect"] . "\"" . $alt . $width . $height . " />";
$new = preg_replace("/protect=(.*?)/i", "", $parser->iNodeValue);
$new = preg_replace("/src=(.*?)/i", $parser->iNodeAttributes["protect"], $new);
str_ireplace($parser->iNodeValue, $new, $content); // Replace the old tag with the new one
} else { // If our viewer isn't visiting from Digg
$alt = "";
$width = "";
$height = "";
if ($parser->iNodeAttributes["alt"]) {
$alt = " alt=\"" . $parser->iNodeAttributes["alt"] . "\"";
}
if ($parser->iNodeAttributes["width"]) {
$width = " width=\"" . $parser->iNodeAttributes["width"] . "\"";
}
if ($parser->iNodeAttributes["height"]) {
$height = " height=\"" . $parser->iNodeAttributes["height"] . "\"";
}
$tag = "
iNodeAttributes["src"] . "\"" . $alt . $width . $height . " />";
str_ireplace($parser->iNodeValue, $new, $content); // Replace the old tag with the new one
}
}
}
}
return $content;
}
add_filter("the_content", "digg_protect");