Subscribe2 - Version 3.7

Version Description

Download this release

Release Info

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

Code changes from version 2.21 to 3.7

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