<?php
/*
Plugin Name: Comments To Mail
Plugin URI: http://www.chaosengine.net/projects/wordpress/comments-to-mail.phps
Description: Convert comment links to mailto: links
Author: Daniel Quinlan
Version: 0.2
Author URI: http://www.chaosengine.net/
*/ 

// Last tested with Wordpress 2.0.10

// Options {{{
function ctm_add_options_subpanel() {
    if(
function_exists('add_options_page')) {
    
add_options_page('Mailto: Comments'
    
'Mailto: Comments'
    
6,
    
basename(__FILE__),
    
'ctm_options_subpanel');
    }
}

function 
ctm_options_subpanel() {

  if (isset(
$_POST['ctm_options_update'])) {
    
update_option('ctm_plugin'
    array(
$_POST['ctm_address'],
             
$_POST['ctm_prefix'],
             
$_POST['ctm_subject'])
      );

    
?><div class="updated"><p><strong><?php 
_e
('Updated.''ctm_plugin')
    
?></strong></p></div><?php
  


  list(
$email_addr$prefix$subject) = get_option('ctm_plugin');

  
$prefix = (empty($prefix)) ? "anti-spam-" $prefix;
  
$subject = (empty($subject)) ? '$1 blog post' $subject;

  
// options form
  
?>
<style>
label {
    font-weight: bold;
}
</style>
<div class=wrap>
  <form method="post">
  <input type="hidden" name="ctm_options_update" value="1">
    <h2><?php _e('Mailto: Comments''ctm_plugin'?></h2>
     <fieldset name="ctm_set1">
    <legend><?php _e('General Settings''ctm_plugin'?></legend>
    <table border="0" cellpadding="2" cellspacing="0">
    <tbody><tr>
        <th align="right" valign="top"><?php _e('Email address''ctm_plugin')?></th>
        <td><input name="ctm_address" type="text" value="<?= $email_addr ?>"><br />
        This will be simply obfuscated.
        </td>
    </tr>
    <tr>
        <th for="ctm_prefix"><?php _e('Anti-spam prefix''ctm_plugin')?></th>
        <td><input name="ctm_prefix" type="text" value="<?= $prefix ?>"><br />
        The obfuscated email address is prefixed with this string.
        </td>
    </tr>
    <tr>
        <th for="ctm_subject"><?php _e('Email subject''ctm_plugin')?></th>
        <td><input name="ctm_subject" type="text" value="<?= $subject ?>"><br />
        Subject of the email, '$1' is the mouse-over text from the original page.
        </td>
    </tr>
    </tbody></table>
     </fieldset>
<div class="submit">
  <input type="submit" name="info_update" value="<?php
    _e
('Update options''ctm_plugin')
    
?> &#187;" /></div>
  </form>
 </div><?php
}
// }}}
// the meaty goodness {{{
function ctm_ob_handler($buffer) {
    
    list(
$email_addr$prefix$subject) = get_option('ctm_plugin');

    return(
preg_replace('|<a href="'.get_settings('siteurl').'/[^"]*?.respond" title="([^"]*)">.*?Comments.*?</a>|''<a href="mailto:'.$prefix.str_replace('@','(at)',$email_addr).'?subject='.$subject.'">Comment</a>'$buffer));
}

function 
ctm_register_ob_handler() {
    
ob_start('ctm_ob_handler');    
}

function 
ctm_shutdown() {
    
ob_end_flush();    
}
// }}}
// Hooks {{{
add_action('init''ctm_register_ob_handler');
add_action('shutdown''ctm_shutdown');
add_action('admin_menu''ctm_add_options_subpanel');
// }}}
// vim:set foldmethod=marker:
?>