Subscribe2 - Version 5.2

Version Description

Download this release

Release Info

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

Code changes from version 5.1 to 5.2

Files changed (4) hide show
  1. ReadMe.txt +90 -3
  2. counterwidget.php +1 -1
  3. subscribe2.php +551 -532
  4. subscribe2.pot +207 -197
ReadMe.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: MattyRob, Skippy, RavanH
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2387904
4
Tags: posts, subscription, email, subscribe, notify, notification
5
Requires at least: 2.0.x
6
- Tested up to: 2.8.4
7
- Stable tag: 5.1
8
9
Sends a list of subscribers an email notification when new posts are published to your blog
10
@@ -40,17 +40,91 @@ This token will automatically be replaced by dynamic subscription information an
40
41
== Frequently Asked Questions ==
42
43
= Where can I get help? =
44
So, you've downloaded the plugin an it isn't doing what you expect. First you should read the included documentation. There is a ReadMe.txt file and a PDF startup guide installed with the plugin.
45
46
Next you could search in the [Subscribe2 Forum](http://getsatisfaction.com/subscribe2/), the [WordPress forums](http://wordpress.org/support/) or the [Subscribe2 blog FAQs](http://subscribe2.wordpress.com/category/faq/).
47
48
- No joy there? Well, if you can't find an answer to your question you can get [paid support](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2387904) by donating at least 20 to the plugin author.
49
50
= Where can I get more information about the plugin features? =
51
52
A comprehensive guide that covers many, if not all, of the Subscribe2 features is available to purchase from the [iAssistant](http://the-iassistant.com/subscribe2-guide/)
53
54
== Screenshots ==
55
56
1. The Posts->Mail Subscribers admin page generated by the plugin.
@@ -60,6 +134,19 @@ A comprehensive guide that covers many, if not all, of the Subscribe2 features i
60
61
== Changelog ==
62
63
= Version 5.1 by Matthew Robinson =
64
65
* Add widget options to add custom text before and a after the dynamic Subscribe2 output - thank to Lee Willis
3
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2387904
4
Tags: posts, subscription, email, subscribe, notify, notification
5
Requires at least: 2.0.x
6
+ Tested up to: 2.9
7
+ Stable tag: 5.2
8
9
Sends a list of subscribers an email notification when new posts are published to your blog
10
40
41
== Frequently Asked Questions ==
42
43
+ = I want HTML email to be the default email type =
44
+
45
+ You need to pay for the [Subscribe2 HTML version](http://wpplugins.com/plugin/46/subscribe2-html).
46
+
47
= Where can I get help? =
48
So, you've downloaded the plugin an it isn't doing what you expect. First you should read the included documentation. There is a ReadMe.txt file and a PDF startup guide installed with the plugin.
49
50
Next you could search in the [Subscribe2 Forum](http://getsatisfaction.com/subscribe2/), the [WordPress forums](http://wordpress.org/support/) or the [Subscribe2 blog FAQs](http://subscribe2.wordpress.com/category/faq/).
51
52
+ No joy there? Well, if you can't find an answer to your question you can get [paid support](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2387904) by donating at least 20 UK pounds to the plugin author.
53
54
= Where can I get more information about the plugin features? =
55
56
A comprehensive guide that covers many, if not all, of the Subscribe2 features is available to purchase from the [iAssistant](http://the-iassistant.com/subscribe2-guide/)
57
58
+ = Some or all email notifications fail to send, why? =
59
+ In the first instance ***check this with your hosting provider***, they have access to your server logs and will be able to tell you where and why emails are being blocked.
60
+
61
+ Some hosting providers place a restriction on the maximum number of recipients in any one email message. Some hosts simply block all emails on certain low-cost hosting plans.
62
+
63
+ Subscribe2 provides a facility to work around this restriction by sending batches of emails. To enable this feature, go to Settings->Subscribe2 and located the setting to restrict the number of recipients per email. If this is set to 30 then each outgoing email notification will only contain addresses for 30 recipients.
64
+
65
+ Reminder: because subscribe2 places all recipients in BCC fields, and places the blog admin in the TO field, the blog admin will receive one email per batched delivery. So if you have 90 subscribers, the blog admin should receive three post notification emails, one for each set of 30 BCC recipients.
66
+
67
+ Batches will occur for each group of message as described above. A site on Dreamhost with many public and registered subscribers could conceivably generate a lot of email for your own inbox.
68
+
69
+ = My host has a limit of X emails per hour / day, can I limit the way Subscribe2 sends emails? =
70
+
71
+ This is more commonly called 'throttling' or 'choking'. PHP is a scripting language and while it is technically possible to throttle emails using script it is not very efficient. It is much better in terms of speed and server overhead (CPU cycles and RAM) to throttle using a server side application.
72
+
73
+ So, Subscribe2 does not and never will offer a throtting option. To solve the problem speak to your hosting provider about changing the restrictions, move to a less restriction hosting package or change hosting providers. Alternatively, there may be another WordPress plugin that can provide this functionality.
74
+
75
+ = Why is my admin address getting emails from Subscribe2? =
76
+
77
+ This plugin sends emails to your subscribers using the BCC (Blind Cardon Copy) header in email messages. Each email is sent TO: the admin address. There may be emails for a plain text excerpt notification, palin text full text and HTML format emails and additionally if the BCCLIMIT has been set due to hosting restrictions duplicate copies of these emails will be sent to the admin address.
78
+
79
+ = I can't find my subscribers / the options / something else =
80
+
81
+ Subscribe2 creates four (4) new admin menus in the back end of WordPress.
82
+
83
+ * Posts -> Mail Subscribers : Allows users with Publish capabilities to send emails to your current subscribers
84
+ * Tools -> Subscribers : Allows you to manually (un)subscribe users by email address, displays lists of currently subscribed users and allows you to bulk subscribe Registered Users
85
+ * Users -> Subscriptions : Allows the currently logged in user to manage their own subscriptions
86
+ * Settings -> Subscribe2 : Allows administrator level users to control many aspects of the plugins operation. It should be pretty self explanatory from the notes on the screen
87
+
88
+ = I'm confused, what are all the different types of subscriber? =
89
+
90
+ There are basically only 2 types of subscriber. Public Subscribers and Registered Subscribers.
91
+
92
+ Public subscribers have provided their email address for email notification of your new posts. When they enter there address on your site they are sent an email asking them to confirm their request and added to a list of Unconfirmed Subscribers. Once they complete their request by clicking on the link in their email they will become Confirmed Subscribers.
93
+
94
+ Registered Users have registered with your WorPress blog (provided you have enabled this in the core WordPress settings). Once registered they can choose to subscribe to specific categories and can also control the type of email they get by choosing plain text in an excerpt or full post format or a full post format with HTML.
95
+
96
+ = Can I put the form elsewhere? (header, footer, sidebar without the widget) =
97
+
98
+ The simple answer is yes you can but this is not supported so you need to figure out any problems that are caused by doing this on your own. Read <a href="http://subscribe2.wordpress.com/2006/09/19/sidebar-without-a-widget/">here</a> for the basic approach.
99
+
100
+ = I'd like to be able to collect more information from users when they subscribe, can I? =
101
+
102
+ Get them to register with your blog rather than using the Subscribe2 form. Additional fields would require much more intensive form processing, checking and entry into the database and since you won't then be able to easily use this information to persoanlise emails there really isn't any point in collecting this data.
103
+
104
+ = I can't find or insert the Subscribe2 token, help! =
105
+
106
+ If, for some reason the Subscribe2 button does not appear in your browser window try refreshing your browser and cache (Shift and Reload in Firefox). If this still fails then insert the token manually. In the Rich Text Editor (TinyMCE) make sure you switch to the "code" view and type in <!--subscribe2-->.
107
+
108
+ = Can I suggest you add X as a feature =
109
+
110
+ I'm open to suggestions but since the software is written by me for use on my site and then shared for free because others may find it useful as it comes don't expect your suggestion to be implemented unless I'll find it useful.
111
+
112
+ = I'd like to be able to send my subscribers notifications in HTML =
113
+
114
+ By default Public Subscribers get plain text emails and only Registered Subscribers can opt to receive email in HTML format. If you really want HTML for all you need to pay for the upgrade. $40US will get you the amended code and updates for 1 year.
115
+
116
+ = Which version should I be using, I'm on WordPress x.x.x? =
117
+ WordPress 2.3 and up require Subscribe2 from the 4.x stable branch. The most recent version is hosted via [Wordpress.org](http://wordpress.org/extend/plugins/subscribe2/).
118
+
119
+ WordPress 2.1.x and 2.2.x require Subscribe2 from the 3.x stable. The most recent version is [3.8](http://downloads.wordpress.org/plugin/subscribe2.3.8.zip).
120
+
121
+ WordPress 2.0.x requires Subscribe2 from the 2.x stable branch. The most recent version is [2.22](http://downloads.wordpress.org/plugin/subscribe2.2.22.zip).
122
+
123
+ = Why doesn't the form appear in my WordPress page? =
124
+ This is usually caused by one of two things. Firstly, it is possible that the form is there but because you haven't logged out of WordPress yourself you are seeing a message about managing your profile instead. Log out of WordPress and it will appear as the subscription form you are probably expecting.
125
+
126
+ Secondly, make sure that the token (<!--subscribe2-->) is correctly entered in your page with a blank line above and below. The easient way to do this is to deactivate the plugin, visit your WordPress page and view the source. The token should be contained in the source code of the page. If it is not there you either have not correctly entered the token or you have another plugin that is stripping the token from the page code.
127
+
128
== Screenshots ==
129
130
1. The Posts->Mail Subscribers admin page generated by the plugin.
134
135
== Changelog ==
136
137
+ = Version 5.2 by Matthew Robinson =
138
+
139
+ * Added screen_icon() to each Subscribe2 admin page
140
+ * Improved addition of links to the Plugins admin page
141
+ * Improved XHTML validity of admin pages
142
+ * Improved display of category hierarchy display in the category form
143
+ * Added ability to use TAGS & CATS keywords in digest mails (position is static irrespective of keyword location)
144
+ * Use PHP variable for Subscribe2 folder to allow for easier renaming (if needed)
145
+ * Fixed a bug in TinyURL encoding introduced when links were click enabled
146
+ * Removed BurnURL from the plugin as it appears to be no longer operational
147
+ * Added urlencode to email addresses in Tools->Subscribers when editing other user preferences
148
+ * Restored several FAQs to the ReadMe file and the [WordPress.org FAQ section](http://wordpress.org/extend/plugins/subscribe2/faq/)
149
+
150
= Version 5.1 by Matthew Robinson =
151
152
* Add widget options to add custom text before and a after the dynamic Subscribe2 output - thank to Lee Willis
counterwidget.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Subscribe2 Counter Widget
4
Plugin URI: http://subscribe2.wordpress.com
5
Description: Adds a sidebar widget to easily customize and display your Subscribe2 subscribers stats.
6
- Version: 5.1
7
Author: Matthew Robinson
8
Author URI: http://subscribe2.wordpress.com
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2387904
3
Plugin Name: Subscribe2 Counter Widget
4
Plugin URI: http://subscribe2.wordpress.com
5
Description: Adds a sidebar widget to easily customize and display your Subscribe2 subscribers stats.
6
+ Version: 5.2
7
Author: Matthew Robinson
8
Author URI: http://subscribe2.wordpress.com
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2387904
subscribe2.php CHANGED
@@ -2,8 +2,8 @@
2
/*
3
Plugin Name: Subscribe2
4
Plugin URI: http://subscribe2.wordpress.com
5
- Description: Notifies an email list when new entries are posted. For support visit the <a href="http://getsatisfaction.com/subscribe2/">Subscribe2 forum</a>.
6
- Version: 5.1
7
Author: Matthew Robinson
8
Author URI: http://subscribe2.wordpress.com
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2387904
@@ -23,35 +23,36 @@ the Free Software Foundation, either version 3 of the License, or
23
24
Subscribe2 is distributed in the hope that it will be useful,
25
but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
GNU General Public License for more details.
28
29
You should have received a copy of the GNU General Public License
30
- along with Subscribe2. If not, see <http://www.gnu.org/licenses/>.
31
*/
32
33
// our version number. Don't touch this or any line below
34
// unless you know exacly what you are doing
35
- define('S2VERSION', '5.1');
36
- define('S2PATH', trailingslashit(dirname(__FILE__)));
37
38
// Set minimum execution time to 5 minutes - won't affect safe mode
39
$safe_mode = array('On', 'ON', 'on', 1);
40
- if ( (!in_array(ini_get('safe_mode'), $safe_mode)) && (ini_get('max_execution_time') < 300) ) {
41
@ini_set('max_execution_time', 300);
42
}
43
44
// Pre-2.6 compatibility
45
- if (!defined('WP_CONTENT_URL')) {
46
- define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
47
}
48
- if (!defined('WP_CONTENT_DIR')) {
49
- define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
50
}
51
52
/* Include buttonsnap library by Owen Winckler */
53
- if (!class_exists('buttonsnap')) {
54
- require(WP_CONTENT_DIR . '/plugins/subscribe2/include/buttonsnap.php');
55
}
56
57
$mysubscribe2 = new s2class;
@@ -112,19 +113,19 @@ class s2class {
112
Hook the menu
113
*/
114
function admin_menu() {
115
- $s2management = add_management_page(__('Subscribers', 'subscribe2'), __('Subscribers', 'subscribe2'), "manage_options", 's2_tools', array(&$this, 'manage_menu'));
116
add_action("admin_print_scripts-$s2management", array(&$this, 'checkbox_form_js'));
117
118
- $s2options = add_options_page(__('Subscribe2 Options', 'subscribe2'), __('Subscribe2', 'subscribe2'), "manage_options", 's2_settings', array(&$this, 'options_menu'));
119
add_action("admin_print_scripts-$s2options", array(&$this, 'checkbox_form_js'));
120
add_action("admin_print_scripts-$s2options", array(&$this, 'option_form_js'));
121
- add_filter('plugin_action_links', array(&$this, 'plugin_action'), -10, 2);
122
123
- $s2user = add_users_page(__('Subscriptions', 'subscribe2'), __('Subscriptions', 'subscribe2'), "read", 's2_users', array(&$this, 'user_menu'));
124
add_action("admin_print_scripts-$s2user", array(&$this, 'checkbox_form_js'));
125
add_action("admin_print_styles-$s2user", array(&$this, 'user_admin_css'));
126
127
- add_submenu_page('post-new.php', __('Mail Subscribers', 'subscribe2'), __('Mail Subscribers', 'subscribe2'), "publish_posts", 's2_posts', array(&$this, 'write_menu'));
128
129
$s2nonce = md5('subscribe2');
130
} // end admin_menu()
@@ -133,22 +134,22 @@ class s2class {
133
Hook for Admin Drop Down Icons
134
*/
135
function ozh_s2_icon() {
136
- return WP_CONTENT_URL . '/plugins/subscribe2/include/email_edit.png';
137
} // end ozh_s2_icon()
138
139
/**
140
Insert Javascript into admin_header
141
*/
142
function checkbox_form_js() {
143
- wp_enqueue_script('s2_checkbox', WP_CONTENT_URL . '/plugins/' . dirname( plugin_basename( __FILE__ ) ) . '/include/s2_checkbox.js', array('jquery'), '1.0');
144
} //end checkbox_form_js()
145
146
function user_admin_css() {
147
- wp_enqueue_style('s2_user_admin', WP_CONTENT_URL . '/plugins/ '. dirname( plugin_basename( __FILE__ ) ) . '/include/s2_user_admin.css', array(), '1.0');
148
}
149
150
function option_form_js() {
151
- wp_enqueue_script('s2_edit', WP_CONTENT_URL . '/plugins/' . dirname( plugin_basename( __FILE__ ) ) . '/include/s2_edit.js', array('jquery'), '1.0');
152
} // end option_form_js()
153
154
/* ===== Install, upgrade, reset ===== */
@@ -157,7 +158,7 @@ class s2class {
157
*/
158
function install() {
159
// include upgrade-functions for maybe_create_table;
160
- if (!function_exists('maybe_create_table')) {
161
require_once(ABSPATH . 'wp-admin/install-helper.php');
162
}
163
$date = date('Y-m-d');
@@ -180,7 +181,7 @@ class s2class {
180
function upgrade() {
181
global $wpdb, $wp_version, $wpmu_version;
182
// include upgrade-functions for maybe_create_table;
183
- if (!function_exists('maybe_create_table')) {
184
require_once(ABSPATH . 'wp-admin/install-helper.php');
185
}
186
$date = date('Y-m-d');
@@ -190,16 +191,16 @@ class s2class {
190
// let's take the time to check process registered users
191
// existing public subscribers are subscribed to all categories
192
$users = $this->get_all_registered('ID');
193
- if (!empty($users)) {
194
- foreach ($users as $user) {
195
$this->register($user);
196
}
197
}
198
// update the options table to serialized format
199
$old_options = $wpdb->get_col("SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name != 's2_future_posts'");
200
201
- if (!empty($old_options)) {
202
- foreach ($old_options as $option) {
203
$value = get_option($option);
204
$option_array = substr($option, 3);
205
$this->subscribe2_options[$option_array] = $value;
@@ -212,27 +213,27 @@ class s2class {
212
update_option('subscribe2_options', $this->subscribe2_options);
213
214
// upgrade old wpmu user meta data to new
215
- if ( (isset($wpmu_version)) || (strpos($wp_version, 'wordpress-mu')) ) {
216
$this->namechange_subscribe2_widget();
217
// loop through all users
218
- foreach ($users as $user) {
219
// get categories which the user is subscribed to (old ones)
220
$categories = get_usermeta($user, 's2_subscribed');
221
$categories = explode(',', $categories);
222
223
// load blogs of user (only if we need them)
224
$blogs = array();
225
- if (count($categories) > 0 && !in_array('-1', $categories)) {
226
$blogs = get_blogs_of_user($user, true);
227
}
228
229
- foreach ($blogs as $blog_id => $blog) {
230
switch_to_blog($blog_id);
231
232
$blog_categories = (array)$wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category'");
233
$subscribed_categories = array_intersect($categories, $blog_categories);
234
- if (!empty($subscribed_categories)) {
235
- foreach ($subscribed_categories as $subscribed_category) {
236
update_usermeta($user, $this->get_usermeta_keyname('s2_cat') . $subscribed_category, $subscribed_category);
237
}
238
update_usermeta($user, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $subscribed_categories));
@@ -242,7 +243,7 @@ class s2class {
242
243
// delete old user meta keys
244
delete_usermeta($user, 's2_subscribed');
245
- foreach ($categories as $cat) {
246
delete_usermeta($user, 's2_cat' . $cat);
247
}
248
}
@@ -265,29 +266,23 @@ class s2class {
265
Performs string substitutions for subscribe2 mail texts
266
*/
267
function substitute($string = '') {
268
- if ('' == $string) {
269
return;
270
}
271
$string = str_replace("BLOGNAME", get_option('blogname'), $string);
272
$string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
273
$string = str_replace("TITLE", stripslashes($this->post_title), $string);
274
- $string = str_replace("PERMALINK", $this->permalink, $string);
275
- if (strstr($string, "TINYLINK")) {
276
$tinylink = file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode($this->permalink));
277
- if ( ($tinylink !== 'Error') || ($tinylink != false) ) {
278
- $string = str_replace("TINYLINK", $tinylink, $string);
279
} else {
280
- $string = str_replace("TINYLINK", $this->permalink, $string);
281
}
282
}
283
- if (strstr($string, "BURNLINK")) {
284
- $burnlink = file_get_contents('http://burnurl.com/?url=' . urlencode($this->permalink) . '&output=plain');
285
- if ( ($burnlink !== 'error') || ($burnlink != false) ) {
286
- $string = str_replace("BURNLINK", $burnlink, $string);
287
- } else {
288
- $string = str_replace("BURNLINK", $this->permalink, $string);
289
- }
290
- }
291
$string = str_replace("MYNAME", stripslashes($this->myname), $string);
292
$string = str_replace("EMAIL", $this->myemail, $string);
293
$string = str_replace("AUTHORNAME", $this->authorname, $string);
@@ -301,11 +296,11 @@ class s2class {
301
Delivers email to recipients in HTML or plaintext
302
*/
303
function mail($recipients = array(), $subject = '', $message = '', $type='text') {
304
- if ( (empty($recipients)) || ('' == $message) ) { return; }
305
306
- if ('html' == $type) {
307
$headers = $this->headers('html');
308
- if ('yes' == $this->subscribe2_options['stylesheet']) {
309
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title><link rel=\"stylesheet\" href=\"" . get_bloginfo('stylesheet_url') . "\" type=\"text/css\" media=\"screen\" /></head><body>" . $message . "</body></html>");
310
} else {
311
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>");
@@ -324,28 +319,27 @@ class s2class {
324
// Construct BCC headers for sending or send individual emails
325
$bcc = '';
326
natcasesort($recipients);
327
- if ( (function_exists('wpmq_mail')) || ($this->subscribe2_options['bcclimit'] == 1) ) {
328
// BCCLimit is 1 so send individual emails
329
- foreach ($recipients as $recipient) {
330
$recipient = trim($recipient);
331
// sanity check -- make sure we have a valid email
332
- if (!is_email($recipient)) { continue; }
333
- if (function_exists('wpmq_mail')) {
334
@wp_mail($recipient, $subject, $mailtext, $headers, NULL, 0);
335
} else {
336
@wp_mail($recipient, $subject, $mailtext, $headers);
337
}
338
}
339
- // Sending completed so return $status
340
- return $status;
341
- } elseif ($this->subscribe2_options['bcclimit'] == 0) {
342
// we're not using BCCLimit
343
- foreach ($recipients as $recipient) {
344
$recipient = trim($recipient);
345
// sanity check -- make sure we have a valid email
346
- if (!is_email($recipient)) { continue; }
347
// and NOT the sender's email, since they'll get a copy anyway
348
- if ( (!empty($recipient)) && ($this->myemail != $recipient) ) {
349
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
350
// Bcc Headers now constructed by phpmailer class
351
}
@@ -355,16 +349,16 @@ class s2class {
355
// we're using BCCLimit
356
$count = 1;
357
$batch = array();
358
- foreach ($recipients as $recipient) {
359
$recipient = trim($recipient);
360
// sanity check -- make sure we have a valid email
361
- if (!is_email($recipient)) { continue; }
362
// and NOT the sender's email, since they'll get a copy anyway
363
- if ( (!empty($recipient)) && ($this->myemail != $recipient) ) {
364
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
365
// Bcc Headers now constructed by phpmailer class
366
}
367
- if ($this->subscribe2_options['bcclimit'] == $count) {
368
$count = 0;
369
$batch[] = $bcc;
370
$bcc = '';
@@ -372,7 +366,7 @@ class s2class {
372
$count++;
373
}
374
// add any partially completed batches to our batch array
375
- if ('' != $bcc) {
376
$batch[] = $bcc;
377
}
378
}
@@ -380,8 +374,8 @@ class s2class {
380
reset($recipients);
381
382
// actually send mail
383
- if ( (isset($batch)) && (!empty($batch)) ) {
384
- foreach ($batch as $bcc) {
385
$newheaders = $headers . "$bcc\r\n";
386
$status = @wp_mail($this->myemail, $subject, $mailtext, $newheaders);
387
}
@@ -396,7 +390,7 @@ class s2class {
396
Construct standard set of email headers
397
*/
398
function headers($type='text') {
399
- if ( (empty($this->myname)) || (empty($this->myemail)) ) {
400
$admin = $this->get_userdata($this->subscribe2_options['sender']);
401
$this->myname = html_entity_decode($admin->display_name, ENT_QUOTES);
402
$this->myemail = $admin->user_email;
@@ -408,7 +402,7 @@ class s2class {
408
$headers .= "Precedence: list\nList-Id: " . get_option('blogname') . "\n";
409
$headers .= "MIME-Version: 1.0\n";
410
$headers .= "X-Mailer: PHP" . phpversion() . "\n";
411
- if ($type == 'html') {
412
// To send HTML mail, the Content-Type header must be set
413
$headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
414
} else {
@@ -422,30 +416,30 @@ class s2class {
422
Sends an email notification of a new post
423
*/
424
function publish($post = 0, $preview = '') {
425
- if (!$post) { return $post; }
426
427
- if ($preview == '') {
428
// we aren't sending a Preview to the current user so carry out checks
429
$s2mail = get_post_meta($post->ID, 's2mail', true);
430
- if ( (isset($_POST['s2_meta_field']) && ($_POST['s2_meta_field'] == 'no')) || (strtolower(trim($s2mail)) == 'no') ) { return $post; }
431
432
// are we doing daily digests? If so, don't send anything now
433
- if ($this->subscribe2_options['email_freq'] != 'never') { return $post; }
434
435
// is the current post a page
436
// and should this not generate a notification email?
437
- if ( ($this->subscribe2_options['pages'] == 'no') && ($post->post_type == 'page') ) {
438
return $post;
439
}
440
441
// is this post set in the future?
442
- if ($post->post_date > current_time('mysql')) {
443
// bail out
444
return $post;
445
}
446
447
//Are we sending notifications for password protected posts?
448
- if ( ($this->subscribe2_options['password'] == "no") && ($post->post_password != '') ) {
449
return $post;
450
}
451
@@ -453,16 +447,16 @@ class s2class {
453
$check = false;
454
// is the current post assigned to any categories
455
// which should not generate a notification email?
456
- foreach (explode(',', $this->subscribe2_options['exclude']) as $cat) {
457
- if (in_array($cat, $post_cats)) {
458
$check = true;
459
}
460
}
461
462
- if ($check) {
463
// hang on -- can registered users subscribe to
464
// excluded categories?
465
- if ('0' == $this->subscribe2_options['reg_override']) {
466
// nope? okay, let's leave
467
return $post;
468
}
@@ -470,13 +464,13 @@ class s2class {
470
471
// Are we sending notifications for Private posts?
472
// Action is added if we are, but double check option and post status
473
- if ( ($this->subscribe2_options['private'] == "yes") && ($post->post_status == 'private') ) {
474
// don't send notification to public users
475
$check = true;
476
}
477
478
// lets collect our subscribers
479
- if (!$check) {
480
// if this post is assigned to an excluded
481
// category, or is a private post then
482
// don't send public subscribers a notification
@@ -486,7 +480,7 @@ class s2class {
486
$registered = $this->get_registered("cats=$post_cats_string");
487
488
// do we have subscribers?
489
- if ( (empty($public)) && (empty($registered)) ) {
490
// if not, no sense doing anything else
491
return $post;
492
}
@@ -495,13 +489,13 @@ class s2class {
495
// we set these class variables so that we can avoid
496
// passing them in function calls a little later
497
$this->post_title = "<a href=\"" . get_permalink($post->ID) . "\">" . $post->post_title . "</a>";
498
- $this->permalink = "<a href=\"" . get_permalink($post->ID) . "\">" . get_permalink($post->ID) . "</a>";
499
500
$author = get_userdata($post->post_author);
501
$this->authorname = $author->display_name;
502
503
// do we send as admin, or post author?
504
- if ('author' == $this->subscribe2_options['sender']) {
505
// get author details
506
$user = &$author;
507
} else {
@@ -521,7 +515,7 @@ class s2class {
521
$mailtext = stripslashes($this->substitute($mailtext));
522
523
$plaintext = $post->post_content;
524
- if (function_exists('strip_shortcodes')) {
525
$plaintext = strip_shortcodes($plaintext);
526
}
527
$gallid = '[gallery id="' . $post->ID . '"]';
@@ -529,9 +523,9 @@ class s2class {
529
$content = apply_filters('the_content', $post->post_content);
530
$content = str_replace("]]>", "]]&gt", $content);
531
$excerpt = $post->post_excerpt;
532
- if ('' == $excerpt) {
533
// no excerpt, is there a <!--more--> ?
534
- if (false !== strpos($plaintext, '<!--more-->')) {
535
list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
536
// strip leading and trailing whitespace
537
$excerpt = strip_tags($excerpt);
@@ -554,7 +548,7 @@ class s2class {
554
$html_body = str_replace("\r\n", "<br />\r\n", $mailtext);
555
$html_body = str_replace("POST", $content, $html_body);
556
557
- if ($preview != '') {
558
$this->myemail = $preview;
559
$this->myname = "Preview";
560
$this->mail(array($preview), $subject, $excerpt_body);
@@ -563,9 +557,9 @@ class s2class {
563
} else {
564
// first we send plaintext summary emails
565
$registered = $this->get_registered("cats=$post_cats_string&format=excerpt");
566
- if (empty($registered)) {
567
$recipients = (array)$public;
568
- } elseif (empty($public)) {
569
$recipients = (array)$registered;
570
} else {
571
$recipients = array_merge((array)$public, (array)$registered);
@@ -584,7 +578,7 @@ class s2class {
584
Hook Subscribe2 into posts published via email
585
*/
586
function publish_phone($id) {
587
- if (!$id) { return; }
588
589
$post = get_post($id);
590
$this->publish($post);
@@ -595,12 +589,12 @@ class s2class {
595
Send confirmation email to the user
596
*/
597
function send_confirm($what = '', $is_remind = false) {
598
- if ($this->filtered == 1) { return true; }
599
- if ( (!$this->email) || (!$what) ) {
600
return false;
601
}
602
$id = $this->get_id($this->email);
603
- if (!$id) {
604
return false;
605
}
606
@@ -611,9 +605,9 @@ class s2class {
611
//use home instead of siteurl incase index.php is not in core wordpress directory
612
$link = get_option('home') . "/?s2=";
613
614
- if ('add' == $what) {
615
$link .= '1';
616
- } elseif ('del' == $what) {
617
$link .= '0';
618
}
619
$link .= md5($this->email);
@@ -622,15 +616,15 @@ class s2class {
622
// sort the headers now so we have all substitute information
623
$mailheaders = $this->headers();
624
625
- if ($is_remind == true) {
626
$body = $this->substitute(stripslashes($this->subscribe2_options['remind_email']));
627
$subject = $this->substitute(stripslashes($this->subscribe2_options['remind_subject']));
628
} else {
629
$body = $this->substitute(stripslashes($this->subscribe2_options['confirm_email']));
630
- if ('add' == $what) {
631
$body = str_replace("ACTION", $this->subscribe, $body);
632
$subject = str_replace("ACTION", $this->subscribe, $this->subscribe2_options['confirm_subject']);
633
- } elseif ('del' == $what) {
634
$body = str_replace("ACTION", $this->unsubscribe, $body);
635
$subject = str_replace("ACTION", $this->unsubscribe, $this->subscribe2_options['confirm_subject']);
636
}
@@ -649,7 +643,7 @@ class s2class {
649
function get_email($id = 0) {
650
global $wpdb;
651
652
- if (!$id) {
653
return false;
654
}
655
return $wpdb->get_var("SELECT email FROM $this->public WHERE id=$id");
@@ -661,7 +655,7 @@ class s2class {
661
function get_id($email = '') {
662
global $wpdb;
663
664
- if (!$email) {
665
return false;
666
}
667
return $wpdb->get_var("SELECT id FROM $this->public WHERE email='$email'");
@@ -674,17 +668,17 @@ class s2class {
674
function activate($email = '') {
675
global $wpdb;
676
677
- if ('' == $email) {
678
- if ('' != $this->email) {
679
$email = $this->email;
680
} else {
681
return false;
682
}
683
}
684
685
- if (false !== $this->is_public($email)) {
686
$check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email='$this->email'");
687
- if ($check) { return; }
688
$wpdb->get_results("UPDATE $this->public SET active='1', ip='$this->ip' WHERE email='$email'");
689
} else {
690
global $current_user;
@@ -696,20 +690,20 @@ class s2class {
696
Add an public subscriber to the subscriber table as unconfirmed
697
*/
698
function add($email = '') {
699
- if ($this->filtered ==1) { return; }
700
global $wpdb;
701
702
- if ('' == $email) {
703
- if ('' != $this->email) {
704
$email = $this->email;
705
} else {
706
return false;
707
}
708
}
709
710
- if (!is_email($email)) { return false; }
711
712
- if (false !== $this->is_public($email)) {
713
$wpdb->get_results("UPDATE $this->public SET date=NOW() WHERE email='$email'");
714
} else {
715
$wpdb->get_results($wpdb->prepare("INSERT INTO $this->public (email, active, date, ip) VALUES (%s, %d, NOW(), %s)", $email, 0, $this->ip));
@@ -722,15 +716,15 @@ class s2class {
722
function delete($email = '') {
723
global $wpdb;
724
725
- if ('' == $email) {
726
- if ('' != $this->email) {
727
$email = $this->email;
728
} else {
729
return false;
730
}
731
}
732
733
- if (!is_email($email)) { return false; }
734
$wpdb->get_results("DELETE FROM $this->public WHERE email='$email'");
735
} // end delete()
736
@@ -740,13 +734,13 @@ class s2class {
740
function toggle($email = '') {
741
global $wpdb;
742
743
- if ( ('' == $email) || (! is_email($email)) ) { return false; }
744
745
// let's see if this is a public user
746
$status = $this->is_public($email);
747
- if (false === $status) { return false; }
748
749
- if ('0' == $status) {
750
$wpdb->get_results("UPDATE $this->public SET active='1' WHERE email='$email'");
751
} else {
752
$wpdb->get_results("UPDATE $this->public SET active='0' WHERE email='$email'");
@@ -757,11 +751,11 @@ class s2class {
757
Send reminder email to unconfirmed public subscribers
758
*/
759
function remind($emails = '') {
760
- if ('' == $emails) { return false; }
761
762
$recipients = explode(",", $emails);
763
- if (!is_array($recipients)) { $recipients = (array)$recipients; }
764
- foreach ($recipients as $recipient) {
765
$this->email = $recipient;
766
$this->send_confirm('add', true);
767
}
@@ -775,7 +769,7 @@ class s2class {
775
list($user, $domain) = split('@', $email);
776
$bar_check = stristr($barred_option, $domain);
777
778
- if (!empty($bar_check)) {
779
return true;
780
} else {
781
return false;
@@ -788,16 +782,16 @@ class s2class {
788
function confirm($content = '') {
789
global $wpdb;
790
791
- if (1 == $this->filtered) { return $content; }
792
793
$code = $_GET['s2'];
794
$action = intval(substr($code, 0, 1));
795
$hash = substr($code, 1, 32);
796
$code = str_replace($hash, '', $code);
797
$id = intval(substr($code, 1));
798
- if ($id) {
799
$this->email = $this->get_email($id);
800
- if ( (!$this->email) || ($hash !== md5($this->email)) ) {
801
return $this->no_such_email;
802
}
803
} else {
@@ -807,36 +801,36 @@ class s2class {
807
// get current status of email so messages are only sent once per emailed link
808
$current = $this->is_public($this->email);
809
810
- if ('1' == $action) {
811
// make this subscription active
812
$this->message = $this->added;
813
- if ('1' != $current) {
814
$this->ip = getenv('REMOTE_ADDR');
815
$this->activate();
816
- if ( ($this->subscribe2_options['admin_email'] == 'subs') || ($this->subscribe2_options['admin_email'] == 'both') ) {
817
$subject = '[' . get_option('blogname') . '] ' . __('New subscription', 'subscribe2');
818
$subject = html_entity_decode($subject, ENT_QUOTES);
819
$message = $this->email . " " . __('subscribed to email notifications!', 'subscribe2');
820
$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='" . $wpdb->prefix . "user_level' AND $wpdb->usermeta.meta_value='10'");
821
$headers = $this->headers();
822
- foreach ($recipients as $recipient) {
823
@wp_mail($recipient, $subject, $message, $headers);
824
}
825
}
826
}
827
$this->filtered = 1;
828
- } elseif ('0' == $action) {
829
// remove this subscriber
830
$this->message = $this->deleted;
831
- if ('0' != $current) {
832
$this->delete();
833
- if ( ($this->subscribe2_options['admin_email'] == 'unsubs') || ($this->subscribe2_options['admin_email'] == 'both') ) {
834
$subject = '[' . get_option('blogname') . '] ' . __('New Unsubscription', 'subscribe2');
835
$subject = html_entity_decode($subject, ENT_QUOTES);
836
$message = $this->email . " " . __('unsubscribed from email notifications!', 'subscribe2');
837
$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='" . $wpdb->prefix . "user_level' AND $wpdb->usermeta.meta_value='10'");
838
$headers = $this->headers();
839
- foreach ($recipients as $recipient) {
840
@wp_mail($recipient, $subject, $message, $headers);
841
}
842
}
@@ -844,7 +838,7 @@ class s2class {
844
$this->filtered = 1;
845
}
846
847
- if ('' != $this->message) {
848
return $this->message;
849
}
850
} // end confirm()
@@ -855,10 +849,10 @@ class s2class {
855
function is_public($email = '') {
856
global $wpdb;
857
858
- if ('' == $email) { return false; }
859
860
$check = $wpdb->get_var("SELECT active FROM $this->public WHERE email='$email'");
861
- if ( ('0' == $check) || ('1' == $check) ) {
862
return $check;
863
} else {
864
return false;
@@ -871,10 +865,10 @@ class s2class {
871
function is_registered($email = '') {
872
global $wpdb;
873
874
- if ('' == $email) { return false; }
875
876
$check = $wpdb->get_var("SELECT email FROM $wpdb->users WHERE user_email='$email'");
877
- if ($check) {
878
return true;
879
} else {
880
return false;
@@ -886,13 +880,13 @@ class s2class {
886
*/
887
function get_public($confirmed = 1) {
888
global $wpdb;
889
- if (1 == $confirmed) {
890
- if ('' == $this->all_public) {
891
$this->all_public = $wpdb->get_col("SELECT email FROM $this->public WHERE active='1'");
892
}
893
return $this->all_public;
894
} else {
895
- if ('' == $this->all_unconfirmed) {
896
$this->all_unconfirmed = $wpdb->get_col("SELECT email FROM $this->public WHERE active='0'");
897
}
898
return $this->all_unconfirmed;
@@ -905,8 +899,8 @@ class s2class {
905
function get_all_registered($id = '') {
906
global $wpdb;
907
908
- if ($this->s2_mu) {
909
- if ($id) {
910
return $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
911
} else {
912
$result = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
@@ -914,7 +908,7 @@ class s2class {
914
return $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids) AND user_activation_key=''");
915
}
916
} else {
917
- if ($id) {
918
return $wpdb->get_col("SELECT ID FROM $wpdb->users");
919
} else {
920
return $wpdb->get_col("SELECT user_email FROM $wpdb->users");
@@ -934,42 +928,42 @@ class s2class {
934
$subscribers = array();
935
936
parse_str($args, $r);
937
- if (!isset($r['format']))
938
$r['format'] = 'all';
939
- if (!isset($r['cats']))
940
$r['cats'] = '';
941
942
$JOIN = ''; $AND = '';
943
// text or HTML subscribers
944
- if ('all' != $r['format']) {
945
$JOIN .= "INNER JOIN $wpdb->usermeta AS b ON a.user_id = b.user_id ";
946
$AND .= " AND b.meta_key='s2_format' AND b.meta_value=";
947
- if ('html' == $r['format']) {
948
$AND .= "'html'";
949
- } elseif ('post' == $r['format']) {
950
$AND .= "'post'";
951
- } elseif ('excerpt' == $r['format']) {
952
$AND .= "'excerpt'";
953
}
954
}
955
956
// specific category subscribers
957
- if ('' != $r['cats']) {
958
$JOIN .= "INNER JOIN $wpdb->usermeta AS c ON a.user_id = c.user_id ";
959
$all = '';
960
- foreach (explode(',', $r['cats']) as $cat) {
961
('' == $and) ? $and = "c.meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$cat'" : $and .= " OR c.meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$cat'";
962
}
963
$AND .= " AND ($and)";
964
}
965
966
- if ($this->s2_mu) {
967
$sql = "SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . "WHERE a.meta_key='" . $wpdb->prefix . "capabilities'" . $AND;
968
} else {
969
$sql = "SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . "WHERE a.meta_key='" . $this->get_usermeta_keyname('s2_subscribed') . "'" . $AND;
970
}
971
$result = $wpdb->get_col($sql);
972
- if ($result) {
973
$ids = implode(',', $result);
974
return $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids) AND user_activation_key = ''");
975
}
@@ -979,14 +973,14 @@ class s2class {
979
Collects the signup date for all public subscribers
980
*/
981
function signup_date($email = '') {
982
- if ('' == $email) { return false; }
983
984
global $wpdb;
985
- if (!empty($this->signup_dates)) {
986
return $this->signup_dates[$email];
987
} else {
988
$results = $wpdb->get_results("SELECT email, date FROM $this->public", ARRAY_N);
989
- foreach ($results as $result) {
990
$this->signup_dates[$result[0]] = $result[1];
991
}
992
return $this->signup_dates[$email];
@@ -997,14 +991,14 @@ class s2class {
997
Collects the ip address for all public subscribers
998
*/
999
function signup_ip($email = '') {
1000
- if ('' == $email) {return false; }
1001
1002
global $wpdb;
1003
- if (!empty($this->signup_ips)) {
1004
return $this->signup_ips[$email];
1005
} else {
1006
$results = $wpdb->get_results("SELECT email, ip FROM $this->public", ARRAY_N);
1007
- foreach ($results as $result) {
1008
$this->signup_ips[$result[0]] = $result[1];
1009
}
1010
return $this->signup_ips[$email];
@@ -1018,36 +1012,36 @@ class s2class {
1018
function register($user_ID = 0) {
1019
global $wpdb;
1020
1021
- if (0 == $user_ID) { return $user_ID; }
1022
$user = get_userdata($user_ID);
1023
$all_cats = get_categories(array('hide_empty' => false));
1024
1025
// Are registered users are allowed to subscribe to excluded categories?
1026
- if ( (0 == $this->subscribe2_options['reg_override']) || ('no' == $this->subscribe2_options['newreg_override']) ) {
1027
$exclude = explode(',', $this->subscribe2_options['exclude']);
1028
- foreach ($all_cats as $cat => $term_id) {
1029
- if (in_array($all_cats[$cat]->term_id, $exclude)) {
1030
$cat = (int)$cat;
1031
unset($all_cats[$cat]);
1032
}
1033
}
1034
}
1035
1036
- foreach ($all_cats as $cat) {
1037
('' == $cats) ? $cats = "$cat->term_id" : $cats .= ",$cat->term_id";
1038
}
1039
1040
- if ('' == $cats) {
1041
// sanity check, might occur if all cats excluded and reg_override = 0
1042
return $user_ID;
1043
}
1044
1045
// has this user previously signed up for email notification?
1046
- if (false !== $this->is_public($user->user_email)) {
1047
// delete this user from the public table, and subscribe them to all the categories
1048
$this->delete($user->user_email);
1049
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
1050
- foreach (explode(',', $cats) as $cat) {
1051
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, "$cat");
1052
}
1053
update_usermeta($user_ID, 's2_format', 'excerpt');
@@ -1055,34 +1049,34 @@ class s2class {
1055
} else {
1056
// create post format entries for all users
1057
$check_format = get_usermeta($user_ID, 's2_format');
1058
- if (empty($check_format)) {
1059
// ensure existing subscription options are not overwritten on upgrade
1060
- if ('html' == $this->subscribe2_options['autoformat']) {
1061
update_usermeta($user_ID, 's2_format', 'html');
1062
- } elseif ('fulltext' == $this->subscribe2_options['autoformat']) {
1063
update_usermeta($user_ID, 's2_format', 'post');
1064
} else {
1065
update_usermeta($user_ID, 's2_format', 'excerpt');
1066
}
1067
update_usermeta($user_ID, 's2_autosub', $this->subscribe2_options['autosub_def']);
1068
// if the are no existing subscriptions, create them if, by default if autosub is on
1069
- if ( ('yes' == $this->subscribe2_options['autosub']) || (('wpreg' == $this->subscribe2_options['autosub']) && ('on' == $_POST['subscribe'])) ) {
1070
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
1071
- foreach (explode(',', $cats) as $cat) {
1072
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, "$cat");
1073
}
1074
}
1075
} else {
1076
// if user is already registered update format remove 's2_excerpt' field and update 's2_format'
1077
- if ('html' == $check_format) {
1078
delete_usermeta($user_ID, 's2_excerpt');
1079
- } elseif ('text' == $check_format) {
1080
update_usermeta($user_ID, 's2_format', get_usermeta($user_ID, 's2_excerpt'));
1081
delete_usermeta($user_ID, 's2_excerpt');
1082
}
1083
}
1084
$subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1085
- if (strstr($subscribed, '-1')) {
1086
// make sure we remove '-1' from any settings
1087
$old_cats = explode(',', $subscribed);
1088
$pos = array_search('-1', $old_cats);
@@ -1098,7 +1092,7 @@ class s2class {
1098
Subscribe all registered users to category selected on Admin Manage Page
1099
*/
1100
function subscribe_registered_users($emails = '', $cats = array()) {
1101
- if ( ('' == $emails) || ('' == $cats) ) { return false; }
1102
global $wpdb;
1103
1104
$useremails = explode(",", $emails);
@@ -1107,17 +1101,17 @@ class s2class {
1107
$sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
1108
$user_IDs = $wpdb->get_col($sql);
1109
1110
- foreach ($user_IDs as $user_ID) {
1111
$old_cats = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1112
- if (!empty($old_cats)) {
1113
$old_cats = explode(',', $old_cats);
1114
$newcats = array_unique(array_merge($cats, $old_cats));
1115
} else {
1116
$newcats = $cats;
1117
}
1118
- if (!empty($newcats)) {
1119
// add subscription to these cat IDs
1120
- foreach ($newcats as $id) {
1121
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id, "$id");
1122
}
1123
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $newcats));
@@ -1130,7 +1124,7 @@ class s2class {
1130
Unsubscribe all registered users to category selected on Admin Manage Page
1131
*/
1132
function unsubscribe_registered_users($emails = '', $cats = array()) {
1133
- if ( ('' == $emails) || ('' == $cats) ) { return false; }
1134
global $wpdb;
1135
1136
$useremails = explode(",", $emails);
@@ -1139,18 +1133,18 @@ class s2class {
1139
$sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
1140
$user_IDs = $wpdb->get_col($sql);
1141
1142
- foreach ($user_IDs as $user_ID) {
1143
$old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1144
$remain = array_diff($old_cats, $cats);
1145
- if (!empty($remain)) {
1146
// remove subscription to these cat IDs and update s2_subscribed
1147
- foreach ($cats as $id) {
1148
delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1149
}
1150
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $remain));
1151
} else {
1152
// remove subscription to these cat IDs and update s2_subscribed to ''
1153
- foreach ($cats as $id) {
1154
delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1155
}
1156
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
@@ -1166,15 +1160,15 @@ class s2class {
1166
$redirect_to_subscriptionpage = false;
1167
1168
// subscribe to new blog
1169
- if (!empty($_GET['s2mu_subscribe'])) {
1170
$blog_id = intval($_GET['s2mu_subscribe']);
1171
- if ($blog_id >= 0) {
1172
switch_to_blog($blog_id);
1173
1174
$user_ID = get_current_user_id();
1175
1176
// if user is not a user of the current blog
1177
- if (!is_blog_user($blog_id)) {
1178
// add user to current blog as subscriber
1179
add_user_to_blog($blog_id, $user_ID, 'subscriber');
1180
// add an action hook for external manipulation of blog and user data
@@ -1184,11 +1178,11 @@ class s2class {
1184
// subscribe to all categories by default
1185
$all_cats = get_categories(array('hide_empty' => false));
1186
1187
- if (0 == $this->subscribe2_options['reg_override']) {
1188
// registered users are not allowed to subscribe to excluded categories
1189
$exclude = explode(',', $this->subscribe2_options['exclude']);
1190
- foreach ($all_cats as $cat => $term) {
1191
- if (in_array($all_cats[$cat]->term_id, $exclude)) {
1192
$cat = (int)$cat;
1193
unset($all_cats[$cat]);
1194
}
@@ -1196,12 +1190,12 @@ class s2class {
1196
}
1197
1198
$cats = array();
1199
- foreach ($all_cats as $cat => $term) {
1200
$term_id = $term->term_id;
1201
$cats[] = $term_id;
1202
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $term_id, $term_id);
1203
}
1204
- if (empty($cats)) {
1205
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
1206
} else {
1207
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $cats));
@@ -1210,10 +1204,10 @@ class s2class {
1210
// don't restore_current_blog(); -> redirect to new subscription page
1211
$redirect_to_subscriptionpage = true;
1212
}
1213
- } elseif (!empty($_GET['s2mu_unsubscribe'])) {
1214
// unsubscribe from a blog
1215
$blog_id = intval($_GET['s2mu_unsubscribe']);
1216
- if ($blog_id >= 0) {
1217
switch_to_blog($blog_id);
1218
1219
$user_ID = get_current_user_id();
@@ -1221,11 +1215,11 @@ class s2class {
1221
// delete subscription to all categories on that blog
1222
$cats = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1223
$cats = explode(',', $cats);
1224
- if (!is_array($cats)) {
1225
$cats = array($cats);
1226
}
1227
1228
- foreach ($cats as $id) {
1229
delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1230
}
1231
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
@@ -1238,10 +1232,10 @@ class s2class {
1238
}
1239
}
1240
1241
- if ($redirect_to_subscriptionpage == true) {
1242
- if (!is_user_member_of_blog($user_ID)) {
1243
$user_blogs = get_active_blog_for_user($user_ID);
1244
- if (is_array($user_blogs)) {
1245
switch_to_blog(key($user_blogs));
1246
} else {
1247
// no longer a member of a blog
@@ -1251,7 +1245,7 @@ class s2class {
1251
}
1252
1253
// redirect to profile page
1254
- if (current_user_can('manage_options')) {
1255
$url = get_option('siteurl') . '/wp-admin/users.php?page=s2_users';
1256
wp_redirect($url);
1257
exit();
@@ -1268,17 +1262,17 @@ class s2class {
1268
if registered user has selected this option
1269
*/
1270
function new_category($new_category='') {
1271
- if ('no' == $this->subscribe2_options['show_autosub']) { return; }
1272
global $wpdb;
1273
1274
- if ('yes' == $this->subscribe2_options['show_autosub']) {
1275
$sql = "SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key='s2_autosub' AND $wpdb->usermeta.meta_value='yes'";
1276
$user_IDs = $wpdb->get_col($sql);
1277
- if ('' == $user_IDs) { return; }
1278
1279
- foreach ($user_IDs as $user_ID) {
1280
$old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1281
- if (!is_array($old_cats)) {
1282
$old_cats = array($old_cats);
1283
}
1284
// add subscription to these cat IDs
@@ -1286,7 +1280,7 @@ class s2class {
1286
$newcats = array_merge($old_cats, (array)$new_category);
1287
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $newcats));
1288
}
1289
- } elseif ('exclude' == $this->subscribe2_options['show_autosub']) {
1290
$excluded_cats = explode(',', $this->subscribe2_options['exclude']);
1291
$excluded_cats[] = $new_category;
1292
$this->subscribe2_options['exclude'] = implode(',', $excluded_cats);
@@ -1299,11 +1293,11 @@ class s2class {
1299
1300
$sql = "SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$deleted_category'";
1301
$user_IDs = $wpdb->get_col($sql);
1302
- if ('' == $user_IDs) { return; }
1303
1304
- foreach ($user_IDs as $user_ID) {
1305
$old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1306
- if (!is_array($old_cats)) {
1307
$old_cats = array($old_cats);
1308
}
1309
// add subscription to these cat IDs
@@ -1319,9 +1313,9 @@ class s2class {
1319
function get_userdata($admin_id) {
1320
global $wpdb, $userdata;
1321
1322
- if (is_numeric($admin_id)) {
1323
$admin = get_userdata($admin_id);
1324
- } elseif ($admin_id == 'admin') {
1325
//ensure compatibility with < 4.16
1326
$admin = get_userdata('1');
1327
} else {
@@ -1329,15 +1323,15 @@ class s2class {
1329
}
1330
1331
// if user record is empty grab the first admin from the database
1332
- if (empty($admin)) {
1333
$sql = "SELECT DISTINCT(ID) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key='" . $wpdb->prefix . "user_level' AND $wpdb->usermeta.meta_value IN (8, 9, 10) LIMIT 1";
1334
$admin = get_userdata($wpdb->get_var($sql));
1335
}
1336
1337
// handle issues from WordPress core where user_level is not set or set low
1338
- if (empty($admin)) {
1339
$role = 'administrator';
1340
- if (!class_exists(WP_User_Search)) {
1341
require(ABSPATH . 'wp-admin/includes/user.php');
1342
}
1343
$wp_user_search = new WP_User_Search( '', '', $role);
@@ -1358,69 +1352,69 @@ class s2class {
1358
//Get Registered Subscribers for bulk management
1359
$registered = $this->get_registered();
1360
$all_users = $this->get_all_registered();
1361
- if (!empty($all_users)) {
1362
$emails = implode(",", $all_users);
1363
}
1364
1365
// was anything POSTed ?
1366
- if (isset($_POST['s2_admin'])) {
1367
check_admin_referer('subscribe2-manage_subscribers' . $s2nonce);
1368
- if ($_POST['addresses']) {
1369
- foreach (preg_split ("/[\s,]+/", $_POST['addresses']) as $email) {
1370
- if ( (is_email($email)) && ($_POST['subscribe']) ) {
1371
$this->activate($email);
1372
$message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) subscribed!', 'subscribe2') . "</strong></p></div>";
1373
- } elseif ( (is_email($email)) && ($_POST['unsubscribe']) ) {
1374
$this->delete($email);
1375
$message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) unsubscribed!', 'subscribe2') . "</strong></p></div>";
1376
}
1377
}
1378
echo $message;
1379
$_POST['what'] = 'confirmed';
1380
- } elseif ($_POST['process']) {
1381
- if ($_POST['delete']) {
1382
- foreach ($_POST['delete'] as $address) {
1383
$this->delete($address);
1384
}
1385
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) deleted!', 'subscribe2') . "</strong></p></div>";
1386
}
1387
- if ($_POST['confirm']) {
1388
- foreach ($_POST['confirm'] as $address) {
1389
$this->toggle($address);
1390
}
1391
$message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>";
1392
}
1393
- if ($_POST['unconfirm']) {
1394
- foreach ($_POST['unconfirm'] as $address) {
1395
$this->toggle($address);
1396
}
1397
$message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>";
1398
}
1399
echo $message;
1400
- } elseif ($_POST['searchterm']) {
1401
$confirmed = $this->get_public();
1402
$unconfirmed = $this->get_public(0);
1403
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1404
- foreach ($subscribers as $subscriber) {
1405
- if (is_numeric(stripos($subscriber, $_POST['searchterm']))) {
1406
$result[] = $subscriber;
1407
}
1408
}
1409
- } elseif ($_POST['remind']) {
1410
$this->remind($_POST['reminderemails']);
1411
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Reminder Email(s) Sent!', 'subscribe2') . "</strong></p></div>";
1412
- } elseif ( ($_POST['sub_categories']) && ('subscribe' == $_POST['manage']) ) {
1413
$this->subscribe_registered_users($_POST['emails'], $_POST['category']);
1414
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Registered Users Subscribed!', 'subscribe2') . "</strong></p></div>";
1415
- } elseif ( ($_POST['sub_categories']) && ('unsubscribe' == $_POST['manage']) ) {
1416
$this->unsubscribe_registered_users($_POST['emails'], $_POST['category']);
1417
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Registered Users Unsubscribed!', 'subscribe2') . "</strong></p></div>";
1418
- } elseif ($_POST['sub_format']) {
1419
- if ($_POST['format'] == 'excerpt') {
1420
$wpdb->get_results("UPDATE $wpdb->usermeta SET meta_value='excerpt' WHERE meta_key='s2_format'");
1421
- } elseif ($_POST['format'] == 'full') {
1422
$wpdb->get_results("UPDATE $wpdb->usermeta SET meta_value='post' WHERE meta_key='s2_format'");
1423
- } elseif ($_POST['format'] == 'html') {
1424
$wpdb->get_results("UPDATE $wpdb->usermeta SET meta_value='html' WHERE meta_key='s2_format'");
1425
}
1426
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Format updated for Registered Users!', 'subscribe2') . "</strong></p></div>";
@@ -1431,72 +1425,72 @@ class s2class {
1431
$confirmed = $this->get_public();
1432
$unconfirmed = $this->get_public(0);
1433
// safety check for our arrays
1434
- if ('' == $confirmed) { $confirmed = array(); }
1435
- if ('' == $unconfirmed) { $unconfirmed = array(); }
1436
- if ('' == $registered) { $registered = array(); }
1437
- if ('' == $all_users) { $all_users = array(); }
1438
1439
$reminderform = false;
1440
$urlpath = str_replace("\\", "/", S2PATH);
1441
$urlpath = trailingslashit(get_option('siteurl')) . substr($urlpath,strpos($urlpath, "wp-content/"));
1442
- if (isset($_GET['s2page'])) {
1443
$page = (int) $_GET['s2page'];
1444
} else {
1445
$page = 1;
1446
}
1447
1448
- if (isset($_POST['what'])) {
1449
$page = 1;
1450
- if ('all' == $_POST['what']) {
1451
$what = 'all';
1452
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1453
- } elseif ('public' == $_POST['what']) {
1454
$what = 'public';
1455
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
1456
- } elseif ('confirmed' == $_POST['what']) {
1457
$what = 'confirmed';
1458
$subscribers = $confirmed;
1459
- } elseif ('unconfirmed' == $_POST['what']) {
1460
$what = 'unconfirmed';
1461
$subscribers = $unconfirmed;
1462
- if (!empty($subscribers)) {
1463
$reminderemails = implode(",", $subscribers);
1464
$reminderform = true;
1465
}
1466
- } elseif (is_numeric($_POST['what'])) {
1467
$what = intval($_POST['what']);
1468
$subscribers = $this->get_registered("cats=$what");
1469
- } elseif ('registered' == $_POST['what']) {
1470
$what = 'registered';
1471
$subscribers = $registered;
1472
- } elseif ('all_users' == $_POST['what']) {
1473
$what = 'all_users';
1474
$subscribers = $all_users;
1475
}
1476
- } elseif (isset($_GET['what'])) {
1477
- if ('all' == $_GET['what']) {
1478
$what = 'all';
1479
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1480
- } elseif ('public' == $_GET['what']) {
1481
$what = 'public';
1482
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
1483
- } elseif ('confirmed' == $_GET['what']) {
1484
$what = 'confirmed';
1485
$subscribers = $confirmed;
1486
- } elseif ('unconfirmed' == $_GET['what']) {
1487
$what = 'unconfirmed';
1488
$subscribers = $unconfirmed;
1489
- if (!empty($subscribers)) {
1490
$reminderemails = implode(",", $subscribers);
1491
$reminderform = true;
1492
}
1493
- } elseif (is_numeric($_GET['what'])) {
1494
$what = intval($_GET['what']);
1495
$subscribers = $this->get_registered("cats=$what");
1496
- } elseif ('registered' == $_GET['what']) {
1497
$what = 'registered';
1498
$subscribers = $registered;
1499
- } elseif ('all_users' == $_GET['what']) {
1500
$what = 'all_users';
1501
$subscribers = $all_users;
1502
}
@@ -1504,12 +1498,12 @@ class s2class {
1504
$what = 'all';
1505
$subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1506
}
1507
- if ($_POST['searchterm']) {
1508
$subscribers = &$result;
1509
$what = 'public';
1510
}
1511
1512
- if (!empty($subscribers)) {
1513
natcasesort($subscribers);
1514
// Displays a page number strip - adapted from code in Akismet
1515
$args['what'] = $what;
@@ -1544,9 +1538,10 @@ class s2class {
1544
1545
// show our form
1546
echo "<div class=\"wrap\">";
1547
echo "<h2>" . __('Manage Subscribers', 'subscribe2') . "</h2>\r\n";
1548
echo "<form method=\"post\" action=\"\">\r\n";
1549
- if (function_exists('wp_nonce_field')) {
1550
wp_nonce_field('subscribe2-manage_subscribers' . $s2nonce);
1551
}
1552
echo "<h2>" . __('Add/Remove Subscribers', 'subscribe2') . "</h2>\r\n";
@@ -1562,12 +1557,12 @@ class s2class {
1562
$this->display_subscriber_dropdown($what, __('Filter', 'subscribe2'));
1563
// show the selected subscribers
1564
$alternate = '';
1565
- if (!empty($subscribers)) {
1566
$exportcsv = implode(",\r\n", $subscribers);
1567
echo "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
1568
echo "<tr class=\"alternate\"><td width=\"50%\"><input type=\"text\" name=\"searchterm\" value=\"\" />&nbsp;\r\n";
1569
echo "<input type=\"submit\" class=\"button-secondary\" name=\"search\" value=\"" . __('Search Subscribers', 'subscribe2') . "\" /></td>\r\n";
1570
- if ($reminderform) {
1571
echo "<td width=\"25%\" align=\"right\"><input type=\"hidden\" name=\"reminderemails\" value=\"" . $reminderemails . "\" />\r\n";
1572
echo "<input type=\"submit\" class=\"button-secondary\" name=\"remind\" value=\"" . __('Send Reminder Email', 'subscribe2') . "\" /></td>\r\n";
1573
} else {
@@ -1579,11 +1574,11 @@ class s2class {
1579
}
1580
1581
echo "<table class=\"widefat\" cellpadding=\"2\" cellspacing=\"2\">";
1582
- if (!empty($subscribers)) {
1583
echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n";
1584
echo "<td align=\"right\">" . $strip . "</td></tr>\r\n";
1585
}
1586
- if (!empty($subscribers)) {
1587
$subscriber_chunks = array_chunk($subscribers, $this->subscribe2_options['entries']);
1588
$chunk = $page - 1;
1589
$subscribers = $subscriber_chunks[$chunk];
@@ -1599,10 +1594,10 @@ class s2class {
1599
echo "<td align=\"center\"><input type=\"checkbox\" name=\"checkall\" value=\"delete_checkall\" /></td>\r\n";
1600
echo "<td align=\"left\"><strong>" . __('Select / Unselect All', 'subscribe2') . "</strong></td></tr>\r\n";
1601
1602
- foreach ($subscribers as $subscriber) {
1603
echo "<tr class=\"$alternate\" style=\"height:1.5em;\">";
1604
echo "<td align=\"center\">\r\n";
1605
- if (in_array($subscriber, $confirmed)) {
1606
echo "</td><td align=\"center\">\r\n";
1607
echo "<input class=\"unconfirm_checkall\" title=\"" . __('Unconfirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"unconfirm[]\" value=\"" . $subscriber . "\" /></td>\r\n";
1608
echo "<td align=\"center\">\r\n";
@@ -1610,7 +1605,7 @@ class s2class {
1610
echo "</td>\r\n";
1611
echo "<td><span style=\"color:#006600\">&#x221A;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1612
echo "(<span style=\"color:#006600\"><abbr title=\"" . $this->signup_ip($subscriber) . "\">" . $this->signup_date($subscriber) . "</abbr></span>)\r\n";
1613
- } elseif (in_array($subscriber, $unconfirmed)) {
1614
echo "<input class=\"confirm_checkall\" title=\"" . __('Confirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"confirm[]\" value=\"" . $subscriber . "\" /></td>\r\n";
1615
echo "<td align=\"center\"></td>\r\n";
1616
echo "<td align=\"center\">\r\n";
@@ -1618,22 +1613,22 @@ class s2class {
1618
echo "</td>\r\n";
1619
echo "<td><span style=\"color:#FF0000\">&nbsp;!&nbsp;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1620
echo "(<span style=\"color:#FF0000\"><abbr title=\"" . $this->signup_ip($subscriber) . "\">" . $this->signup_date($subscriber) . "</abbr></span>)\r\n";
1621
- } elseif (in_array($subscriber, $all_users)) {
1622
echo "</td><td align=\"center\"></td><td align=\"center\"></td>\r\n";
1623
echo "<td><span style=\"color:#006600\">&reg;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1624
- echo "(<a href=\"" . get_option('siteurl') . "/wp-admin/users.php?page=s2_users&amp;email=$subscriber\">" . __('edit', 'subscribe2') . "</a>)\r\n";
1625
}
1626
echo "</td></tr>\r\n";
1627
('alternate' == $alternate) ? $alternate = '' : $alternate = 'alternate';
1628
}
1629
} else {
1630
- if ($_POST['searchterm']) {
1631
echo "<tr><td align=\"center\"><b>" . __('No matching subscribers found', 'subscribe2') . "</b></td></tr>\r\n";
1632
} else {
1633
echo "<tr><td align=\"center\"><b>" . __('NONE', 'subscribe2') . "</b></td></tr>\r\n";
1634
}
1635
}
1636
- if (!empty($subscribers)) {
1637
echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n";
1638
echo "<td align=\"right\">" . $strip . "</td></tr>\r\n";
1639
}
@@ -1670,22 +1665,22 @@ class s2class {
1670
global $s2nonce;
1671
1672
// was anything POSTed?
1673
- if (isset($_POST['s2_admin'])) {
1674
check_admin_referer('subscribe2-options_subscribers' . $s2nonce);
1675
- if ($_POST['reset']) {
1676
$this->reset();
1677
echo "<div id=\"message\" class=\"updated fade\"><p><strong>$this->options_reset</strong></p></div>";
1678
- } elseif ($_POST['preview']) {
1679
global $user_email;
1680
- if ('never' == $this->subscribe2_options['email_freq']) {
1681
$post = get_posts('numberposts=1');
1682
$this->publish($post[0], $user_email);
1683
} else {
1684
- $this->subscribe2_cron($user_email);
1685
}
1686
- } elseif ($_POST['submit']) {
1687
// BCClimit
1688
- if ( (is_numeric($_POST['bcc'])) && ($_POST['bcc'] >= 0) ) {
1689
$this->subscribe2_options['bcclimit'] = $_POST['bcc'];
1690
}
1691
// admin_email
@@ -1693,7 +1688,7 @@ class s2class {
1693
1694
// send as author or admin?
1695
$sender = 'author';
1696
- if (is_numeric($_POST['sender'])) {
1697
$sender = $_POST['sender'];
1698
}
1699
$this->subscribe2_options['sender'] = $sender;
@@ -1708,18 +1703,18 @@ class s2class {
1708
// send per-post or digest emails
1709
$email_freq = $_POST['email_freq'];
1710
$scheduled_time = wp_next_scheduled('s2_digest_cron');
1711
- if ( ($email_freq != $this->subscribe2_options['email_freq']) || ($_POST['hour'] != date('H', $scheduled_time)) ) {
1712
$this->subscribe2_options['email_freq'] = $email_freq;
1713
wp_clear_scheduled_hook('s2_digest_cron');
1714
$scheds = (array)wp_get_schedules();
1715
$interval = ( isset($scheds[$email_freq]['interval']) ) ? (int) $scheds[$email_freq]['interval'] : 0;
1716
- if ($interval == 0) {
1717
// if we are on per-post emails remove last_cron entry
1718
unset($this->subscribe2_options['last_s2cron']);
1719
} else {
1720
// if we are using digest schedule the event and prime last_cron as now
1721
$time = time() + $interval;
1722
- if ($interval < 86400) {
1723
// Schedule CRON events occurring less than daily starting now and periodically thereafter
1724
$timestamp = &$time;
1725
} else {
@@ -1727,7 +1722,7 @@ class s2class {
1727
$timestamp = mktime($_POST['hour'], 0, 0, date('m', $time), date('d', $time), date('Y', $time));
1728
}
1729
wp_schedule_event($timestamp, $email_freq, 's2_digest_cron');
1730
- if (!isset($this->subscribe2_options['last_s2cron'])) {
1731
$this->subscribe2_options['last_s2cron'] = current_time('mysql');
1732
}
1733
}
@@ -1735,56 +1730,56 @@ class s2class {
1735
1736
// email subject and body templates
1737
// ensure that are not empty before updating
1738
- if (!empty($_POST['notification_subject'])) {
1739
$this->subscribe2_options['notification_subject'] = $_POST['notification_subject'];
1740
}
1741
- if (!empty($_POST['mailtext'])) {
1742
$this->subscribe2_options['mailtext'] = $_POST['mailtext'];
1743
}
1744
- if (!empty($_POST['confirm_subject'])) {
1745
$this->subscribe2_options['confirm_subject'] = $_POST['confirm_subject'];
1746
}
1747
- if (!empty($_POST['confirm_email'])) {
1748
$this->subscribe2_options['confirm_email'] = $_POST['confirm_email'];
1749
}
1750
- if (!empty($_POST['remind_subject'])) {
1751
$this->subscribe2_options['remind_subject'] = $_POST['remind_subject'];
1752
}
1753
- if (!empty($_POST['remind_email'])) {
1754
$this->subscribe2_options['remind_email'] = $_POST['remind_email'];
1755
}
1756
1757
// excluded categories
1758
- if (!empty($_POST['category'])) {
1759
$exclude_cats = implode(',', $_POST['category']);
1760
} else {
1761
$exclude_cats = '';
1762
}
1763
$this->subscribe2_options['exclude'] = $exclude_cats;
1764
// allow override?
1765
- (isset($_POST['reg_override'])) ? $override = '1' : $override = '0';
1766
$this->subscribe2_options['reg_override'] = $override;
1767
1768
// default WordPress page where Subscribe2 token is placed
1769
- if ( (is_numeric($_POST['page'])) && ($_POST['page'] >= 0) ) {
1770
$this->subscribe2_options['s2page'] = $_POST['page'];
1771
}
1772
1773
// Number of subscriber per page
1774
- if ( (is_numeric($_POST['entries'])) && ($_POST['entries'] > 0) ) {
1775
$this->subscribe2_options['entries'] =$_POST['entries'];
1776
}
1777
1778
// show meta link?
1779
- ($_POST['show_meta'] == '1') ? $showmeta = '1' : $showmeta = '0';
1780
$this->subscribe2_options['show_meta'] = $showmeta;
1781
1782
// show button?
1783
- ($_POST['show_button'] == '1') ? $showbutton = '1' : $showbutton = '0';
1784
$this->subscribe2_options['show_button'] = $showbutton;
1785
1786
// show widget in Presentation->Widgets
1787
- ($_POST['widget'] == '1') ? $showwidget = '1' : $showwidget = '0';
1788
$this->subscribe2_options['widget'] = $showwidget;
1789
1790
//automatic subscription
@@ -1804,12 +1799,13 @@ class s2class {
1804
}
1805
// show our form
1806
echo "<div class=\"wrap\">";
1807
echo "<h2>" . __('Subscribe2 Settings', 'subscribe2') . "</h2>\r\n";
1808
echo "<a href=\"http://subscribe2.wordpress.com/\">" . __('Plugin Blog', 'subscribe2') . "</a> | ";
1809
echo "<a href=\"http://getsatisfaction.com/subscribe2/\">" . __('Support Forum', 'subscribe2') . "</a> | ";
1810
echo "<a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2387904\">" . __('Make a donation via PayPal', 'subscribe2') . "</a>";
1811
echo "<form method=\"post\" action=\"\">\r\n";
1812
- if (function_exists('wp_nonce_field')) {
1813
wp_nonce_field('subscribe2-options_subscribers' . $s2nonce);
1814
}
1815
echo "<input type=\"hidden\" name=\"s2_admin\" value=\"options\" />\r\n";
@@ -1829,68 +1825,68 @@ class s2class {
1829
1830
echo "<br /><br />" . __('Send Admins notifications for new', 'subscribe2') . ': ';
1831
echo "<label><input type=\"radio\" name=\"admin_email\" value=\"subs\"";
1832
- if ('subs' == $this->subscribe2_options['admin_email']) {
1833
echo " checked=\"checked\"";
1834
}
1835
echo " /> " . __('Subscriptions', 'subscribe2') . "</label>&nbsp;&nbsp;";
1836
echo "<label><input type=\"radio\" name=\"admin_email\" value=\"unsubs\"";
1837
- if ('unsubs' == $this->subscribe2_options['admin_email']) {
1838
echo " checked=\"checked\"";
1839
}
1840
echo " /> " . __('Unsubscriptions', 'subscribe2') . "</label>&nbsp;&nbsp;";
1841
echo "<label><input type=\"radio\" name=\"admin_email\" value=\"both\"";
1842
- if ('both' == $this->subscribe2_options['admin_email']) {
1843
echo " checked=\"checked\"";
1844
}
1845
echo " /> " . __('Both', 'subscribe2') . "</label>&nbsp;&nbsp;";
1846
echo "<label><input type=\"radio\" name=\"admin_email\" value=\"none\"";
1847
- if ('none' == $this->subscribe2_options['admin_email']) {
1848
echo " checked=\"checked\"";
1849
}
1850
echo " /> " . __('Neither', 'subscribe2') . "</label><br /><br />\r\n";
1851
1852
echo __('Include theme CSS stylesheet in HTML notifications', 'subscribe2') . ': ';
1853
echo "<label><input type=\"radio\" name=\"stylesheet\" value=\"yes\"";
1854
- if ('yes' == $this->subscribe2_options['stylesheet']) {
1855
echo " checked=\"checked\"";
1856
}
1857
echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
1858
echo "<label><input type=\"radio\" name=\"stylesheet\" value=\"no\"";
1859
- if ('no' == $this->subscribe2_options['stylesheet']) {
1860
echo " checked=\"checked\"";
1861
}
1862
echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
1863
1864
echo __('Send Emails for Pages', 'subscribe2') . ': ';
1865
echo "<label><input type=\"radio\" name=\"pages\" value=\"yes\"";
1866
- if ('yes' == $this->subscribe2_options['pages']) {
1867
echo " checked=\"checked\"";
1868
}
1869
echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
1870
echo "<label><input type=\"radio\" name=\"pages\" value=\"no\"";
1871
- if ('no' == $this->subscribe2_options['pages']) {
1872
echo " checked=\"checked\"";
1873
}
1874
echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
1875
echo __('Send Emails for Password Protected Posts', 'subscribe2') . ': ';
1876
echo "<label><input type=\"radio\" name=\"password\" value=\"yes\"";
1877
- if ('yes' == $this->subscribe2_options['password']) {
1878
echo " checked=\"checked\"";
1879
}
1880
echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
1881
echo "<label><input type=\"radio\" name=\"password\" value=\"no\"";
1882
- if ('no' == $this->subscribe2_options['password']) {
1883
echo " checked=\"checked\"";
1884
}
1885
echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
1886
echo __('Send Emails for Private Posts', 'subscribe2') . ': ';
1887
echo "<label><input type=\"radio\" name=\"private\" value=\"yes\"";
1888
- if ('yes' == $this->subscribe2_options['private']) {
1889
echo " checked=\"checked\"";
1890
}
1891
echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
1892
echo "<label><input type=\"radio\" name=\"private\" value=\"no\"";
1893
- if ('no' == $this->subscribe2_options['private']) {
1894
echo " checked=\"checked\"";
1895
}
1896
echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
@@ -1898,17 +1894,17 @@ class s2class {
1898
echo "<label>\r\n";
1899
$this->admin_dropdown(true);
1900
echo "</label><br /><br />\r\n";
1901
- if (function_exists('wp_schedule_event')) {
1902
echo __('Send Emails', 'subscribe2') . ": <br /><br />\r\n";
1903
$this->display_digest_choices();
1904
echo __('For digest notifications, date order for posts is', 'subscribe2') . ": \r\n";
1905
echo "<label><input type=\"radio\" name=\"cron_order\" value=\"desc\"";
1906
- if ('desc' == $this->subscribe2_options['cron_order']) {
1907
echo " checked=\"checked\"";
1908
}
1909
echo " /> " . __('Descending', 'subscribe2') . "</label>&nbsp;&nbsp;";
1910
echo "<label><input type=\"radio\" name=\"cron_order\" value=\"asc\"";
1911
- if ('asc' == $this->subscribe2_options['cron_order']) {
1912
echo " checked=\"checked\"";
1913
}
1914
echo " /> " . __('Ascending', 'subscribe2') . "</label><br /><br />\r\n";
@@ -1936,7 +1932,6 @@ class s2class {
1936
echo "<dt><b>TABLE</b></dt><dd>" . __("a list of post titles<br />(<i>for digest emails only</i>)", 'subscribe2') . "</dd>\r\n";
1937
echo "<dt><b>PERMALINK</b></dt><dd>" . __("the post's permalink<br />(<i>for per-post emails only</i>)", 'subscribe2') . "</dd>\r\n";
1938
echo "<dt><b>TINYLINK</b></dt><dd>" . __("the post's permalink after conversion by TinyURL<br />(<i>for per-post emails only</i>)", 'subscribe2') . "</dd>\r\n";
1939
- echo "<dt><b>BURNLINK</b></dt><dd>" . __("the post's permalink after conversion by BurnURL<br />(<i>for per-post emails only</i>)", 'subscribe2') . "</dd>\r\n";
1940
echo "<dt><b>MYNAME</b></dt><dd>" . __("the admin or post author's name", 'subscribe2') . "</dd>\r\n";
1941
echo "<dt><b>EMAIL</b></dt><dd>" . __("the admin or post author's email", 'subscribe2') . "</dd>\r\n";
1942
echo "<dt><b>AUTHORNAME</b></dt><dd>" . __("the post author's name", 'subscribe2') . "</dd>\r\n";
@@ -1963,7 +1958,7 @@ class s2class {
1963
echo"</p>";
1964
$this->display_category_form(explode(',', $this->subscribe2_options['exclude']));
1965
echo "<center><label><input type=\"checkbox\" name=\"reg_override\" value=\"1\"";
1966
- if ('1' == $this->subscribe2_options['reg_override']) {
1967
echo " checked=\"checked\"";
1968
}
1969
echo " /> " . __('Allow registered users to subscribe to excluded categories?', 'subscribe2') . "</label></center><br />\r\n";
@@ -1992,21 +1987,21 @@ class s2class {
1992
1993
// show link to WordPress page in meta
1994
echo "<br /><br /><label><input type=\"checkbox\" name=\"show_meta\" value=\"1\"";
1995
- if ('1' == $this->subscribe2_options['show_meta']) {
1996
echo " checked=\"checked\"";
1997
}
1998
echo " /> " . __('Show a link to your subscription page in "meta"?', 'subscribe2') . "</label><br /><br />\r\n";
1999
2000
// show QuickTag button
2001
echo "<label><input type=\"checkbox\" name=\"show_button\" value=\"1\"";
2002
- if ('1' == $this->subscribe2_options['show_button']) {
2003
echo " checked=\"checked\"";
2004
}
2005
echo " /> " . __('Show the Subscribe2 button on the Write toolbar?', 'subscribe2') . "</label><br /><br />\r\n";
2006
2007
// show Widget
2008
echo "<label><input type=\"checkbox\" name=\"widget\" value=\"1\"";
2009
- if ('1' == $this->subscribe2_options['widget']) {
2010
echo " checked=\"checked\"";
2011
}
2012
echo " /> " . __('Enable Subscribe2 Widget?', 'subscribe2') . "</label><br /><br />\r\n";
@@ -2017,82 +2012,82 @@ class s2class {
2017
echo"<p>";
2018
echo __('Subscribe new users registering with your blog', 'subscribe2') . ":<br />\r\n";
2019
echo "<label><input type=\"radio\" name=\"autosub\" value=\"yes\"";
2020
- if ('yes' == $this->subscribe2_options['autosub']) {
2021
echo " checked=\"checked\"";
2022
}
2023
echo " /> " . __('Automatically', 'subscribe2') . "</label>&nbsp;&nbsp;";
2024
echo "<label><input type=\"radio\" name=\"autosub\" value=\"wpreg\"";
2025
- if ('wpreg' == $this->subscribe2_options['autosub']) {
2026
echo " checked=\"checked\"";
2027
}
2028
echo " /> " . __('Display option on Registration Form', 'subscribe2') . "</label>&nbsp;&nbsp;";
2029
echo "<label><input type=\"radio\" name=\"autosub\" value=\"no\"";
2030
- if ('no' == $this->subscribe2_options['autosub']) {
2031
echo " checked=\"checked\"";
2032
}
2033
echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2034
echo __('Auto-subscribe includes any excluded categories', 'subscribe2') . ":<br />\r\n";
2035
echo "<label><input type=\"radio\" name=\"newreg_override\" value=\"yes\"";
2036
- if ('yes' == $this->subscribe2_options['newreg_override']) {
2037
echo " checked=\"checked\"";
2038
}
2039
echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2040
echo "<label><input type=\"radio\" name=\"newreg_override\" value=\"no\"";
2041
- if ('no' == $this->subscribe2_options['newreg_override']) {
2042
echo " checked=\"checked\"";
2043
}
2044
echo " />" . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2045
echo __('Registration Form option is checked by default', 'subscribe2') . ":<br />\r\n";
2046
echo "<label><input type=\"radio\" name=\"wpregdef\" value=\"yes\"";
2047
- if ('yes' == $this->subscribe2_options['wpregdef']) {
2048
echo " checked=\"checked\"";
2049
}
2050
echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2051
echo "<label><input type=\"radio\" name=\"wpregdef\" value=\"no\"";
2052
- if ('no' == $this->subscribe2_options['wpregdef']) {
2053
echo " checked=\"checked\"";
2054
}
2055
echo " />" . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2056
echo __('Auto-subscribe users to receive email as', 'subscribe2') . ": <br />\r\n";
2057
echo "<label><input type=\"radio\" name=\"autoformat\" value=\"html\"";
2058
- if ('html' == $this->subscribe2_options['autoformat']) {
2059
echo "checked=\"checked\" ";
2060
}
2061
echo "/> " . __('HTML', 'subscribe2') ."</label>&nbsp;&nbsp;";
2062
echo "<label><input type=\"radio\" name=\"autoformat\" value=\"fulltext\" ";
2063
- if ('fulltext' == $this->subscribe2_options['autoformat']) {
2064
echo "checked=\"checked\" ";
2065
}
2066
echo "/> " . __('Plain Text - Full', 'subscribe2') . "</label>&nbsp;&nbsp;";
2067
echo "<label><input type=\"radio\" name=\"autoformat\" value=\"text\" ";
2068
- if ('text' == $this->subscribe2_options['autoformat']) {
2069
echo "checked=\"checked\" ";
2070
}
2071
echo "/> " . __('Plain Text - Excerpt', 'subscribe2') . "</label><br /><br />";
2072
echo __('Registered Users have the option to auto-subscribe to new categories', 'subscribe2') . ": <br />\r\n";
2073
echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"yes\"";
2074
- if ('yes' == $this->subscribe2_options['show_autosub']) {
2075
echo " checked=\"checked\"";
2076
}
2077
echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2078
echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"no\"";
2079
- if ('no' == $this->subscribe2_options['show_autosub']) {
2080
echo " checked=\"checked\"";
2081
}
2082
echo " />" . __('No', 'subscribe2') . "</label>&nbsp;&nbsp;";
2083
echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"exclude\"";
2084
- if ('exclude' == $this->subscribe2_options['show_autosub']) {
2085
echo " checked=\"checked\"";
2086
}
2087
echo " />" .__('New categories are immediately excluded', 'subscribe2') . "</label><br /><br />";
2088
echo __('Option for Registered Users to auto-subscribe to new categories is checked by default', 'subscribe2') . ": <br />\r\n";
2089
echo "<label><input type=\"radio\" name=\"autosub_def\" value=\"yes\"";
2090
- if ('yes' == $this->subscribe2_options['autosub_def']) {
2091
echo " checked=\"checked\"";
2092
}
2093
echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2094
echo "<label><input type=\"radio\" name=\"autosub_def\" value=\"no\"";
2095
- if ('no' == $this->subscribe2_options['autosub_def']) {
2096
echo " checked=\"checked\"";
2097
}
2098
echo " />" . __('No', 'subscribe2');
@@ -2127,15 +2122,15 @@ class s2class {
2127
function user_menu() {
2128
global $user_ID, $s2nonce;
2129
2130
- if (isset($_GET['email'])) {
2131
global $wpdb;
2132
- $user_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '" . $_GET['email'] . "'");
2133
} else {
2134
get_currentuserinfo();
2135
}
2136
2137
// was anything POSTed?
2138
- if ( (isset($_POST['s2_admin'])) && ('user' == $_POST['s2_admin']) ) {
2139
check_admin_referer('subscribe2-user_subscribers' . $s2nonce);
2140
2141
echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Subscription preferences updated.', 'subscribe2') . "</strong></p></div>\n";
@@ -2144,37 +2139,37 @@ class s2class {
2144
2145
$cats = $_POST['category'];
2146
2147
- if ( (empty($cats)) || ($cats == '-1') ) {
2148
$oldcats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
2149
- if ($oldcats) {
2150
- foreach ($oldcats as $cat) {
2151
delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat);
2152
}
2153
}
2154
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
2155
- } elseif ($cats == 'digest') {
2156
$all_cats = get_categories(array('hide_empty' => false));
2157
- foreach ($all_cats as $cat) {
2158
('' == $catids) ? $catids = "$cat->term_id" : $catids .= ",$cat->term_id";
2159
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat->term_id, $cat->term_id);
2160
}
2161
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $catids);
2162
} else {
2163
- if (!is_array($cats)) {
2164
- $cats = array($_POST['category']);
2165
}
2166
$old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
2167
$remove = array_diff($old_cats, $cats);
2168
$new = array_diff($cats, $old_cats);
2169
- if (!empty($remove)) {
2170
// remove subscription to these cat IDs
2171
- foreach ($remove as $id) {
2172
delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
2173
}
2174
}
2175
- if (!empty($new)) {
2176
// add subscription to these cat IDs
2177
- foreach ($new as $id) {
2178
update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id, $id);
2179
}
2180
}
@@ -2184,56 +2179,57 @@ class s2class {
2184
2185
// show our form
2186
echo "<div class=\"wrap\">";
2187
echo "<h2>" . __('Notification Settings', 'subscribe2') . "</h2>\r\n";
2188
- if (isset($_GET['email'])) {
2189
$user = get_userdata($user_ID);
2190
echo "<span style=\"color: red;line-height: 300%;\">" . __('Editing Subscribe2 preferences for user', 'subscribe2') . ": " . $user->display_name . "</span>";
2191
}
2192
echo "<form method=\"post\" action=\"\">";
2193
echo "<p>";
2194
- if (function_exists('wp_nonce_field')) {
2195
wp_nonce_field('subscribe2-user_subscribers' . $s2nonce);
2196
}
2197
echo "<input type=\"hidden\" name=\"s2_admin\" value=\"user\" />";
2198
- if ($this->subscribe2_options['email_freq'] == 'never') {
2199
echo __('Receive email as', 'subscribe2') . ": &nbsp;&nbsp;";
2200
echo "<label><input type=\"radio\" name=\"s2_format\" value=\"html\"";
2201
- if ('html' == get_usermeta($user_ID, 's2_format')) {
2202
echo "checked=\"checked\" ";
2203
}
2204
echo "/> " . __('HTML', 'subscribe2') ."</label>&nbsp;&nbsp;";
2205
echo "<label><input type=\"radio\" name=\"s2_format\" value=\"post\" ";
2206
- if ('post' == get_usermeta($user_ID, 's2_format')) {
2207
echo "checked=\"checked\" ";
2208
}
2209
echo "/> " . __('Plain Text - Full', 'subscribe2') . "</label>&nbsp;&nbsp;";
2210
echo "<label><input type=\"radio\" name=\"s2_format\" value=\"excerpt\" ";
2211
- if ('excerpt' == get_usermeta($user_ID, 's2_format')) {
2212
echo "checked=\"checked\" ";
2213
}
2214
echo "/> " . __('Plain Text - Excerpt', 'subscribe2') . "</label><br /><br />\r\n";
2215
2216
- if ($this->subscribe2_options['show_autosub'] == 'yes') {
2217
echo __('Automatically subscribe me to newly created categories', 'subscribe2') . ': &nbsp;&nbsp;';
2218
echo "<label><input type=\"radio\" name=\"new_category\" value=\"yes\" ";
2219
- if ('yes' == get_usermeta($user_ID, 's2_autosub')) {
2220
echo "checked=\"checked\" ";
2221
}
2222
echo "/> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2223
echo "<label><input type=\"radio\" name=\"new_category\" value=\"no\" ";
2224
- if ('no' == get_usermeta($user_ID, 's2_autosub')) {
2225
echo "checked=\"checked\" ";
2226
}
2227
- echo "/> " . __('No', 'subscribe2') . "</label><br /><br />";
2228
echo "</p>";
2229
}
2230
2231
// subscribed categories
2232
- if ($this->s2_mu) {
2233
global $blog_id;
2234
$subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
2235
// if we are subscribed to the current blog display an "unsubscribe" link
2236
- if (!empty($subscribed)) {
2237
$unsubscribe_link = get_bloginfo('url') . "/wp-admin/?s2mu_unsubscribe=". $blog_id;
2238
echo "<p><a href=\"". $unsubscribe_link ."\" class=\"button\">" . __('Unsubscribe me from this blog', 'subscribe2') . "</a></p>";
2239
} else {
@@ -2250,14 +2246,14 @@ class s2class {
2250
// we're doing daily digests, so just show
2251
// subscribe / unnsubscribe
2252
echo __('Receive periodic summaries of new posts?', 'subscribe2') . ': &nbsp;&nbsp;';
2253
- echo "<p><label>";
2254
echo "<input type=\"radio\" name=\"category\" value=\"digest\" ";
2255
- if (get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))) {
2256
- echo "checked=\"yes\" ";
2257
}
2258
echo "/> " . __('Yes', 'subscribe2') . "</label> <label><input type=\"radio\" name=\"category\" value=\"-1\" ";
2259
- if (!get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))) {
2260
- echo "checked=\"yes\" ";
2261
}
2262
echo "/> " . __('No', 'subscribe2');
2263
echo "</label></p>";
@@ -2268,23 +2264,24 @@ class s2class {
2268
echo "</form>\r\n";
2269
2270
// list of subscribed blogs on wordpress mu
2271
- if ($this->s2_mu) {
2272
global $blog_id;
2273
$blogs = get_blog_list(0, 'all');
2274
2275
$blogs_subscribed = array();
2276
$blogs_notsubscribed = array();
2277
2278
- foreach ($blogs as $key => $blog) {
2279
// switch to blog
2280
switch_to_blog($blog['blog_id']);
2281
2282
// check that the plugin is active on the current blog
2283
$current_plugins = get_option('active_plugins');
2284
- if (!is_array($current_plugins)) {
2285
$current_plugins = (array)$current_plugins;
2286
}
2287
- if (!in_array('subscribe2/subscribe2.php', $current_plugins)) {
2288
continue;
2289
}
2290
@@ -2292,7 +2289,7 @@ class s2class {
2292
$subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
2293
2294
$blogname = get_bloginfo('name');
2295
- if (strlen($blogname) > 30) {
2296
$blog['blogname'] = wp_html_excerpt($blogname, 30) . "..";
2297
} else {
2298
$blog['blogname'] = $blogname;
@@ -2302,7 +2299,7 @@ class s2class {
2302
$blog['subscribe_page'] = get_bloginfo('url') . "/wp-admin/users.php?page=s2_users";
2303
2304
$key = strtolower($blog['blogname'] . "-" . $blog['blog_id']);
2305
- if (!empty($subscribed)) {
2306
$blogs_subscribed[$key] = $blog;
2307
} else {
2308
$blogs_notsubscribed[$key] = $blog;
@@ -2310,17 +2307,17 @@ class s2class {
2310
restore_current_blog();
2311
}
2312
2313
- if (!empty($blogs_subscribed)) {
2314
ksort($blogs_subscribed);
2315
echo "<h2>" . __('Subscribed Blogs', 'subscribe2') . "</h2>\r\n";
2316
echo "<ul class=\"s2_blogs\">\r\n";
2317
- foreach ($blogs_subscribed as $blog) {
2318
echo "<li><span class=\"name\"><a href=\"" . $blog['blogurl'] . "\" title=\"" . $blog['description'] . "\">" . $blog['blogname'] . "</a></span>\r\n";
2319
- if ($blog_id == $blog['blog_id']) {
2320
echo "<span class=\"buttons\">" . __('Viewing Settings Now', 'subscribe2') . "</span>\r\n";
2321
} else {
2322
echo "<span class=\"buttons\">";
2323
- if (is_blog_user($blog['blog_id'])) {
2324
echo "<a href=\"". $blog['subscribe_page'] . "\">" . __('View Settings', 'subscribe2') . "</a>\r\n";
2325
}
2326
echo "<a href=\"" . $blog['blogurl'] . "/wp-admin/?s2mu_unsubscribe=" . $blog['blog_id'] . "\">" . __('Unsubscribe', 'subscribe2') . "</a></span>\r\n";
@@ -2331,17 +2328,17 @@ class s2class {
2331
echo "</ul>\r\n";
2332
}
2333
2334
- if (!empty($blogs_notsubscribed)) {
2335
ksort($blogs_notsubscribed);
2336
echo "<h2>" . __('Subscribe to new blogs', 'subscribe2') . "</h2>\r\n";
2337
echo "<ul class=\"s2_blogs\">";
2338
- foreach ($blogs_notsubscribed as $blog) {
2339
echo "<li><span class=\"name\"><a href=\"" . $blog['blogurl'] . "\" title=\"" . $blog['description'] . "\">" . $blog['blogname'] . "</a></span>\r\n";
2340
- if ($blog_id == $blog['blog_id']) {
2341
echo "<span class=\"buttons\">" . __('Viewing Settings Now', 'subscribe2') . "</span>\r\n";
2342
} else {
2343
echo "<span class=\"buttons\">";
2344
- if (is_blog_user($blog['blog_id'])) {
2345
echo "<a href=\"". $blog['subscribe_page'] . "\">" . __('View Settings', 'subscribe2') . "</a>\r\n";
2346
}
2347
echo "<a href=\"" . $blog['blogurl'] . "/wp-admin/?s2mu_subscribe=" . $blog['blog_id'] . "\">" . __('Subscribe', 'subscribe2') . "</a></span>\r\n";
@@ -2367,32 +2364,32 @@ class s2class {
2367
global $wpdb, $s2nonce, $current_user;
2368
2369
// was anything POSTed?
2370
- if (isset($_POST['s2_admin']) && ('mail' == $_POST['s2_admin']) ) {
2371
check_admin_referer('subscribe2-write_subscribers' . $s2nonce);
2372
- if ('confirmed' == $_POST['what']) {
2373
$recipients = $this->get_public();
2374
- } elseif ('unconfirmed' == $_POST['what']) {
2375
$recipients = $this->get_public(0);
2376
- } elseif ('public' == $_POST['what']) {
2377
$confirmed = $this->get_public();
2378
$unconfirmed = $this->get_public(0);
2379
$recipients = array_merge((array)$confirmed, (array)$unconfirmed);
2380
- } elseif (is_numeric($_POST['what'])) {
2381
$cat = intval($_POST['what']);
2382
$recipients = $this->get_registered("cats=$cat");
2383
- } elseif ('all_users' == $_POST['what']) {
2384
$recipients = $this->get_all_registered();
2385
} else {
2386
$recipients = $this->get_registered();
2387
}
2388
$subject = $this->substitute(stripslashes(strip_tags($_POST['subject'])));
2389
$body = $this->substitute(stripslashes($_POST['content']));
2390
- if (('' != $current_user->display_name) || ('' != $current_user->user_email)) {
2391
$this->myname = html_entity_decode($current_user->display_name, ENT_QUOTES);
2392
$this->myemail = $current_user->user_email;
2393
}
2394
$status = $this->mail($recipients, $subject, $body, 'text');
2395
- if ($status) {
2396
$message = $this->mail_sent;
2397
} else {
2398
global $phpmailer;
@@ -2400,16 +2397,18 @@ class s2class {
2400
}
2401
}
2402
2403
- if ('' != $message) {
2404
echo "<div id=\"message\" class=\"updated\"><strong><p>" . $message . "</p></strong></div>\r\n";
2405
}
2406
// show our form
2407
- echo "<div class=\"wrap\"><h2>" . __('Send an email to subscribers', 'subscribe2') . "</h2>\r\n";
2408
echo "<form method=\"post\" action=\"\">\r\n";
2409
- if (function_exists('wp_nonce_field')) {
2410
wp_nonce_field('subscribe2-write_subscribers' . $s2nonce);
2411
}
2412
- if (isset($_POST['subject'])) {
2413
$subject = $_POST['subject'];
2414
} else {
2415
$subject = __('A message from', 'subscribe2') . " " . get_option('blogname');
@@ -2441,11 +2440,11 @@ class s2class {
2441
$all_cats = get_categories(array('hide_empty' => false));
2442
$exclude = explode(',', $this->subscribe2_options['exclude']);
2443
2444
- if (0 == $override) {
2445
// registered users are not allowed to subscribe to
2446
// excluded categories
2447
- foreach ($all_cats as $cat => $term_id) {
2448
- if (in_array($all_cats[$cat]->term_id, $exclude)) {
2449
$cat = (int)$cat;
2450
unset($all_cats[$cat]);
2451
}
@@ -2460,23 +2459,23 @@ class s2class {
2460
echo "<label><input type=\"checkbox\" name=\"checkall\" value=\"cat_checkall\" /> " . __('Select / Unselect All', 'subscribe2') . "</label>\r\n";
2461
echo "</td></tr>\r\n";
2462
echo "<tr valign=\"top\"><td width=\"50%\" align=\"left\">\r\n";
2463
- foreach ($all_cats as $cat) {
2464
- if ( ($i >= $half) && (0 == $j) ){
2465
echo "</td><td width=\"50%\" align=\"left\">\r\n";
2466
$j++;
2467
}
2468
- if (0 == $j) {
2469
echo "<label><input class=\"cat_checkall\" type=\"checkbox\" name=\"category[]\" value=\"" . $cat->term_id . "\"";
2470
- if (in_array($cat->term_id, $selected)) {
2471
echo " checked=\"checked\" ";
2472
}
2473
- echo " /> <abbr title=\"" . $cat->slug . "\">" . $cat->name . "</abbr></label><br />\r\n";
2474
} else {
2475
echo "<label><input class=\"cat_checkall\" type=\"checkbox\" name=\"category[]\" value=\"" . $cat->term_id . "\"";
2476
- if (in_array($cat->term_id, $selected)) {
2477
echo " checked=\"checked\" ";
2478
}
2479
- echo " /> <abbr title=\"" . $cat->slug . "\">" . $cat->name . "</abbr></label><br />\r\n";
2480
}
2481
$i++;
2482
}
@@ -2504,60 +2503,60 @@ class s2class {
2504
// count the number of subscribers
2505
$count['confirmed'] = $wpdb->get_var("SELECT COUNT(id) FROM $this->public WHERE active='1'");
2506
$count['unconfirmed'] = $wpdb->get_var("SELECT COUNT(id) FROM $this->public WHERE active='0'");
2507
- if (in_array('unconfirmed', $exclude)) {
2508
$count['public'] = $count['confirmed'];
2509
- } elseif (in_array('confirmed', $exclude)) {
2510
$count['public'] = $count['unconfirmed'];
2511
} else {
2512
$count['public'] = ($count['confirmed'] + $count['unconfirmed']);
2513
}
2514
- if ($this->s2_mu) {
2515
$count['all_users'] = $wpdb->get_var("SELECT COUNT(meta_key) FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
2516
} else {
2517
$count['all_users'] = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
2518
}
2519
- if ($this->s2_mu) {
2520
$count['registered'] = $wpdb->get_var("SELECT COUNT(meta_key) FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities' AND meta_key='" . $this->get_usermeta_keyname('s2_subscribed') . "'");
2521
} else {
2522
$count['registered'] = $wpdb->get_var("SELECT COUNT(meta_key) FROM $wpdb->usermeta WHERE meta_key='" . $this->get_usermeta_keyname('s2_subscribed') . "'");
2523
}
2524
$count['all'] = ($count['confirmed'] + $count['unconfirmed'] + $count['all_users']);
2525
- if ($this->s2_mu) {
2526
- foreach ($all_cats as $cat) {
2527
$count[$cat->name] = $wpdb->get_var("SELECT COUNT(a.meta_key) FROM $wpdb->usermeta AS a INNER JOIN $wpdb->usermeta AS b ON a.user_id = b.user_id WHERE a.meta_key='" . $wpdb->prefix . "capabilities' AND b.meta_key='" . $this->get_usermeta_keyname('s2_cat') . $cat->term_id . "'");
2528
}
2529
} else {
2530
- foreach ($all_cats as $cat) {
2531
$count[$cat->name] = $wpdb->get_var("SELECT COUNT(meta_value) FROM $wpdb->usermeta WHERE meta_key='" . $this->get_usermeta_keyname('s2_cat') . $cat->term_id . "'");
2532
}
2533
}
2534
2535
// do have actually have some subscribers?
2536
- if ( (0 == $count['confirmed']) && (0 == $count['unconfirmed']) && (0 == $count['all_users']) ) {
2537
// no? bail out
2538
return;
2539
}
2540
2541
echo "<select name=\"what\">\r\n";
2542
- foreach ($who as $whom => $display) {
2543
- if (in_array($whom, $exclude)) { continue; }
2544
- if (0 == $count[$whom]) { continue; }
2545
2546
echo "<option value=\"" . $whom . "\"";
2547
- if ($whom == $selected) { echo " selected=\"selected\" "; }
2548
echo ">$display (" . ($count[$whom]) . ")</option>\r\n";
2549
}
2550
2551
- if ($count['registered'] > 0) {
2552
- foreach ($all_cats as $cat) {
2553
- if (in_array($cat->term_id, $exclude)) { continue; }
2554
echo "<option value=\"" . $cat->term_id . "\"";
2555
- if ($cat->term_id == $selected) { echo " selected=\"selected\" "; }
2556
echo "> &nbsp;&nbsp;" . $cat->name . "&nbsp;(" . $count[$cat->name] . ") </option>\r\n";
2557
}
2558
}
2559
echo "</select>";
2560
- if (false !== $submit) {
2561
echo "&nbsp;<input type=\"submit\" class=\"button-secondary\" value=\"$submit\" />\r\n";
2562
}
2563
} // end display_subscriber_dropdown()
@@ -2573,9 +2572,9 @@ class s2class {
2573
$admins = $wpdb->get_results($sql);
2574
2575
// handle issues from WordPress core where user_level is not set or set low
2576
- if (empty($admins)) {
2577
$role = 'administrator';
2578
- if (!class_exists(WP_User_Search)) {
2579
require(ABSPATH . 'wp-admin/includes/user.php');
2580
}
2581
$wp_user_search = new WP_User_Search( '', '', $role);
@@ -2584,15 +2583,15 @@ class s2class {
2584
$admins = $wpdb->get_results($sql);
2585
}
2586
2587
- if ($inc_author) {
2588
$author[] = (object)array('ID' => 'author', 'display_name' => 'Post Author');
2589
$admins = array_merge($author, $admins);
2590
}
2591
2592
echo "<select name=\"sender\">\r\n";
2593
- foreach ($admins as $admin) {
2594
echo "<option value=\"" . $admin->ID . "\"";
2595
- if ($admin->ID == $this->subscribe2_options['sender']) {
2596
echo " selected=\"selected\"";
2597
}
2598
echo ">" . $admin->display_name . "</option>\r\n";
@@ -2610,15 +2609,17 @@ class s2class {
2610
$schedule = (array)wp_get_schedules();
2611
$schedule = array_merge(array('never' => array('interval' => 0, 'display' => __('For each Post', 'subscribe2'))), $schedule);
2612
$sort = array();
2613
- foreach ((array)$schedule as $key => $value) $sort[$key] = $value['interval'];
2614
asort($sort);
2615
$schedule_sorted = array();
2616
- foreach ($sort as $key => $value) {
2617
$schedule_sorted[$key] = $schedule[$key];
2618
}
2619
- foreach ($schedule_sorted as $key => $value) {
2620
echo "<label><input type=\"radio\" name=\"email_freq\" value=\"" . $key . "\"";
2621
- if ($key == $this->subscribe2_options['email_freq']) {
2622
echo " checked=\"checked\" ";
2623
}
2624
echo " /> " . $value['display'] . "</label><br />\r\n";
@@ -2626,9 +2627,9 @@ class s2class {
2626
echo "<br />" . __('Send Digest Notification at', 'subscribe2') . ": \r\n";
2627
$hours = array('12am', '1am', '2am', '3am', '4am', '5am', '6am', '7am', '8am', '9am', '10am', '11am', '12pm', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm');
2628
echo "<select name=\"hour\">\r\n";
2629
- while ($hour = current($hours)) {
2630
echo "<option value=\"" . key($hours) . "\"";
2631
- if ( (key($hours) == date('H', $scheduled_time)) && (!empty($scheduled_time)) ){
2632
echo " selected=\"selected\"";
2633
}
2634
echo ">" . $hour . "</option>\r\n";
@@ -2636,14 +2637,14 @@ class s2class {
2636
}
2637
echo "</select>\r\n";
2638
echo "<strong><em style=\"color: red\">" . __('This option will work for digest notification sent daily or less frequently', 'subscribe2') . "</em></strong>\r\n";
2639
- if ($scheduled_time) {
2640
$datetime = get_option('date_format') . ' @ ' . get_option('time_format');
2641
echo "<p>" . __('Current UTC time is', 'subscribe2') . ": \r\n";
2642
echo "<strong>" . date_i18n($datetime, false, 'gmt') . "</strong></p>\r\n";
2643
echo "<p>" . __('Current blog time is', 'subscribe2') . ": \r\n";
2644
echo "<strong>" . date_i18n($datetime) . "</strong></p>\r\n";
2645
echo "<p>" . __('Next email notification will be sent when your blog time is after', 'subscribe2') . ": \r\n";
2646
- echo "<strong>" . date_i18n($datetime, wp_next_scheduled('s2_digest_cron')) . "</strong></p>\r\n";
2647
} else {
2648
echo "<br />";
2649
}
@@ -2656,8 +2657,8 @@ class s2class {
2656
global $wpdb, $wp_version, $wpmu_version;
2657
2658
// Is this WordPressMU or not?
2659
- if ( (isset($wpmu_version)) || (strpos($wp_version, 'wordpress-mu')) ) {
2660
- switch($metaname) {
2661
case 's2_subscribed':
2662
case 's2_cat':
2663
return $wpdb->prefix . $metaname;
@@ -2669,30 +2670,31 @@ class s2class {
2669
}
2670
2671
/**
2672
- Adds a link directly to the settings page from the plugin page
2673
*/
2674
- function plugin_action($links, $file) {
2675
- if ($file == plugin_basename(dirname(__FILE__).'/subscribe2.php')) {
2676
- $s2link[] = "<a href='options-general.php?page=s2_settings'><b>" . __('Settings', 'subscribe2') . "</b></a>";
2677
- $links = array_merge($s2link, $links);
2678
}
2679
return $links;
2680
- } // end plugin_action()
2681
2682
/**
2683
Adds information to the WordPress registration screen for new users
2684
*/
2685
function register_form() {
2686
- if ('wpreg' == $this->subscribe2_options['autosub']) {
2687
echo "<p>\r\n<label>";
2688
echo __('Check here to Subscribe to email notifications for new posts') . ":<br />\r\n";
2689
echo "<input type=\"checkbox\" name=\"subscribe\"";
2690
- if ('yes' == $this->subscribe2_options['wpregdef']) {
2691
echo " checked=\"checked\"";
2692
}
2693
echo " /></label>\r\n";
2694
echo "</p>\r\n";
2695
- } elseif ('yes' == $this->subscribe2_options['autosub']) {
2696
echo "<p>\r\n<center>\r\n";
2697
echo __('By registering with this blog you are also agreeing to receive email notifications for new posts but you can unsubscribe at anytime', 'subscribe2') . ".<br />\r\n";
2698
echo "</center></p>\r\n";
@@ -2703,9 +2705,9 @@ class s2class {
2703
Process function to add action if user selects to subscribe to posts during registration
2704
*/
2705
function register_post() {
2706
- if ('on' == $_POST['subscribe']) {
2707
$user = get_userdatabylogin($_POST['user_login']);
2708
- if (0 == $user->ID) { return; }
2709
$this->register($user->ID);
2710
}
2711
}
@@ -2714,7 +2716,7 @@ class s2class {
2714
Create meta box on write pages
2715
*/
2716
function s2_meta_init() {
2717
- if (function_exists('add_meta_box')) {
2718
add_meta_box('subscribe2', __('Subscribe2 Notification Override', 'subscribe2' ), array(&$this, 's2_meta_box'), 'post', 'advanced');
2719
add_meta_box('subscribe2', __('Subscribe2 Notification Override', 'subscribe2' ), array(&$this, 's2_meta_box'), 'page', 'advanced');
2720
} else {
@@ -2732,7 +2734,7 @@ class s2class {
2732
echo "<input type=\"hidden\" name=\"s2meta_nonce\" id=\"s2meta_nonce\" value=\"" . wp_create_nonce(md5(plugin_basename(__FILE__))) . "\" />";
2733
echo __("Check here to disable sending of an email notification for this post/page", 'subscribe2');
2734
echo "&nbsp;&nbsp;<input type=\"checkbox\" name=\"s2_meta_field\" value=\"no\"";
2735
- if ($s2mail == 'no') {
2736
echo " checked=\"checked\"";
2737
}
2738
echo " />";
@@ -2754,19 +2756,19 @@ class s2class {
2754
Meta box form handler
2755
*/
2756
function s2_meta_handler($post_id) {
2757
- if ( (!isset($_POST['s2meta_nonce'])) || (!wp_verify_nonce($_POST['s2meta_nonce'], md5(plugin_basename(__FILE__)))) ) { return $post_id; }
2758
2759
- if ('page' == $_POST['post_type']) {
2760
- if (!current_user_can('edit_page', $post_id)) { return $post_id; }
2761
} else {
2762
- if (!current_user_can('edit_post', $post_id)) { return $post_id; }
2763
}
2764
2765
- if ( (isset($_POST['s2_meta_field'])) && ($_POST['s2_meta_field'] == 'no') ) {
2766
- update_post_meta($post_id, 's2mail', $_POST['s2_meta_field']);
2767
- } else {
2768
- delete_post_meta($post_id, 's2mail');
2769
- }
2770
} // end s2_meta_box_handler()
2771
2772
/* ===== template and filter functions ===== */
@@ -2774,45 +2776,45 @@ class s2class {
2774
Display our form; also handles (un)subscribe requests
2775
*/
2776
function filter($content = '') {
2777
- if ( ('' == $content) || (!strstr($content, '<!--subscribe2-->')) ) { return $content; }
2778
$this->s2form = $this->form;
2779
2780
global $user_ID;
2781
get_currentuserinfo();
2782
- if ($user_ID) {
2783
- if (current_user_can('manage_options')) {
2784
$this->s2form = $this->use_profile_admin;
2785
} else {
2786
$this->s2form = $this->use_profile_users;
2787
}
2788
}
2789
- if ( (isset($_POST['subscribe'])) || (isset($_POST['unsubscribe'])) ) {
2790
global $wpdb, $user_email;
2791
- if (!is_email($_POST['email'])) {
2792
$this->s2form = $this->form . $this->not_an_email;
2793
- } elseif ($this->is_barred($_POST['email'])) {
2794
$this->s2form = $this->form . $this->barred_domain;
2795
} else {
2796
$this->email = $_POST['email'];
2797
$this->ip = $_POST['ip'];
2798
// does the supplied email belong to a registered user?
2799
$check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email = '$this->email'");
2800
- if ('' != $check) {
2801
// this is a registered email
2802
$this->s2form = $this->please_log_in;
2803
} else {
2804
// this is not a registered email
2805
// what should we do?
2806
- if (isset($_POST['subscribe'])) {
2807
// someone is trying to subscribe
2808
// lets see if they've tried to subscribe previously
2809
- if ('1' !== $this->is_public($this->email)) {
2810
// the user is unknown or inactive
2811
$this->add();
2812
$status = $this->send_confirm('add');
2813
// set a variable to denote that we've already run, and shouldn't run again
2814
$this->filtered = 1;
2815
- if ($status) {
2816
$this->s2form = $this->confirmation_sent;
2817
} else {
2818
$this->s2form = $this->error;
@@ -2822,15 +2824,15 @@ class s2class {
2822
$this->s2form = $this->already_subscribed;
2823
}
2824
$this->action = 'subscribe';
2825
- } elseif (isset($_POST['unsubscribe'])) {
2826
// is this email a subscriber?
2827
- if (false == $this->is_public($this->email)) {
2828
$this->s2form = $this->form . $this->not_subscribed;
2829
} else {
2830
$status = $this->send_confirm('del');
2831
// set a variable to denote that we've already run, and shouldn't run again
2832
$this->filtered = 1;
2833
- if ($status) {
2834
$this->s2form = $this->confirmation_sent;
2835
} else {
2836
$this->s2form = $this->error;
@@ -2851,7 +2853,7 @@ class s2class {
2851
*/
2852
function query_filter() {
2853
// don't interfere if we've already done our thing
2854
- if (1 == $this->filtered) { return; }
2855
2856
global $wpdb;
2857
@@ -2859,7 +2861,7 @@ class s2class {
2859
return "page_id=" . $this->subscribe2_options['s2page'];
2860
} else {
2861
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' LIMIT 1");
2862
- if ($id) {
2863
return "page_id=$id";
2864
} else {
2865
return "showposts=1";
@@ -2872,7 +2874,7 @@ class s2class {
2872
*/
2873
function title_filter($title) {
2874
// don't interfere if we've already done our thing
2875
- if (in_the_loop()) {
2876
return __('Subscription Confirmation', 'subscribe2');
2877
} else {
2878
return $title;
@@ -2895,11 +2897,11 @@ class s2class {
2895
echo $before_title . $title . $after_title;
2896
echo "<div class=\"" . $div . "\">";
2897
$content = s2class::filter('<!--subscribe2-->');
2898
- if (!empty($widgetprecontent)) {
2899
echo $widgetprecontent;
2900
}
2901
echo $content;
2902
- if (!empty($widgetpostcontent)) {
2903
echo $widgetpostcontent;
2904
}
2905
echo "</div>";
@@ -2911,13 +2913,13 @@ class s2class {
2911
*/
2912
function widget_subscribe2widget_control() {
2913
$options = $newoptions = get_option('widget_subscribe2widget');
2914
- if ($_POST["s2w-submit"]) {
2915
$newoptions['title'] = strip_tags(stripslashes($_POST["s2w-title"]));
2916
$newoptions['div'] = sanitize_title(strip_tags(stripslashes($_POST["s2w-div"])));
2917
$newoptions['widgetprecontent'] = stripslashes($_POST["s2w-widgetprecontent"]);
2918
$newoptions['widgetpostcontent'] = stripslashes($_POST["s2w-widgetpostcontent"]);
2919
}
2920
- if ($options != $newoptions) {
2921
$options = $newoptions;
2922
update_option('widget_subscribe2widget', $options);
2923
}
@@ -2941,7 +2943,7 @@ class s2class {
2941
*/
2942
function register_subscribe2widget() {
2943
//Check Sidebar Widget and Subscribe2 plugins are activated
2944
- if ( !function_exists('register_sidebar_widget') || !class_exists('s2class')) {
2945
return;
2946
} else {
2947
register_sidebar_widget('Subscribe2', array(&$this, 'widget_subscribe2widget'));
@@ -2954,22 +2956,22 @@ class s2class {
2954
global $wpdb;
2955
$blogs = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
2956
2957
- foreach ($blogs as $blog) {
2958
switch_to_blog($blog);
2959
2960
$sidebars = get_option('sidebars_widgets');
2961
- if ( (empty($sidebars)) || (!is_array($sidebars)) ) { return; }
2962
$changed = false;
2963
- foreach ($sidebars as $s =>$sidebar) {
2964
- if ( (empty($sidebar)) || (!is_array($sidebar)) ) { break; }
2965
- foreach ($sidebar as $w => $widget) {
2966
- if ($widget == 'subscribe2widget') {
2967
$sidebars[$s][$w] = 'subscribe2';
2968
$changed = true;
2969
}
2970
}
2971
}
2972
- if ($changed) {
2973
update_option('sidebar_widgets', $sidebars);
2974
}
2975
}
@@ -2980,7 +2982,7 @@ class s2class {
2980
Add hook for Minimeta Widget plugin
2981
*/
2982
function add_minimeta() {
2983
- if ($this->subscribe2_options['s2page'] != 0) {
2984
echo "<li><a href=\"" . get_option('siteurl') . "/?page_id=" . $this->subscribe2_options['s2page'] . "\">" . __('[Un]Subscribe to Posts', 'subscribe2') . "</a></li>\r\n";
2985
}
2986
} // end add_minimeta()
@@ -2991,11 +2993,11 @@ class s2class {
2991
Register our button in the QuickTags bar
2992
*/
2993
function button_init() {
2994
- if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) { return; }
2995
- if ('true' == get_user_option('rich_editing') ) {
2996
global $wp_db_version;
2997
//check if we are using WordPress 2.5+
2998
- if ($wp_db_version >= 7098) {
2999
// Use WordPress 2.5+ hooks
3000
add_filter('mce_external_plugins', array(&$this, 'mce3_plugin'));
3001
add_filter('mce_buttons', array(&$this, 'mce3_button'));
@@ -3007,7 +3009,7 @@ class s2class {
3007
}
3008
} else {
3009
buttonsnap_separator();
3010
- buttonsnap_jsbutton(WP_CONTENT_URL . '/plugins/subscribe2/include/s2_button.png', __('Subscribe2', 'subscribe2'), 's2_insert_token();');
3011
}
3012
} // end button_init()
3013
@@ -3015,7 +3017,7 @@ class s2class {
3015
Add buttons for WordPress 2.5+ using built in hooks
3016
*/
3017
function mce3_plugin($arr) {
3018
- $path = WP_CONTENT_URL . '/plugins/subscribe2/tinymce3/editor_plugin.js';
3019
$arr['subscribe2'] = $path;
3020
return $arr;
3021
}
@@ -3038,7 +3040,7 @@ class s2class {
3038
}
3039
3040
function tinymce2_before_init() {
3041
- $this->fullpath = WP_CONTENT_URL . '/plugins/subscribe2/tinymce/';
3042
echo "tinyMCE.loadPlugin('subscribe2quicktags', '" . $this->fullpath . "');\n";
3043
}
3044
@@ -3067,9 +3069,11 @@ class s2class {
3067
Send a daily digest of today's new posts
3068
*/
3069
function subscribe2_cron($preview = '') {
3070
global $wpdb;
3071
3072
- if ('' == $preview) {
3073
// update last_s2cron execution time before completing or bailing
3074
$now = current_time('mysql');
3075
$prev = $this->subscribe2_options['last_s2cron'];
@@ -3077,20 +3081,20 @@ class s2class {
3077
update_option('subscribe2_options', $this->subscribe2_options);
3078
3079
//set up SQL query based on options
3080
- if ($this->subscribe2_options['private'] == 'yes' ) {
3081
$status = "'publish', 'private'";
3082
} else {
3083
$status = "'publish'";
3084
}
3085
3086
- if ($this->subscribe2_options['page'] == 'yes' ) {
3087
- $type = "'post', 'page'";
3088
} else {
3089
$type = "'post'";
3090
}
3091
3092
// collect posts
3093
- if ($this->subscribe2_options['cron_order'] == 'desc') {
3094
$posts = $wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content, post_type, post_password, post_date FROM $wpdb->posts WHERE post_date >= '$prev' AND post_date < '$now' AND post_status IN ($status) AND post_type IN ($type) ORDER BY post_date DESC");
3095
} else {
3096
$posts = $wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content, post_type, post_password, post_date FROM $wpdb->posts WHERE post_date >= '$prev' AND post_date < '$now' AND post_status IN ($status) AND post_type IN ($type) ORDER BY post_date ASC");
@@ -3101,64 +3105,80 @@ class s2class {
3101
}
3102
3103
// do we have any posts?
3104
- if (empty($posts)) { return; }
3105
3106
// if we have posts, let's prepare the digest
3107
$datetime = get_option('date_format') . ' @ ' . get_option('time_format');
3108
$all_post_cats = array();
3109
$table = '';
3110
$message_post= '';
3111
$message_posttime = '';
3112
- foreach ($posts as $post) {
3113
$post_cats = wp_get_post_categories($post->ID);
3114
$post_cats_string = implode(',', $post_cats);
3115
$all_post_cats = array_unique(array_merge($all_post_cats, $post_cats));
3116
$check = false;
3117
// is the current post assigned to any categories
3118
// which should not generate a notification email?
3119
- foreach (explode(',', $this->subscribe2_options['exclude']) as $cat) {
3120
- if (in_array($cat, $post_cats)) {
3121
$check = true;
3122
}
3123
}
3124
// is the current post set by the user to
3125
// not generate a notification email?
3126
$s2mail = get_post_meta($post->ID, 's2mail', true);
3127
- if (strtolower(trim($s2mail)) == 'no') {
3128
$check = true;
3129
}
3130
// is the current post private
3131
// and should this not generate a notification email?
3132
- if ( ($this->subscribe2_options['password'] == "no") && ($post->post_password != '') ) {
3133
$check = true;
3134
}
3135
// if this post is excluded
3136
// don't include it in the digest
3137
- if ($check) {
3138
continue;
3139
}
3140
('' == $table) ? $table = "* " . $post->post_title : $table .= "\r\n* " . $post->post_title;
3141
$message_post .= $post->post_title . "\r\n";
3142
- $message_post .= get_permalink($post->ID) . "\r\n\r\n";
3143
$message_posttime .= $post->post_title . "\r\n";
3144
$message_posttime .= __('Posted on', 'subscribe2') . ": " . mysql2date($datetime, $post->post_date) . "\r\n";
3145
- $message_posttime .= get_permalink($post->ID) . "\r\n\r\n";
3146
$excerpt = $post->post_excerpt;
3147
- if ('' == $excerpt) {
3148
// no excerpt, is there a <!--more--> ?
3149
- if (false !== strpos($post->post_content, '<!--more-->')) {
3150
- list($excerpt, $more) = explode('<!--more-->', $post->post_content, 2);
3151
- $excerpt = strip_tags($excerpt);
3152
- if (function_exists('strip_shortcodes')) {
3153
$excerpt = strip_shortcodes($excerpt);
3154
}
3155
} else {
3156
$excerpt = strip_tags($post->post_content);
3157
- if (function_exists('strip_shortcodes')) {
3158
$excerpt = strip_shortcodes($excerpt);
3159
}
3160
$words = explode(' ', $excerpt, $this->excerpt_length + 1);
3161
- if (count($words) > $this->excerpt_length) {
3162
array_pop($words);
3163
array_push($words, '[...]');
3164
$excerpt = implode(' ', $words);
@@ -3176,7 +3196,7 @@ class s2class {
3176
$message_posttime = trim($message_posttime);
3177
3178
//sanity check - don't send a mail if the content is empty
3179
- if (!$message_post && !$message_posttime && !$table) {
3180
return;
3181
}
3182
@@ -3189,17 +3209,16 @@ class s2class {
3189
$email_freq = $this->subscribe2_options['email_freq'];
3190
$display = $scheds[$email_freq]['display'];
3191
$subject = "[" . stripslashes(get_option('blogname')) . "] " . $display . " " . __('Digest Email', 'subscribe2');
3192
- $mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
3193
$mailtext = stripslashes($this->substitute($mailtext));
3194
$mailtext = str_replace("TABLE", $table, $mailtext);
3195
$mailtext = str_replace("POSTTIME", $message_posttime, $mailtext);
3196
$mailtext = str_replace("POST", $message_post, $mailtext);
3197
3198
// prepare recipients
3199
- if ($preview != '') {
3200
$this->myemail = $preview;
3201
$this->myname = "Preview";
3202
- $this->mail(array($preview), $subject, $mailtext);
3203
} else {
3204
$public = $this->get_public();
3205
$all_post_cats_string = implode(',', $all_post_cats);
@@ -3218,15 +3237,15 @@ class s2class {
3218
$this->subscribe2_options = get_option('subscribe2_options');
3219
3220
add_action('init', array(&$this, 'subscribe2'));
3221
- if ('1' == $this->subscribe2_options['show_button']) {
3222
add_action('init', array(&$this, 'button_init'));
3223
}
3224
// add action to display widget if option is enabled
3225
- if ('1' == $this->subscribe2_options['widget']) {
3226
add_action('plugins_loaded', array(&$this, 'register_subscribe2widget'));
3227
}
3228
// add action to handle WPMU subscriptions and unsubscriptions
3229
- if ( (isset($_GET['s2mu_subscribe'])) || (isset($_GET['s2mu_unsubscribe'])) ) {
3230
add_action('init', array(&$this, 'wpmu_subscribe'));
3231
}
3232
} // end s2init()
@@ -3234,10 +3253,10 @@ class s2class {
3234
function subscribe2() {
3235
global $table_prefix, $wp_version, $wpmu_version;
3236
3237
- load_plugin_textdomain('subscribe2', 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
3238
3239
// Is this WordPressMU or not?
3240
- if ( (isset($wpmu_version)) || (strpos($wp_version, 'wordpress-mu')) ) {
3241
$this->s2_mu = true;
3242
} else {
3243
$this->s2_mu = false;
@@ -3245,20 +3264,20 @@ class s2class {
3245
3246
// do we need to install anything?
3247
$this->public = $table_prefix . "subscribe2";
3248
- if (!mysql_query("DESCRIBE " . $this->public)) { $this->install(); }
3249
//do we need to upgrade anything?
3250
- if ( (is_array($this->subscribe2_options)) && ($this->subscribe2_options['version'] !== S2VERSION) ) {
3251
add_action('shutdown', array(&$this, 'upgrade'));
3252
}
3253
3254
- if (isset($_GET['s2'])) {
3255
// someone is confirming a request
3256
add_filter('query_string', array(&$this, 'query_filter'));
3257
add_filter('the_title', array(&$this, 'title_filter'));
3258
add_filter('the_content', array(&$this, 'confirm'));
3259
}
3260
3261
- if ( (isset($_POST['s2_admin'])) && ($_POST['csv']) ) {
3262
$date = date('Y-m-d');
3263
header("Content-Description: File Transfer");
3264
header("Content-type: application/octet-stream");
@@ -3280,7 +3299,7 @@ class s2class {
3280
add_filter('cron_schedules', array(&$this, 'add_weekly_sched'));
3281
3282
// add actions for other plugins
3283
- if ('1' == $this->subscribe2_options['show_meta']) {
3284
add_action('wp_meta', array(&$this, 'add_minimeta'), 0);
3285
}
3286
// Add filters for Ozh Admin Menu
@@ -3291,7 +3310,7 @@ class s2class {
3291
3292
3293
// add action to display editor buttons if option is enabled
3294
- if ('1' == $this->subscribe2_options['show_button']) {
3295
add_action('edit_page_form', array(&$this, 's2_edit_form'));
3296
add_action('edit_form_advanced', array(&$this, 's2_edit_form'));
3297
}
@@ -3302,7 +3321,7 @@ class s2class {
3302
add_action('add_user_to_blog', array(&$this, 'register'), 10, 1);
3303
3304
// add actions for processing posts based on per-post or cron email settings
3305
- if ($this->subscribe2_options['email_freq'] != 'never') {
3306
add_action('s2_digest_cron', array(&$this, 'subscribe2_cron'));
3307
} else {
3308
add_action('new_to_publish', array(&$this, 'publish'));
@@ -3311,7 +3330,7 @@ class s2class {
3311
add_action('private_to_publish', array(&$this, 'publish'));
3312
add_action('future_to_publish', array(&$this, 'publish'));
3313
add_action('publish_phone', array(&$this, 'publish_phone'));
3314
- if ($this->subscribe2_options['private'] == "yes") {
3315
add_action('new_to_private', array(&$this, 'publish'));
3316
add_action('draft_to_private', array(&$this, 'publish'));
3317
add_action('pending_to_private', array(&$this, 'publish'));
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: 5.2
7
Author: Matthew Robinson
8
Author URI: http://subscribe2.wordpress.com
9
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2387904
23
24
Subscribe2 is distributed in the hope that it will be useful,
25
but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
GNU General Public License for more details.
28
29
You should have received a copy of the GNU General Public License
30
+ along with Subscribe2. If not, see <http://www.gnu.org/licenses/>.
31
*/
32
33
// our version number. Don't touch this or any line below
34
// unless you know exacly what you are doing
35
+ define( 'S2VERSION', '5.2' );
36
+ define( 'S2PATH', trailingslashit(dirname(__FILE__)) );
37
+ define( 'S2DIR', plugin_basename(dirname(__FILE__)) );
38
39
// Set minimum execution time to 5 minutes - won't affect safe mode
40
$safe_mode = array('On', 'ON', 'on', 1);
41
+ if ( !in_array(ini_get('safe_mode'), $safe_mode) && ini_get('max_execution_time') < 300 ) {
42
@ini_set('max_execution_time', 300);
43
}
44
45
// Pre-2.6 compatibility
46
+ if ( !defined('WP_CONTENT_URL') ) {
47
+ define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' );
48
}
49
+ if ( !defined('WP_CONTENT_DIR') ) {
50
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
51
}
52
53
/* Include buttonsnap library by Owen Winckler */
54
+ if ( !class_exists('buttonsnap') ) {
55
+ require( WP_CONTENT_DIR . '/plugins/' . S2DIR . '/include/buttonsnap.php' );
56
}
57
58
$mysubscribe2 = new s2class;
113
Hook the menu
114
*/
115
function admin_menu() {
116
+ $s2management = add_management_page(__('Subscribers', 'subscribe2'), __('Subscribers', 'subscribe2'), "level_10", 's2_tools', array(&$this, 'manage_menu'));
117
add_action("admin_print_scripts-$s2management", array(&$this, 'checkbox_form_js'));
118
119
+ $s2options = add_options_page(__('Subscribe2 Options', 'subscribe2'), __('Subscribe2', 'subscribe2'), "level_10", 's2_settings', array(&$this, 'options_menu'));
120
add_action("admin_print_scripts-$s2options", array(&$this, 'checkbox_form_js'));
121
add_action("admin_print_scripts-$s2options", array(&$this, 'option_form_js'));
122
+ add_filter('plugin_row_meta', array(&$this, 'plugin_links'), 10, 2);
123
124
+ $s2user = add_users_page(__('Subscriptions', 'subscribe2'), __('Subscriptions', 'subscribe2'), "level_0", 's2_users', array(&$this, 'user_menu'));
125
add_action("admin_print_scripts-$s2user", array(&$this, 'checkbox_form_js'));
126
add_action("admin_print_styles-$s2user", array(&$this, 'user_admin_css'));
127
128
+ add_submenu_page('post-new.php', __('Mail Subscribers', 'subscribe2'), __('Mail Subscribers', 'subscribe2'), "level_2", 's2_posts', array(&$this, 'write_menu'));
129
130
$s2nonce = md5('subscribe2');
131
} // end admin_menu()
134
Hook for Admin Drop Down Icons
135
*/
136
function ozh_s2_icon() {
137
+ return WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/email_edit.png';
138
} // end ozh_s2_icon()
139
140
/**
141
Insert Javascript into admin_header
142
*/
143
function checkbox_form_js() {
144
+ wp_enqueue_script('s2_checkbox', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_checkbox.js', array('jquery'), '1.0');
145
} //end checkbox_form_js()
146
147
function user_admin_css() {
148
+ wp_enqueue_style('s2_user_admin', WP_CONTENT_URL . '/plugins/ '. S2DIR . '/include/s2_user_admin.css', array(), '1.0');
149
}
150
151
function option_form_js() {
152
+ wp_enqueue_script('s2_edit', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_edit.js', array('jquery'), '1.0');
153
} // end option_form_js()
154
155
/* ===== Install, upgrade, reset ===== */
158
*/
159
function install() {
160
// include upgrade-functions for maybe_create_table;
161
+ if ( !function_exists('maybe_create_table') ) {
162
require_once(ABSPATH . 'wp-admin/install-helper.php');
163
}
164
$date = date('Y-m-d');
181
function upgrade() {
182
global $wpdb, $wp_version, $wpmu_version;
183
// include upgrade-functions for maybe_create_table;
184
+ if ( !function_exists('maybe_create_table') ) {
185
require_once(ABSPATH . 'wp-admin/install-helper.php');
186
}
187
$date = date('Y-m-d');
191
// let's take the time to check process registered users
192
// existing public subscribers are subscribed to all categories
193
$users = $this->get_all_registered('ID');
194
+ if ( !empty($users) ) {
195
+ foreach ( $users as $user ) {
196
$this->register($user);
197
}
198
}
199
// update the options table to serialized format
200
$old_options = $wpdb->get_col("SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name != 's2_future_posts'");
201
202
+ if ( !empty($old_options) ) {
203
+ foreach ( $old_options as $option ) {
204
$value = get_option($option);
205
$option_array = substr($option, 3);
206
$this->subscribe2_options[$option_array] = $value;
213
update_option('subscribe2_options', $this->subscribe2_options);
214
215
// upgrade old wpmu user meta data to new
216
+ if ( isset($wpmu_version) || strpos($wp_version, 'wordpress-mu') ) {
217
$this->namechange_subscribe2_widget();
218
// loop through all users
219
+ foreach ( $users as $user ) {
220
// get categories which the user is subscribed to (old ones)
221
$categories = get_usermeta($user, 's2_subscribed');
222
$categories = explode(',', $categories);
223
224
// load blogs of user (only if we need them)
225
$blogs = array();
226
+ if ( count($categories) > 0 && !in_array('-1', $categories) ) {
227
$blogs = get_blogs_of_user($user, true);
228
}
229
230
+ foreach ( $blogs as $blog_id => $blog ) {
231
switch_to_blog($blog_id);
232
233
$blog_categories = (array)$wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category'");
234
$subscribed_categories = array_intersect($categories, $blog_categories);
235
+ if ( !empty($subscribed_categories) ) {
236
+ foreach ( $subscribed_categories as $subscribed_category ) {
237
update_usermeta($user, $this->get_usermeta_keyname('s2_cat') . $subscribed_category, $subscribed_category);
238
}
239
update_usermeta($user, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $subscribed_categories));
243
244
// delete old user meta keys
245
delete_usermeta($user, 's2_subscribed');
246
+ foreach ( $categories as $cat ) {
247
delete_usermeta($user, 's2_cat' . $cat);
248
}
249
}
266
Performs string substitutions for subscribe2 mail texts
267
*/
268
function substitute($string = '') {
269
+ if ( '' == $string ) {
270
return;
271
}
272
$string = str_replace("BLOGNAME", get_option('blogname'), $string);
273
$string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
274
$string = str_replace("TITLE", stripslashes($this->post_title), $string);
275
+ $link = "<a href=\"" . $this->permalink . "\">" . $this->permalink . "</a>";
276
+ $string = str_replace("PERMALINK", $link, $string);
277
+ if ( strstr($string, "TINYLINK") ) {
278
$tinylink = file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode($this->permalink));
279
+ if ( $tinylink !== 'Error' || $tinylink != false ) {
280
+ $tlink = "<a href=\"" . $tinylink . "\">" . $tinylink . "</a>";
281
+ $string = str_replace("TINYLINK", $tlink, $string);
282
} else {
283
+ $string = str_replace("TINYLINK", $link, $string);
284
}
285
}
286
$string = str_replace("MYNAME", stripslashes($this->myname), $string);
287
$string = str_replace("EMAIL", $this->myemail, $string);
288
$string = str_replace("AUTHORNAME", $this->authorname, $string);
296
Delivers email to recipients in HTML or plaintext
297
*/
298
function mail($recipients = array(), $subject = '', $message = '', $type='text') {
299
+ if ( empty($recipients) || '' == $message ) { return; }
300
301
+ if ( 'html' == $type ) {
302
$headers = $this->headers('html');
303
+ if ( 'yes' == $this->subscribe2_options['stylesheet'] ) {
304
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title><link rel=\"stylesheet\" href=\"" . get_bloginfo('stylesheet_url') . "\" type=\"text/css\" media=\"screen\" /></head><body>" . $message . "</body></html>");
305
} else {
306
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>");
319
// Construct BCC headers for sending or send individual emails
320
$bcc = '';
321
natcasesort($recipients);
322
+ if ( function_exists('wpmq_mail') || $this->subscribe2_options['bcclimit'] == 1 ) {
323
// BCCLimit is 1 so send individual emails
324
+ foreach ( $recipients as $recipient ) {
325
$recipient = trim($recipient);
326
// sanity check -- make sure we have a valid email
327
+ if ( !is_email($recipient) ) { continue; }
328
+ if ( function_exists('wpmq_mail') ) {
329
@wp_mail($recipient, $subject, $mailtext, $headers, NULL, 0);
330
} else {
331
@wp_mail($recipient, $subject, $mailtext, $headers);
332
}
333
}
334
+ return;
335
+ } elseif ( $this->subscribe2_options['bcclimit'] == 0 ) {
336
// we're not using BCCLimit
337
+ foreach ( $recipients as $recipient ) {
338
$recipient = trim($recipient);
339
// sanity check -- make sure we have a valid email
340
+ if ( !is_email($recipient) ) { continue; }
341
// and NOT the sender's email, since they'll get a copy anyway
342
+ if ( !empty($recipient) && $this->myemail != $recipient ) {
343
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
344
// Bcc Headers now constructed by phpmailer class
345
}
349
// we're using BCCLimit
350
$count = 1;
351
$batch = array();
352
+ foreach ( $recipients as $recipient ) {
353
$recipient = trim($recipient);
354
// sanity check -- make sure we have a valid email
355
+ if ( !is_email($recipient) ) { continue; }
356
// and NOT the sender's email, since they'll get a copy anyway
357
+ if ( !empty($recipient) && $this->myemail != $recipient ) {
358
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
359
// Bcc Headers now constructed by phpmailer class
360
}
361
+ if ( $this->subscribe2_options['bcclimit'] == $count ) {
362
$count = 0;
363
$batch[] = $bcc;
364
$bcc = '';
366
$count++;
367
}
368
// add any partially completed batches to our batch array
369
+ if ( '' != $bcc ) {
370
$batch[] = $bcc;
371
}
372
}
374
reset($recipients);
375
376
// actually send mail
377
+ if ( isset($batch) && !empty($batch) ) {
378
+ foreach ( $batch as $bcc ) {
379
$newheaders = $headers . "$bcc\r\n";
380
$status = @wp_mail($this->myemail, $subject, $mailtext, $newheaders);
381
}
390
Construct standard set of email headers
391
*/
392
function headers($type='text') {
393
+ if ( empty($this->myname) || empty($this->myemail) ) {
394
$admin = $this->get_userdata($this->subscribe2_options['sender']);
395
$this->myname = html_entity_decode($admin->display_name, ENT_QUOTES);
396
$this->myemail = $admin->user_email;
402
$headers .= "Precedence: list\nList-Id: " . get_option('blogname') . "\n";
403
$headers .= "MIME-Version: 1.0\n";
404
$headers .= "X-Mailer: PHP" . phpversion() . "\n";
405
+ if ( $type == 'html' ) {
406
// To send HTML mail, the Content-Type header must be set
407
$headers .= "Content-Type: " . get_bloginfo('html_type') . "; charset=\"". get_bloginfo('charset') . "\"\n";
408
} else {
416
Sends an email notification of a new post