svn.filsa.org wordpress_dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 phil 1
<?php
2
/*
3
Plugin Name: mail2wordpress
24 phil 4
Plugin URI: http://mail2wordpress.filsa.net/
12 phil 5
Description: Post emails to your blog, and image attachments
18 phil 6
Version:0.3
12 phil 7
Author: Phil Suh
8
Author URI: http://filsa.net/
9
*/
10
 
11
/*
12
 - initialize some settings
13
 - load settings
14
 - save settings
15
 - show admin page
16
*/
17
 
18
// ------- OPTIONS ------------
19
 
20
global $m2wp_option_names;
21
global $m2wp_option_default_values;
14 phil 22
$m2wp_option_names = array('authorize_type','auth_approved_senders','attach_max_size');
12 phil 23
$m2wp_option_default_values = array(false,'','1000');
24
 
25
 
16 phil 26
function m2wp_wordpress_wtf() {
27
}
28
 
29
 
12 phil 30
function m2wp_get_options() {
31
        $options = get_option( 'm2wp_options' );
32
 
33
        if ( !isset( $options['version'] ) || $options['version'] < m2wp_VERSION ) {
34
                        $options = m2wp_upgrade_options( $options );
35
                        m2wp_set_options( $options );
36
        }
37
 
38
        return $options;
39
}
40
 
16 phil 41
function m2wp_get_option ($option) {
12 phil 42
        $options = m2wp_get_options();
43
        if ( isset( $options[$option] ) )
16 phil 44
                return $options[$option];
12 phil 45
        return null;
46
}
47
 
16 phil 48
 
12 phil 49
function m2wp_set_option( $option, $value ) {
50
        $options = m2wp_get_options();
51
        $options[$option] = $value;
52
        m2wp_set_options($options);
53
}
54
 
55
function m2wp_set_options($options) {
56
        update_option( 'm2wp_options', $options );
57
}
58
 
59
function m2wp_upgrade_options( $options ) {
60
        global $m2wp_option_names;
61
        global $m2wp_option_default_values;
62
        $defaults = array_combine($m2wp_option_names, $m2wp_option_default_values);
63
 
64
        if ( is_array( $options ) && !empty( $options ) )
65
                        $options = array_merge( $defaults, $options );
66
        else
67
                        $options = $defaults;
68
        $options['version'] = M2WP_VERSION;
69
 
70
        return $options;
71
}
72
 
14 phil 73
function m2wp_admin_saved_options_notice() {
74
        echo "<div id='m2wp-warning' class='updated fade'><p>Settings saved.</p></div>";
75
}
76
 
