<?php
/*
Plugin Name: auto-more
Plugin URI: http://ashwinbihari.com/
Description: This plugin adds a <!--more--> tag after the first paragraph once the whole post is of a certain length.
Version: 0.2
Author: Ashwin Bihari
Author URI: http://ashwinbihari.com/

Revision:
    0.1    01/07/05    Initial Release
    0.2    01/11/05    Look for <!--more--> tag in post and ignore post if found.
*/ 

$max_char_count 1000;

// This just echoes the chosen line, we'll position it later
function auto_more($id) {
    global 
$wpdb$tableposts$max_char_count;
    
$post $wpdb->get_var("SELECT post_content FROM $tableposts WHERE id=$id");
   
    if (!
eregi('\<\!--more--\>'$post)) {
        
$post_len strlen($post);    

        
$pos strpos($post"\n");
        
$output '';
        if (
$post_len $max_char_count) {
            
$output .= substr($post0$pos);
            
$output .= "<p><!--more--></p>";
            
$output .= substr($post$pos);

        
$output addslashes($output);
        
$results=$wpdb->query("UPDATE $tableposts SET post_content = '$output' WHERE ID = $id");
        }
    }
    
        return 
$id;
    
}
add_action('publish_post','auto_more',1);
add_action('edit_post','auto_more',1);
?>