Subscribe2 - Version 3.6

Version Description

Download this release

Release Info

Developer MattyRob
Plugin Icon 128x128 Subscribe2
Version 3.6
Comparing to
See all releases

Code changes from version 2.10 to 3.6

ReadMe.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: MattyRob, Skippy, Ravan
3
Donate link: http://subscribe2.wordpress.com/donate/
4
Tags: posts, subscription, email
5
Requires at least: 2.0.x
6
- Tested up to: 2.1
7
8
Sends a list of subscribers an email notification when new posts are published to your blog
9
@@ -77,6 +77,101 @@ Batches will occur for each group of message as described above. A site on Drea
77
78
== Version History ==
79
80
Version 2.10 by Matthew Robinson
81
* Improved sign up process by double checking email address
82
* Fix for submenu issues encountered in WP 2.0.6
3
Donate link: http://subscribe2.wordpress.com/donate/
4
Tags: posts, subscription, email
5
Requires at least: 2.0.x
6
+ Tested up to: 2.2
7
8
Sends a list of subscribers an email notification when new posts are published to your blog
9
77
78
== Version History ==
79
80
+ Version 3.6 by Matthew Robinson
81
+
82
+ * Fixed a typo in Content-Type mail headers
83
+ * Fixed Auto Register functions to obey Excluded Categories
84
+ * Added option to check WP-Register checkbox by default
85
+
86
+ Version 3.5 by Matthew Robinson
87
+
88
+ * Fixed a bug in the upgrade function that was messing up the options settings
89
+ * Updated the include.php file to preset recently introduced option settings
90
+
91
+ Version 3.4 by Matthew Robinson
92
+
93
+ * QuickTag button now displays a Marker! (HUGE thanks to Raven!)
94
+ * Fix for excluded categories in User Menu
95
+ * BCCLIMIT typo corrected in Mail function
96
+ * Call to translation files moved to avoid call to undefined function
97
+ * Options added to send mails for pages and password protected posts
98
+ * Option added to display subscription checkbox in WordPress Register screen
99
+ * Small typo and layout amendments
100
+
101
+ Version 3.3 by Matthew Robinson
102
+
103
+ * QuickTag button added! Works with Visual and Standard Editor. __Look in Code for token addition if using RTE.__
104
+ * Current Server time displayed for Cron tasks
105
+ * Fixed bug so Registered users now identified correctly
106
+ * Upgrade function called via WordPress hook to prevent calls to undefined functions
107
+ * Fixed a bug affecting Registered Users not appearing in the drop down list
108
+ * Improved handling of the Subscribe2 option array
109
+
110
+ Version 3.2 by Matthew Robinson
111
+
112
+ * Fixed a bug affecting Registered Users not appearing in the drop down list
113
+ * Improved handling of the Subscribe2 option array
114
+
115
+ Version 3.1 by Matthew Robinson
116
+
117
+ * Amended code to use core cron functionality for future posts and digest notifications, no longer need WP-Cron
118
+ * Improved HTML code generated for admin pages
119
+ * Removed sending of emails for WordPress Pages
120
+ * Fixed display issues if S2PAGE is not defined
121
+
122
+ Version 3.0 by Matthew Robinson
123
+
124
+ * Updated for WordPress 2.1 Branch
125
+
126
+ Version 2.20 by Matthew Robinson
127
+
128
+ * Fixed a typo in Content-Type mail headers
129
+ * Fixed Auto Register functions to obey Excluded Categories
130
+
131
+ Version 2.19 by Matthew Robinson
132
+
133
+ * Fixed a bug in the upgrade function that was messing up the options settings
134
+
135
+ Version 2.18 by Matthew Robinson
136
+
137
+ * BCCLIMIT typo corrected in Mail function
138
+ * Call to translation files moved to avoid call to undefined function
139
+ * Small typo and layout amendments
140
+
141
+ Version 2.17 by Matthew Robinson
142
+
143
+ * Current Server time displayed for Cron tasks
144
+ * Fixed bug so Registered users now identified correctly
145
+ * Upgrade function called via WordPress hook to prevent calls to undefined functions
146
+
147
+ Version 2.16 by Matthew Robinson
148
+
149
+ * Fixed a bug affecting Registered Users not appearing in the drop down list
150
+ * Improved handling of the Subscribe2 option array
151
+
152
+ Version 2.15 by Matthew Robinson
153
+
154
+ * Improved HTML code generated for admin pages
155
+ * Fixed display issues if S2PAGE is not defined
156
+
157
+ Version 2.14 by Matthew Robinson
158
+
159
+ * Amended DREAMHOST setting to BCCLIMIT as more hosts are limiting emails
160
+ * Fixed oversight in upgrade() function
161
+
162
+ Version 2.13 by Matthew Robinson
163
+
164
+ * Added WordPress nonce functionality to improve admin security
165
+
166
+ Version 2.12 by Matthew Robinson
167
+
168
+ * Fix for missing Quicktags (probably since version 2.2.10)
169
+ * Fix for occasional email issue where excerpts are incomplete
170
+
171
+ Version 2.11 by Matthew Robinson
172
+ * Fixed bug that would cause all subscribers to get digest emails
173
+ * Added Select All check box to category listing
174
+
175
Version 2.10 by Matthew Robinson
176
* Improved sign up process by double checking email address
177
* Fix for submenu issues encountered in WP 2.0.6
subscribe2/include.php CHANGED
@@ -6,10 +6,26 @@ if (!isset($this->subscribe2_options['autosub'])) {
6
$this->subscribe2_options['autosub'] = "no";
7
} // option to autosubscribe registered users to new categories
8
9
if (!isset($this->subscribe2_options['autoformat'])) {
10
$this->subscribe2_options['autoformat'] = "text";
11
} // option for default auto-subscription email format
12
13
if (!isset($this->subscribe2_options['exclude'])) {
14
$this->subscribe2_options['exclude'] = "";
15
} // option for excluded categories
@@ -32,11 +48,11 @@ if (!isset($this->subscribe2_options['barred'])) {
32
} // option containing domains barred from public registration
33
34
if (!isset($this->subscribe2_options['mailtext'])) {
35
- $this->subscribe2_options['mailtext'] = "BLOGNAME has posted a new item, 'TITLE'\r\nPOST\r\nYou may view the latest post at\r\nPERMALINK\r\nYou received this e-mail because you asked to be notified when new updates are posted.\r\nBest regards,\r\nMYNAME\r\nEMAIL";
36
} // Default notification email text
37
38
if (!isset($this->subscribe2_options['confirm_email'])) {
39
- $this->subscribe2_options['confirm_email'] = "In order to confirm your request for BLOGNAME, please click on the link below:\n\nLINK\n\nIf you did not request this, please feel free to disregard this notice!\n\nThank you,\nMYNAME.";
40
} // Default confirmation email text
41
42
if (!isset($this->subscribe2_options['remind_email'])) {
6
$this->subscribe2_options['autosub'] = "no";
7
} // option to autosubscribe registered users to new categories
8
9
+ if (!isset($this->subscribe2_options['wpregdef'])) {
10
+ $this->subscribe2_options['wpregdef'] = "no";
11
+ } // option to
12
+
13
if (!isset($this->subscribe2_options['autoformat'])) {
14
$this->subscribe2_options['autoformat'] = "text";
15
} // option for default auto-subscription email format
16
17
+ if (!isset($this->subscribe2_options['pages'])) {
18
+ $this->subscribe2_options['pages'] = "no";
19
+ } // option for sending notifications for WordPress pages
20
+
21
+ if (!isset($this->subscribe2_options['password'])) {
22
+ $this->subscribe2_options['password'] = "no";
23
+ } // option for sending notifications for posts that are password protected
24
+
25
+ if (!isset($this->subscribe2_options['email_freq'])) {
26
+ $this->subscribe2_options['email_freq'] = "never";
27
+ } // option for sending emails per-post or as a digest email on a cron schedule
28
+
29
if (!isset($this->subscribe2_options['exclude'])) {
30
$this->subscribe2_options['exclude'] = "";
31
} // option for excluded categories
48
} // option containing domains barred from public registration
49
50
if (!isset($this->subscribe2_options['mailtext'])) {
51
+ $this->subscribe2_options['mailtext'] = "BLOGNAME has posted a new item, 'TITLE'\n\nPOST\n\nYou may view the latest post at\nPERMALINK\n\nYou received this e-mail because you asked to be notified when new updates are posted.\nBest regards,\nMYNAME\nEMAIL";
52
} // Default notification email text
53
54
if (!isset($this->subscribe2_options['confirm_email'])) {
55
+ $this->subscribe2_options['confirm_email'] = "BLOGNAME has received a request to ACTION for this email address. To complete your request please click on the link below:\n\nLINK\n\nIf you did not request this, please feel free to disregard this notice!\n\nThank you,\nMYNAME.";
56
} // Default confirmation email text
57
58
if (!isset($this->subscribe2_options['remind_email'])) {
subscribe2/spacer.gif ADDED
Binary file
subscribe2/subscribe2.php CHANGED
@@ -1,2001 +1,2210 @@
1
- <?php
2
- /*
3
- Plugin Name: Subscribe2
4
- Plugin URI: http://subscribe2.wordpress.com
5
- Description: Notifies an email list when new entries are posted.
6
- Version: 2.2.10
7
- Author: Matthew Robinson
8
- Author URI: http://subscribe2.wordpress.com
9
- */
10
-
11
- /*
12
- Copyright (C) 2006 Matthew Robinson
13
- Based on the Original Subscribe2 plugin by
14
- Copyright (C) 2005 Scott Merrill (skippy@skippy.net)
15
-
16
- This program is free software; you can redistribute it and/or
17
- modify it under the terms of the GNU General Public License
18
- as published by the Free Software Foundation; either version 2
19
- of the License, or (at your option) any later version.
20
-
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
-
26
- You should have received a copy of the GNU General Public License
27
- along with this program; if not, write to the Free Software
28
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
- http://www.gnu.org/licenses/gpl.html
30
- */
31
-
32
- // use Owen's excellent ButtonSnap library
33
- include(ABSPATH . '/wp-content/plugins/buttonsnap.php');
34
-
35
- // change this to TRUE if you're on Dreamhost
36
- // (or any other host that limits the number of recipients
37
- // permitted on each outgoing email message)
38
- define('DREAMHOST', false);
39
-
40
- // by default, subscribe2 grabs the first page from your database for use
41
- // when displaying the confirmation screen to public subscribers.
42
- // You can override this by specifying a page ID below.
43
- define('S2PAGE', '0');
44
-
45
- // change this to TRUE if you want a daily digest of the day's posts
46
- // send to your subscribers
47
- define('S2DIGEST', false);
48
-
49
- // our version number. Don't touch.
50
- define('S2VERSION', '2.2.10');
51
-
52
- // start our class
53
- class subscribe2 {
54
- // variables and constructor are declared at the end
55
-
56
- /**
57
- Load all our strings
58
- */
59
- function load_strings() {
60
- // adjust the output of Subscribe2 here
61
-
62
- $this->please_log_in = "<p>" . __('To manage your subscription options please ', 'subscribe2') . "<a href=\"" . get_settings('siteurl') . "/wp-login.php\">login</a>.</p>";
63
-
64
- $this->use_profile = "<p>" . __('You may manage your subscription options from your ', 'subscribe2') . "<a href=\"" . get_settings('siteurl') . "/wp-admin/profile.php?page=" . plugin_basename(__FILE__) . "\">profile</a>.</p>";
65
-
66
- $this->confirmation_sent = "<p>" . __('A confirmation message is on its way!', 'subscribe2') . "</p>";
67
-
68
- $this->already_subscribed = "<p>" . __('That email address is already subscribed.', 'subscribe2') . "</p>";
69
-
70
- $this->not_subscribed = "<p>" . __('That email address is not subscribed.', 'subscribe2') . "</p>";
71
-
72
- $this->not_an_email = "<p>" . __('Sorry, but that does not look like an email address to me.', 'subscribe2') . "</p>";
73
-
74
- $this->barred_domain = "<p>" . __('Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2') . "</p>";
75
-
76
- $this->mail_sent = "<p>" . __('Message sent!', 'subscribe2') . "</p>";
77
-
78
- $this->form = "<form method=\"post\" action=\"\">" . __('Your email:', 'subscribe2') . "&#160;<input type=\"text\" name=\"email\" value=\"\" size=\"20\" />&#160;<br /><input type=\"radio\" name=\"s2_action\" value=\"subscribe\" checked=\"checked\" /> " . __('Subscribe', 'subscribe2') . " <input type=\"radio\" name=\"s2_action\" value=\"unsubscribe\" /> " . __('Unsubscribe', 'subscribe2') . " &#160;<input type=\"submit\" value=\"" . __('Send', 'subscribe2') . "\" /></form>\r\n";
79
-
80
- // confirmation messages
81
- $this->no_such_email = "<p>" . __('No such email address is registered.', 'subscribe2') . "</p>";
82
-
83
- $this->added = "<p>" . __('You have successfully subscribed!', 'subscribe2') . "</p>";
84
-
85
- $this->deleted = "<p>" . __('You have successfully unsubscribed.', 'subscribe2') . "</p>";
86
-
87
- $this->confirm_subject = "[" . get_settings('blogname') . "] " . __('Please confirm your request', 'subscribe2');
88
-
89
- $this->remind_subject = "[" . get_settings('blogname') . "] " . __('Subscription Reminder', 'subscribe2');
90
-
91
- $this->subscribe = __('subscribe', 'subscribe2'); //ACTION replacement in subscribing confirmation email
92
-
93
- $this->unsubscribe = __('unsubscribe', 'subscribe2'); //ACTION replacement in unsubscribing in confirmation email
94
-
95
- // menu strings
96
- $this->options_saved = __('Options saved!', 'subscribe2');
97
- $this->options_reset = __('Options reset!', 'subscribe2');
98
- } // end load_strings()
99
-
100
- /* ===== WordPress menu registration ===== */
101
- /**
102
- Hook the menu
103
- */
104
- function admin_menu() {
105
- add_management_page(__('Subscribers', 'subscribe2'), __('Subscribers', 'subscribe2'), "manage_options", __FILE__, array(&$this, 'manage_menu'));
106
- add_options_page(__('Subscribe2 Options', 'subscribe2'), __('Subscribe2','subscribe2'), "manage_options", __FILE__, array(&$this, 'options_menu'));
107
- add_submenu_page('profile.php', __('Subscriptions', 'subscribe2'), __('Subscriptions', 'subscribe2'), "read", __FILE__, array(&$this, 'user_menu'));
108
- add_submenu_page('post.php', __('Mail Subscribers','subscribe2'), __('Mail Subscribers', 'subscribe2'),"manage_options", __FILE__, array(&$this, 'write_menu'));
109
- }
110
-
111
- /* ===== ButtonSnap configuration ===== */
112
- /**
113
- Register our button in the QuickTags bar
114
- */
115
- function s2_button_init() {
116
- $url = get_settings('siteurl') . '/wp-content/plugins/subscribe2/s2_button.png';
117
- buttonsnap_textbutton($url, 'Subscribe2', '<!--subscribe2-->');
118
- buttonsnap_register_marker('subscribe2', 's2_marker');
119
- }
120
-
121
- /**
122
- Style a marker in the Rich Text Editor for our tag
123
-
124
- By default, the RTE suppresses output of HTML comments, so this places a CSS style on our token in order to make it display
125
- */
126
- function subscribe2_css() {
127
- $marker_url = get_settings('siteurl') . '/wp-content/plugins/subscribe2/s2_marker.png';
128
- echo "
129
- .s2_marker {
130
- display: block;
131
- height: 45px;
132
- margin-top: 5px;
133
- background-image: url({$marker_url});
134
- background-repeat: no-repeat;
135
- background-position: center;
136
- }
137
- ";
138
- }
139
-
140
- /* ===== Install, upgrade, reset ===== */
141
- /**
142
- Install our table
143
- */
144
- function install() {
145
- // include upgrade-functions for maybe_create_table;
146
- if (! function_exists('maybe_create_table')) {
147
- require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
148
- }
149
- $date = date('Y-m-d');
150
- $sql = "CREATE TABLE $this->public (
151
- id int(11) NOT NULL auto_increment,
152
- email varchar(64) NOT NULL default '',
153
- active tinyint(1) default 0,
154
- date DATE default '$date' NOT NULL,
155
- PRIMARY KEY (id) )";
156
-
157
- // create the table, as needed
158
- maybe_create_table($this->public, $sql);
159
- $this->reset();
160
- } // end install()
161
-
162
- /**
163
- Upgrade the database
164
- */
165
- function upgrade() {
166
- global $wpdb;
167
-
168
- // include upgrade-functions for maybe_create_table;
169
- if (! function_exists('maybe_create_table')) {
170
- require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
171
- }
172
- $date = date('Y-m-d');
173
- maybe_add_column($this->public, 'date', "ALTER TABLE `$this->public` ADD `date` DATE DEFAULT '$date' NOT NULL AFTER `active`;");
174
-
175
- // let's take the time to check process registered users
176
- // existing public subscribers are subscribed to all categories
177
- $users = $wpdb->get_col("SELECT ID FROM $wpdb->users");
178
- if (! empty($users)) {
179
- foreach ($users as $user) {
180
- $this->register($user);
181
- }
182
- }
183
- // update the options table to serialized format
184
- // We'll deal with s2_future_posts another time
185
- // TODO: Fix s2_future posts
186
- $old_options = $wpdb->get_col("SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name != 's2_future_posts'");
187
-
188
- if (!empty($old_options)) {
189
- foreach ($old_options as $option) {
190
- $value = get_option($option);
191
- $option_array = substr($option, 3);
192
- $this->subscribe2_options[$option_array] = $value;
193
- delete_option($option);
194
- }
195
- }
196
- $this->subscribe2_options['version'] = S2VERSION;
197
- update_option('subscribe2_options', $this->subscribe2_options);
198
- } // end upgrade()
199
-
200
- /**
201
- Reset our options
202
- */
203
- function reset() {
204
- delete_option('subscribe2_options');
205
- unset($this->subscribe2_options);
206
- require(ABSPATH . "/wp-content/plugins/subscribe2/include.php");
207
- } // end reset()
208
-
209
- /* ===== mail handling ===== */
210
- /**
211
- Performs string substitutions for subscribe2 mail texts
212
- */
213
- function substitute($string = '') {
214
- if ('' == $string) {
215
- return;
216
- }
217
- $string = str_replace('BLOGNAME', get_settings('blogname'), $string);
218
- $string = str_replace('BLOGLINK', get_bloginfo('url'), $string);
219
- $string = str_replace('TITLE', stripslashes($this->post_title), $string);
220
- $string = str_replace('PERMALINK', $this->permalink, $string);
221
- $string = str_replace('MYNAME', stripslashes($this->myname), $string);
222
- $string = str_replace('EMAIL', $this->myemail, $string);
223
- $string = str_replace('AUTHORNAME', $this->authorname, $string);
224
- return $string;
225
- } // end sustitute()
226
-
227
- /**
228
- Delivers email to recipients in HTML or plaintext
229
- */
230
- function mail ($recipients = array(), $subject = '', $message = '', $type='text') {
231
- if ( (empty($recipients)) || ('' == $message) ) { return; }
232
-
233
- // Set sender details
234
- if ('' == $this->myname) {
235
- $admin = get_userdata(1);
236
- $this->myname = $admin->display_name;
237
- $this->myemail = $admin->user_email;
238
- }
239
- $headers = "From: $this->myname <$this->myemail>\n";
240
- $headers .= "Return-Path: <$this->myemail>\n";
241
- $headers .= "X-Mailer:PHP" . phpversion() . "\n";
242
- $headers .= "Precedence: list\nList-Id: " . get_settings('blogname') . "\n";
243
-
244
- if ('html' == $type) {
245
- // To send HTML mail, the Content-type header must be set
246
- $headers .= "MIME-Version: 1.0\n";
247
- $headers .= "Content-type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
248
- $mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>";
249
- } else {
250
- $headers .= "MIME-Version: 1.0\n";
251
- $headers .= "Content-type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
252
- $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
253
- $message = preg_replace('|&amp;|', '&', $message);
254
- $mailtext = wordwrap(strip_tags($message), 80, "\n");
255
- }
256
-
257
- // BCC all recipients
258
- $bcc = '';
259
- if ( (defined('DREAMHOST') && true == DREAMHOST) &&
260
- (count($recipients) > 30) ) {
261
- // we're on Dreamhost, and have more than 30 susbcribers
262
- $count = 1;
263
- $batch = array();
264
- foreach ($recipients as $recipient) {
265
- // advance the array pointer by one, for use down below
266
- // the array pointer _is not_ advanced by the foreach() loop itself
267
- next($recipients);
268
- $recipient = trim($recipient);
269
- // sanity check -- make sure we have a valid email
270
- if (! is_email($recipient)) { continue; }
271
- // and NOT the sender's email, since they'll
272
- // get a copy anyway
273
- if ( (! empty($recipient)) && ($this->myemail != $recipient) ) {
274
- ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ",\r\n $recipient";
275
- // Headers constructed as per definition at http://www.ietf.org/rfc/rfc2822.txt
276
- }
277
- if (30 == $count) {
278
- $count = 1;
279
- $batch[] = $bcc;
280
- $bcc = '';
281
- } else {
282
- if (false == current($recipients)) {
283
- // we've reached the end of the subscriber list
284
- // add what we have to the batch, and move on
285
- $batch[] = $bcc;
286
- break;
287
- } else {
288
- $count++;
289
- }
290
- }
291
- }
292
- // rewind the array, just to be safe
293
- reset($recipients);
294
- } else {
295
- // we're not on dreamhost, or have less than 30
296
- // subscribers, so do it normal
297
- foreach ($recipients as $recipient) {
298
- $recipient = trim($recipient);
299
- // sanity check -- make sure we have a valid email
300
- if (! is_email($recipient)) { continue; }
301
- // and NOT the sender's email, since they'll
302
- // get a copy anyway
303
- if ( (! empty($recipient)) && ($this->myemail != $recipient) ) {
304
- ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ",\r\n $recipient";
305
- // Headers constructed as per definition at http://www.ietf.org/rfc/rfc2822.txt
306
- }
307
- }
308
- $headers .= "$bcc\r\n";
309
- }
310
- // actually send mail
311
- if ( (defined('DREAMHOST') && true == DREAMHOST) && (isset($batch)) ) {
312
- foreach ($batch as $bcc) {
313
- $newheaders = $headers . "$bcc\r\n";
314
- @wp_mail($this->myemail, $subject, $mailtext, $newheaders);
315
- }
316
- } else {
317
- @wp_mail($this->myemail, $subject, $mailtext, $headers);
318
- }
319
- } // end mail()
320
-
321
- /**
322
- Sends an email notification of a new post
323
- */
324
- function publish($id = 0, $cron = 0) {
325
- if (! $id) { return $id; }
326
-
327
- // are we doing daily digests? If so, don't send anything now
328
- if ( defined('S2DIGEST') && true == S2DIGEST ) { return; }
329
-
330
- // we need to determine whether this is a new post, or an edit
331
- if (0 == $cron) {
332
- // we're not being called from WP-Cron
333
- if ($this->private) {
334
- // this post was published from draft status
335
- // OR is an edit of an existing post
336
- // so send no notification
337
- return $id;
338
- }
339
- }
340
-
341
- $post_cats = wp_get_post_cats('1', $id);
342
- $post_cats_string = implode(',', $post_cats);
343
- $check = false;
344
- // is the current post assigned to any categories
345
- // which should not generate a notification email?
346
- foreach (explode(',', $this->get_excluded_cats()) as $cat) {
347
- if (in_array($cat, $post_cats)) {
348
- $check = true;
349
- }
350
- }
351
- // if so, bail out
352
- if ($check) {
353
- // hang on -- can registered users subscribe to
354
- // excluded categories?
355
- if ('0' == $this->subscribe2_options['reg_override']) {
356
- // nope? okay, let's leave
357
- return $id;
358
- }
359
- }
360
-
361
- global $wpdb;
362
- $post = & get_post($id);
363
- // is this post set in the future?
364
- if ($post->post_date > current_time('mysql')) {
365
- // is wp-cron installed?
366
- if (function_exists('wp_cron_init')) {
367
- // are we doing daily digests?
368
- if ( defined('S2DIGEST') && false == S2DIGEST ) {
369
- // not doing daily digests, so
370
- // add this post to the list of
371
- // future posts
372
- $our_post = array('id' => $id, 'date' => $post->post_date);
373
- $future_posts = get_option('s2_future_posts');
374
- $future_posts[] = $our_post;
375
- update_option('s2_future_posts', $future_posts);
376
- }
377
- }
378
- // bail out
379
- return $id;
380
- }
381
-
382
- // lets collect our public subscribers
383
- // and all our registered subscribers for these categories
384
- if (! $check) {
385
- // if this post is assigned to an excluded
386
- // category, then this test will prevent
387
- // the public from receiving notification
388
- $public = $this->get_public();
389
- }
390
- $registered = $this->get_registered("cats=$post_cats_string");
391
-
392
- // do we have subscribers?
393
- if ( empty($public) && empty($registered) ) {
394
- // if not, no sense doing anything else
395
- return $id;
396
- }
397
- // we set these class variables so that we can avoid
398
- // passing them in function calls a little later
399
- $this->post_title = $post->post_title;
400
- $this->permalink = "<a href=\"" . get_permalink($id) . "\">" . get_permalink($id) . "</a>";
401
-
402
- $author = get_userdata($post->post_author);
403
- $this->authorname = $author->display_name;
404
-
405
- // do we send as admin, or post author?
406
- if ('author' == $this->subscribe2_options['sender']) {
407
- // get author details
408
- $user =& $author;
409
- } else {
410
- // get admin details
411
- $user = get_userdata(1);
412
- }
413
- $this->myemail = $user->user_email;
414
- $this->myname = $user->display_name;
415
- // Get email subject
416
- $subject = $this->substitute(stripslashes($this->s2_subject));
417
- // Get the message template
418
- $mailtext = $this->substitute(stripslashes($this->subscribe2_options['mailtext']));
419
-
420
- $plaintext = $post->post_content;
421
- $content = apply_filters('the_content', $post->post_content);
422
- $content = str_replace(']]>', ']]&gt', $content);
423
- $excerpt = $post->post_excerpt;
424
- if ('' == $excerpt) {
425
- // no excerpt, is there a <!--more--> ?
426
- if (false !== strpos($plaintext, '<!--more-->')) {
427
- list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
428
- // strip leading and trailing whitespace
429
- $excerpt = strip_tags($excerpt);
430
- $excerpt = trim($excerpt);
431
- } else {
432
- // no <!--more-->, so grab the first 55 words
433
- $excerpt = strip_tags($plaintext);
434
- $excerpt_length = 55;
435
- $words = explode(' ', $plaintext, $excerpt_length + 1);
436
- if (count($words) > $excerpt_length) {
437
- array_pop($words);
438
- array_push($words, '[...]');
439
- $excerpt = implode(' ', $words);
440
- }
441
- }
442
-
443
- }
444
- // first we send plaintext summary emails
445
- $body = str_replace('POST', $excerpt, $mailtext);
446
- $registered = $this->get_registered("cats=$post_cats_string&format=text&amount=excerpt");
447
- if (empty($registered)) {
448
- $recipients = (array)$public;
449
- }
450
- elseif (empty($public)) {
451
- $recipients = (array)$registered;
452
- } else {
453
- $recipients = array_merge((array)$public, (array)$registered);
454
- }
455
- $this->mail($recipients, $subject, $body);
456
- // next we send plaintext full content emails
457
- $body = str_replace('POST', strip_tags($plaintext), $mailtext);
458
- $this->mail($this->get_registered("cats=$post_cats_string&format=text&amount=post"), $subject, $body);
459
- // finally we send html full content emails
460
- $body = str_replace("\r\n", "<br />\r\n", $mailtext);
461
- $body = str_replace('POST', $content, $body);
462
- $this->mail($this->get_registered("cats=$post_cats_string&format=html"), $subject, $body, 'html');
463
-
464
- return $id;
465
- } // end publish()
466
-
467
- /**
468
- Sends a notification when a draft post is published
469
- */
470
- function private2publish($id = 0) {
471
- if (0 == $id) { return $id; }
472
-
473
- $this->publish($id);
474
- $this->private = TRUE;
475
- return $id;
476
- } // end private2publish()
477
-
478
- /**
479
- Prevents notifications from being sent when editing posts
480
- */
481
- function edit($id = 0) {
482
- if (0 == $id) { return; }
483
-
484
- $this->private = TRUE;
485
- return $id;
486
- }
487
-
488
- /**
489
- Send confirmation email to the user
490
- */
491
- function send_confirm($what = '', $is_remind = FALSE) {
492
- if ($this->filtered == 1) { return; }
493
- if ( (! $this->email) || (! $what) ) {
494
- return false;
495
- }
496
- $id = $this->get_id($this->email);
497
- if (! $id) {
498
- return false;
499
- }
500
-
501
- // generate the URL "?s2=ACTION+HASH+ID"
502
- // ACTION = 1 to subscribe, 0 to unsubscribe
503
- // HASH = md5 hash of email address
504
- // ID = user's ID in the subscribe2 table
505
- $link = get_settings('siteurl') . "?s2=";
506
-
507
- if ('add' == $what) {
508
- $link .= '1';
509
- } elseif ('del' == $what) {
510
- $link .= '0';
511
- }
512
- $link .= md5($this->email);
513
- $link .= $id;
514
-
515
- $admin = get_userdata(1);
516
- $this->myname = $admin->display_name;
517
-
518
- if ($is_remind == TRUE) {
519
- $body = $this->substitute(stripslashes($this->subscribe2_options['remind_email']));
520
- $subject = stripslashes($this->remind_subject);
521
- } else {
522
- $body = $this->substitute(stripslashes($this->subscribe2_options['confirm_email']));
523
- if ('add' == $what) {
524
- $body = str_replace("ACTION", $this->subscribe, $body);
525
- } elseif ('del' == $what) {
526
- $body = str_replace("ACTION", $this->unsubscribe, $body);
527
- }
528
- $subject = stripslashes($this->confirm_subject);
529
- }
530
-
531
- $body = str_replace("LINK", $link, $body);
532
-
533
- $mailheaders .= "From: $admin->display_name <$admin->user_email>\n";
534
- $mailheaders .= "Return-Path: <$admin->user_email>\n";
535
- $mailheaders .= "X-Mailer:PHP" . phpversion() . "\n";
536
- $mailheaders .= "Precedence: list\nList-Id: " . get_settings('blogname') . "\n";
537
- $mailheaders .= "MIME-Version: 1.0\n";
538
- $mailheaders .= "Content-type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
539
-
540
- @wp_mail ($this->email, $subject, $body, $mailheaders);
541
- } // end send_confirm()
542
-
543
- /* ===== Category functions ===== */
544
- /**
545
- Returns a comma-separated list of category IDs which should not generate notifications
546
- */
547
- function get_excluded_cats() {
548
- if ('' != $this->excluded_cats) {
549
- return $this->excluded_cats;
550
- } else {
551
- global $wpdb;
552
- $this->excluded_cats = $this->subscribe2_options['exclude'];
553
- return $this->excluded_cats;
554
- }
555
- } // end get_excluded_cats()
556
-
557
- /**
558
- Return either a comma-separated list of all the category IDs in the blog or an array of cat_ID => cat_name
559
- */
560
- function get_all_categories($select = 'id') {
561
- global $wpdb;
562
- if ('id' == $select) {
563
- return implode(',', $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories"));
564
- } else {
565
- $cats = array();
566
- $result = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_N);
567
- foreach ($result as $result) {
568
- $cats[$result[0]] = $result[1];
569
- }
570
- return $cats;
571
- }
572
- } // end get_all_categories()
573
-
574
- /* ===== Subscriber functions ===== */
575
- /**
576
- Given a public subscriber ID, returns the email address
577
- */
578
- function get_email ($id = 0) {
579
- global $wpdb;
580
-
581
- if (! $id) {
582
- return false;
583
- }
584
- return $wpdb->get_var("SELECT email FROM $this->public WHERE id=$id");
585
- } // end get_email
586
-
587
- /**
588
- Given a public subscriber email, returns the subscriber ID
589
- */
590
- function get_id ($email = '') {
591
- global $wpdb;
592
-
593
- if (! $email) {
594
- return false;
595
- }
596
- return $wpdb->get_var("SELECT id FROM $this->public WHERE email='$email'");
597
- } // end get_id()
598
-
599
- /**
600
- Activate an email address
601
- If the address is not already present, it will be added
602
- */
603
- function activate ($email = '') {
604
- global $wpdb;
605
-
606
- if ('' == $email) {
607
- if ('' != $this->email) {
608
- $email = $this->email;
609
- } else {
610
- return false;
611
- }
612
- }
613
-
614
- if (false !== $this->is_public($email)) {
615
- $check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email='$this->email'");
616
- if ($check) { return; }
617
- $wpdb->get_results("UPDATE $this->public SET active='1' WHERE email='$email'");
618
- } else {
619
- $wpdb->get_results("INSERT INTO $this->public (email, active, date) VALUES ('$email', '1', NOW())");
620
- }
621
- } // end activate()
622
-
623
- /**
624
- Add an unconfirmed email address to the subscriber list
625
- */
626
- function add ($email = '') {
627
- if ($this->filtered ==1) { return; }
628
- global $wpdb;
629
-
630
- if ('' == $email) {
631
- if ('' != $this->email) {
632
- $email = $this->email;
633
- } else {
634
- return false;
635
- }
636
- }
637
-
638
- if (! is_email($email)) { return false; }
639
-
640
- if (false !== $this->is_public($email)) {
641
- $wpdb->get_results("UPDATE $this->public SET date=NOW() WHERE email='$email'");
642
- } else {
643
- $wpdb->get_results("INSERT INTO $this->public (email, active, date) VALUES ('$email', '0', NOW())");
644
- }
645
- } // end add()
646
-
647
- /**
648
- Remove a user from the subscription table
649
- */
650
- function delete($email = '') {
651
- global $wpdb;
652
-
653
- if ('' == $email) {
654
- if ('' != $this->email) {
655
- $email = $this->email;
656
- } else {
657
- return false;
658
- }
659
- }
660
-
661
- if (! is_email($email)) { return false; }
662
- $wpdb->get_results("DELETE FROM $this->public WHERE email='$email'");
663
- } // end delete()
664
-
665
- /**
666
- Toggle a public subscriber's status
667
- */
668
- function toggle($email = '') {
669
- global $wpdb;
670
-
671
- if ( ('' == $email) || (! is_email($email)) ) { return false; }
672
-
673
- // let's see if this is a public user
674
- $status = $this->is_public($email);
675
- if (false === $status) { return false; }
676
-
677
- if ('0' == $status) {
678
- $wpdb->get_results("UPDATE $this->public SET active='1' WHERE email='$email'");
679
- } else {
680
- $wpdb->get_results("UPDATE $this->public SET active='0' WHERE email='$email'");
681
- }
682
- } // end toggle()
683
-
684
- /**
685
- Send reminder email to unconfirmed public subscribers
686
- */
687
- function remind($emails = '') {
688
- if ('' == $emails) { return false; }
689
-
690
- $admin = get_userdata(1);
691
- $this->myname = $admin->display_name;
692
-
693
- $recipients = explode(",", $emails);
694
- if (! is_array($recipients)) { $recipients = array(); }
695
- foreach ($recipients as $recipient) {
696
- $this->email = $recipient;
697
- $this->send_confirm('add', TRUE);
698
- }
699
- } //end remind()
700
-
701
- /**
702
- Export email list to CSV download
703
- */
704
- function exportcsv($emails = '') {
705
- if ('' == $emails) {return false; }
706
-
707
- $f = fopen(ABSPATH . '/wp-content/email.csv', 'w');
708
- fwrite($f, $emails);
709
- fclose($f);
710
- } //end exportcsv
711
-
712
- /**
713
- Check email is not from a barred domain
714
- */
715
- function is_barred($email='') {
716
- $barred_option = $this->subscribe2_options['barred'];
717
- list($user, $domain) = split('@', $email);
718
- $bar_check = stristr($barred_option, $domain);
719
-
720
- if(!empty($bar_check)) {
721
- return true;
722
- } else {
723
- return false;
724
- }
725
- } //end is_barred()
726
-
727
- /**
728
- Confirm request from the link emailed to the user and email the admin
729
- */
730
- function confirm($content = '') {
731
- global $wpdb;
732
-
733
- if (1 == $this->filtered) { return $content; }
734
-
735
- $code = $_GET['s2'];
736
- $action = intval(substr($code, 0, 1));
737
- $hash = substr($code, 1, 32);
738
- $code = str_replace($hash, '', $code);
739
- $id = intval(substr($code, 1));
740
- if ($id) {
741
- $this->email = $this->get_email($id);
742
- if ( (!$this->email) || ($hash !== md5($this->email)) ) {
743
- return $this->no_such_email;
744
- }
745
- } else {
746
- return $this->no_such_email;
747
- }
748
-
749
- if ('1' == $action) {
750
- // make this subscription active
751
- $this->activate();
752
- $this->message = $this->added;
753
- $subject = '[' . get_settings('blogname') . '] ' . __('New subscriber', 'subscribe2');
754
- $message = "$this->email " . __('subscribed to email notifications!', 'subscribe2');
755
- $recipients = $wpdb->get_col("SELECT DISTINCT(user_email) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key='wp_user_level' AND $wpdb->usermeta.meta_value='10'");
756
- $this->mail($recipients, $subject, $message);
757
- $this->filtered = 1;
758
- } elseif ('0' == $action) {
759
- // remove this subscriber
760
- $this->delete();
761
- $this->message = $this->deleted;
762
- $this->filtered = 1;
763
- }
764
-
765
- if ('' != $this->message) {
766
- return $this->message;
767
- }
768
- } // end confirm
769
-
770
- /**
771
- Is the supplied email address a public subscriber?
772
- */
773
- function is_public($email = '') {
774
- global $wpdb;
775
-
776
- if ('' == $email) { return false; }
777
-
778
- $check = $wpdb->get_var("SELECT active FROM $this->public WHERE email='$email'");
779
- if ( ('0' == $check) || ('1' == $check) ) {
780
- return $check;
781
- } else {
782
- return false;
783
- }
784
- } // end is_public
785
-
786
- /**
787
- Is the supplied email address a registered user of the blog?
788
- */
789
- function is_registered($email = '') {
790
- global $wpdb;
791
-
792
- if ('' == $email) { return false; }
793
-
794
- $check = $wpdb->get_var("SELECT email FROM $wpdb->users WHERE user_email='$email'");
795
- if ($check) {
796
- return true;
797
- } else {
798
- return false;
799
- }
800
- }
801
-
802
- /**
803
- Return an array of all the public subscribers
804
- */
805
- function get_public ($confirmed = 1) {
806
- global $wpdb;
807
- if (1 == $confirmed) {
808
- if ('' == $this->all_public) {
809
- $this->all_public = $wpdb->get_col("SELECT email FROM $this->public WHERE active='1'");
810
- }
811
- return $this->all_public;
812
- } else {
813
- if ('' == $this->all_unconfirmed) {
814
- $this->all_unconfirmed = $wpdb->get_col("SELECT email FROM $this->public WHERE active='0'");
815
- }
816
- return $this->all_unconfirmed;
817
- }
818
- } // end get_public()
819
-
820
- /**
821
- Return an array of registered subscribers
822
- Collect all the registered users of the blog who are subscribed to the specified categories
823
- */
824
- function get_registered ($args = '') {
825
- global $wpdb;
826
-
827
- $format = '';
828
- $amount = '';
829
- $cats = '';
830
- $subscribers = array();
831
-
832
- parse_str($args, $r);
833
- if (! isset($r['cats']))
834
- $r['cats'] = '';
835
- if (! isset($r['format']))
836
- $r['format'] = 'all';
837
- if (! isset($r['amount']))
838
- $r['amount'] = 'all';
839
-
840
- $JOIN = ''; $AND = '';
841
- // text or HTML subscribers
842
- if ('all' != $r['format']) {
843
- $JOIN .= "INNER JOIN $wpdb->usermeta AS b ON a.user_id = b.user_id ";
844
- $AND .= " AND b.meta_key='s2_format' AND b.meta_value=";
845
- if ('html' == $r['format']) {
846
- $AND .= "'html'";
847
- } elseif ('text' == $r['format']) {
848
- $AND .= "'text'";
849
- }
850
- }
851
-
852
- // full post or excerpt subscribers
853
- if ('all' != $r['amount']) {
854
- $JOIN .= "INNER JOIN $wpdb->usermeta AS c ON a.user_id = c.user_id ";
855
- $AND .= " AND c.meta_key='s2_excerpt' AND c.meta_value=";
856
- if ('excerpt' == $r['amount']) {
857
- $AND .= "'excerpt'";
858
- } elseif ('post' == $r['amount']) {
859
- $AND.= "'post'";
860
- }
861
- }
862
-
863
- // specific category subscribers
864
- if ('' != $r['cats']) {
865
- $JOIN .= "INNER JOIN $wpdb->usermeta AS d ON a.user_id = d.user_id ";
866
- foreach (explode(',', $r['cats']) as $cat) {
867
- ('' == $and) ? $and = "d.meta_key='s2_cat$cat'" : $and .= " OR d.meta_key='s2_cat$cat'";
868
- }
869
- $AND .= "AND ($and)";
870
- }
871
-
872
- $sql = "SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . " WHERE a.meta_key='s2_subscribed'" . $AND;
873
- $result = $wpdb->get_col($sql);
874
- if ($result) {
875
- $ids = implode(',', $result);
876
- return $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids)");
877
- }
878
- } // end get_registered()
879
-
880
- /**
881
- Collects the signup date for all public subscribers
882
- */
883
- function signup_date($email = '') {
884
- if ('' == $email) { return false; }
885
-
886
- global $wpdb;
887
- if (! empty($this->signup_dates)) {
888
- return $this->signup_dates[$email];
889
- } else {
890
- $results = $wpdb->get_results("SELECT email, date FROM $this->public", ARRAY_N);
891
- foreach ($results as $result) {
892
- $this->signup_dates[$result[0]] = $result[1];
893
- }
894
- return $this->signup_dates[$email];
895
- }
896
- } // end signup_date()
897
-
898
- /**
899
- Create the appropriate usermeta values when a user registers
900
- If the registering user had previously subscribed to notifications, this function will delete them from the public subscriber list first
901
- */
902
- function register ($user_id = 0) {
903
- global $wpdb;
904
-
905
- if (0 == $user_id) { return $user_id; }
906
- $user = get_userdata($user_id);
907
-
908
- // has this user previously signed up for email notification?
909
- if (false !== $this->is_public($user->user_email)) {
910
- // delete this user from the public table, and subscribe them to all the categories
911
- $this->delete($user->user_email);
912
- update_usermeta($user_id, 's2_subscribed', $this->get_all_categories());
913
- foreach(explode(',', $this->get_all_categories()) as $cat) {
914
- update_usermeta($user_id, 's2_cat' . $cat, "$cat");
915
- }
916
- update_usermeta($user_id, 's2_format', 'text');
917
- update_usermeta($user_id, 's2_excerpt', 'excerpt');
918
- } else {
919
- // add the usermeta for new registrations, but don't subscribe them
920
- $check = get_usermeta($user_id, 's2_subscribed');
921
- // ensure existing subscriptions are not overwritten on upgrade
922
- if (empty($check)) {
923
- if ('yes' == $this->subscribe2_options['s2_autosub']) {
924
- update_usermeta($user_id, 's2_subscribed', $this->get_all_categories());
925
- foreach(explode(',', $this->get_all_categories()) as $cat) {
926
- update_usermeta($user_id, 's2_cat' . $cat, "$cat");
927
- }
928
- if ('html' == $this->subscribe2_options['s2_autoformat']) {
929
- update_usermeta($user_id, 's2_format', 'html');
930
- update_usermeta($user_id, 's2_excerpt', 'post');
931
- } elseif ('fulltext' == $this->subscribe2_options['s2_autoformat']) {
932
- update_usermeta($user_id, 's2_format', 'text');
933
- update_usermeta($user_id, 's2_excerpt', 'post');
934
- } else {
935
- update_usermeta($user_id, 's2_format', 'text');
936
- update_usermeta($user_id, 's2_excerpt', 'excerpt');
937
- }
938
- } else {
939
- update_usermeta($user_id, 's2_subscribed', '');
940
- update_usermeta($user_id, 's2_format', 'text');
941
- update_usermeta($user_id, 's2_excerpt', 'excerpt');
942
- }
943
- }
944
- }
945
- return $user_id;
946
- } // end register()
947
-
948
- /**
949
- Subscribe all registered users to category selected on Admin Manage Page
950
- */
951
- function subscribe_registered_users ($emails = '', $cats = '') {
952
- if (('' == $emails) || ('' == $cats)) { return false; }
953
- global $wpdb;
954
-
955
- $useremails = explode(",", $emails);
956
- $useremails = implode("', '", $useremails);
957
-
958
- $sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
959
- $user_IDs = $wpdb->get_col($sql);
960
- $cats = $_POST['category'];
961
- if (! is_array($cats)) {
962
- $cats = array($_POST['category']);
963
- }
964
-
965
- foreach ($user_IDs as $user_ID) {
966
- $old_cats = explode(',', get_usermeta($user_ID, 's2_subscribed'));
967
- if (! is_array($old_cats)) {
968
- $old_cats = array($old_cats);
969
- }
970
- $new = array_diff($cats, $old_cats);
971
- if (! empty($new)) {
972
- // add subscription to these cat IDs
973
- foreach ($new as $id) {
974
- update_usermeta($user_ID, 's2_cat' . $id, "$id");
975
- }
976
- }
977
- $newcats = array_merge($cats, $old_cats);
978
- update_usermeta($user_ID, 's2_subscribed', implode(',', $newcats));
979
- }
980
- } // end subscribe_registered_users
981
-
982
- /**
983
- Unsubscribe all registered users to category selected on Admin Manage Page
984
- */
985
- function unsubscribe_registered_users ($emails = '', $cats = '') {
986
- if (('' == $emails) || ('' == $cats)) { return false; }
987
- global $wpdb;
988
-
989
- $useremails = explode(",", $emails);
990
- $useremails = implode("', '", $useremails);
991
-
992
- $sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
993
- $user_IDs = $wpdb->get_col($sql);
994
- $cats = $_POST['category'];
995
- if (! is_array($cats)) {
996
- $cats = array($_POST['category']);
997
- }
998
-
999
- foreach ($user_IDs as $user_ID) {
1000
- $old_cats = explode(',', get_usermeta($user_ID, 's2_subscribed'));
1001
- if (! is_array($old_cats)) {
1002
- $old_cats = array($old_cats);
1003
- }
1004
- $remain = array_diff($old_cats, $cats);
1005
- if (! empty($remain)) {
1006
- // remove subscription to these cat IDs and update s2_subscribed
1007
- foreach ($cats as $id) {
1008
- delete_usermeta($user_ID, 's2_cat' . $id, "$id");
1009
- }
1010
- update_usermeta($user_ID, 's2_subscribed', implode(',', $remain));
1011
- } else {
1012
- // remove subscription to these cat IDs and update s2_subscribed to ''
1013
- foreach ($cats as $id) {
1014
- delete_usermeta($user_ID, 's2_cat' . $id, "$id");
1015
- }
1016
- update_usermeta($user_ID, 's2_subscribed', '');
1017
- }
1018
- }
1019
- } // end unsubscribe_registered_users
1020
-
1021
- /**
1022
- Autosubscribe registered users to newly created categories
1023
- if registered user has selected this option
1024
- */
1025
- function autosub_new_category ($new_category='') {
1026
- global $wpdb;
1027
-
1028
- $sql = "SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key='s2_autosub' AND $wpdb->usermeta.meta_value='yes'";
1029
- $user_IDs = $wpdb->get_col($sql);
1030
- if ('' == $user_IDs) { return; }
1031
-
1032
- foreach ($user_IDs as $user_ID) {
1033
- $old_cats = explode(',', get_usermeta($user_ID, 's2_subscribed'));
1034
- if (! is_array($old_cats)) {
1035
- $old_cats = array($old_cats);
1036
- }
1037
- // add subscription to these cat IDs
1038
- update_usermeta($user_ID, 's2_cat' . $new_category, "$new_category");
1039
- $newcats = array_merge($old_cats, (array)$new_category);
1040
- update_usermeta($user_ID, 's2_subscribed', implode(',', $newcats));
1041
- }
1042
- } // end autosub_new_category
1043
-
1044
- /* ===== Menus ===== */
1045
- /**
1046
- Our management page
1047
- */
1048
- function manage_menu() {
1049
- global $wpdb;
1050
-
1051
- //Get Registered Subscribers for bulk management
1052
- $registered = $this->get_registered();
1053
- if(!empty($registered)) {
1054
- $emails = implode(",", $registered);
1055
- }
1056
-
1057
- $what = '';
1058
- $reminderform = '';
1059
-
1060
- // was anything POSTed ?
1061
- if (isset($_POST['s2_admin'])) {
1062
- if ('subscribe' == $_POST['s2_admin']) {
1063
- foreach (preg_split ("/[\s,]+/", $_POST['addresses']) as $email) {
1064
- if (is_email($email)) {
1065
- $this->activate($email);
1066
- }
1067
- }
1068
- $_POST['what'] = 'confirmed';
1069
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . __('Address(es) subscribed!', 'subscribe2') . "</p></strong></div>";
1070
- } elseif ('delete' == $_POST['s2_admin']) {
1071
- $this->delete($_POST['email']);
1072
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . $_POST['email'] . ' ' . __('deleted!', 'subscribe2') . "</p></strong></div>";
1073
- } elseif ('toggle' == $_POST['s2_admin']) {
1074
- $this->toggle($_POST['email']);
1075
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . $_POST['email'] . ' ' . __('status changed!', 'subscribe2') . "</p></strong></div>";
1076
- } elseif ('remind' == $_POST['s2_admin']) {
1077
- $this->remind($_POST['reminderemails']);
1078
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . __('Reminder Email(s) Sent!','subscribe2') . "</p></strong></div>";
1079
- } elseif ('exportcsv' == $_POST['s2_admin']) {
1080
- $this->exportcsv($_POST['exportcsv']);
1081
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . __('CSV File Created in wp-content','subscribe2') . "</p></strong></div>";
1082
- } elseif ( ('register' == $_POST['s2_admin']) && ('Subscribe' == $_POST['submit']) ) {
1083
- $this->subscribe_registered_users($_POST['emails'], $_POST['category']);
1084
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . __('Registered Users Subscribed!','subscribe2') . "</p></strong></div>";
1085
- } elseif ( ('register' == $_POST['s2_admin']) && ('Unsubscribe' == $_POST['submit']) ) {
1086
- $this->unsubscribe_registered_users($_POST['emails'], $_POST['category']);
1087
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>" . __('Registered Users Unsubscribed!','subscribe2') . "</p></strong></div>";
1088
- }
1089
- }
1090
-
1091
- if (isset($_POST['what'])) {
1092
- if ('all' == $_POST['what']) {
1093
- $what = 'all';
1094
- $confirmed = $this->get_public();
1095
- $unconfirmed = $this->get_public(0);
1096
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$registered);
1097
- } elseif ('public' == $_POST['what']) {
1098
- $what = 'public';
1099
- $confirmed = $this->get_public();
1100
- $unconfirmed = $this->get_public(0);
1101
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
1102
- } elseif ('confirmed' == $_POST['what']) {
1103
- $what = 'confirmed';
1104
- $confirmed = $this->get_public();
1105
- $subscribers = $confirmed;
1106
- } elseif ('unconfirmed' == $_POST['what']) {
1107
- $what = 'unconfirmed';
1108
- $unconfirmed = $this->get_public(0);
1109
- $subscribers = $unconfirmed;
1110
- if (!empty($unconfirmed)) {
1111
- $reminderemails = implode(",", $unconfirmed);
1112
- $reminderform = "<span class=\"submit\"><form method=\"post\" action=\"\"><input type=\"hidden\" name=\"reminderemails\" value=\"$reminderemails\" /><input type=\"hidden\" name=\"s2_admin\" value=\"remind\" /><input type=\"submit\" name=\"submit\" value=\"" . __('Send Reminder Email','subscribe2') . "\" /></form></span>";
1113
- }
1114
- } elseif (is_numeric($_POST['what'])) {
1115
- $what = intval($_POST['what']);
1116
- $subscribers = $this->get_registered("cats=$what");
1117
- } elseif ('registered' == $_POST['what']) {
1118
- $what = 'registered';
1119
- $subscribers = $registered;
1120
- }
1121
- } elseif ('' == $what) {
1122
- $what = 'registered';
1123
- $subscribers = $registered;
1124
- $registermessage = '';
1125
- if (empty($subscribers)) {
1126
- $confirmed = $this->get_public();
1127
- $subscribers = $confirmed;
1128
- $what = 'confirmed';
1129
- if (empty ($subscribers)) {
1130
- $unconfirmed = $this->get_public(0);
1131
- $subscribers = $unconfirmed;
1132
- $what = 'unconfirmed';
1133
- if (empty($subscribers)) {
1134
- $what = 'all';
1135
- }
1136
- }
1137
- }
1138
- }
1139
- if (!empty($subscribers)) {
1140
- natcasesort($subscribers);
1141
- }
1142
- // safety check for our arrays
1143
- if ('' == $confirmed) { $confirmed = array(); }
1144
- if ('' == $unconfirmed) { $unconfirmed = array(); }
1145
- if ('' == $registered) { $registered = array(); }
1146
-
1147
- // show our form
1148
- echo "<div class=\"wrap\">";
1149
- echo "<h2>" . __('Subscribe Addresses', 'subscribe2') . "</h2>\r\n";
1150
- echo "<form method=\"post\" action=\"\">\r\n";
1151
- echo "<span style=\"align:left\">" . __('Enter addresses, one per line or comma-seperated', 'subscribe2') . "</span><br />\r\n";
1152
- echo "<textarea rows=\"2\" cols=\"80\" name=\"addresses\"></textarea>";
1153
- echo "<span class=\"submit\"><input type=\"submit\" name=\"submit\" value=\"" . __('Subscribe', 'subscribe2') . "\"/>";
1154
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"subscribe\" /></span>";
1155
- echo "</form></div>";
1156
-
1157
- // subscriber lists
1158
- echo "<div class=\"wrap\"><h2>" . __('Subscribers', 'subscribe2') . "</h2>\r\n";
1159
-
1160
- $this->display_subscriber_dropdown($what, __('Filter', 'subscribe2'));
1161
- // show the selected subscribers
1162
- $alternate = 'alternate';
1163
- if (!empty($subscribers)) {
1164
- echo "<p align=\"center\"><b>" . __('Registered on the left, confirmed in the middle, unconfirmed on the right', 'subscribe2') . "</b></p>";
1165
- if (is_writable(ABSPATH . '/wp-content')) {
1166
- $exportcsv = implode(",", $subscribers);
1167
- echo "<span class=\"submit\"><form method=\"post\" action=\"\"><input type=\"hidden\" name=\"exportcsv\" value=\"$exportcsv\" /><input type=\"hidden\" name=\"s2_admin\" value=\"exportcsv\" /><input type=\"submit\" name=\"submit\" value=\"" . __('Save Emails to CSV File','subscribe2') . "\" /></form></span>";
1168
- }
1169
- }
1170
- echo "<table cellpadding=\"2\" cellspacing=\"2\">";
1171
- if (!empty($subscribers)) {
1172
- foreach ($subscribers as $subscriber) {
1173
- echo "<tr class=\"$alternate\">";
1174
- echo "<td width=\"75%\"";
1175
- if (in_array($subscriber, $unconfirmed)) {
1176
- echo " align=\"right\">";
1177
- } elseif (in_array($subscriber, $confirmed)) {
1178
- echo "align=\"center\">";
1179
- } else {
1180
- echo "align=\"left\" colspan=\"3\">";
1181
- }
1182
- echo "<a href=\"mailto:$subscriber\">$subscriber</a>\r\n";
1183
- if (in_array($subscriber, $unconfirmed) || in_array($subscriber, $confirmed) ) {
1184
- echo "(" . $this->signup_date($subscriber) . ")</td>";
1185
- echo "<td width=\"5%\" align=\"center\"><form method=\"post\" action=\"\"><input type=\"hidden\" name=\"email\" value=\"$subscriber\" /><input type=\"hidden\" name=\"s2_admin\" value=\"toggle\" /><input type=\"hidden\" name=\"what\" value=\"$what\" /><input type=\"submit\" name=\"submit\" value=\"";
1186
- (in_array($subscriber, $unconfirmed)) ? $foo = '&lt;-' : $foo= '-&gt;';
1187
- echo "$foo\" /></form></td>";
1188
- echo "<td width=\"2%\" align=\"center\"><form method=\"post\" action=\"\"><span class=\"delete\"><input type=\"hidden\" name=\"email\" value=\"$subscriber\" /><input type=\"hidden\" name=\"s2_admin\" value=\"delete\" /><input type=\"hidden\" name=\"what\" value=\"$what\" /><input type=\"submit\" name=\"submit\" value=\"X\" /></span></form>";
1189
- }
1190
- echo "</td></tr>\r\n";
1191
- ('alternate' == $alternate) ? $alternate = '' : $alternate = 'alternate';
1192
- }
1193
- } else {
1194
- echo "<tr><td align=\"center\"><b>" . __('NONE', 'subscribe2') . "</b></td></tr>\r\n";
1195
- }
1196
- echo "</table>";
1197
- if (!empty($reminderform)) {echo $reminderform;}
1198
- echo "</div>\r\n";
1199
-
1200
- //show bulk managment form
1201
- echo "<div class=\"wrap\">";
1202
- echo "<h2 >" . __('Categories', 'subscribe2') . "</h2>\r\n";
1203
- echo __('Existing Registered Users can be automatically (un)subscribed to categories using this section.', 'subscribe2') . "<br />\r\n";
1204
- echo "<strong><em style=\"color: red\">" . __('Consider User Privacy as changes cannot be undone', 'subscribe2') . "</em></strong><br />\r\n";
1205
- echo "<span class=\"submit\"><form method=\"post\" action=\"\"><input type=\"hidden\" name=\"emails\" value=\"$emails\" /><input type=\"hidden\" name=\"s2_admin\" value=\"register\" />";
1206
- $this->display_category_form(explode(',', $this->get_excluded_cats()));
1207
- echo "<input type=\"submit\" id=\"deletepost\" name=\"submit\" value=\"" . __('Subscribe','subscribe2') . "\" />";
1208
- echo "<input type=\"submit\" id=\"deletepost\" name=\"submit\" value=\"" . __('Unsubscribe','subscribe2') . "\" /></form></span>";
1209
-
1210
- echo "</div>\r\n";
1211
- echo "<div style=\"clear: both;\"><p>&nbsp;</p></div>";
1212
-
1213
- include(ABSPATH . '/wp-admin/admin-footer.php');
1214
- // just to be sure
1215
- die;
1216
- } // end manage_menu()
1217
-
1218
- /**
1219
- Our options page
1220
- */
1221
- function options_menu() {
1222
- // was anything POSTed?
1223
- if (isset($_POST['s2_admin'])) {
1224
- if ('RESET' == $_POST['s2_admin']) {
1225
- $this->reset();
1226
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>$this->options_reset</p></strong></div>";
1227
- } elseif ('options' == $_POST['s2_admin']) {
1228
- // excluded categories
1229
- if (!empty($_POST['category'])) {
1230
- $exclude_cats = implode(',', $_POST['category']);
1231
- } else {
1232
- $exclude_cats = '';
1233
- }
1234
- $this->subscribe2_options['exclude'] = $exclude_cats;
1235
- // allow override?
1236
- (isset($_POST['reg_override'])) ? $override = '1' : $override = '0';
1237
- $this->subscribe2_options['reg_override'] = $override;
1238
-
1239
- // show button?
1240
- ($_POST['show_button'] == '1') ? $showbutton = '1' : $showbutton = '0';
1241
- $this->subscribe2_options['show_button'] = $showbutton;
1242
-
1243
- // send as author or admin?
1244
- $sender = 'author';
1245
- if ('admin' == $_POST['sender']) {
1246
- $sender = 'admin';
1247
- }
1248
- $this->subscribe2_options['sender'] = $sender;
1249
-
1250
- // email templates
1251
- $mailtext = $_POST['mailtext'];
1252
- $this->subscribe2_options['mailtext'] = $mailtext;
1253
- $confirm_email = $_POST['confirm_email'];
1254
- $this->subscribe2_options['confirm_email'] = $confirm_email;
1255
- $remind_email = $_POST['remind_email'];
1256
- $this->subscribe2_options['remind_email'] = $remind_email;
1257
-
1258
- //automatic subscription
1259
- $autosub_option = $_POST['autosub'];
1260
- $this->subscribe2_options['autosub']= $autosub_option;
1261
- $autosub_format_option = $_POST['autoformat'];
1262
- $this->subscribe2_options['autoformat']= $autosub_format_option;
1263
-
1264
- //barred domains
1265
- $barred_option = $_POST['barred'];
1266
- $this->subscribe2_options['barred'] = $barred_option;
1267
- echo "<div id=\"message\" class=\"updated fade\"><strong><p>$this->options_saved</p></strong></div>";
1268
- update_option( 'subscribe2_options', $this->subscribe2_options );
1269
- }
1270
- }
1271
- // show our form
1272
- echo "<div class=\"wrap\">";
1273
- echo "<form method=\"post\" action=\"\">";
1274
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"options\" />";
1275
- echo "<h2>" . __('Delivery Options', 'subscribe2') . ":</h2>";
1276
- echo __('Send Email From', 'subscribe2') . ': ';
1277
- echo "<input type=\"radio\" name=\"sender\" value=\"author\" ";
1278
- if ('author' == $this->subscribe2_options['sender']) {
1279
- echo "checked=\"checked\" ";
1280
- }
1281
- echo " /> " . __('Author of the post', 'subscribe2') . " &nbsp;&nbsp;";
1282
- echo "<input type=\"radio\" name=\"sender\" value=\"admin\" ";
1283
- if ('admin' == $this->subscribe2_options['sender']) {
1284
- echo "checked=\"checked\" ";
1285
- }
1286
- echo " /> " . __('Blog Admin', 'subscribe2') . "<br />\r\n";
1287
- echo "<h2>" . __('Email Templates', 'subscribe2') . "</h2>\r\n";
1288
- echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"1\" class=\"editform\">";
1289
- echo "<tr><td>";
1290
- echo __('New Post email (must not be empty)', 'subscribe2') . ":";
1291
- echo "<br />\r\n";
1292
- echo "<textarea rows=\"9\" cols=\"60\" name=\"mailtext\">" . stripslashes($this->subscribe2_options['mailtext']) . "</textarea><p>\r\n";
1293
- echo "</td><td valign=\"top\" rowspan=\"3\">";
1294
- echo "<h3>" . __('Message substitions', 'subscribe2') . "</h3>\r\n";
1295
- echo "<dl>";
1296
- echo "<dt><b>BLOGNAME</b></dt><dd>" . get_bloginfo('name') . "</dd>\r\n";
1297
- echo "<dt><b>BLOGLINK</b></dt><dd>" . get_bloginfo('url') . "</dd>\r\n";
1298
- echo "<dt><b>TITLE</b></dt><dd>" . __("the post's title", 'subscribe2') . "</dd>\r\n";
1299
- echo "<dt><b>POST</b></dt><dd>" . __("the excerpt or the entire post<br />(<i>based on the subscriber's preferences</i>)", 'subscribe2') . "</dd>\r\n";
1300
- echo "<dt><b>PERMALINK</b></dt><dd>" . __("the post's permalink", 'subscribe2') . "</dd>\r\n";
1301
- echo "<dt><b>MYNAME</b></dt><dd>" . __("the admin or post author's name", 'subscribe2') . "</dd>\r\n";
1302
- echo "<dt><b>EMAIL</b></dt><dd>" . __("the admin or post author's email", 'subscribe2') . "</dd>\r\n";
1303
- echo "<dt><b>AUTHORNAME</b></dt><dd>" . __("the post author's name", 'subscribe2') . "</dd>\r\n";
1304
- echo "<dt><b>LINK</b></dt><dd>" . __("the generated link to confirm a request<br />(<i>only used in the confirmation email template</i>)", 'subscribe2') . "</dd>\r\n";
1305
- echo "<dt><b>ACTION</b></dt><dd>" . __("Action performed by LINK in confirmation email<br />(<i>only used in the confirmation email template</i>)", 'subscribe2') . "</dd>\r\n";
1306
- echo "</dl></td></tr><tr><td>";
1307
- echo __('Subscribe / Unsubscribe confirmation email', 'subscribe2') . ":<br />\r\n";
1308
- echo "<textarea rows=\"9\" cols=\"60\" name=\"confirm_email\">" . stripslashes($this->subscribe2_options['confirm_email']) . "</textarea><p>";
1309
- echo "</td></tr><tr><td>";
1310
- echo __('Reminder email to Unconfirmed Subscribers', 'subscribe2') . ":<br />\r\n";
1311
- echo "<textarea rows=\"9\" cols=\"60\" name=\"remind_email\">" . stripslashes($this->subscribe2_options['remind_email']) . "</textarea><p>";
1312
- echo "</td></tr></table>\r\n";
1313
-
1314
- // excluded categories
1315
- echo "<h2>" . __('Excluded Categories', 'subscribe2') . "</h2>\r\n";
1316
- $this->display_category_form(explode(',', $this->get_excluded_cats()));
1317
- echo "<p align=\"center\"><input type=\"checkbox\" name=\"reg_override\" value=\"1\"";
1318
- if ('1' == $this->subscribe2_options['reg_override']) {
1319
- echo "checked=\"checked\"";
1320
- }
1321
- echo "/> " . __('Allow registered users to subscribe to excluded categories?', 'subscribe2') . "</p>";
1322
- echo "<h2>" . __('Writing Options', 'subscribe2') . "</h2>\r\n";
1323
- echo "<p align=\"center\"><input type=\"checkbox\" name=\"show_button\" value=\"1\"";
1324
- if ('1' == $this->subscribe2_options['show_button']) {
1325
- echo "checked=\"checked\"";
1326
- }
1327
- echo "/> " . __('Show the Subscribe2 button on the Write toolbar?', 'subscribe2') . "</p>";
1328
-
1329
- //Auto Subscription for new registrations
1330
- echo "<h2>" . __('Auto Subscribe', 'subscribe2') . "</h2>\r\n";
1331
- echo __('Automatically subscribe new users registering with your blog.', 'subscribe2') . "<br />\r\n";
1332
- echo "<input type=\"radio\" name=\"autosub\" value=\"yes\" ";
1333
- if ('yes' == $this->subscribe2_options['autosub']) {
1334
- echo "checked=\"checked\" ";
1335
- }
1336
- echo " /> " . __('Yes', 'subscribe2') . " &nbsp;&nbsp;";
1337
- echo "<input type=\"radio\" name=\"autosub\" value=\"no\" ";
1338
- if ('no' == $this->subscribe2_options['autosub']) {
1339
- echo "checked=\"checked\" ";
1340
- }
1341
- echo " /> " . __('No', 'subscribe2') . "<br /><br />\r\n";
1342
- echo __('Auto-subscribe users to receive email as', 'subscribe2') . ": <br />\r\n";
1343
- echo "<input type=\"radio\" name=\"autoformat\" value=\"html\"";
1344
- if ('html' == $this->subscribe2_options['autoformat']) {
1345
- echo "checked=\"checked\" ";
1346
- }
1347
- echo "/> " . __('HTML', 'subscribe2') ." &nbsp;&nbsp;";
1348
- echo "<input type=\"radio\" name=\"autoformat\" value=\"fulltext\" ";
1349
- if ('fulltext' == $this->subscribe2_options['autoformat']) {
1350
- echo "checked=\"checked\" ";
1351
- }
1352
- echo "/> " . __('Plain Text - Full', 'subscribe2') . " &nbsp;&nbsp;";
1353
- echo "<input type=\"radio\" name=\"autoformat\" value=\"text\" ";
1354
- if ('text' == $this->subscribe2_options['autoformat']) {
1355
- echo "checked=\"checked\" ";
1356
- }
1357
- echo "/> " . __('Plain Text - Excerpt', 'subscribe2') . " &nbsp;&nbsp;";
1358
-
1359
- //barred domains
1360
- echo "<h2>" . __('Barred Domains', 'subscribe2') . "</h2>\r\n";
1361
- echo __('Enter domains to bar from public subscriptions: <br /> (Use a new line for each entry and omit the "@" symbol, for example email.com)', 'subscribe2');
1362
- echo "<textarea style=\"width: 98%;\" rows=\"4\" cols=\"60\" name=\"barred\">" . $this->subscribe2_options['barred'] . "</textarea>";
1363
-
1364
- // submit
1365
- echo "<p align=\"center\"><span class=\"submit\"><input type=\"submit\" id=\"save\" name=\"submit\" value=\"" . __('Submit', 'subscribe2') . "\" /></span></p>";
1366
- echo "</form>\r\n";
1367
- echo "</div><div class=\"wrap\">";
1368
-
1369
- // reset
1370
- echo "<h2>" . __('Reset Default', 'subscribe2') . "</h2>\r\n";
1371
- echo "<p>" . __('Use this to reset all options to their defaults. This <strong><em>will not</em></strong> modify your list of subscribers.', 'subscribe2') . "</p>\r\n";
1372
- echo "<form method=\"post\" action=\"\">";
1373
- echo "<p align=\"center\"><span class=\"submit\">";
1374
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"RESET\" />";
1375
- echo "<input type=\"submit\" id=\"deletepost\" name=\"submit\" value=\"" . __('RESET', 'subscribe2') .
1376
- "\" />";
1377
- echo "</span></p></form></div>\r\n";
1378
-
1379
- include(ABSPATH . '/wp-admin/admin-footer.php');
1380
- // just to be sure
1381
- die;
1382
- } // end options_menu()
1383
-
1384
- /**
1385
- Our profile menu
1386
- */
1387
- function user_menu() {
1388
- global $user_ID;
1389
-
1390
- get_currentuserinfo();
1391
-
1392
- // was anything POSTed?
1393
- if ( (isset($_POST['s2_admin'])) && ('user' == $_POST['s2_admin']) ) {
1394
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Subscription preferences updated.', 'subscribe2') . "</strong></p></div>\n";
1395
- $format = 'text';
1396
- $post = 'post';
1397
- if ('html' == $_POST['s2_format']) {
1398
- $format = 'html';
1399
- }
1400
- if ('excerpt' == $_POST['s2_excerpt']) {
1401
- $post = 'excerpt';
1402
- }
1403
- update_usermeta($user_ID, 's2_excerpt', $post);
1404
- update_usermeta($user_ID, 's2_format', $format);
1405
- update_usermeta($user_ID, 's2_autosub', $_POST['new_category']);
1406
-
1407
- $cats = $_POST['category'];
1408
- if (empty($cats)) {
1409
- $cats = explode(',', get_usermeta($user_ID, 's2_subscribed'));
1410
- if ($cats) {
1411
- foreach ($cats as $cat) {
1412
- delete_usermeta($user_ID, "s2_cat" . $cat);
1413
- }
1414
- }
1415
- update_usermeta($user_ID, 's2_subscribed', '');
1416
- } else {
1417
- if (! is_array($cats)) {
1418
- $cats = array($_POST['category']);
1419
- }
1420
- $old_cats = explode(',', get_usermeta($user_ID, 's2_subscribed'));
1421
- $remove = array_diff($old_cats, $cats);
1422
- $new = array_diff($cats, $old_cats);
1423
- if (! empty($remove)) {
1424
- // remove subscription to these cat IDs
1425
- foreach ($remove as $id) {
1426
- delete_usermeta($user_ID, "s2_cat" .$id);
1427
- }
1428
- }
1429
- if (! empty($new)) {
1430
- // add subscription to these cat IDs
1431
- foreach ($new as $id) {
1432
- update_usermeta($user_ID, 's2_cat' . $id, "$id");
1433
- }
1434
- }
1435
- update_usermeta($user_ID, 's2_subscribed', implode(',', $cats));
1436
- }
1437
- }
1438
-
1439
- // show our form
1440
- echo "<div class=\"wrap\">";
1441
- echo "<h2>" . __('Notification Settings', 'subscribe2') . "</h2>\r\n";
1442
- echo "<form method=\"post\" action=\"\">";
1443
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"user\" />";
1444
- if ( defined('S2DIGEST') && FALSE == S2DIGEST ) {
1445
- echo __('Receive email as', 'subscribe2') . ": &nbsp;&nbsp;";
1446
- echo "<input type=\"radio\" name=\"s2_format\" value=\"html\"";
1447
- if ('html' == get_usermeta($user_ID, 's2_format')) {
1448
- echo "checked=\"checked\" ";
1449
- }
1450
- echo "/> " . __('HTML', 'subscribe2') ." &nbsp;&nbsp;";
1451
- echo "<input type=\"radio\" name=\"s2_format\" value=\"text\" ";
1452
- if ('text' == get_usermeta($user_ID, 's2_format')) {
1453
- echo "checked=\"checked\" ";
1454
- }
1455
- echo "/> " . __('Plain Text', 'subscribe2') . "<br /><br />\r\n";
1456
-
1457
- echo __('Email contains', 'subscribe2') . ": &nbsp;&nbsp;";
1458
- $amount = array ('excerpt' => __('Excerpt Only', 'subscribe2'), 'post' => __('Full Post', 'subscribe2'));
1459
- foreach ($amount as $key => $value) {
1460
- echo "<input type=\"radio\" name=\"s2_excerpt\" value=\"" . $key . "\"";
1461
- if ($key == get_usermeta($user_ID, 's2_excerpt')) {
1462
- echo " checked=\"checked\"";
1463
- }
1464
- echo " /> $value ";
1465
- }
1466
- echo "<p style=\"color: red\">" . __('Note: HTML format will always deliver the full post.', 'subscribe2') . "</p>\r\n";
1467
- echo __('Automatically subscribe me to newly created categories', 'subscribe2') . ': &nbsp;&nbsp;';
1468
- echo "<input type=\"radio\" name=\"new_category\" value=\"yes\" ";
1469
- if ('yes' == get_usermeta($user_ID, 's2_autosub')) {
1470
- echo "checked=\"yes\" ";
1471
- }
1472
- echo "/> Yes <input type=\"radio\" name=\"new_category\" value=\"no\" ";
1473
- if ('no' == get_usermeta($user_ID, 's2_autosub')) {
1474
- echo "checked=\"yes\" ";
1475
- }
1476
- echo "/> No<br /><br />";
1477
-
1478
- // subscribed categories
1479
- echo "<h2>" . __('Subscribed Categories', 'subscribe2') . "</h2>\r\n";
1480
- $this->display_category_form(explode(',', get_usermeta($user_ID, 's2_subscribed')), $this->subscribe2_options['reg_override']);
1481
- } else {
1482
- // we're doing daily digests, so just show
1483
- // subscribe / unnsubscribe
1484
- echo __('Receive daily summary of new posts?', 'subscribe2') . ': &nbsp;&nbsp;';
1485
- echo "<input type=\"radio\" name=\"category\" value=\"1\" ";
1486
- if (get_usermeta($user_ID, 's2_subscribed')) {
1487
- echo "checked=\"yes\" ";
1488
- }
1489
- echo "/> Yes <input type=\"radio\" name=\"category\" value=\"\" ";
1490
- if (! get_usermeta($user_ID, 's2_subscribed')) {
1491
- echo "checked=\"yes\" ";
1492
- }
1493
- echo "/> No";
1494
- }
1495
-
1496
- // submit
1497
- echo "<p align=\"right\"><span class=\"submit\"><input type=\"submit\" name=\"submit\" value=\"" . __("Update Preferences &raquo;", 'subscribe2') . "\" /></span></p>";
1498
- echo "</form></div>\r\n";
1499
-
1500
- include(ABSPATH . '/wp-admin/admin-footer.php');
1501
- // just to be sure
1502
- die;
1503
- } // end user_menu()
1504
-
1505
- /**
1506
- Display the Write sub-menu
1507
- */
1508
- function write_menu() {
1509
- // was anything POSTed?
1510
- if (isset($_POST['s2_admin']) && ('mail' == $_POST['s2_admin']) ) {
1511
- if ('confirmed' == $_POST['what']) {
1512
- $recipients = $this->get_public();
1513
- } elseif ('unconfirmed' == $_POST['what']) {
1514
- $recipients = $this->get_public(0);
1515
- } elseif ('public' == $_POST['what']) {
1516
- $confirmed = $this->get_public();
1517
- $unconfirmed = $this->get_public(0);
1518
- $recipients = array_merge((array)$confirmed, (array)$unconfirmed);
1519
- } elseif (is_numeric($_POST['what'])) {
1520
- $cat = intval($_POST['what']);
1521
- $recipients = $this->get_registered("cats=$cat");
1522
- } else {
1523
- $recipients = $this->get_registered();
1524
- }
1525
- global $user_identity, $user_email;
1526
- get_currentuserinfo();
1527
- $this->myname = $user_identity;
1528
- $this->myemail = $user_email;
1529
- $subject = strip_tags($_POST['subject']);
1530
- $message = stripslashes($_POST['message']);
1531
- $this->mail($recipients, $subject, $message, 'text');
1532
- $message = $this->mail_sent;
1533
- }
1534
-
1535
- if ('' != $message) {
1536
- echo "<div id=\"message\" class=\"updated\"><strong><p>" . $message . "</p></strong></div>\r\n";
1537
- }
1538
- // show our form
1539
- echo "<div class=\"wrap\"><h2>" . __('Send email to all subscribers', 'subscribe2') . "</h2>\r\n";
1540
- echo "<form method=\"post\" action=\"\">\r\n";
1541
- echo __('Subject', 'subscribe2') . ": <input type=\"text\" size=\"69\" name=\"subject\" value=\"" . __('A message from ', 'subscribe2') . get_settings('blogname') . "\" /> <br />";
1542
- echo "<textarea rows=\"12\" cols=\"75\" name=\"message\"></textarea>";
1543
- echo "<br />\r\n";
1544
- echo __('Recipients: ', 'subscribe2');
1545
- $this->display_subscriber_dropdown('registered', false, array('all'));
1546
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"mail\" />";
1547
- echo "&nbsp;&nbsp;<span class=\"submit\"><input type=\"submit\" name=\"submit\" value=\"" . __('Send', 'subscribe2') . "\" /></span>&nbsp;";
1548
- echo "</form></div>\r\n";
1549
- echo "<div style=\"clear: both;\"><p>&nbsp;</p></div>";
1550
-
1551
- include(ABSPATH . '/wp-admin/admin-footer.php');
1552
- // just to be sure
1553
- die;
1554
- } // end write_menu()
1555
-
1556
- /* ===== helper functions: forms and stuff ===== */
1557
- /**
1558
- Display a table of categories with checkboxes
1559
-
1560
- Optionally pre-select those categories specified
1561
- */
1562
- function display_category_form($selected = array(), $override = 1) {
1563
- global $wpdb;
1564
-
1565
- $all_cats = $this->get_all_categories('array');
1566
- if (0 == $override) {
1567
- // registered users are not allowed to subscribe to
1568
- // excluded categories
1569
- foreach (explode(',', $this->get_excluded_cats()) as $cat) {
1570
- $category = get_category($cat);
1571
- $excluded[$cat] = $category->cat_name;
1572
- }
1573
- $all_cats = array_diff($all_cats, $excluded);
1574
- }
1575
-
1576
- $half = (count($all_cats) / 2);
1577
- $i = 0;
1578
- $j = 0;
1579
- echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"5\" class=\"editform\">";
1580
- echo "<tr valign=\"top\"><td width=\"50%\" align=\"left\">";
1581
- foreach ($all_cats as $cat_ID => $cat_name) {
1582
- if ( ($i >= $half) && (0 == $j) ){
1583
- echo "</td><td width=\"50%\" align=\"left\">";
1584
- $j++;
1585
- }
1586
- if (0 == $j) {
1587
- echo "<input type=\"checkbox\" name=\"category[]\" value=\"" . $cat_ID . "\"";
1588
- if (in_array($cat_ID, $selected)) {
1589
- echo " checked=\"checked\" ";
1590
- }
1591
- echo " /> " . $cat_name . "<br />\r\n";
1592
- } else {
1593
-
1594
- echo "<input type=\"checkbox\" name=\"category[]\" value=\"" . $cat_ID . "\"";
1595
- if (in_array($cat_ID, $selected)) {
1596
- echo " checked=\"checked\" ";
1597
- }
1598
- echo " /> " . $cat_name . "<br />\r\n";
1599
- }
1600
- $i++;
1601
- }
1602
- echo "</td></tr></table>\r\n";
1603
- } // end display_category_form()
1604
-
1605
- /**
1606
- Display a drop-down form to select subscribers
1607
- $selected is the option to select
1608
- $submit is the text to use on the Submit button
1609
- */
1610
- function display_subscriber_dropdown ($selected = 'registered', $submit = '', $exclude = array()) {
1611
- global $wpdb;
1612
-
1613
- $who = array('all' => __('All Subscribers', 'subscribe2'),
1614
- 'public' => __('Public Subscribers', 'subscribe2'),
1615
- 'confirmed' => ' &nbsp;&nbsp;' . __('Confirmed', 'subscribe2'),
1616
- 'unconfirmed' => ' &nbsp;&nbsp;' . __('Unconfirmed', 'subscribe2'),
1617
- 'registered' => __('Registered Subscribers', 'subscribe2'));
1618
-
1619
- // count the number of subscribers
1620
- $count['confirmed'] = $wpdb->get_var("SELECT COUNT(id) FROM $this->public WHERE active='1'");
1621
- $count['unconfirmed'] = $wpdb->get_var("SELECT COUNT(id) FROM $this->public WHERE active='0'");
1622
- if (in_array('unconfirmed', $exclude)) {
1623
- $count['public'] = $count['confirmed'];
1624
- } elseif (in_array('confirmed', $exclude)) {
1625
- $count['public'] = $count['unconfirmed'];
1626
- } else {
1627
- $count['public'] = ($count['confirmed'] + $count['unconfirmed']);
1628
- }
1629
- $count['registered'] = $wpdb->get_var("SELECT COUNT(meta_key) FROM $wpdb->usermeta WHERE meta_key='s2_subscribed'");
1630
- $count['all'] = ($count['confirmed'] + $count['unconfirmed'] + $count['registered']);
1631
- foreach ($this->get_all_categories('array') as $cat_ID => $cat_name) {
1632
- $count[$cat_name] = $wpdb->get_var("SELECT COUNT(meta_value) FROM $wpdb->usermeta WHERE meta_key='s2_cat$cat_ID'");
1633
- }
1634
-
1635
- // do have actually have some subscribers?
1636
- if ( (0 == $count['confirmed']) && (0 == $count['unconfirmed']) && (0 == $count['registered']) ) {
1637
- // no? bail out
1638
- return;
1639
- }
1640
-
1641
- if (false !== $submit) {
1642
- echo "<form method=\"post\" action=\"\">";
1643
- }
1644
- echo "<select name=\"what\">\r\n";
1645
- foreach ($who as $whom => $display) {
1646
- if (in_array($whom, $exclude)) { continue; }
1647
- if (0 == $count[$whom]) { continue; }
1648
-
1649
- echo "<option value=\"$whom\"";
1650
- if ($whom == $selected) { echo " selected=\"selected\" "; }
1651
- echo ">$display (" . ($count[$whom]) . ")</option>\r\n";
1652
- }
1653
-
1654
- if ($count['registered'] > 0) {
1655
- foreach ($this->get_all_categories('array') as $cat_ID => $cat_name) {
1656
- if (in_array($cat_ID, $exclude)) { continue; }
1657
- if (0 == $count[$cat_name]) { continue; }
1658
- echo "<option value=\"$cat_ID\"";
1659
- if ($cat_ID == $selected) { echo " selected=\"selected\" "; }
1660
- echo "> &nbsp;&nbsp;$cat_name (" . $count[$cat_name] . ") </option>\r\n";
1661
- }
1662
- }
1663
- echo "</select>";
1664
- if (false !== $submit) {
1665
- echo "<span class=\"submit\"><input type=\"submit\" value=\"$submit\" /></span></form>\r\n";
1666
- }
1667
- } // end display_subscriber_dropdown()
1668
-
1669
- /* ===== template and filter functions ===== */
1670
- /**
1671
- Display our form; also handles (un)subscribe requests
1672
- */
1673
- function filter($content = '') {
1674
- if (('' == $content) || (! preg_match('|<!--subscribe2-->|', $content))) { return $content; }
1675
- $this->s2form = $this->form;
1676
-
1677
- global $user_ID;
1678
- get_currentuserinfo();
1679
- if ($user_ID) {
1680
- $this->s2form = $this->use_profile;
1681
- }
1682
- if (isset($_POST['s2_action'])) {
1683
- global $wpdb, $user_email;
1684
- if (! is_email($_POST['email'])) {
1685
- $this->s2form = $this->form . $this->not_an_email;
1686
- } elseif ($this->is_barred($_POST['email'])) {
1687
- $this->s2form = $this->form . $this->barred_domain;
1688
- } else {
1689
- $this->email = $_POST['email'];
1690
- // does the supplied email belong to a registered user?
1691
- $check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email = '$this->email'");
1692
- if ('' != $check) {
1693
- // this is a registered email
1694
- $this->s2form = $this->please_log_in;
1695
- } else {
1696
- // this is not a registered email
1697
- // what should we do?
1698
- if ('subscribe' == $_POST['s2_action']) {
1699
- // someone is trying to subscribe
1700
- // lets see if they've tried to subscribe previously
1701
- if ('1' !== $this->is_public($this->email)) {
1702
- // the user is unknown or inactive
1703
- $this->add();
1704
- $this->send_confirm('add');
1705
- // set a variable to denote that we've already run, and shouldn't run again
1706
- $this->filtered = 1; //set this to not send duplicate emails
1707
- $this->s2form = $this->confirmation_sent;
1708
- } else {
1709
- // they're already subscribed
1710
- $this->s2form = $this->already_subscribed;
1711
- }
1712
- $this->action = 'subscribe';
1713
- } elseif ('unsubscribe' == $_POST['s2_action']) {
1714
- // is this email a subscriber?
1715
- if (false == $this->is_public($this->email)) {
1716
- $this->s2form = $this->form . $this->not_subscribed;
1717
- } else {
1718
- $this->send_confirm('del');
1719
- // set a variable to denote that we've already run, and shouldn't run again
1720
- $this->filtered = 1;
1721
- $this->s2form = $this->confirmation_sent;
1722
- }
1723
- $this->action='unsubscribe';
1724
- }
1725
- }
1726
- }
1727
- }
1728
- return preg_replace('|(<p>)(\n)*<!--subscribe2-->(\n)*(</p>)|', $this->s2form, $content);
1729
- } // end filter()
1730
-
1731
- /**
1732
- Overrides the default query when handling a (un)subscription confirmation
1733
- This is basically a trick: if the s2 variable is in the query string, just grab the first static page
1734
- and override it's contents later with title_filter() and template_filter()
1735
- */
1736
- function query_filter() {
1737
- // don't interfere if we've already done our thing
1738
- if (1 == $this->filtered) { return; }
1739
-
1740
- global $wpdb;
1741
-
1742
- if ( defined('S2PAGE') && 0 !== S2PAGE ) {
1743
- return "page_id=" . S2PAGE;
1744
- } else {
1745
- $id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status='static' LIMIT 1");
1746
- if ($id) {
1747
- return "page_id=$id";
1748
- } else {
1749
- return "showposts=1";
1750
- }
1751
- }
1752
- } // end query_filter()
1753
-
1754
- /**
1755
- Overrides the page title
1756
- */
1757
- function title_filter() {
1758
- // don't interfere if we've already done our thing
1759
- if (1 == $this->filtered) { return; }
1760
- return __('Subscription Confirmation', 'subscribe2');
1761
- } // end title_filter()
1762
-
1763
- /**
1764
- Override the template filter to make sure a special template is not used
1765
- */
1766
- function template_filter() {
1767
- // don't interfere if we've already done our thing
1768
- if (1 == $this->filtered) { return; }
1769
- return;
1770
- } // end template_filter()
1771
-
1772
- /* ===== wp-cron functions ===== */
1773
- /**
1774
- Send notifications for any posts that are now visible
1775
- */
1776
- function subscribe2_hourly() {
1777
- $future_posts = get_option('s2_future_posts');
1778
-
1779
- // if we have no future posts, bail out
1780
- if (! $future_posts) { return; }
1781
-
1782
- // this will hold the posts that aren't yet visible
1783
- $not_yet = array();
1784
-
1785
- foreach ($future_posts as $post) {
1786
- if ( current_time('mysql') > $post['date'] ) {
1787
- // this post is now visible, so let's
1788
- // send a notification
1789
- $this->publish($post['id'], 1);
1790
- } else {
1791
- array_push($not_yet, $post);
1792
- }
1793
- }
1794
- // are the number of elements in $not_yet
1795
- // the same as in $future posts?
1796
- if ( count($not_yet) != count($future_posts) ) {
1797
- // if not, then some posts have been removed
1798
- // from $future_posts, and the remainder need
1799
- // to be recorded back to the database
1800
- update_option('s2_future_posts', $not_yet);
1801
- }
1802
- } // end subscribe2_hourly
1803
-
1804
- /**
1805
- Send a daily digest of today's new posts
1806
- */
1807
- function subscribe2_daily() {
1808
- global $wpdb;
1809
-
1810
- // collect yesterday's posts
1811
- $yesterday = date('Y-m-d', (get_option('wp_cron_daily_lastrun')-60));
1812
- $posts = $wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content FROM $wpdb->posts WHERE post_date > '$yesterday 00:00:00' AND post_date < '$yesterday 23:59:59' AND post_status='publish'");
1813
-
1814
- // do we have any posts?
1815
- if (! $posts) { return; }
1816
-
1817
- // if we have posts, let's prepare the digest
1818
- foreach ($posts as $post) {
1819
- $post_cats = wp_get_post_cats('1', $post->ID);
1820
- $post_cats_string = implode(',', $post_cats);
1821
- $check = false;
1822
- // is the current post assigned to any categories
1823
- // which should not generate a notification email?
1824
- foreach (explode(',', $this->get_excluded_cats()) as $cat) {
1825
- if (in_array($cat, $post_cats)) {
1826
- $check = true;
1827
- }
1828
- }
1829
- // if this post is in an excluded category,
1830
- // don't include it in the digest
1831
- if ($check) {
1832
- continue;
1833
- }
1834
- $message .= $post->post_title . "\r\n";
1835
- $message .= get_permalink($post->ID) . "\r\n";
1836
- $excerpt = $post->post_excerpt;
1837
- if ('' == $excerpt) {
1838
- // no excerpt, is there a <!--more--> ?
1839
- if (false !== strpos($post->post_content, '<!--more-->')) {
1840
- list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
1841
- // strip leading and trailing whitespace
1842
- $excerpt = trim($excerpt);
1843
- } else {
1844
- $excerpt = strip_tags($post->post_content);
1845
- $words = explode(' ', $excerpt, 56);
1846
- if (count($words) > 55) {
1847
- array_pop($words);
1848
- array_push($words, '[...]');
1849
- $excerpt = implode(' ', $words);
1850
- }
1851
- }
1852
- }
1853
- $message .= $excerpt . "\r\n\r\n";
1854
- }
1855
-
1856
- $author = get_userdata($post->post_author);
1857
- $this->authorname = $author->display_name;
1858
-
1859
- // do we send as admin, or post author?
1860
- if ('author' == $this->subscribe2_options['sender']) {
1861
- // get author details
1862
- $user =& $author;
1863
- } else {
1864
- // get admin detailts
1865
- $user = get_userdata(1);
1866
- }
1867
- $this->myemail = $user->user_email;
1868
- $this->myname = $user->display_name;
1869
-
1870
- $subject = '[' . stripslashes(get_settings('blogname')) . '] ' . __('Daily Digest', 'subscribe2') . ' ' . $yesterday;
1871
- $public = $this->get_public();
1872
- $registered = $this->get_registered();
1873
- $recipients = array_merge((array)$public, (array)$registered);
1874
- $mailtext = $this->substitute(stripslashes($this->subscribe2_options['mailtext']));
1875
- $body = str_replace('POST', $message, $mailtext);
1876
- $this->mail($recipients, $subject, $body);
1877
- } // end subscribe2_daily
1878
-
1879
- /**
1880
- If the to-be-deleted post was future-dated, remove it from the list of future-dated posts
1881
- */
1882
- function delete_future($id = 0) {
1883
- if (0 == $id) { return $id; }
1884
-
1885
- $future = get_settings('s2_future_posts');
1886
- // if we have no future-dated posts scheduled, bail out
1887
- if ( ! $future) {
1888
- return $id;
1889
- }
1890
- foreach ($future as $post) {
1891
- // is the deleted post in the list of future posts?
1892
- if ($id == $post['id']) {
1893
- // skip it
1894
- continue;
1895
- } else {
1896
- // add this to the new list of future posts
1897
- $new_future[] = $post;
1898
- }
1899
- }
1900
- if ($new_future != $future) {
1901
- update_option('s2_future_posts', $new_future);
1902
- }
1903
- } // end delete_future()
1904
-
1905
- /* ===== Our constructor ===== */
1906
- /**
1907
- Subscribe2 constructor
1908
- */
1909
- function subscribe2() {
1910
- global $table_prefix;
1911
-
1912
- load_plugin_textdomain('subscribe2', 'wp-content/plugins/subscribe2');
1913
-
1914
- // load the options
1915
- $this->subscribe2_options = array();
1916
- $this->subscribe2_options = get_option('subscribe2_options');
1917
-
1918
- // do we need to install anything?
1919
- $this->public = $table_prefix . "subscribe2";
1920
- if(mysql_query("SELECT COUNT(*) FROM ".$this->public)==FALSE) { $this->install(); }
1921
- //do we need to upgrade anything?
1922
- if ($this->subscribe2_options['version'] !== S2VERSION) {
1923
- $this->upgrade();
1924
- }
1925
-
1926
- if (isset($_GET['s2'])) {
1927
- // someone is confirming a request
1928
- add_filter('query_string', array(&$this, 'query_filter'));
1929
- add_filter('the_title', array(&$this, 'title_filter'));
1930
- add_filter('the_content', array(&$this, 'confirm'));
1931
- }
1932
-
1933
- add_action('admin_menu', array(&$this, 'admin_menu'));
1934
- add_action('publish_post', array(&$this, 'publish'));
1935
- add_action('edit_post', array(&$this, 'edit'));
1936
- add_action('private_to_published', array(&$this, 'private2publish'));
1937
- add_action('user_register', array(&$this, 'register'));
1938
- add_action('create_category', array(&$this, 'autosub_new_category'));
1939
- add_filter('the_content', array(&$this, 'filter'));
1940
- add_action('wp_cron_hourly', array(&$this, 'subscribe2_hourly'));
1941
- if (defined('S2DIGEST') && TRUE == S2DIGEST) {
1942
- add_action('wp_cron_daily', array(&$this, 'subscribe2_daily'));
1943
- }
1944
- add_action('delete_post', array(&$this, 'delete_future'));
1945
- // add our button
1946
- if ('1' == $this->subscribe2_options['show_button']) {
1947
- add_action('init', array(&$this, 's2_button_init'));
1948
- add_action('marker_css', array(&$this, 'subscribe2_css'));
1949
- }
1950
- // load our strings
1951
- $this->load_strings();
1952
- } // end subscribe2()
1953
-
1954
- /* ===== our variables ===== */
1955
- // cache variables
1956
- var $version = '';
1957
- var $all_public = '';
1958
- var $all_unconfirmed = '';
1959
- var $excluded_cats = '';
1960
- var $post_title = '';
1961
- var $permalink = '';
1962
- var $myname = '';
1963
- var $myemail = '';
1964
- var $s2_subject = '[BLOGNAME] TITLE';
1965
- var $signup_dates = array();
1966
- var $private = false;
1967
- var $filtered = 0;
1968
-
1969
- // state variables used to affect processing
1970
- var $action = '';
1971
- var $email = '';
1972
- var $message = '';
1973
- var $error = '';
1974
-
1975
- // some messages
1976
- var $please_log_in = '';
1977
- var $use_profile = '';
1978
- var $confirmation_sent = '';
1979
- var $already_subscribed = '';
1980
- var $not_subscribed ='';
1981
- var $not_an_email = '';
1982
- var $barred_domain = '';
1983
- var $mail_sent = '';
1984
- var $form = '';
1985
- var $no_such_email = '';
1986
- var $added = '';
1987
- var $deleted = '';
1988
- var $confirm_subject = '';
1989
- var $options_saved = '';
1990
- var $options_reset = '';
1991
-
1992
- } // end class subscribe2
1993
-
1994
- function s2init() {
1995
- global $subscribe2;
1996
- $mysubscribe2 = new subscribe2();
1997
- $mysubscribe2->subscribe2();
1998
- }
1999
-
2000
- add_action('init', 's2init');
2001
?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Subscribe2
4
+ Plugin URI: http://subscribe2.wordpress.com
5
+ Description: Notifies an email list when new entries are posted. Tested with WordPress 2.1.x and 2.2.x.
6
+ Version: 3.6
7
+ Author: Matthew Robinson
8
+ Author URI: http://subscribe2.wordpress.com
9
+ */
10
+
11
+ /*
12
+ Copyright (C) 2006-7 Matthew Robinson
13
+ Based on the Original Subscribe2 plugin by
14
+ Copyright (C) 2005 Scott Merrill (skippy@skippy.net)
15
+
16
+ This program is free software; you can redistribute it and/or
17
+ modify it under the terms of the GNU General Public License
18
+ as published by the Free Software Foundation; either version 2
19
+ of the License, or (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
+ http://www.gnu.org/licenses/gpl.html
30
+ */
31
+
32
+ // If you are on a host that limits the number of recipients
33
+ // permitted on each outgoing email message
34
+ // change the value on the line below to your hosts limit
35
+ define('BCCLIMIT', '0');
36
+
37
+ // by default, Subscribe2 grabs the first page from your database for use
38
+ // when displaying the confirmation screen to public subscribers.
39
+ // You can override this by specifying a page ID on the line below.
40
+ define('S2PAGE', '0');
41
+
42
+ // our version number. Don't touch this or any line below
43
+ // unless you know exacly what you are doing
44
+ define('S2VERSION', '3.6');
45
+
46
+ // use Owen's excellent ButtonSnap library
47
+ require(ABSPATH . '/wp-content/plugins/buttonsnap.php');
48
+
49
+ $mysubscribe2 = new s2class;
50
+ $mysubscribe2->s2init();
51
+
52
+ // start our class
53
+ class s2class {
54
+ // variables and constructor are declared at the end
55
+
56
+ /**
57
+ Load all our strings
58
+ */
59
+ function load_strings() {
60
+ // adjust the output of Subscribe2 here
61
+
62
+ $this->please_log_in = "<p>" . __('To manage your subscription options please ', 'subscribe2') . "<a href=\"" . get_settings('siteurl') . "/wp-login.php\">login</a>.</p>";
63
+
64
+ $this->use_profile_admin = "<p>" . __('You may manage your subscription options from your ', 'subscribe2') . "<a href=\"" . get_settings('siteurl') . "/wp-admin/users.php?page=" . plugin_basename(__FILE__) . "\">profile</a>.</p>";
65
+
66
+ $this->use_profile_users = "<p>" . __('You may manage your subscription options from your ', 'subscribe2') . "<a href=\"" . get_settings('siteurl') . "/wp-admin/profile.php?page=" . plugin_basename(__FILE__) . "\">profile</a>.</p>";
67
+
68
+ $this->confirmation_sent = "<p>" . __('A confirmation message is on its way!', 'subscribe2') . "</p>";
69
+
70
+ $this->already_subscribed = "<p>" . __('That email address is already subscribed.', 'subscribe2') . "</p>";
71
+
72
+ $this->not_subscribed = "<p>" . __('That email address is not subscribed.', 'subscribe2') . "</p>";
73
+
74
+ $this->not_an_email = "<p>" . __('Sorry, but that does not look like an email address to me.', 'subscribe2') . "</p>";
75
+
76
+ $this->barred_domain = "<p>" . __('Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2') . "</p>";
77
+
78
+ $this->mail_sent = "<p>" . __('Message sent!', 'subscribe2') . "</p>";
79
+
80
+ $this->form = "<form method=\"post\" action=\"\">" . __('Your email:', 'subscribe2') . "&#160;<input type=\"text\" name=\"email\" value=\"\" size=\"20\" />&#160;<br /><input type=\"radio\" name=\"s2_action\" value=\"subscribe\" checked=\"checked\" /> " . __('Subscribe', 'subscribe2') . " <input type=\"radio\" name=\"s2_action\" value=\"unsubscribe\" /> " . __('Unsubscribe', 'subscribe2') . " &#160;<input type=\"submit\" value=\"" . __('Send', 'subscribe2') . "\" /></form>\r\n";
81
+
82
+ // confirmation messages
83
+ $this->no_such_email = "<p>" . __('No such email address is registered.', 'subscribe2') . "</p>";
84
+
85
+ $this->added = "<p>" . __('You have successfully subscribed!', 'subscribe2') . "</p>";
86
+
87
+ $this->deleted = "<p>" . __('You have successfully unsubscribed.', 'subscribe2') . "</p>";
88
+
89
+ $this->confirm_subject = "[" . get_settings('blogname') . "] " . __('Please confirm your request', 'subscribe2');
90
+
91
+ $this->remind_subject = "[" . get_settings('blogname') . "] " . __('Subscription Reminder', 'subscribe2');
92
+
93
+ $this->subscribe = __('subscribe', 'subscribe2'); //ACTION replacement in subscribing confirmation email
94
+
95
+ $this->unsubscribe = __('unsubscribe', 'subscribe2'); //ACTION replacement in unsubscribing in confirmation email
96
+
97
+ // menu strings
98
+ $this->options_saved = __('Options saved!', 'subscribe2');
99
+ $this->options_reset = __('Options reset!', 'subscribe2');
100
+ } // end load_strings()
101
+
102
+ /* ===== WordPress menu registration ===== */
103
+ /**
104
+ Hook the menu
105
+ */
106
+ function admin_menu() {
107
+ add_management_page(__('Subscribers', 'subscribe2'), __('Subscribers', 'subscribe2'), "manage_options", __FILE__, array(&$this, 'manage_menu'));
108
+ add_options_page(__('Subscribe2 Options', 'subscribe2'), __('Subscribe2','subscribe2'), "manage_options", __FILE__, array(&$this, 'options_menu'));
109
+ if (current_user_can('manage_options')) {
110
+ add_submenu_page('users.php', __('Subscriptions', 'subscribe2'), __('Subscriptions', 'subscribe2'), "read", __FILE__, array(&$this, 'user_menu'));
111
+ } else {
112
+ add_submenu_page('profile.php', __('Subscriptions', 'subscribe2'), __('Subscriptions', 'subscribe2'), "read", __FILE__, array(&$this, 'user_menu'));
113
+ }
114
+ add_submenu_page('post-new.php', __('Mail Subscribers','subscribe2'), __('Mail Subscribers', 'subscribe2'),"manage_options", __FILE__, array(&$this, 'write_menu'));
115
+ $s2nonce = md5('subscribe2');
116
+ }
117
+
118
+ /**
119
+ Insert Javascript into admin_header
120
+ */
121
+ function admin_head() {
122
+ echo "<script type=\"text/javascript\">\r\n";
123
+ echo "<!--\r\n";
124
+ echo "function setAll(theElement) {\r\n";
125
+ echo " var theForm = theElement.form, z = 0;\r\n";
126
+ echo " for(z=0; z<theForm.length;z++){\r\n";
127
+ echo " if(theForm[z].type == 'checkbox' && theForm[z].name == 'category[]'){\r\n";
128
+ echo " theForm[z].checked = theElement.checked;\r\n";
129
+ echo " }\r\n";
130
+ echo " }\r\n";
131
+ echo "}\r\n";
132
+ echo "-->\r\n";
133
+ echo "</script>\r\n";
134
+ }
135
+
136
+ function add_weekly_sched($sched) {
137
+ $sched['weekly'] = array('interval' => 604800, 'display' => __('Once Weekly','subscribe2'));
138
+ return $sched;
139
+ }
140
+
141
+ /* ===== Install, upgrade, reset ===== */
142
+ /**
143
+ Install our table
144
+ */
145
+ function install() {
146
+ // include upgrade-functions for maybe_create_table;
147
+ if (!function_exists('maybe_create_table')) {
148
+ require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
149
+ }
150
+ $date = date('Y-m-d');
151
+ $sql = "CREATE TABLE $this->public (
152
+ id int(11) NOT NULL auto_increment,
153
+ email varchar(64) NOT NULL default '',
154
+ active tinyint(1) default 0,
155
+ date DATE default '$date' NOT NULL,
156
+ PRIMARY KEY (id) )";
157
+
158
+ // create the table, as needed
159
+ maybe_create_table($this->public, $sql);
160
+ $this->reset();
161
+ } // end install()
162
+
163
+ /**
164
+ Upgrade the database
165
+ */
166
+ function upgrade() {
167
+ global $wpdb;
168
+
169
+ // include upgrade-functions for maybe_create_table;
170
+ if (!function_exists('maybe_create_table')) {
171
+ require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
172
+ }
173
+ $date = date('Y-m-d');
174
+ maybe_add_column($this->public, 'date', "ALTER TABLE `$this->public` ADD `date` DATE DEFAULT '$date' NOT NULL AFTER `active`;");
175
+
176
+ // let's take the time to check process registered users
177
+ // existing public subscribers are subscribed to all categories
178
+ $users = $wpdb->get_col("SELECT ID FROM $wpdb->users");
179
+ if (!empty($users)) {
180
+ foreach ($users as $user) {
181
+ $this->register($user);
182
+ }
183
+ }
184
+ // update the options table to serialized format
185
+ $old_options = $wpdb->get_col("SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name != 's2_future_posts'");
186
+
187
+ if (!empty($old_options)) {
188
+ foreach ($old_options as $option) {
189
+ $value = get_option($option);
190
+ $option_array = substr($option, 3);
191
+ $this->subscribe2_options[$option_array] = $value;
192
+ delete_option($option);
193
+ }
194
+ }
195
+ $this->subscribe2_options['version'] = S2VERSION;
196
+ //double check that the options are in the database
197
+ require(ABSPATH . "/wp-content/plugins/subscribe2/include.php");
198
+ update_option('subscribe2_options', $this->subscribe2_options);
199
+ } // end upgrade()
200
+
201
+ /**
202
+ Reset our options
203
+ */
204
+ function reset() {
205
+ delete_option('subscribe2_options');
206
+ unset($this->subscribe2_options);
207
+ require(ABSPATH . "/wp-content/plugins/subscribe2/include.php");
208
+ update_option('subscribe2_options', $this->subscribe2_options);
209
+ } // end reset()
210
+
211
+ /* ===== mail handling ===== */
212
+ /**
213
+ Performs string substitutions for subscribe2 mail texts
214
+ */
215
+ function substitute($string = '') {
216
+ if ('' == $string) {
217
+ return;
218
+ }
219
+ $string = str_replace('BLOGNAME', get_settings('blogname'), $string);
220
+ $string = str_replace('BLOGLINK', get_bloginfo('url'), $string);
221
+ $string = str_replace('TITLE', stripslashes($this->post_title), $string);
222
+ $string = str_replace('PERMALINK', $this->permalink, $string);
223
+ $string = str_replace('MYNAME', stripslashes($this->myname), $string);
224
+ $string = str_replace('EMAIL', $this->myemail, $string);
225
+ $string = str_replace('AUTHORNAME', $this->authorname, $string);
226
+ return $string;
227
+ } // end sustitute()
228
+
229
+ /**
230
+ Delivers email to recipients in HTML or plaintext
231
+ */
232
+ function mail ($recipients = array(), $subject = '', $message = '', $type='text') {
233
+ if ( (empty($recipients)) || ('' == $message) ) { return; }
234
+
235
+ // Set sender details
236
+ if ('' == $this->myname) {
237
+ $admin = get_userdata(1);
238
+ $this->myname = $admin->display_name;
239
+ $this->myemail = $admin->user_email;
240
+ }
241
+ $headers = "From: " . $this->myname . " <" . $this->myemail . ">\n";
242
+ $headers .= "Return-Path: <" . $this->myemail . ">\n";
243
+ $headers .= "Reply-To: " . $this->myemail . "\n";
244
+ $headers .= "X-Mailer:PHP" . phpversion() . "\n";
245
+ $headers .= "Precedence: list\nList-Id: " . get_settings('blogname') . "\n";
246
+
247
+ if ('html' == $type) {
248
+ // To send HTML mail, the Content-Type header must be set
249
+ $headers .= "MIME-Version: 1.0\n";
250
+ $headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
251
+ $mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>";
252
+ } else {
253
+ $headers .= "MIME-Version: 1.0\n";
254
+ $headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset') . "\"\n";
255
+ $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
256
+ $message = preg_replace('|&amp;|', '&', $message);
257
+ $mailtext = wordwrap(strip_tags($message), 80, "\n");
258
+ }
259
+
260
+ // BCC all recipients
261
+ $bcc = '';
262
+ if ( (defined('BCCLIMIT') && (BCCLIMIT > 0) ) &&
263
+ (count($recipients) > BCCLIMIT) ) {
264
+ // we're on Dreamhost, and have more than 30 susbcribers
265
+ $count = 1;
266
+ $batch = array();
267
+ foreach ($recipients as $recipient) {
268
+ // advance the array pointer by one, for use down below
269
+ // the array pointer _is not_ advanced by the foreach() loop itself
270
+ next($recipients);
271
+ $recipient = trim($recipient);
272
+ // sanity check -- make sure we have a valid email
273
+ if (!is_email($recipient)) { continue; }
274
+ // and NOT the sender's email, since they'll
275
+ // get a copy anyway
276
+ if ( (! empty($recipient)) && ($this->myemail != $recipient) ) {
277
+ ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ",\r\n $recipient";
278
+ // Headers constructed as per definition at http://www.ietf.org/rfc/rfc2822.txt
279
+ }
280
+ if (BCCLIMIT == $count) {
281
+ $count = 1;
282
+ $batch[] = $bcc;
283
+ $bcc = '';
284
+ } else {
285
+ if (false == current($recipients)) {
286
+ // we've reached the end of the subscriber list
287
+ // add what we have to the batch, and move on
288
+ $batch[] = $bcc;
289
+ break;
290
+ } else {
291
+ $count++;
292
+ }
293
+ }
294
+ }
295
+ // rewind the array, just to be safe
296
+ reset($recipients);
297
+ } else {
298
+ // we're not on dreamhost, or have less than 30
299
+ // subscribers, so do it normal
300
+ foreach ($recipients as $recipient) {
301
+ $recipient = trim($recipient);
302
+ // sanity check -- make sure we have a valid email
303
+ if (!is_email($recipient)) { continue; }
304
+ // and NOT the sender's email, since they'll
305
+ // get a copy anyway
306
+ if ( (!empty($recipient)) && ($this->myemail != $recipient) ) {
307
+ ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ",\r\n $recipient";
308
+ // Headers constructed as per definition at http://www.ietf.org/rfc/rfc2822.txt
309
+ }
310
+ }
311
+ $headers .= "$bcc\r\n";
312
+ }
313
+ // actually send mail
314
+ if ( (defined('BCCLIMIT')) && (BCCLIMIT > 0) && (isset($batch)) ) {
315
+ foreach ($batch as $bcc) {
316
+ $newheaders = $headers . "$bcc\r\n";
317
+ @wp_mail($this->myemail, $subject, $mailtext, $newheaders);
318
+ }
319
+ } else {
320
+ @wp_mail($this->myemail, $subject, $mailtext, $headers);
321
+ }
322
+ } // end mail()
323
+
324
+ /**
325
+ Sends an email notification of a new post
326
+ */
327
+ function publish($id = 0) {
328
+ if (!$id) { return $id; }
329
+
330
+ // are we doing daily digests? If so, don't send anything now
331
+ if ($this->subscribe2_options['email_freq'] != 'never') { return; }
332
+
333
+ // we need to determine whether this is a new post, or an edit
334
+ if ($this->private) {
335
+ // this post was published from draft status
336
+ // OR is an edit of an existing post
337
+ // so send no notification
338
+ return $id;
339
+ }
340
+
341
+ $post_cats = wp_get_post_cats('1', $id);
342
+ $post_cats_string = implode(',', $post_cats);
343
+ $check = false;
344
+ // is the current post assigned to any categories
345
+ // which should not generate a notification email?
346
+ foreach (explode(',', $this->subscribe2_options['exclude']) as $cat) {
347
+ if (in_array($cat, $post_cats)) {
348
+ $check = true;
349
+ }
350
+ }
351
+ // if so, bail out
352
+ if ($check) {
353
+ // hang on -- can registered users subscribe to
354
+ // excluded categories?
355
+ if ('0' == $this->subscribe2_options['reg_override']) {
356
+ // nope? okay, let's leave
357
+ return $id;
358
+ }
359
+ }
360
+
361
+ global $wpdb;
362
+ $post =& get_post($id);
363
+ // is the post password protected?
364
+ if ( ($this->subscribe2_options['password'] == "no") && ($post->post_password != '') ) {return $id; }
365
+
366
+ // is this post set in the future?
367
+ if ($post->post_date > current_time('mysql')) {
368
+ // bail out
369
+ return $id;
370
+ }
371
+
372
+ // lets collect our public subscribers
373
+ // and all our registered subscribers for these categories
374
+ if (!$check) {
375
+ // if this post is assigned to an excluded
376
+ // category, then this test will prevent
377
+ // the public from receiving notification
378
+ $public = $this->get_public();
379
+ }
380
+ $registered = $this->get_registered("cats=$post_cats_string");
381
+
382
+ // do we have subscribers?
383
+ if ( (empty($public)) && (empty($registered)) ) {
384
+ // if not, no sense doing anything else
385
+ return $id;
386
+ }
387
+ // we set these class variables so that we can avoid
388
+ // passing them in function calls a little later
389
+ $this->post_title = $post->post_title;
390
+ $this->permalink = "<a href=\"" . get_permalink($id) . "\">" . get_permalink($id) . "</a>";
391
+
392
+ $author = get_userdata($post->post_author);
393
+ $this->authorname = $author->display_name;
394
+
395
+ // do we send as admin, or post author?
396
+ if ('author' == $this->subscribe2_options['sender']) {
397
+ // get author details
398
+ $user =& $author;
399
+ } else {
400
+ // get admin details
401
+ $user = get_userdata(1);
402
+ }
403
+ $this->myemail = $user->user_email;
404
+ $this->myname = $user->display_name;
405
+ // Get email subject
406
+ $subject = $this->substitute(stripslashes($this->s2_subject));
407
+ // Get the message template
408
+ $mailtext = $this->substitute(stripslashes($this->subscribe2_options['mailtext']));
409
+
410
+ $plaintext = $post->post_content;
411
+ $content = apply_filters('the_content', $post->post_content);
412
+ $content = str_replace(']]>', ']]&gt', $content);
413
+ $excerpt = $post->post_excerpt;
414
+ if ('' == $excerpt) {
415
+ // no excerpt, is there a <!--more--> ?
416
+ if (false !== strpos($plaintext, '<!--more-->')) {
417
+ list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
418
+ // strip leading and trailing whitespace
419
+ $excerpt = strip_tags($excerpt);
420
+ $excerpt = trim($excerpt);
421
+ } else {
422
+ // no <!--more-->, so grab the first 55 words
423
+ $excerpt = strip_tags($plaintext);
424
+ $excerpt_length = 55;
425
+ $words = explode(' ', $excerpt, $excerpt_length + 1);
426
+ if (count($words) > $excerpt_length) {
427
+ array_pop($words);
428
+ array_push($words, '[...]');
429
+ $excerpt = implode(' ', $words);
430
+ }
431
+ }
432
+ }
433
+
434
+ // first we send plaintext summary emails
435
+ $body = str_replace('POST', $excerpt, $mailtext);
436
+ $registered = $this->get_registered("cats=$post_cats_string&format=text&amount=excerpt");
437
+ if (empty($registered)) {
438
+ $recipients = (array)$public;
439
+ }
440
+ elseif (empty($public)) {
441
+ $recipients = (array)$registered;
442
+ } else {
443
+ $recipients = array_merge((array)$public, (array)$registered);
444
+ }
445
+ $this->mail($recipients, $subject, $body);
446
+ // next we send plaintext full content emails
447
+ $body = str_replace('POST', strip_tags($plaintext), $mailtext);
448
+ $this->mail($this->get_registered("cats=$post_cats_string&format=text&amount=post"), $subject, $body);
449
+ // finally we send html full content emails
450
+ $body = str_replace("\r\n", "<br />\r\n", $mailtext);
451
+ $body = str_replace('POST', $content, $body);
452
+ $this->mail($this->get_registered("cats=$post_cats_string&format=html"), $subject, $body, 'html');
453
+
454
+ return $id;
455
+ } // end publish()
456
+
457
+ /**
458
+ Sends a notification when a draft post is published
459
+ */
460
+ function private2publish($id = 0) {
461
+ if (0 == $id) { return $id; }
462
+
463
+ $this->publish($id);
464
+ $this->private = TRUE;
465
+ return $id;
466
+ } // end private2publish()
467
+
468
+ /**
469
+ Prevents notifications from being sent when editing posts
470
+ */
471
+ function edit($id = 0) {
472
+ if (0 == $id) { return; }
473
+
474
+ $this->private = TRUE;
475
+ return $id;
476
+ }
477
+
478
+ /**
479
+ Send confirmation email to the user
480
+ */
481
+ function send_confirm($what = '', $is_remind = FALSE) {
482
+ if ($this->filtered == 1) { return; }
483
+ if ( (!$this->email) || (!$what) ) {
484
+ return false;
485
+ }
486
+ $id = $this->get_id($this->email);
487
+ if (!$id) {
488
+ return false;
489
+ }
490
+
491
+ // generate the URL "?s2=ACTION+HASH+ID"
492
+ // ACTION = 1 to