12 phil 77
function m2wp_admin_page() {
78
        global $m2wp_option_names;
79
        global $m2wp_option_default_values;
80
        $options = m2wp_get_options();
81
        $nonce = wp_create_nonce('m2wp-nonce-code');
82
        $mailserver_options = array('mailserver_url','mailserver_port','mailserver_login','mailserver_pass','default_email_category');
83
 
84
        if (isset($_POST['Submit'])) {
85
                $checknonce=$_POST['_wpnonce'];
86
                if (! wp_verify_nonce($checknonce, 'm2wp-nonce-code') ) die('Security on this page has timed out. Log out and back and try again.');
87
                foreach ($mailserver_options as $optname) {
88
                        $optval = $_POST[$optname];
89
                        if (! empty($optval)) update_option($optname, $optval);
90
                }
91
                foreach ($m2wp_option_names as $optname) {
92
                        $optval = $_POST[$optname];
93
                        if (! empty($optval)) $options[$optname] = $optval;
94
                        if ('authorize_type' == $optname && empty($optval)) {
95
                                $options[$optname] = false;
96
                        }
97
                }
98
                m2wp_set_options($options);
14 phil 99
                add_action('admin_notices', 'm2wp_admin_saved_options_notice');
12 phil 100
        }
101
        ?>
102
        <div class="wrap">
103
        <div id="icon-options-general" class="icon32"><br /></div>
104
                <h2>Mail2Wordpress</h2>
105
 
106
                <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>
107
                <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>
108
                <p>The script is linked to this plugin. If you deactivate this plugin, the script will not run.</p>
109
                <p>You can configure the script below.</p>
110
 
111
                <h3>Email Server Configuration</h3>
112
                <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>
113
                <form action="" method="POST" name="m2wp-form">
114
                <input type="hidden" name="_wpnonce" value="<?php echo $nonce; ?>">
115
 
116
                <table class="form-table">
117
                        <tr valign="top">
118
                        <th scope="row"><label for="mailserver_url"><?php _e('Mail Server') ?></label></th>
119
                        <td><input name="mailserver_url" type="text" id="mailserver_url" value="<?php form_option('mailserver_url'); ?>" class="regular-text" />
120
                        <label for="mailserver_port"><?php _e('Port') ?></label>
121
                        <input name="mailserver_port" type="text" id="mailserver_port" value="<?php form_option('mailserver_port'); ?>" class="small-text" />
122
                        </td>
123
                        </tr>
124
                        <tr valign="top">
125
                        <th scope="row"><label for="mailserver_login"><?php _e('Login Name') ?></label></th>
126
                        <td><input name="mailserver_login" type="text" id="mailserver_login" value="<?php form_option('mailserver_login'); ?>" class="regular-text" /></td>
127
                        </tr>
128
                        <tr valign="top">
129
                        <th scope="row"><label for="mailserver_pass"><?php _e('Password') ?></label></th>
130
                        <td>
131
                        <input name="mailserver_pass" type="text" id="mailserver_pass" value="<?php form_option('mailserver_pass'); ?>" class="regular-text" />
132
                        </td>
133
                        </tr>
134
                        <tr valign="top">
135
                        <th scope="row"><label for="default_email_category"><?php _e('Default Mail Category') ?></label></th>
136
                        <td>
137
                        <?php
138
                        wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_email_category', 'orderby' => 'name', 'selected' => get_option('default_email_category'), 'hierarchical' => true));
139
                        ?>
140
                        </td>
141
                        </tr>          
142
                </table>
143
 
144
 
145
                <h3>Authorization Options</h3>
146
 
147
 
148
                <table class="form-table">
149
                        <tr valign="top">
14 phil 150
                        <th scope="row"><?php _e('Accept incoming emails') ?></th>
12 phil 151
                        <td>
152
                        <fieldset><legend class="hidden">Authorize</legend>
153
                        <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 />
154
                        <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>
155
                        </fieldset>
156
                        </td>
157
                        </tr>
14 phil 158
 
159
                        <tr valign="top">
160
                        <th scope="row">Approved Senders Addresses</th>
161
                        <td><fieldset><legend class="hidden">Approved Senders List</legend>
162
                        <p><label for="auth_approved_senders">When an email is processed, it will be checked to see if the sender is on this list. If they are not, the email will be discarded. Recommended setting. One email per line.</label></p>
163
                        <p>
24 phil 164
                        <textarea name="auth_approved_senders" rows="3" cols="40" id="auth_approved_senders" class="large-text code"><?php echo $options['auth_approved_senders']; ?></textarea>
14 phil 165
                        </p>
166
                        </fieldset></td>
167
                        </tr>
168
 
169
                        </tr>
12 phil 170
                        <tr valign="top">
171
                        <th scope="row"><label for="attach_max_size"><?php _e('Maximum Email Attachment Size (in Kilobytes)') ?></label></th>
172
                        <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>
173
                        </tr>
174
 
175
                </table>
176
 
14 phil 177
                <p>&nbsp;<br /><input type="submit" name="Submit" value="Save Changes" class="button-primary" /></p>
12 phil 178
                </form>
179
 
180
        </div>
181
 
182
        <?php
14 phil 183
 
12 phil 184
}
185
 
186
 
187
function m2wp_plugin_menu() {
188
  add_options_page('Mail2Wordpress Options', 'Mail2Wordpress', 8, __FILE__, 'm2wp_admin_page');
189
}
190
 
191
 
192
 
193
function m2wp_admin_notice() {
194
        global $m2wp_admin_notice_text;
195
        if ('' != $m2wp_admin_notice_text) {
196
                echo "
197
                <div id='mail2wp-warning' class='updated fade'><p><strong>".
198
                __($m2wp_admin_notice_text)."</strong></p></div>
199
                ";
200
                $m2wp_admin_notice_text = '';
201
        }
202
}
203
 
204
function m2wp_activate() {
205
        m2wp_get_options();
206
        //$m2wp_admin_notice_text = 'Welcome to Mail2Wordpress. Configure from Settings -> Mail2Wordpress';
207
        //add_action('admin_notices', 'm2wp_admin_notice');
208
        set_option('m2wp_enabled', 'true');
209
}
210
function m2wp_deactivate() {
211
        //delete_option('m2wp_options'); //wipes out the entire config!
212
        delete_option('m2wp_enabled');
213
}
214
 
215
// INIT
216
register_activation_hook(__FILE__, 'm2wp_activate');
217
register_deactivation_hook(__FILE__, 'm2wp_deactivate');
218
 
219
add_action('admin_menu', 'm2wp_plugin_menu');
220
 
18 phil 221
define( 'M2WP_VERSION', '0.3' );
12 phil 222
 
223
 
224
?>