svn.filsa.org wordpress_dev

Compare Revisions

Ignore whitespace Rev 11 → Rev 12

/trunk/plugins/mail2wordpress/mail2wordpress.php
0,0 → 1,208
<?php
/*
Plugin Name: mail2wordpress
Plugin URI: http://filsa.net/code/mail2wordpress
Description: Post emails to your blog, and image attachments
Version:0.5
Author: Phil Suh
Author URI: http://filsa.net/
*/
 
/*
- initialize some settings
- load settings
- save settings
- show admin page
*/
 
// ------- OPTIONS ------------
 
global $m2wp_option_names;
global $m2wp_option_default_values;
$m2wp_option_names = array('authorize_type','auth_accept_authors','attach_max_size');
$m2wp_option_default_values = array(false,'','1000');
 
 
function m2wp_get_options() {
$options = get_option( 'm2wp_options' );
 
if ( !isset( $options['version'] ) || $options['version'] < m2wp_VERSION ) {
$options = m2wp_upgrade_options( $options );
m2wp_set_options( $options );
}
 
return $options;
}
 
function m2wp_get_option( $option ) {
$options = m2wp_get_options();
if ( isset( $options[$option] ) )
return $options[$option];
return null;
}
 
function m2wp_set_option( $option, $value ) {
$options = m2wp_get_options();
$options[$option] = $value;
m2wp_set_options($options);
}
 
function m2wp_set_options($options) {
update_option( 'm2wp_options', $options );
}
 
function m2wp_upgrade_options( $options ) {
global $m2wp_option_names;
global $m2wp_option_default_values;
$defaults = array_combine($m2wp_option_names, $m2wp_option_default_values);
 
if ( is_array( $options ) && !empty( $options ) )
$options = array_merge( $defaults, $options );
else
$options = $defaults;
$options['version'] = M2WP_VERSION;
 
return $options;
}
 
function m2wp_admin_page() {
global $m2wp_option_names;
global $m2wp_option_default_values;
$options = m2wp_get_options();
$nonce = wp_create_nonce('m2wp-nonce-code');
$mailserver_options = array('mailserver_url','mailserver_port','mailserver_login','mailserver_pass','default_email_category');
if (isset($_POST['Submit'])) {
$checknonce=$_POST['_wpnonce'];
if (! wp_verify_nonce($checknonce, 'm2wp-nonce-code') ) die('Security on this page has timed out. Log out and back and try again.');
foreach ($mailserver_options as $optname) {
$optval = $_POST[$optname];
if (! empty($optval)) update_option($optname, $optval);
}
foreach ($m2wp_option_names as $optname) {
$optval = $_POST[$optname];
if (! empty($optval)) $options[$optname] = $optval;
if ('authorize_type' == $optname && empty($optval)) {
$options[$optname] = false;
}
}
m2wp_set_options($options);
?><h3>Quite is it.</h3><?php
}
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br /></div>
<h2>Mail2Wordpress</h2>
<p>Mail2Wordpress provides a script that can connect to a POP3 mailbox and post each mail it finds as a Wordpress post. It is very similar to the wp-mail.php script included in Wordpress, however it also processes IMAGE attachments (other types of attachments are ignored).</p>
<p>However, just installing the script is not enough. You also must use a scheduling tool (such as cron) to activate the script. Refer to the <a href="http://codex.wordpress.org/Blog_by_Email#Step_3_-_Publish_Your_E-mail_Posts" title="Step 3 - Publish Your Email Posts" target="_blank">wp-mail.php docs (Step 3)</a>, but substitute the following url for every mention of wp-mail.php: <?php echo WP_PLUGIN_URL . '/mail2wordpress/mail2wp.php' ;?></p>
<p>The script is linked to this plugin. If you deactivate this plugin, the script will not run.</p>
<p>You can configure the script below.</p>
<h3>Email Server Configuration</h3>
<p>This is the same configuration as "post by Email" section of the "Writing" settings, just here for convenience. Changes made in either spot reflect in the other.</p>
<form action="" method="POST" name="m2wp-form">
<input type="hidden" name="_wpnonce" value="<?php echo $nonce; ?>">
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="mailserver_url"><?php _e('Mail Server') ?></label></th>
<td><input name="mailserver_url" type="text" id="mailserver_url" value="<?php form_option('mailserver_url'); ?>" class="regular-text" />
<label for="mailserver_port"><?php _e('Port') ?></label>
<input name="mailserver_port" type="text" id="mailserver_port" value="<?php form_option('mailserver_port'); ?>" class="small-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="mailserver_login"><?php _e('Login Name') ?></label></th>
<td><input name="mailserver_login" type="text" id="mailserver_login" value="<?php form_option('mailserver_login'); ?>" class="regular-text" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="mailserver_pass"><?php _e('Password') ?></label></th>
<td>
<input name="mailserver_pass" type="text" id="mailserver_pass" value="<?php form_option('mailserver_pass'); ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="default_email_category"><?php _e('Default Mail Category') ?></label></th>
<td>
<?php
wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_email_category', 'orderby' => 'name', 'selected' => get_option('default_email_category'), 'hierarchical' => true));
?>
</td>
</tr>
</table>
<h3>Authorization Options</h3>
 
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Accept incoming emails:') ?></th>
<td>
<fieldset><legend class="hidden">Authorize</legend>
<label for="authorize_type"><input name="authorize_type" type="radio" id="authorize_type" value="NONE" align="left" <?php if($options['authorize_type']=='NONE') echo 'checked=checked"' ?> />&nbsp;from anyone (not recommended).</label><br />
<label for="authorize_type"><input name="authorize_type" type="radio" id="authorize_type" value="EMAILADDR" align="left" <?php if($options['authorize_type']=='EMAILADDR') echo 'checked=checked"' ?> />&nbsp;from approved senders list (below).</label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="attach_max_size"><?php _e('Maximum Email Attachment Size (in Kilobytes)') ?></label></th>
<td><input name="attach_max_size" type="text" id="attach_max_size" size="5" maxlength="5" value="<?php echo $options['attach_max_size']; ?>" class="small-text" />Kb</td>
</tr>
</table>
<input type="submit" name="Submit" value="Save Changes" class="button-primary" />
</form>
</div>
<?php
foreach ($options as $key=>$val) {
echo "$key: $val<br />";
}
}
 
 
function m2wp_plugin_menu() {
add_options_page('Mail2Wordpress Options', 'Mail2Wordpress', 8, __FILE__, 'm2wp_admin_page');
}
 
 
 
function m2wp_admin_notice() {
global $m2wp_admin_notice_text;
if ('' != $m2wp_admin_notice_text) {
echo "
<div id='mail2wp-warning' class='updated fade'><p><strong>".
__($m2wp_admin_notice_text)."</strong></p></div>
";
$m2wp_admin_notice_text = '';
}
}
 
function m2wp_activate() {
m2wp_get_options();
//$m2wp_admin_notice_text = 'Welcome to Mail2Wordpress. Configure from Settings -> Mail2Wordpress';
//add_action('admin_notices', 'm2wp_admin_notice');
set_option('m2wp_enabled', 'true');
}
function m2wp_deactivate() {
//delete_option('m2wp_options'); //wipes out the entire config!
delete_option('m2wp_enabled');
}
 
// INIT
register_activation_hook(__FILE__, 'm2wp_activate');
register_deactivation_hook(__FILE__, 'm2wp_deactivate');
 
add_action('admin_menu', 'm2wp_plugin_menu');
 
define( 'M2WP_VERSION', '0.5' );
 
 
?>