<?php
/*
Plugin Name: no nofollow
Plugin URI: http://bronski.net/data/nonofollow/
Description: Remove rel='nofollow' after a given number of days to give the site admin a chance to check for spam. If a comment is still present after that time rel='nofollow' is removed automatically. If this is your first time using this plugin you will need to run the <a href="admin.php?page=nonofollow.php&nonofollowsetup" onclick="window.open(this.href, 'popupwindow', 'width=400,height=150,scrollbars,resizable'); return false;">setup script</a> first in order to create the required option-setting in your database.
Version: 1.2
Author: Christoph Rummel
Author URI: http://bronski.net/
*/

if (is_plugin_page()) {

require_once(
ABSPATH 'wp-config.php');

if (isset(
$_REQUEST['nonofollowsetup'])) {
    
$wpdb->hide_errors();
    
$notfollowedyet $wpdb->get_results("SELECT * FROM $wpdb->options WHERE option_name = 'nofollow_days'");
    if (
$notfollowedyet) { ?>
<div class="wrap">
<h2>No NoFollow Setup</h2>
<p>
Plugin was already installed.
</p>
</div>
<?php
    
} else {
        
$wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description) VALUES ('nofollow_days', '2', 'number of days after which nofollow is removed');");
?>
<div class="wrap">
<h2>No NoFollow Setup</h2>
<p>
Plugin was successfully installed.
</p>
</div>
<?php
    
}
    
$wpdb->show_errors();
}

if (isset(
$_REQUEST['updatenofollowdays'])) {
    
$nofollow_days $_POST['nofollow_days'];
    
$wpdb->query("UPDATE $wpdb->options SET option_value = '$nofollow_days' WHERE option_name = 'nofollow_days'");
}

$nofollow_days $wpdb->get_var("SELECT option_value FROM $wpdb->options where option_name = 'nofollow_days'");

?>
<div class="wrap">
<h2>No NoFollow Options</h2>

<p>
<form name="nonofollowoptions" method="post" action="admin.php?page=nonofollow.php&updatenofollowdays">
Number of days after which <code>rel='nofollow'</code> is removed from links:
<input name="nofollow_days" type="text" value="<?php echo $nofollow_days?>" size="2" />
</p>
<p>
<input type="submit" name="Submit" value="Update Options &raquo;" />
</p>
</form>
</div>
<?php

} else {

function 
nonofollow_admin_menu() {
    
add_options_page('No NoFollow''No NoFollow'5basename(__FILE__));
}

$nofollow_days $wpdb->get_var("SELECT option_value FROM $wpdb->options where option_name = 'nofollow_days'");
$remove_nofollow_after = ( time() - ( 86400 $nofollow_days ) );

function 
no_nofollow_link($text) {
    global 
$comment$remove_nofollow_after;
    
$date mysql2date('U'$comment->comment_date);
    if ( 
$date $remove_nofollow_after ) {
        
$text str_replace(' rel="nofollow"'''$text);
    }
    return 
$text;
}

function 
no_nofollow_url($text) {
    global 
$comment$remove_nofollow_after;
    
$date mysql2date('U'$comment->comment_date);
    if ( 
$date $remove_nofollow_after ) {
        
$text str_replace(" rel='external nofollow'"" rel='external'"$text);
    }
    return 
$text;
}

add_action('admin_menu''nonofollow_admin_menu');

add_filter('comment_text''no_nofollow_link'20);
add_filter('get_comment_author_link''no_nofollow_url');

}

?>