function post_rotation()
{
    global $wpdb;
    global $limit_start;
    global $matches;
    $pr_interval = get_option('pr_interval');
    $this_moment = strtotime(current_time('mysql'));
    $post_type = 'post';
    $post_status = 'publish';
    $latest_post_time = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY post_date DESC LIMIT 0,1", $post_type, $post_status));
    $wpdb->flush();
    $selectedpost = selectedpost($limit_start);
    if ($this_moment - strtotime($latest_post_time) > $pr_interval * 3600) {
        if ($matches > 0) {
            $mysql_current_time = current_time('mysql');
            $mysql_gmt_current_time = get_gmt_from_date($mysql_current_time);
            $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_date = %s, post_date_gmt = %s WHERE ID = %d", $mysql_current_time, $mysql_gmt_current_time, $selectedpost));
            if (get_option('pr_also_alter_last_modified') == 1) {
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_modified = %s, post_modified_gmt = %s WHERE ID = %d", $mysql_current_time, $mysql_gmt_current_time, $selectedpost));
            }
            $wpdb->flush();
        }
    }
}
if (get_option('pr_enabled') == 1) {
    $this_moment = strtotime(current_time('mysql'));
    $post_type = 'post';
    $post_status = 'publish';
    $newest_post_time = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE post_type = %s AND post_status = %s ORDER BY post_date DESC LIMIT 0,1", $post_type, $post_status));
    $wpdb->flush();
    $newest_post_time = strtotime($newest_post_time);
    $diference = $this_moment - $newest_post_time;
    $pr_interval = get_option('pr_interval');
    $pr_interval = $pr_interval * 3600;
    echo '<h3>Rotation is enabled</h3>';
    if ($matches == 0) {
        echo '<p class="detail">... but there is no post that matches with your criteria!</p>';
    } else {
        echo '<p class="detail">In ' . convert($pr_interval - $diference) . ' this post will be ready for being altered:</p>';
        echo '<p class="detail">(post ID: ' . selectedpost($limit_start) . ') - ' . get_post(selectedpost($limit_start))->post_title . '</p>';
    }
} else {
    echo '<h3>Rotation is disabled</h3>';
}
?>

<table class="form-table">
<tr>
<td>
<input type="checkbox" id="pr_enabled" name="pr_enabled" value="1" <?php 
checked(get_option('pr_enabled'));
?>
/>
<label>Enable rotation.</label>
</td>