Subscribe2 - Version 6.1

Version Description

Download this release

Release Info

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

Code changes from version 6.0 to 6.1

Files changed (4) hide show
  1. ReadMe.txt +32 -6
  2. include/widget.php +42 -16
  3. subscribe2.php +3737 -3701
  4. subscribe2.pot +227 -210
ReadMe.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_butt
4
Tags: posts, subscription, email, subscribe, notify, notification
5
Requires at least: 2.8
6
Tested up to: 3.0.1
7
- Stable tag: 6.0
8
9
Sends a list of subscribers an email notification when new posts are published to your blog
10
@@ -32,8 +32,8 @@ If you want to send HTML emails to Public Subscribers too then upgrade to [Subsc
32
4. Configure the options to taste, including the email template and any categories which should be excluded from notification
33
5. Click the "Tools" admin menu link, and select "Subscribers".
34
6. Manually subscribe people as you see fit.
35
- 7. Create a [WordPress Page](http://codex.wordpress.org/Pages) to display the subscription form. When creating the page, you may click the "S2" button on the QuickBar to automatically insert the subscribe2 token. Or, if you prefer, you may manually insert the subscribe2 token:
36
- <!--subscribe2-->
37
***Ensure the token is on a line by itself and that it has a blank line above and below.***
38
This token will automatically be replaced by dynamic subscription information and will display all forms and messages as necessary.
39
8. In the WordPress "Settings" area for Subscribe2 select the page name in the "Appearance" section that of the WordPress page created in step 7.
@@ -115,9 +115,25 @@ The simple answer is yes you can but this is not supported so you need to figure
115
116
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.
117
118
- = I can't find or insert the Subscribe2 token, help! =
119
120
- 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-->.
121
122
= My digest email didn't send, how can I resend it? =
123
@@ -144,7 +160,7 @@ WordPress 2.0.x requires Subscribe2 from the 2.x stable branch. The most recent
144
= Why doesn't the form appear in my WordPress page? =
145
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.
146
147
- 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.
148
149
== Screenshots ==
150
@@ -155,6 +171,16 @@ Secondly, make sure that the token (<!--subscribe2-->) is correctly entered in y
155
156
== Changelog ==
157
158
= Version 6.0 by Matthew Robinson =
159
160
* Improved case sensitive SQL queries to avoid issues on some server configurations
4
Tags: posts, subscription, email, subscribe, notify, notification
5
Requires at least: 2.8
6
Tested up to: 3.0.1
7
+ Stable tag: 6.1
8
9
Sends a list of subscribers an email notification when new posts are published to your blog
10
32
4. Configure the options to taste, including the email template and any categories which should be excluded from notification
33
5. Click the "Tools" admin menu link, and select "Subscribers".
34
6. Manually subscribe people as you see fit.
35
+ 7. Create a [WordPress Page](http://codex.wordpress.org/Pages) to display the subscription form. When creating the page, you may click the "S2" button on the QuickBar to automatically insert the subscribe2 token. Or, if you prefer, you may manually insert the subscribe2 shortcode or token:
36
+ [subscribe2] or the HTML invisible <!--subscribe2-->
37
***Ensure the token is on a line by itself and that it has a blank line above and below.***
38
This token will automatically be replaced by dynamic subscription information and will display all forms and messages as necessary.
39
8. In the WordPress "Settings" area for Subscribe2 select the page name in the "Appearance" section that of the WordPress page created in step 7.
115
116
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.
117
118
+ = How do I use the Subscribe2 shortcode? =
119
120
+ In version 6.1 of Subscribe2 the new standard WordPress shortcode [subscribe2] was introduced. By default, it behaves same as old Subscribe2 token, <--subscribe2-->, which means that it will show the same Subscribe2 output in your chosen page in WordPress or in the Widget.
121
+
122
+ But it also has advanced options, which are related to form. The default form contains two buttons for subscribing and unsubscribing. You may, for example, only want form that handles unsubscribing, so the shortcode accepts a **hide** parameter to hide one of the buttons.
123
+
124
+ If you use the shortcode [subscribe2 hide="subscribe"] then the button for subscribing will be hidden and similarly if you use [subscribe2 hide="unsubscribe"], only button for subscribing will be shown.
125
+
126
+ The new shortcode also accepts two further attributes, these are **id** and **url**. To understand these parameters you need to understand that Subscribe2 returns a user to the default WordPress Page on your site where you use the shortcode or token however in some circumstances you may ant to override this behaviour. If you specify a WordPress page id using the id parameter or a full URL using the url parameter then the user would be returned to the alternative page.
127
+
128
+ There are many scenarios in which to use new options, but here is an example:
129
+
130
+ * Two separate WordPress pages, �Subscribe� that shows only Subscribe button, and �Unsubscibe�, that shows only Unsubscibe button. Both pages also have text that should help users in use of form.
131
+ * In the widget, show only Subscribe button and post form content to page �Subcribe�
132
+ * In the Subscribe2 email template for new post, add text �You can unsubscribe on a following page:� which is followed with link to �Unsubscribe� page
133
+
134
+ = I can't find or insert the Subscribe2 token or shortcode, help! =
135
+
136
+ 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] or <!--subscribe2-->.
137
138
= My digest email didn't send, how can I resend it? =
139
160
= Why doesn't the form appear in my WordPress page? =
161
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.
162
163
+ Secondly, make sure that the token ([subscribe2] or <!--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.
164
165
== Screenshots ==
166
171
172
== Changelog ==
173
174
+ = Version 6.1 by Matthew Robinson =
175
+
176
+ * Fixed a glitch in the HTML tags in the Subscribe2 Widget that affected drag and drop functions in WordPress - thanks to Marty McOmber
177
+ * Improved detection of Multisite installs - thanks to Nada Oneal
178
+ * Fixed precontent and postcontent in the Widget to retain entered HTML tags - reported by Rob Saxe
179
+ * Fixed a few small typos in the inline code comments and email subjects
180
+ * Fixed a bug where Bulk Management changes to move all users to Plain Text Full content would result in blank settings - reported by Sean @ GetSatisfaction
181
+ * Fixed issued with TIME and AUTHORNAME keywords in digest emails - thanks to Robert @ GetSatisfaction
182
+ * Introduced a more flexible Subscribe2 shortcode - thanks to Milan for the patch code
183
+
184
= Version 6.0 by Matthew Robinson =
185
186
* Improved case sensitive SQL queries to avoid issues on some server configurations
include/widget.php CHANGED
@@ -18,11 +18,19 @@ class S2_Form_widget extends WP_Widget {
18
$div = empty($instance['div']) ? 'search' : $instance['div'];
19
$widgetprecontent = empty($instance['widgetprecontent']) ? '' : $instance['widgetprecontent'];
20
$widgetpostcontent = empty($instance['widgetpostcontent']) ? '' : $instance['widgetpostcontent'];
21
echo $before_widget;
22
echo $before_title . $title . $after_title;
23
echo "<div class=\"" . $div . "\">";
24
- global $mysubscribe2;
25
- $content = $mysubscribe2->filter('<!--subscribe2-->');
26
if ( !empty($widgetprecontent) ) {
27
echo $widgetprecontent;
28
}
@@ -41,8 +49,10 @@ class S2_Form_widget extends WP_Widget {
41
$instance = $old_instance;
42
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
43
$instance['div'] = strip_tags(stripslashes($new_instance['div']));
44
- $instance['widgetprecontent'] = strip_tags(stripslashes($new_instance['widgetprecontent']));
45
- $instance['widgetpostcontent'] = strip_tags(stripslashes($new_instance['widgetpostcontent']));
46
47
return $instance;
48
}
@@ -54,9 +64,9 @@ class S2_Form_widget extends WP_Widget {
54
// set some defaults, getting any old options first
55
$options = get_option('widget_subscribe2widget');
56
if ( $options === false ) {
57
- $defaults = array('title' => 'Subscribe2', 'div' => 'search', 'widgetprecontent' => '', 'widgetpostcontent' => '');
58
} else {
59
- $defaults = array('title' => $options['title'], 'div' => $options['div'], 'widgetprecontent' => $options['widgetprecontent'], 'widgetpostcontent' => $options['widgetpostcontent']);
60
delete_option('widget_subscribe2widget');
61
}
62
// code to obtain old settings too
@@ -66,17 +76,33 @@ class S2_Form_widget extends WP_Widget {
66
$div= htmlspecialchars($instance['div'], ENT_QUOTES);
67
$widgetprecontent = htmlspecialchars($instance['widgetprecontent'], ENT_QUOTES);
68
$widgetpostcontent = htmlspecialchars($instance['widgetpostcontent'], ENT_QUOTES);
69
70
- echo "<div\r\n";
71
- echo "<p><label for=\"" . $this->get_field_name('title') . "\">" . __('Title', 'subscribe2') . ":";
72
- echo "<input class=\"widefat\" id=\"" . $this->get_field_id('title') . "\" name=\"" . $this->get_field_name('title') . "\" type=\"text\" value=\"" . $title . "\" /></label></p>";
73
- echo "<p><label for=\"" . $this->get_field_name('div') . "\">" . __('Div class name', 'subscribe2') . ":";
74
- echo "<input class=\"widefat\" id=\"" . $this->get_field_id('div') . "\" name=\"" . $this->get_field_name('div') . "\" type=\"text\" value=\"" . $div . "\" /></label></p>";
75
- echo "<p><label for=\"" . $this->get_field_name('widgetprecontent') . "\">" . __('Pre-Content', 'subscribe2') . ":";
76
- echo "<input class=\"widefat\" id=\"" . $this->get_field_name('widgetprecontent') . "\" name=\"" . $this->get_field_name('widgetprecontent') . "\" type=\"text\" value=\"" . $widgetprecontent . "\" /></label></p>";
77
- echo "<p><label for=\"" . $this->get_field_name('widgetpostcontent') . "\">" . __('Post-Content', 'subscribe2') . ":";
78
- echo "<input class=\"widefat\" id=\"" . $this->get_field_id('widgetpostcontent') . "\" name=\"" . $this->get_field_name('widgetpostcontent') . "\" type=\"text\" value=\"" . $widgetpostcontent . "\" /></label></p>";
79
- echo "</div\r\n";
80
}
81
} // End S2_Form_widget class
82
?>
18
$div = empty($instance['div']) ? 'search' : $instance['div'];
19
$widgetprecontent = empty($instance['widgetprecontent']) ? '' : $instance['widgetprecontent'];
20
$widgetpostcontent = empty($instance['widgetpostcontent']) ? '' : $instance['widgetpostcontent'];
21
+ $hidebutton = empty($instance['hidebutton']) ? 'none' : $instance['hidebutton'];
22
+ $postto = empty($instance['postto']) ? '' : $instance['postto'];
23
+ if ( $hidebutton == 'subscribe' || $hidebutton == 'unsubscribe' ) {
24
+ $hide = " hide=\"" . $hidebutton . "\"";
25
+ }
26
+ if ( $postto ) {
27
+ $postid = " id=\"" . $postto . "\"";
28
+ }
29
+ $shortcode = "[subscribe2" . $hide . $postid . "]";
30
echo $before_widget;
31
echo $before_title . $title . $after_title;
32
echo "<div class=\"" . $div . "\">";
33
+ $content = do_shortcode( $shortcode );
34
if ( !empty($widgetprecontent) ) {
35
echo $widgetprecontent;
36
}
49
$instance = $old_instance;
50
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
51
$instance['div'] = strip_tags(stripslashes($new_instance['div']));
52
+ $instance['widgetprecontent'] = stripslashes($new_instance['widgetprecontent']);
53
+ $instance['widgetpostcontent'] = stripslashes($new_instance['widgetpostcontent']);
54
+ $instance['hidebutton'] = strip_tags(stripslashes($new_instance['hidebutton']));
55
+ $instance['postto'] = stripslashes($new_instance['postto']);
56
57
return $instance;
58
}
64
// set some defaults, getting any old options first
65
$options = get_option('widget_subscribe2widget');
66
if ( $options === false ) {
67
+ $defaults = array('title' => 'Subscribe2', 'div' => 'search', 'widgetprecontent' => '', 'widgetpostcontent' => '', 'hidebutton' => 'none', 'postto' => '');
68
} else {
69
+ $defaults = array('title' => $options['title'], 'div' => $options['div'], 'widgetprecontent' => $options['widgetprecontent'], 'widgetpostcontent' => $options['widgetpostcontent'], 'hidebutton' => $options['hidebutton'], 'postto' => $options['postto']);
70
delete_option('widget_subscribe2widget');
71
}
72
// code to obtain old settings too
76
$div= htmlspecialchars($instance['div'], ENT_QUOTES);
77
$widgetprecontent = htmlspecialchars($instance['widgetprecontent'], ENT_QUOTES);
78
$widgetpostcontent = htmlspecialchars($instance['widgetpostcontent'], ENT_QUOTES);
79
+ $hidebutton = htmlspecialchars($instance['hidebutton'], ENT_QUOTES);
80
+ $postto = htmlspecialchars($instance['postto'], ENT_QUOTES);
81
82
+ global $wpdb;
83
+ $sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish'";
84
+ $pages = $wpdb->get_results($sql);
85
+
86
+ echo "<div>\r\n";
87
+ echo "<p><label for=\"" . $this->get_field_name('title') . "\">" . __('Title', 'subscribe2') . ":\r\n";
88
+ echo "<input class=\"widefat\" id=\"" . $this->get_field_id('title') . "\" name=\"" . $this->get_field_name('title') . "\" type=\"text\" value=\"" . $title . "\" /></label></p>\r\n";
89
+ echo "<p><label for=\"" . $this->get_field_name('div') . "\">" . __('Div class name', 'subscribe2') . ":\r\n";
90
+ echo "<input class=\"widefat\" id=\"" . $this->get_field_id('div') . "\" name=\"" . $this->get_field_name('div') . "\" type=\"text\" value=\"" . $div . "\" /></label></p>\r\n";
91
+ echo "<p><label for=\"" . $this->get_field_name('widgetprecontent') . "\">" . __('Pre-Content', 'subscribe2') . ":\r\n";
92
+ echo "<textarea class=\"widefat\" id=\"" . $this->get_field_name('widgetprecontent') . "\" name=\"" . $this->get_field_name('widgetprecontent') . "\" rows=\"2\" cols=\"25\">" . $widgetprecontent . "</textarea></label></p>\r\n";
93
+ echo "<p><label for=\"" . $this->get_field_name('widgetpostcontent') . "\">" . __('Post-Content', 'subscribe2') . ":\r\n";
94
+ echo "<textarea class=\"widefat\" id=\"" . $this->get_field_id('widgetpostcontent') . "\" name=\"" . $this->get_field_name('widgetpostcontent') . "\" rows=\"2\" cols=\"25\">" . $widgetpostcontent . "</textarea></label></p>\r\n";
95
+ echo "<p><label for=\"" . $this->get_field_name('hidebutton') . "\">" . __('Hide button', 'subscribe2') . ":<br />\r\n";
96
+ echo "<input name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"none\"". checked('none', $hidebutton, false) . "/>" . __('None', 'subscribe2') . "<br /><input name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"subscribe\"". checked('subscribe', $hidebutton, false) . "/>" . __('Subscribe', 'subscribe2') . "<br /><input name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"unsubscribe\"". checked('unsubscribe', $hidebutton, false) . "/>" . __('Unsubscribe', 'subscribe2') . "</label></p>\r\n";
97
+ if ( !empty($pages) ) {
98
+ echo "<p><label for=\"" . $this->get_field_name('postto') . "\">" . __('Post form content to page', 'subscribe2') . ":\r\n";
99
+ echo "<select id=\"" . $this->get_field_id('postto') . "\" name=\"" . $this->get_field_name('postto') . "\">\r\n";
100
+ echo "<option value=\"\">" . __('Use Subscribe2 Default', 'subscribe2') . "</option>\r\n";
101
+ global $mysubscribe2;
102
+ $mysubscribe2->pages_dropdown($postto);
103
+ echo "</select></label></p>\r\n";
104
+ }
105
+ echo "</div>\r\n";
106
}
107
} // End S2_Form_widget class
108
?>
subscribe2.php CHANGED
@@ -1,3702 +1,3738 @@
1
- <?php
2
- /*
3
- Plugin Name: Subscribe2
4
- Plugin URI: http://subscribe2.wordpress.com
5
- Description: Notifies an email list when new entries are posted.
6
- Version: 6.0
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
10
- */
11
-
12
- /*
13
- Copyright (C) 2006-10 Matthew Robinson
14
- Based on the Original Subscribe2 plugin by
15
- Copyright (C) 2005 Scott Merrill (skippy@skippy.net)
16
-
17
- This file is part of Subscribe2.
18
-
19
- Subscribe2 is free software: you can redistribute it and/or modify
20
- it under the terms of the GNU General Public License as published by
21
- the Free Software Foundation, either version 3 of the License, or
22
- (at your option) any later version.
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', '6.0' );
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
- /* Include buttonsnap library by Owen Winckler */
46
- if ( !class_exists('buttonsnap') ) {
47
- require( WP_CONTENT_DIR . '/plugins/' . S2DIR . '/include/buttonsnap.php' );
48
- }
49
-
50
- $mysubscribe2 = new s2class;
51
- $mysubscribe2->s2init();
52
-
53
- // start our class
54
- class s2class {
55
- // variables and constructor are declared at the end
56
-
57
- /**
58
- Load all our strings
59
- */
60
- function load_strings() {
61
- // adjust the output of Subscribe2 here
62
-
63
- $this->please_log_in = "<p>" . __('To manage your subscription options please', 'subscribe2') . " <a href=\"" . get_option('siteurl') . "/wp-login.php\">" . __('login', 'subscribe2') . "</a>.</p>";
64
-
65
- $this->use_profile_admin = "<p>" . __('You may manage your subscription options from your', 'subscribe2') . " <a href=\"" . get_option('siteurl') . "/wp-admin/users.php?page=s2_users\">" . __('profile', 'subscribe2') . "</a>.</p>";
66
- if ( $this->s2_mu === true) {
67
- global $blog_id, $user_ID;
68
- if ( !is_blog_user($blog_id) ) {
69
- // if we are on multisite and the user is not a member of this blog change the link
70
- $this->use_profile_admin = "<p><a href=\"" . get_option('siteurl') . "/wp-admin/?s2mu_subscribe=" . $blog_id . "\">" . __('Subscribe', 'subscribe2') . "</a>" . __('to email notifications when this blog posts new content', 'subscribe2') . ".</p>";
71
- }
72
- }
73
-
74
- $this->use_profile_users = "<p>" . __('You may manage your subscription options from your', 'subscribe2') . " <a href=\"" . get_option('siteurl') . "/wp-admin/profile.php?page=s2_users\">" . __('profile', 'subscribe2') . "</a>.</p>";
75
- if ( $this->s2_mu === true) {
76
- global $blog_id, $user_ID;
77
- if ( !is_blog_user($blog_id) ) {
78
- // if we are on multisite and the user is not a member of this blog change the link
79
- $this->use_profile_users = "<p><a href=\"" . get_option('siteurl') . "/wp-admin/?s2mu_subscribe=" . $blog_id . "\">" . __('Subscribe', 'subscribe2') . "</a>" . __('to email notifications when this blog posts new content', 'subscribe2') . ".</p>";
80
- }
81
- }
82
-
83
- $this->confirmation_sent = "<p>" . __('A confirmation message is on its way!', 'subscribe2') . "</p>";
84
-
85
- $this->already_subscribed = "<p>" . __('That email address is already subscribed.', 'subscribe2') . "</p>";
86
-
87
- $this->not_subscribed = "<p>" . __('That email address is not subscribed.', 'subscribe2') . "</p>";
88
-
89
- $this->not_an_email = "<p>" . __('Sorry, but that does not look like an email address to me.', 'subscribe2') . "</p>";
90
-
91
- $this->barred_domain = "<p>" . __('Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2') . "</p>";
92
-
93
- $this->error = "<p>" . __('Sorry, there seems to be an error on the server. Please try again later.', 'subscribe2') . "</p>";
94
-
95
- $this->no_page = "<p>" . __('You must to create a WordPress page for this plugin to work correctly.', 'subscribe2') . "<p>";
96
-
97
- $this->mail_sent = "<p>" . __('Message sent!', 'subscribe2') . "</p>";
98
-
99
- $this->mail_failed = "<p>" . __('Message failed! Check your settings and check with your hosting provider', 'subscribe2') . "</p>";
100
-
101
- $this->form = "<form method=\"post\" action=\"\"><input type=\"hidden\" name=\"ip\" value=\"" . $_SERVER['REMOTE_ADDR'] . "\" /><p>" . __('Your email:', 'subscribe2') . "<br /><input type=\"text\" name=\"email\" value=\"" . __('Enter email address...', 'subscribe2') . "\" size=\"20\" onfocus=\"if (this.value == '" . __('Enter email address...', 'subscribe2') . "') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = '" . __('Enter email address...', 'subscribe2') . "';}\" /></p><p><input type=\"submit\" name=\"subscribe\" value=\"" . __('Subscribe', 'subscribe2') . "\" />&nbsp;<input type=\"submit\" name=\"unsubscribe\" value=\"" . __('Unsubscribe', 'subscribe2') . "\" /></p></form>\r\n";
102
-
103
- // confirmation messages
104
- $this->no_such_email = "<p>" . __('No such email address is registered.', 'subscribe2') . "</p>";
105
-
106
- $this->added = "<p>" . __('You have successfully subscribed!', 'subscribe2') . "</p>";
107
-
108
- $this->deleted = "<p>" . __('You have successfully unsubscribed.', 'subscribe2') . "</p>";
109
-
110
- $this->subscribe = __('subscribe', 'subscribe2'); //ACTION replacement in subscribing confirmation email
111
-
112
- $this->unsubscribe = __('unsubscribe', 'subscribe2'); //ACTION replacement in unsubscribing in confirmation email
113
-
114
- // menu strings
115
- $this->options_saved = __('Options saved!', 'subscribe2');
116
- $this->options_reset = __('Options reset!', 'subscribe2');
117
- } // end load_strings()
118
-
119
- /* ===== WordPress menu registration and scripts ===== */
120
- /**
121
- Hook the menu
122
- */
123
- function admin_menu() {
124
- $s2management = add_management_page(__('Subscribers', 'subscribe2'), __('Subscribers', 'subscribe2'), "manage_options", 's2_tools', array(&$this, 'manage_menu'));
125
- add_action("admin_print_scripts-$s2management", array(&$this, 'checkbox_form_js'));
126
-
127
- $s2options = add_options_page(__('Subscribe2 Options', 'subscribe2'), __('Subscribe2', 'subscribe2'), "manage_options", 's2_settings', array(&$this, 'options_menu'));
128
- add_action("admin_print_scripts-$s2options", array(&$this, 'checkbox_form_js'));
129
- add_action("admin_print_scripts-$s2options", array(&$this, 'option_form_js'));
130
- add_filter('plugin_row_meta', array(&$this, 'plugin_links'), 10, 2);
131
-
132
- $s2user = add_users_page(__('Your Subscriptions', 'subscribe2'), __('Your Subscriptions', 'subscribe2'), "read", 's2_users', array(&$this, 'user_menu'));
133
- add_action("admin_print_scripts-$s2user", array(&$this, 'checkbox_form_js'));
134
- add_action("admin_print_styles-$s2user", array(&$this, 'user_admin_css'));
135
-
136
- add_submenu_page('post-new.php', __('Mail Subscribers', 'subscribe2'), __('Mail Subscribers', 'subscribe2'), "publish_posts", 's2_posts', array(&$this, 'write_menu'));
137
-
138
- $s2nonce = md5('subscribe2');
139
- } // end admin_menu()
140
-
141
- /**
142
- Hook for Admin Drop Down Icons
143
- */
144
- function ozh_s2_icon() {
145
- return WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/email_edit.png';
146
- } // end ozh_s2_icon()
147
-
148
- /**
149
- Insert Javascript into admin_header
150
- */
151
- function checkbox_form_js() {
152
- wp_enqueue_script('s2_checkbox', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_checkbox.js', array('jquery'), '1.0');
153
- } //end checkbox_form_js()
154
-
155
- function user_admin_css() {
156
- wp_enqueue_style('s2_user_admin', WP_CONTENT_URL . '/plugins/ '. S2DIR . '/include/s2_user_admin.css', array(), '1.0');
157
- }
158
-
159
- function option_form_js() {
160
- wp_enqueue_script('s2_edit', WP_CONTENT_URL . '/plugins/' . S2DIR . '/include/s2_edit.js', array('jquery'), '1.0');
161
- } // end option_form_js()
162
-
163
- /* ===== Install, upgrade, reset ===== */
164
- /**
165
- Install our table
166
- */
167
- function install() {
168
- // include upgrade-functions for maybe_create_table;
169
- if ( !function_exists('maybe_create_table') ) {
170
- require_once(ABSPATH . 'wp-admin/install-helper.php');
171
- }
172
- $date = date('Y-m-d');
173
- $sql = "CREATE TABLE $this->public (
174
- id int(11) NOT NULL auto_increment,
175
- email varchar(64) NOT NULL default '',
176
- active tinyint(1) default 0,
177
- date DATE default '$date' NOT NULL,
178
- ip char(64) NOT NULL default 'admin',
179
- PRIMARY KEY (id) )";
180
-
181
- // create the table, as needed
182
- maybe_create_table($this->public, $sql);
183
-
184
- // safety check if options exist and if not create them
185
- if ( !is_array($this->subscribe2_options) ) {
186
- $this->reset();
187
- }
188
- } // end install()
189
-
190
- /**
191
- Upgrade the database
192
- */
193
- function upgrade() {
194
- global $wpdb, $wp_version, $wpmu_version;
195
- // include upgrade-functions for maybe_add_column;
196
- if ( !function_exists('maybe_add_column') ) {
197
- require_once(ABSPATH . 'wp-admin/install-helper.php');
198
- }
199
- $date = date('Y-m-d');
200
- maybe_add_column($this->public, 'date', "ALTER TABLE $this->public ADD date DATE DEFAULT '$date' NOT NULL AFTER active;");
201
- maybe_add_column($this->public, 'ip', "ALTER TABLE $this->public ADD ip char(64) DEFAULT 'admin' NOT NULL AFTER date;");
202
-
203
- // let's take the time to check process registered users
204
- // existing public subscribers are subscribed to all categories
205
- $users = $this->get_all_registered('ID');
206
- if ( !empty($users) ) {
207
- foreach ( $users as $user ) {
208
- $this->register($user);
209
- }
210
- }
211
- // update the options table to serialized format
212
- $old_options = $wpdb->get_col("SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name != 's2_future_posts'");
213
-
214
- if ( !empty($old_options) ) {
215
- foreach ( $old_options as $option ) {
216
- $value = get_option($option);
217
- $option_array = substr($option, 3);
218
- $this->subscribe2_options[$option_array] = $value;
219
- delete_option($option);
220
- }
221
- }
222
- $this->subscribe2_options['version'] = S2VERSION;
223
- // ensure that the options are in the database
224
- require(S2PATH . "include/options.php");
225
- // correct autoformat to upgrade from pre 5.6
226
- if ( $this->subscribe2_options['autoformat'] == 'text' ) {
227
- $this->subscribe2_options['autoformat'] = 'excerpt';
228
- }
229
- if ( $this->subscribe2_options['autoformat'] == 'full' ) {
230
- $this->subscribe2_options['autoformat'] = 'post';
231
- }
232
- update_option('subscribe2_options', $this->subscribe2_options);
233
-
234
- // upgrade old wpmu user meta data to new
235
- if ( $this->s2_mu === true ) {
236
- $this->namechange_subscribe2_widget();
237
- // loop through all users
238
- foreach ( $users as $user ) {
239
- // get categories which the user is subscribed to (old ones)
240
- $categories = get_usermeta($user, 's2_subscribed');
241
- $categories = explode(',', $categories);
242
-
243
- // load blogs of user (only if we need them)
244
- $blogs = array();
245
- if ( count($categories) > 0 && !in_array('-1', $categories) ) {
246
- $blogs = get_blogs_of_user($user, true);
247
- }
248
-
249
- foreach ( $blogs as $blog_id => $blog ) {
250
- switch_to_blog($blog_id);
251
-
252
- $blog_categories = (array)$wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category'");
253
- $subscribed_categories = array_intersect($categories, $blog_categories);
254
- if ( !empty($subscribed_categories) ) {
255
- foreach ( $subscribed_categories as $subscribed_category ) {
256
- update_usermeta($user, $this->get_usermeta_keyname('s2_cat') . $subscribed_category, $subscribed_category);
257
- }
258
- update_usermeta($user, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $subscribed_categories));
259
- }
260
- restore_current_blog();
261
- }
262
-
263
- // delete old user meta keys
264
- delete_usermeta($user, 's2_subscribed');
265
- foreach ( $categories as $cat ) {
266
- delete_usermeta($user, 's2_cat' . $cat);
267
- }
268
- }
269
- }
270
-
271
- // ensure existing public subscriber emails are all sanitized
272
- $confirmed = $this->get_public();
273
- $unconfirmed = $this->get_public(0);
274
- $public_subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
275
-
276
- foreach ( $public_subscribers as $email ) {
277
- $new_email = $this->sanitize_email($email);
278
- if ( $email !== $new_email ) {
279
- $wpdb->get_results("UPDATE $this->public SET email='$new_email' WHERE CAST(email as binary)='$email'");
280
- }
281
- }
282
- } // end upgrade()
283
-
284
- /**
285
- Reset our options
286
- */
287
- function reset() {
288
- delete_option('subscribe2_options');
289
- wp_clear_scheduled_hook('s2_digest_cron');
290
- unset($this->subscribe2_options);
291
- require(S2PATH . "include/options.php");
292
- update_option('subscribe2_options', $this->subscribe2_options);
293
- } // end reset()
294
-
295
- /* ===== mail handling ===== */
296
- /**
297
- Performs string substitutions for subscribe2 mail texts
298
- */
299
- function substitute($string = '') {
300
- if ( '' == $string ) {
301
- return;
302
- }
303
- $string = str_replace("BLOGNAME", html_entity_decode(get_option('blogname'), ENT_QUOTES), $string);
304
- $string = str_replace("BLOGLINK", get_option('home'), $string);
305
- $string = str_replace("TITLE", stripslashes($this->post_title), $string);
306
- $link = "<a href=\"" . $this->permalink . "\">" . $this->permalink . "</a>";
307
- $string = str_replace("PERMALINK", $link, $string);
308
- if ( strstr($string, "TINYLINK") ) {
309
- $tinylink = file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode($this->permalink));
310
- if ( $tinylink !== 'Error' || $tinylink != false ) {
311
- $tlink = "<a href=\"" . $tinylink . "\">" . $tinylink . "</a>";
312
- $string = str_replace("TINYLINK", $tlink, $string);
313
- } else {
314
- $string = str_replace("TINYLINK", $link, $string);
315
- }
316
- }
317
- $string = str_replace("DATE", $this->post_date, $string);
318
- $string = str_replace("TIME", $this->post_time, $string);
319
- $string = str_replace("MYNAME", stripslashes($this->myname), $string);
320
- $string = str_replace("EMAIL", $this->myemail, $string);
321
- $string = str_replace("AUTHORNAME", stripslashes($this->authorname), $string);
322
- $string = str_replace("CATS", $this->post_cat_names, $string);
323
- $string = str_replace("TAGS", $this->post_tag_names, $string);
324
- $string = str_replace("COUNT", $this->post_count, $string);
325
-
326
- return $string;
327
- } // end substitute()
328
-
329
- /**
330
- Delivers email to recipients in HTML or plaintext
331
- */
332
- function mail($recipients = array(), $subject = '', $message = '', $type='text') {
333
- if ( empty($recipients) || '' == $message ) { return; }
334
-
335
- if ( 'html' == $type ) {
336
- $headers = $this->headers('html');
337
- if ( 'yes' == $this->subscribe2_options['stylesheet'] ) {
338
- $mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title><link rel=\"stylesheet\" href=\"" . get_stylesheet_uri() . "\" type=\"text/css\" media=\"screen\" /></head><body>" . $message . "</body></html>");
339
- } else {
340
- $mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>");
341
- }
342
- } else {
343
- $headers = $this->headers();
344
- $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message);
345
- $message = preg_replace('|&amp;|', '&', $message);
346
- $message = wordwrap(strip_tags($message), 80, "\n");
347
- $mailtext = apply_filters('s2_plain_email', $message);
348
- }
349
-
350
- // Replace any escaped html symbols in subject
351
- $subject = html_entity_decode($subject, ENT_QUOTES);
352
-
353
- // Construct BCC headers for sending or send individual emails
354
- $bcc = '';
355
- natcasesort($recipients);
356
- if ( function_exists('wpmq_mail') || $this->subscribe2_options['bcclimit'] == 1 ) {
357
- // BCCLimit is 1 so send individual emails
358
- foreach ( $recipients as $recipient ) {
359
- $recipient = trim($recipient);
360
- // sanity check -- make sure we have a valid email
361
- if ( !is_email($recipient) || empty($recipient) ) { continue; }
362
- // Use the mail queue provided we are not sending a preview
363
- if ( function_exists('wpmq_mail') && !$this->preview_email ) {
364
- @wp_mail($recipient, $subject, $mailtext, $headers, '', 0);
365
- } else {
366
- @wp_mail($recipient, $subject, $mailtext, $headers);
367
- }
368
- }
369
- return true;
370
- } elseif ( $this->subscribe2_options['bcclimit'] == 0 ) {
371
- // we're not using BCCLimit
372
- foreach ( $recipients as $recipient ) {
373
- $recipient = trim($recipient);
374
- // sanity check -- make sure we have a valid email
375
- if ( !is_email($recipient) ) { continue; }
376
- // and NOT the sender's email, since they'll get a copy anyway
377
- if ( !empty($recipient) && $this->myemail != $recipient ) {
378
- ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
379
- // Bcc Headers now constructed by phpmailer class
380
- }
381
- }
382
- $headers .= "$bcc\n";
383
- } else {
384
- // we're using BCCLimit
385
- $count = 1;
386
- $batch = array();
387
- foreach ( $recipients as $recipient ) {
388
- $recipient = trim($recipient);
389
- // sanity check -- make sure we have a valid email
390
- if ( !is_email($recipient) ) { continue; }
391
- // and NOT the sender's email, since they'll get a copy anyway
392
- if ( !empty($recipient) && $this->myemail != $recipient ) {
393
- ('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
394
- // Bcc Headers now constructed by phpmailer class
395
- }
396
- if ( $this->subscribe2_options['bcclimit'] == $count ) {
397
- $count = 0;
398
- $batch[] = $bcc;
399
- $bcc = '';
400
- }
401
- $count++;
402
- }
403
- // add any partially completed batches to our batch array
404
- if ( '' != $bcc ) {
405
- $batch[] = $bcc;
406
- }
407
- }
408
- // rewind the array, just to be safe
409
- reset($recipients);
410
-
411
- // actually send mail
412
- if ( isset($batch) && !empty($batch) ) {
413
- foreach ( $batch as $bcc ) {
414
- $newheaders = $headers . "$bcc\n";
415
- $status = @wp_mail($this->myemail, $subject, $mailtext, $newheaders);
416
- }
417
- } else {
418
- $status = @wp_mail($this->myemail, $subject, $mailtext, $headers);
419
- }
420
- return $status;
421
- } // end mail()
422
-
423
- /**
424
- Construct standard set of email headers
425
- */
426
- function headers($type='text') {
427
- if ( empty($this->myname) || empty($this->myemail) ) {
428
- $admin = $this->get_userdata($this->subscribe2_options['sender']);
429
- $this->myname = html_entity_decode($admin->display_name, ENT_QUOTES);
430
- $this->myemail = $admin->user_email;
431
- }
432
-
433
- $header['From'] = $this->myname . " <" . $this->myemail . ">";
434
- $header['Reply-To'] = $this->myname . " <" . $this->myemail . ">";
435
- $header['Return-path'] = "<" . $this->myemail . ">";
436
- $header['Precedence'] = "list\nList-Id: " . get_option('blogname') . "";
437
- $header['X-Mailer'] = "PHP" . phpversion() . "";
438
- if ( $type == 'html' ) {
439
- // To send HTML mail, the Content-Type header must be set
440
- $header['Content-Type'] = get_option('html_type') . "; charset=\"". get_option('blog_charset') . "\"";
441
- } else {
442
- $header['Content-Type'] = "text/plain; charset=\"". get_option('blog_charset') . "\"";
443
- }
444
-
445
- // apply header filter to allow on-the-fly amendments
446
- $header = apply_filters('s2_email_headers', $header);
447
- // collapse the headers using $key as the header name
448
- foreach ( $header as $key => $value ) {
449
- $headers[$key] = $key . ": " . $value;
450
- }
451
- $headers = implode("\n", $headers);
452
- $headers .= "\n";
453
-
454
- return $headers;
455
- } // end headers()
456
-
457
- /**
458
- Sends an email notification of a new post
459
- */
460
- function publish($post = 0, $preview = '') {
461
- if ( !$post ) { return $post; }
462
-
463
- if ( $preview == '' ) {
464
- // we aren't sending a Preview to the current user so carry out checks
465
- $s2mail = get_post_meta($post->ID, 's2mail', true);
466
- if ( (isset($_POST['s2_meta_field']) && $_POST['s2_meta_field'] == 'no') || strtolower(trim($s2mail)) == 'no' ) { return $post; }
467
-
468
- // are we doing daily digests? If so, don't send anything now
469
- if ( $this->subscribe2_options['email_freq'] != 'never' ) { return $post; }
470
-
471
- // is the current post of a type that should generate a notification email?
472
- // uses s2_post_types filter to allow for custom post types in WP 3.0
473
- if ( $this->subscribe2_options['pages'] == 'yes' ) {
474
- $s2_post_types = array('page', 'post');
475
- } else {
476
- $s2_post_types = array('post');
477
- }
478
- $s2_post_types = apply_filters('s2_post_types', $s2_post_types);
479
- if ( !in_array($post->post_type, $s2_post_types) ) {
480
- return $post;
481
- }
482
-
483
- // is this post set in the future?
484
- if ( $post->post_date > current_time('mysql') ) {
485
- // bail out
486
- return $post;
487
- }
488
-
489
- //Are we sending notifications for password protected posts?
490
- if ( $this->subscribe2_options['password'] == "no" && $post->post_password != '' ) {
491
- return $post;
492
- }
493
-
494
- $post_cats = wp_get_post_categories($post->ID);
495
- $check = false;
496
- // is the current post assigned to any categories
497
- // which should not generate a notification email?
498
- foreach ( explode(',', $this->subscribe2_options['exclude']) as $cat ) {
499
- if ( in_array($cat, $post_cats) ) {
500
- $check = true;
501
- }
502
- }
503
-
504
- if ( $check ) {
505
- // hang on -- can registered users subscribe to
506
- // excluded categories?
507
- if ( '0' == $this->subscribe2_options['reg_override'] ) {
508
- // nope? okay, let's leave
509
- return $post;
510
- }
511
- }
512
-
513
- // Are we sending notifications for Private posts?
514
- // Action is added if we are, but double check option and post status
515
- if ( $this->subscribe2_options['private'] == "yes" && $post->post_status == 'private' ) {
516
- // don't send notification to public users
517
- $check = true;
518
- }
519
-
520
- // lets collect our subscribers
521
- if ( !$check ) {
522
- // if this post is assigned to an excluded
523
- // category, or is a private post then
524
- // don't send public subscribers a notification
525
- $public = $this->get_public();
526
- }
527
- $post_cats_string = implode(',', $post_cats);
528
- $registered = $this->get_registered("cats=$post_cats_string");
529
-
530
- // do we have subscribers?
531
- if ( empty($public) && empty($registered) ) {
532
- // if not, no sense doing anything else
533
- return $post;
534
- }
535
- }
536
-
537
- // we set these class variables so that we can avoid
538
- // passing them in function calls a little later
539
- $this->post_title = "<a href=\"" . get_permalink($post->ID) . "\">" . html_entity_decode($post->post_title, ENT_QUOTES) . "</a>";
540
- $this->permalink = get_permalink($post->ID);
541
- $this->post_date = get_the_time(get_option('date_format'));
542
- $this->post_time = get_the_time();
543
-
544
- $author = get_userdata($post->post_author);
545
- $this->authorname = $author->display_name;
546
-
547
- // do we send as admin, or post author?
548
- if ( 'author' == $this->subscribe2_options['sender'] ) {
549
- // get author details
550
- $user = &$author;
551
- } else {
552
- // get admin details
553
- $user = $this->get_userdata($this->subscribe2_options['sender']);
554
- }
555
- $this->myemail = $user->user_email;
556
- $this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
557
-
558
- $this->post_cat_names = implode(', ', wp_get_post_categories($post->ID, array('fields' => 'names')));
559
- $this->post_tag_names = implode(', ', wp_get_post_tags($post->ID, array('fields' => 'names')));
560
-
561
- // Get email subject
562
- $subject = stripslashes(strip_tags($this->substitute($this->subscribe2_options['notification_subject'])));
563
- // Get the message template
564
- $mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
565
- $mailtext = stripslashes($this->substitute($mailtext));
566
-
567
- $plaintext = $post->post_content;
568
- if ( function_exists('strip_shortcodes') ) {
569
- $plaintext = strip_shortcodes($plaintext);
570
- }
571
- $gallid = '[gallery id="' . $post->ID . '"]';
572
- $post->post_content = str_replace('[gallery]', $gallid, $post->post_content);
573
- $content = apply_filters('the_content', $post->post_content);
574
- $content = str_replace("]]>", "]]&gt", $content);
575
- $excerpt = $post->post_excerpt;
576
- if ( '' == $excerpt ) {
577
- // no excerpt, is there a <!--more--> ?
578
- if ( false !== strpos($plaintext, '<!--more-->') ) {
579
- list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
580
- // strip leading and trailing whitespace
581
- $excerpt = strip_tags($excerpt);
582
- $excerpt = trim($excerpt);
583
- } else {
584
- // no <!--more-->, so grab the first 55 words
585
- $excerpt = strip_tags($plaintext);
586
- $words = explode(' ', $excerpt, $this->excerpt_length + 1);
587
- if (count($words) > $this->excerpt_length) {
588
- array_pop($words);
589
- array_push($words, '[...]');
590
- $excerpt = implode(' ', $words);
591
- }
592
- }
593
- }
594
- $html_excerpt = $post->post_excerpt;
595
- if ( '' == $html_excerpt ) {
596
- // no excerpt, is there a <!--more--> ?
597
- if ( false !== strpos($content, '<!--more-->') ) {
598
- list($html_excerpt, $more) = explode('<!--more-->', $content, 2);
599
- // strip leading and trailing whitespace
600
- $html_excerpt = balanceTags($html_excerpt);
601
- $html_excerpt = trim($html_excerpt);
602
- } else {
603
- // no <!--more-->, so grab the first 55 words
604
- $words = explode(' ', $content, $this->excerpt_length + 1);
605
- if (count($words) > $this->excerpt_length) {
606
- array_pop($words);
607
- array_push($words, '[...]');
608
- $html_excerpt = implode(' ', $words);
609
- $html_excerpt = trim(balanceTags($html_excerpt));
610
- }
611
- }
612
- }
613
-
614
- // prepare mail body texts
615
- $excerpt_body = str_replace("POST", $excerpt, $mailtext);
616
- $full_body = str_replace("POST", strip_tags($plaintext), $mailtext);
617
- $html_body = str_replace("\r\n", "<br />\r\n", $mailtext);
618
- $html_body = str_replace("POST", $content, $html_body);
619
- $html_excerpt_body = str_replace("\r\n", "<br />\r\n", $mailtext);
620
- $html_excerpt_body = str_replace("POST", $html_excerpt, $html_excerpt_body);
621
-
622
- if ( $preview != '' ) {
623
- $this->myemail = $preview;
624
- $this->myname = "Preview";
625
- $this->mail(array($preview), $subject, $excerpt_body);
626
- $this->mail(array($preview), $subject, $full_body);
627
- $this->mail(array($preview), $subject, $html_body, 'html');
628
- $this->mail(array($preview), $subject, $html_excerpt_body, 'html');
629
- } else {
630
- // first we send plaintext summary emails
631
- $registered = $this->get_registered("cats=$post_cats_string&format=excerpt");
632
- if ( empty($registered) ) {
633
- $recipients = (array)$public;
634
- } elseif ( empty($public) ) {
635
- $recipients = (array)$registered;
636
- } else {
637
- $recipients = array_merge((array)$public, (array)$registered);
638
- }
639
- $this->mail($recipients, $subject, $excerpt_body);
640
-
641
- // next we send plaintext full content emails
642
- $this->mail($this->get_registered("cats=$post_cats_string&format=post"), $subject, $full_body);
643
-
644
- // next we send html excerpt content emails
645
- $this->mail($this->get_registered("cats=$post_cats_string&format=html_excerpt"), $subject, $html_excerpt_body, 'html');
646
-
647
- // finally we send html full content emails
648
- $this->mail($this->get_registered("cats=$post_cats_string&format=html"), $subject, $html_body, 'html');
649
- }
650
- } // end publish()
651
-
652
- /**
653
- Hook Subscribe2 into posts published via email
654
- */
655
- function publish_phone($id) {
656
- if ( !$id ) { return; }
657
-
658
- $post = get_post($id);
659
- $this->publish($post);
660
- return $post;
661
- } // end publish_phone()
662
-
663
- /**
664
- Send confirmation email to the user
665
- */
666
- function send_confirm($what = '', $is_remind = false) {
667
- if ( $this->filtered == 1 ) { return true; }
668
- if ( !$this->email || !$what ) {
669
- return false;
670
- }
671
- $id = $this->get_id($this->email);
672
- if ( !$id ) {
673
- return false;
674
- }
675
-
676
- // generate the URL "?s2=ACTION+HASH+ID"
677
- // ACTION = 1 to subscribe, 0 to unsubscribe
678
- // HASH = md5 hash of email address
679
- // ID = user's ID in the subscribe2 table
680
- // use home instead of siteurl incase index.php is not in core wordpress directory
681
- $link = get_option('home') . "/?s2=";
682
-
683
- if ( 'add' == $what ) {
684
- $link .= '1';
685
- } elseif ( 'del' == $what ) {
686
- $link .= '0';
687
- }
688
- $link .= md5($this->email);
689
- $link .= $id;
690
-
691
- // sort the headers now so we have all substitute information
692
- $mailheaders = $this->headers();
693
-
694
- if ( $is_remind == true ) {
695
- $body = $this->substitute(stripslashes($this->subscribe2_options['remind_email']));
696
- $subject = $this->substitute(stripslashes($this->subscribe2_options['remind_subject']));
697
- } else {
698
- $body = $this->substitute(stripslashes($this->subscribe2_options['confirm_email']));
699
- if ( 'add' == $what ) {
700
- $body = str_replace("ACTION", $this->subscribe, $body);
701
- $subject = str_replace("ACTION", $this->subscribe, $this->subscribe2_options['confirm_subject']);
702
- } elseif ( 'del' == $what ) {
703
- $body = str_replace("ACTION", $this->unsubscribe, $body);
704
- $subject = str_replace("ACTION", $this->unsubscribe, $this->subscribe2_options['confirm_subject']);
705
- }
706
- $subject = html_entity_decode($this->substitute(stripslashes($subject)), ENT_QUOTES);
707
- }
708
-
709
- $body = str_replace("LINK", $link, $body);
710
-
711
- if ( $is_remind == true && function_exists('wpmq_mail') ) {
712
- // could be sending lots of reminders so queue them if wpmq is enabled
713
- @wp_mail($this->email, $subject, $body, $mailheaders, '', 0);
714
- } else {
715
- return @wp_mail($this->email, $subject, $body, $mailheaders);
716
- }
717
- } // end send_confirm()
718
-
719
- /* ===== Subscriber functions ===== */
720
- /**
721
- Given a public subscriber ID, returns the email address
722
- */
723
- function get_email($id = 0) {
724
- global $wpdb;
725
-
726
- if ( !$id ) {
727
- return false;
728
- }
729
- return $wpdb->get_var("SELECT email FROM $this->public WHERE id=$id");
730
- } // end get_email()
731
-
732
- /**
733
- Given a public subscriber email, returns the subscriber ID
734
- */
735
- function get_id($email = '') {
736
- global $wpdb;
737
-
738
- if ( !$email ) {
739
- return false;
740
- }
741
- return $wpdb->get_var("SELECT id FROM $this->public WHERE email='$email'");
742
- } // end get_id()
743
-
744
- /**
745
- Activate an public subscriber email address
746
- If the address is not already present, it will be added
747
- */
748
- function activate($email = '') {
749
- global $wpdb;
750
-
751
- if ( '' == $email ) {
752
- if ( '' != $this->email ) {
753
- $email = $this->email;
754
- } else {
755
- return false;
756
- }
757
- }
758
-
759
- if ( false !== $this->is_public($email) ) {
760
- $check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email='$this->email'");
761
- if ( $check ) { return; }
762
- $wpdb->get_results("UPDATE $this->public SET active='1', ip='$this->ip' WHERE CAST(email as binary)='$email'");
763
- } else {
764
- global $current_user;
765
- $wpdb->get_results($wpdb->prepare("INSERT INTO $this->public (email, active, date, ip) VALUES (%s, %d, NOW(), %s)", $email, 1, $current_user->user_login));
766
- }
767
- } // end activate()
768
-
769
- /**
770
- Add an public subscriber to the subscriber table as unconfirmed
771
- */
772
- function add($email = '') {
773
- if ( $this->filtered ==1 ) { return; }
774
- global $wpdb;
775
-
776
- if ( '' == $email ) {
777
- if ( '' != $this->email ) {
778
- $email = $this->email;
779
- } else {
780
- return false;
781
- }
782
- }
783
-
784
- if ( !is_email($email) ) { return false; }
785
-
786
- if ( false !== $this->is_public($email) ) {
787
- $wpdb->get_results("UPDATE $this->public SET date=NOW() WHERE CAST(email as binary)='$email'");
788
- } else {
789
- $wpdb->get_results($wpdb->prepare("INSERT INTO $this->public (email, active, date, ip) VALUES (%s, %d, NOW(), %s)", $email, 0, $this->ip));
790
- }
791
- } // end add()
792
-
793
- /**
794
- Remove a public subscriber user from the subscription table
795
- */
796
- function delete($email = '') {
797
- global $wpdb;
798
-
799
- if ( '' == $email ) {
800
- if ( '' != $this->email ) {
801
- $email = $this->email;
802
- } else {
803
- return false;
804
- }
805
- }
806
-
807
- if ( !is_email($email) ) { return false; }
808
- $wpdb->get_results("DELETE FROM $this->public WHERE CAST(email as binary)='$email'");
809
- } // end delete()
810
-
811
- /**
812
- Toggle a public subscriber's status
813
- */
814
- function toggle($email = '') {
815
- global $wpdb;
816
-
817
- if ( '' == $email || ! is_email($email) ) { return false; }
818
-
819
- // let's see if this is a public user
820
- $status = $this->is_public($email);
821
- if ( false === $status ) { return false; }
822
-
823
- if ( '0' == $status ) {
824
- $wpdb->get_results("UPDATE $this->public SET active='1' WHERE CAST(email as binary)='$email'");
825
- } else {
826
- $wpdb->get_results("UPDATE $this->public SET active='0' WHERE CAST(email as binary)='$email'");
827
- }
828
- } // end toggle()
829
-
830
- /**
831
- Send reminder email to unconfirmed public subscribers
832
- */
833
- function remind($emails = '') {
834
- if ( '' == $emails ) { return false; }
835
-
836
- $recipients = explode(",", $emails);
837
- if ( !is_array($recipients) ) { $recipients = (array)$recipients; }
838
- foreach ( $recipients as $recipient ) {
839
- $this->email = $recipient;
840
- $this->send_confirm('add', true);
841
- }
842
- } //end remind()
843
-
844
- /**
845
- Check email is not from a barred domain
846
- */
847
- function is_barred($email='') {
848
- $barred_option = $this->subscribe2_options['barred'];
849
- list($user, $domain) = split('@', $email);
850
- $bar_check = stristr($barred_option, $domain);
851
-
852
- if ( !empty($bar_check) ) {
853
- return true;
854
- } else {
855
- return false;
856
- }
857
- } //end is_barred()
858
-
859
- /**
860
- Confirm request from the link emailed to the user and email the admin
861
- */
862
- function confirm($content = '') {
863
- global $wpdb;
864
-
865
- if ( 1 == $this->filtered ) { return $content; }
866
-
867
- $code = $_GET['s2'];
868
- $action = intval(substr($code, 0, 1));
869
- $hash = substr($code, 1, 32);
870
- $code = str_replace($hash, '', $code);
871
- $id = intval(substr($code, 1));
872
- if ( $id ) {
873
- $this->email = $this->sanitize_email($this->get_email($id));
874
- if ( !$this->email || $hash !== md5($this->email) ) {
875
- return $this->no_such_email;
876
- }
877
- } else {
878
- return $this->no_such_email;
879
- }
880
-
881
- // get current status of email so messages are only sent once per emailed link
882
- $current = $this->is_public($this->email);
883
-
884
- if ( '1' == $action ) {
885
- // make this subscription active
886
- $this->message = $this->added;
887
- if ( '1' != $current ) {
888
- $this->ip = $_SERVER['REMOTE_ADDR'];
889
- $this->activate();
890
- if ( $this->subscribe2_options['admin_email'] == 'subs' || $this->subscribe2_options['admin_email'] == 'both' ) {
891
- ( '' == get_option('blogname') ) ? $subject = "" : $subject = "[" . stripslashes(get_option('blogname')) . "] ";
892
- $subject .= __('New subscription', 'subscribe2');
893
- $subject = html_entity_decode($subject, ENT_QUOTES);
894
- $message = $this->email . " " . __('subscribed to email notifications!', 'subscribe2');
895
- $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'");
896
- if ( empty($recipients) ) {
897
- $role = 'administrator';
898
- if ( !class_exists(WP_User_Search) ) {
899
- require(ABSPATH . 'wp-admin/includes/user.php');
900
- }
901
- $wp_user_search = new WP_User_Search( '', '', $role);
902
- $admins_string = implode(', ', $wp_user_search->get_results());
903
- $sql = "SELECT user_email FROM $wpdb->users WHERE ID IN (" . $admins_string . ")";
904
- $recipients = $wpdb->get_col($sql);
905
- }
906
- $headers = $this->headers();
907
- foreach ( $recipients as $recipient ) {
908
- @wp_mail($recipient, $subject, $message, $headers);
909
- }
910
- }
911
- }
912
- $this->filtered = 1;
913
- } elseif ( '0' == $action ) {
914
- // remove this subscriber
915
- $this->message = $this->deleted;
916
- if ( '0' != $current ) {
917
- $this->delete();
918
- if ( $this->subscribe2_options['admin_email'] == 'unsubs' || $this->subscribe2_options['admin_email'] == 'both' ) {
919
- ( '' == get_option('blogname') ) ? $subject = "" : $subject = "[" . stripslashes(get_option('blogname')) . "] ";
920
- $subject .= __('New Unsubscription', 'subscribe2');
921
- $subject = html_entity_decode($subject, ENT_QUOTES);
922
- $message = $this->email . " " . __('unsubscribed from email notifications!', 'subscribe2');
923
- $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'");
924
- if ( empty($recipients) ) {
925
- $role = 'administrator';
926
- if ( !class_exists(WP_User_Search) ) {
927
- require(ABSPATH . 'wp-admin/includes/user.php');
928
- }
929
- $wp_user_search = new WP_User_Search( '', '', $role);
930
- $admins_string = implode(', ', $wp_user_search->get_results());
931
- $sql = "SELECT user_email FROM $wpdb->users WHERE ID IN (" . $admins_string . ")";
932
- $recipients = $wpdb->get_col($sql);
933
- }
934
- $headers = $this->headers();
935
- foreach ( $recipients as $recipient ) {
936
- @wp_mail($recipient, $subject, $message, $headers);
937
- }
938
- }
939
- }
940
- $this->filtered = 1;
941
- }
942
-
943
- if ( '' != $this->message ) {
944
- return $this->message;
945
- }
946
- } // end confirm()
947
-
948
- /**
949
- Is the supplied email address a public subscriber?
950
- */
951
- function is_public($email = '') {
952
- global $wpdb;
953
-
954
- if ( '' == $email ) { return false; }
955
-
956
- // run the query and force case sensitivity
957
- $check = $wpdb->get_var("SELECT active FROM $this->public WHERE CAST(email as binary)='$email'");
958
- if ( '0' == $check || '1' == $check ) {
959
- return $check;
960
- } else {
961
- return false;
962
- }
963
- } // end is_public
964
-
965
- /**
966
- Is the supplied email address a registered user of the blog?
967
- */
968
- function is_registered($email = '') {
969
- global $wpdb;
970
-
971
- if ( '' == $email ) { return false; }
972
-
973
- $check = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_email='$email'");
974
- if ( $check ) {
975
- return true;
976
- } else {
977
- return false;
978
- }
979
- } // end is_registered()
980
-
981
- /**
982
- Return Registered User ID from email
983
- */
984
- function get_user_id($email = '') {
985
- global $wpdb;
986
-
987
- if ( '' == $email ) { return false; }
988
-
989
- $id = $wpdb->get_var("SELECT id FROM $wpdb->users WHERE user_email='$email'");
990
-
991
- return $id;
992
- } // end get_user_id()
993
-
994
- /**
995
- Return an array of all the public subscribers
996
- */
997
- function get_public($confirmed = 1) {
998
- global $wpdb;
999
- if ( 1 == $confirmed ) {
1000
- if ( '' == $this->all_public ) {
1001
- $this->all_public = $wpdb->get_col("SELECT email FROM $this->public WHERE active='1'");
1002
- }
1003
- return $this->all_public;
1004
- } else {
1005
- if ( '' == $this->all_unconfirmed ) {
1006
- $this->all_unconfirmed = $wpdb->get_col("SELECT email FROM $this->public WHERE active='0'");
1007
- }
1008
- return $this->all_unconfirmed;
1009
- }
1010
- } // end get_public()
1011
-
1012
- /**
1013
- Return an array of all subscribers
1014
- */
1015
- function get_all_registered($id = '') {
1016
- global $wpdb;
1017
-
1018
- if ( $this->s2_mu ) {
1019
- if ( $id ) {
1020
- return $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
1021
- } else {
1022
- $result = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
1023
- $ids = implode(',', $result);
1024
- return $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids)");
1025
- }
1026
- } else {
1027
- if ( $id ) {
1028
- return $wpdb->get_col("SELECT ID FROM $wpdb->users");
1029
- } else {
1030
- return $wpdb->get_col("SELECT user_email FROM $wpdb->users");
1031
- }
1032
- }
1033
- }
1034
-
1035
- /**
1036
- Return an array of registered subscribers
1037
- Collect all the registered users of the blog who are subscribed to the specified categories
1038
- */
1039
- function get_registered($args = '') {
1040
- global $wpdb;
1041
-
1042
- $format = '';
1043
- $cats = '';
1044
- $subscribers = array();
1045
-
1046
- parse_str($args, $r);
1047
- if ( !isset($r['format']) )
1048
- $r['format'] = 'all';
1049
- if ( !isset($r['cats']) )
1050
- $r['cats'] = '';
1051
-
1052
- $JOIN = ''; $AND = '';
1053
- // text or HTML subscribers
1054
- if ( 'all' != $r['format'] ) {
1055
- $JOIN .= "INNER JOIN $wpdb->usermeta AS b ON a.user_id = b.user_id ";
1056
- $AND .= " AND b.meta_key='s2_format' AND b.meta_value=";
1057
- if ( 'html' == $r['format'] ) {
1058
- $AND .= "'html'";
1059
- } elseif ( 'html_excerpt' == $r['format'] ) {
1060
- $AND .= "'html_excerpt'";
1061
- } elseif ( 'post' == $r['format'] ) {
1062
- $AND .= "'post'";
1063
- } elseif ( 'excerpt' == $r['format'] ) {
1064
- $AND .= "'excerpt'";
1065
- }
1066
- }
1067
-
1068
- // specific category subscribers
1069
- if ( '' != $r['cats'] ) {
1070
- $JOIN .= "INNER JOIN $wpdb->usermeta AS c ON a.user_id = c.user_id ";
1071
- $all = '';
1072
- foreach ( explode(',', $r['cats']) as $cat ) {
1073
- ('' == $and) ? $and = "c.meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$cat'" : $and .= " OR c.meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$cat'";
1074
- }
1075
- $AND .= " AND ($and)";
1076
- }
1077
-
1078
- if ( $this->s2_mu ) {
1079
- $sql = "SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . "WHERE a.meta_key='" . $wpdb->prefix . "capabilities'" . $AND;
1080
- } else {
1081
- $sql = "SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . "WHERE a.meta_key='" . $this->get_usermeta_keyname('s2_subscribed') . "'" . $AND;
1082
- }
1083
- $result = $wpdb->get_col($sql);
1084
- if ( $result ) {
1085
- $ids = implode(',', $result);
1086
- return $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids)");
1087
- }
1088
- } // end get_registered()
1089
-
1090
- /**
1091
- Collects the signup date for all public subscribers
1092
- */
1093
- function signup_date($email = '') {
1094
- if ( '' == $email ) { return false; }
1095
-
1096
- global $wpdb;
1097
- if ( !empty($this->signup_dates) ) {
1098
- return $this->signup_dates[$email];
1099
- } else {
1100
- $results = $wpdb->get_results("SELECT email, date FROM $this->public", ARRAY_N);
1101
- foreach ( $results as $result ) {
1102
- $this->signup_dates[$result[0]] = $result[1];
1103
- }
1104
- return $this->signup_dates[$email];
1105
- }
1106
- } // end signup_date()
1107
-
1108
- /**
1109
- Collects the ip address for all public subscribers
1110
- */
1111
- function signup_ip($email = '') {
1112
- if ( '' == $email ) {return false; }
1113
-
1114
- global $wpdb;
1115
- if ( !empty($this->signup_ips) ) {
1116
- return $this->signup_ips[$email];
1117
- } else {
1118
- $results = $wpdb->get_results("SELECT email, ip FROM $this->public", ARRAY_N);
1119
- foreach ( $results as $result ) {
1120
- $this->signup_ips[$result[0]] = $result[1];
1121
- }
1122
- return $this->signup_ips[$email];
1123
- }
1124
- } // end signup_ip()
1125
-
1126
- /**
1127
- function to ensure email is compliant with internet messaging standards
1128
- */
1129
- function sanitize_email($email) {
1130
- if ( !is_email($email) ) { return; }
1131
-
1132
- // ensure that domain is in lowercase as per internet email standards
1133
- list($name, $domain) = explode('@', $email, 2);
1134
- return $name . "@" . strtolower($domain);;
1135
- } // end sanitize_email()
1136
-
1137
- /**
1138
- Create the appropriate usermeta values when a user registers
1139
- If the registering user had previously subscribed to notifications, this function will delete them from the public subscriber list first
1140
- */
1141
- function register($user_ID = 0) {
1142
- global $wpdb;
1143
-
1144
- if ( 0 == $user_ID ) { return $user_ID; }
1145
- $user = get_userdata($user_ID);
1146
- $all_cats = get_categories(array('hide_empty' => false));
1147
-
1148
- // Are registered users are allowed to subscribe to excluded categories?
1149
- if ( 0 == $this->subscribe2_options['reg_override'] || 'no' == $this->subscribe2_options['newreg_override'] ) {
1150
- $exclude = explode(',', $this->subscribe2_options['exclude']);
1151
- foreach ( $all_cats as $cat => $term_id ) {
1152
- if ( in_array($all_cats[$cat]->term_id, $exclude) ) {
1153
- $cat = (int)$cat;
1154
- unset($all_cats[$cat]);
1155
- }
1156
- }
1157
- }
1158
-
1159
- foreach ( $all_cats as $cat ) {
1160
- ('' == $cats) ? $cats = "$cat->term_id" : $cats .= ",$cat->term_id";
1161
- }
1162
-
1163
- if ( '' == $cats ) {
1164
- // sanity check, might occur if all cats excluded and reg_override = 0
1165
- return $user_ID;
1166
- }
1167
-
1168
- // has this user previously signed up for email notification?
1169
- if ( false !== $this->is_public($this->sanitize_email($user->user_email)) ) {
1170
- // delete this user from the public table, and subscribe them to all the categories
1171
- $this->delete($user->user_email);
1172
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
1173
- foreach ( explode(',', $cats) as $cat ) {
1174
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, "$cat");
1175
- }
1176
- update_usermeta($user_ID, 's2_format', 'excerpt');
1177
- update_usermeta($user_ID, 's2_autosub', $this->subscribe2_options['autosub_def']);
1178
- } else {
1179
- // create post format entries for all users
1180
- $check_format = get_usermeta($user_ID, 's2_format');
1181
- if ( empty($check_format) ) {
1182
- // ensure existing subscription options are not overwritten on upgrade
1183
- if ( in_array($this->subscribe2_options['autoformat'], array('html', 'html_excerpt', 'post', 'excerpt')) ) {
1184
- update_usermeta($user_ID, 's2_format', $this->subscribe2_options['autoformat']);
1185
- } else {
1186
- update_usermeta($user_ID, 's2_format', 'excerpt');
1187
- }
1188
- update_usermeta($user_ID, 's2_autosub', $this->subscribe2_options['autosub_def']);
1189
- // if the are no existing subscriptions, create them if, by default if autosub is on
1190
- if ( 'yes' == $this->subscribe2_options['autosub'] || ( 'wpreg' == $this->subscribe2_options['autosub'] && 'on' == $_POST['subscribe'] ) ) {
1191
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
1192
- foreach ( explode(',', $cats) as $cat ) {
1193
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, "$cat");
1194
- }
1195
- }
1196
- } else {
1197
- // if user is already registered update format remove 's2_excerpt' field and update 's2_format'
1198
- if ( 'html' == $check_format ) {
1199
- delete_usermeta($user_ID, 's2_excerpt');
1200
- } elseif ( 'text' == $check_format ) {
1201
- update_usermeta($user_ID, 's2_format', get_usermeta($user_ID, 's2_excerpt'));
1202
- delete_usermeta($user_ID, 's2_excerpt');
1203
- }
1204
- }
1205
- $subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1206
- if ( strstr($subscribed, '-1') ) {
1207
- // make sure we remove '-1' from any settings
1208
- $old_cats = explode(',', $subscribed);
1209
- $pos = array_search('-1', $old_cats);
1210
- unset($old_cats[$pos]);
1211
- $cats = implode(',', $old_cats);
1212
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
1213
- }
1214
- }
1215
- return $user_ID;
1216
- } // end register()
1217
-
1218
- /**
1219
- Subscribe all registered users to category selected on Admin Manage Page
1220
- */
1221
- function subscribe_registered_users($emails = '', $cats = array()) {
1222
- if ( '' == $emails || '' == $cats ) { return false; }
1223
- global $wpdb;
1224
-
1225
- $useremails = explode(",", $emails);
1226
- $useremails = implode("', '", $useremails);
1227
-
1228
- $sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
1229
- $user_IDs = $wpdb->get_col($sql);
1230
-
1231
- foreach ( $user_IDs as $user_ID ) {
1232
- $old_cats = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1233
- if ( !empty($old_cats) ) {
1234
- $old_cats = explode(',', $old_cats);
1235
- $newcats = array_unique(array_merge($cats, $old_cats));
1236
- } else {
1237
- $newcats = $cats;
1238
- }
1239
- if ( !empty($newcats) ) {
1240
- // add subscription to these cat IDs
1241
- foreach ( $newcats as $id ) {
1242
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id, "$id");
1243
- }
1244
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $newcats));
1245
- }
1246
- unset($newcats);
1247
- }
1248
- } // end subscribe_registered_users()
1249
-
1250
- /**
1251
- Unsubscribe all registered users to category selected on Admin Manage Page
1252
- */
1253
- function unsubscribe_registered_users($emails = '', $cats = array()) {
1254
- if ( '' == $emails || '' == $cats ) { return false; }
1255
- global $wpdb;
1256
-
1257
- $useremails = explode(",", $emails);
1258
- $useremails = implode("', '", $useremails);
1259
-
1260
- $sql = "SELECT ID FROM $wpdb->users WHERE user_email IN ('$useremails')";
1261
- $user_IDs = $wpdb->get_col($sql);
1262
-
1263
- foreach ( $user_IDs as $user_ID ) {
1264
- $old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1265
- $remain = array_diff($old_cats, $cats);
1266
- if ( !empty($remain) ) {
1267
- // remove subscription to these cat IDs and update s2_subscribed
1268
- foreach ( $cats as $id ) {
1269
- delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1270
- }
1271
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $remain));
1272
- } else {
1273
- // remove subscription to these cat IDs and update s2_subscribed to ''
1274
- foreach ( $cats as $id ) {
1275
- delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1276
- }
1277
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
1278
- }
1279
- unset($remain);
1280
- }
1281
- } // end unsubscribe_registered_users()
1282
-
1283
- /**
1284
- Handles bulk changes to email format for Registered Subscribers
1285
- */
1286
- function format_change($format, $subscribers_string) {
1287
- if ( empty($format) ) { return; }
1288
-
1289
- global $wpdb;
1290
- $emails ='';
1291
- $subscribers = explode(',', $subscribers_string);
1292
- foreach ( $subscribers as $subscriber ) {
1293
- ( '' == $emails) ? $emails = "'$subscriber'" : $emails .= ",'$subscriber'";
1294
- }
1295
- $ids = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE user_email IN ($emails)");
1296
- $ids = implode(',', $ids);
1297
- $sql = "UPDATE $wpdb->usermeta SET meta_value='{$format}' WHERE meta_key='s2_format' AND user_id IN ($ids)";
1298
- $wpdb->get_results("UPDATE $wpdb->usermeta SET meta_value='{$format}' WHERE meta_key='s2_format' AND user_id IN ($ids)");
1299
- } // end bulk_manage()
1300
-
1301
- /**
1302
- Handles subscriptions and unsubscriptions for different blogs on WPMU installs
1303
- */
1304
- function wpmu_subscribe() {
1305
- $redirect_to_subscriptionpage = false;
1306
-
1307
- // subscribe to new blog
1308
- if ( !empty($_GET['s2mu_subscribe']) ) {
1309
- $blog_id = intval($_GET['s2mu_subscribe']);
1310
- if ( $blog_id >= 0 ) {
1311
- switch_to_blog($blog_id);
1312
-
1313
- $user_ID = get_current_user_id();
1314
-
1315
- // if user is not a user of the current blog
1316
- if ( !is_blog_user($blog_id) ) {
1317
- // add user to current blog as subscriber
1318
- add_user_to_blog($blog_id, $user_ID, 'subscriber');
1319
- // add an action hook for external manipulation of blog and user data
1320
- do_action_ref_array('subscribe2_wpmu_subscribe', array($user_ID, $blog_id));
1321
- }
1322
-
1323
- // subscribe to all categories by default
1324
- $all_cats = get_categories(array('hide_empty' => false));
1325
-
1326
- if ( 0 == $this->subscribe2_options['reg_override'] ) {
1327
- // registered users are not allowed to subscribe to excluded categories
1328
- $exclude = explode(',', $this->subscribe2_options['exclude']);
1329
- foreach ( $all_cats as $cat => $term ) {
1330
- if ( in_array($all_cats[$cat]->term_id, $exclude) ) {
1331
- $cat = (int)$cat;
1332
- unset($all_cats[$cat]);
1333
- }
1334
- }
1335
- }
1336
-
1337
- $cats = array();
1338
- foreach ( $all_cats as $cat => $term ) {
1339
- $term_id = $term->term_id;
1340
- $cats[] = $term_id;
1341
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $term_id, $term_id);
1342
- }
1343
- if ( empty($cats) ) {
1344
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
1345
- } else {
1346
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $cats));
1347
- }
1348
-
1349
- // don't restore_current_blog(); -> redirect to new subscription page
1350
- $redirect_to_subscriptionpage = true;
1351
- }
1352
- } elseif ( !empty($_GET['s2mu_unsubscribe']) ) {
1353
- // unsubscribe from a blog
1354
- $blog_id = intval($_GET['s2mu_unsubscribe']);
1355
- if ( $blog_id >= 0 ) {
1356
- switch_to_blog($blog_id);
1357
-
1358
- $user_ID = get_current_user_id();
1359
-
1360
- // delete subscription to all categories on that blog
1361
- $cats = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
1362
- $cats = explode(',', $cats);
1363
- if ( !is_array($cats) ) {
1364
- $cats = array($cats);
1365
- }
1366
-
1367
- foreach ( $cats as $id ) {
1368
- delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
1369
- }
1370
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
1371
-
1372
- // add an action hook for external manipulation of blog and user data
1373
- do_action_ref_array('subscribe2_wpmu_unsubscribe', array($user_ID, $blog_id));
1374
-
1375
- restore_current_blog();
1376
- $redirect_to_subscriptionpage = true;
1377
- }
1378
- }
1379
-
1380
- if ( $redirect_to_subscriptionpage == true ) {
1381
- if ( !is_user_member_of_blog($user_ID) ) {
1382
- $user_blogs = get_active_blog_for_user($user_ID);
1383
- if ( is_array($user_blogs) ) {
1384
- switch_to_blog(key($user_blogs));
1385
- } else {
1386
- // no longer a member of a blog
1387
- wp_redirect(get_option('siteurl')); // redirect to front page
1388
- exit();
1389
- }
1390
- }
1391
-
1392
- // redirect to profile page
1393
- if ( current_user_can('manage_options') ) {
1394
- $url = get_option('siteurl') . '/wp-admin/users.php?page=s2_users';
1395
- wp_redirect($url);
1396
- exit();
1397
- } else {
1398
- $url = get_option('siteurl') . '/wp-admin/profile.php?page=s2_users';
1399
- wp_redirect($url);
1400
- exit();
1401
- }
1402
- }
1403
- } // end wpmu_subscribe()
1404
-
1405
- /**
1406
- Autosubscribe registered users to newly created categories
1407
- if registered user has selected this option
1408
- */
1409
- function new_category($new_category='') {
1410
- if ( 'no' == $this->subscribe2_options['show_autosub'] ) { return; }
1411
- global $wpdb;
1412
-
1413
- if ( 'yes' == $this->subscribe2_options['show_autosub'] ) {
1414
- $sql = "SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key='s2_autosub' AND $wpdb->usermeta.meta_value='yes'";
1415
- $user_IDs = $wpdb->get_col($sql);
1416
- if ( '' == $user_IDs ) { return; }
1417
-
1418
- foreach ( $user_IDs as $user_ID ) {
1419
- $old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1420
- if ( !is_array($old_cats) ) {
1421
- $old_cats = array($old_cats);
1422
- }
1423
- // add subscription to these cat IDs
1424
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $new_category, "$new_category");
1425
- $newcats = array_merge($old_cats, (array)$new_category);
1426
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $newcats));
1427
- }
1428
- } elseif ( 'exclude' == $this->subscribe2_options['show_autosub'] ) {
1429
- $excluded_cats = explode(',', $this->subscribe2_options['exclude']);
1430
- $excluded_cats[] = $new_category;
1431
- $this->subscribe2_options['exclude'] = implode(',', $excluded_cats);
1432
- update_option('subscribe2_options', $this->subscribe2_options);
1433
- }
1434
- } // end new_category()
1435
-
1436
- function delete_category($deleted_category='') {
1437
- global $wpdb;
1438
-
1439
- $sql = "SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_key='" . $this->get_usermeta_keyname('s2_cat') . "$deleted_category'";
1440
- $user_IDs = $wpdb->get_col($sql);
1441
- if ( '' == $user_IDs ) { return; }
1442
-
1443
- foreach ( $user_IDs as $user_ID ) {
1444
- $old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
1445
- if ( !is_array($old_cats) ) {
1446
- $old_cats = array($old_cats);
1447
- }
1448
- // add subscription to these cat IDs
1449
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $deleted_category, '');
1450
- $remain = array_diff($old_cats, (array)$deleted_category);
1451
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $remain));
1452
- }
1453
- }
1454
-
1455
- /**
1456
- Get admin data from record 1 or first user with admin rights
1457
- */
1458
- function get_userdata($admin_id) {
1459
- global $wpdb, $userdata;
1460
-
1461
- if ( is_numeric($admin_id) ) {
1462
- $admin = get_userdata($admin_id);
1463
- } elseif ( $admin_id == 'admin' ) {
1464
- //ensure compatibility with < 4.16
1465
- $admin = get_userdata('1');
1466
- } else {
1467
- $admin = &$userdata;
1468
- }
1469
-
1470
- // if user record is empty grab the first admin from the database
1471
- if ( empty($admin) ) {
1472
- $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";
1473
- $admin = get_userdata($wpdb->get_var($sql));
1474
- }
1475
-
1476
- // handle issues from WordPress core where user_level is not set or set low
1477
- if ( empty($admin) ) {
1478
- $role = 'administrator';
1479
- if ( !class_exists(WP_User_Search) ) {
1480
- require(ABSPATH . 'wp-admin/includes/user.php');
1481
- }
1482
- $wp_user_search = new WP_User_Search( '', '', $role);
1483
- $results = $wp_user_search->get_results();
1484
- $admin = $results[0];
1485
- }
1486
-
1487
- return $admin;
1488
- } //end get_userdata()
1489
-
1490
- /* ===== Menus ===== */
1491
- /**
1492
- Our management page
1493
- */
1494
- function manage_menu() {
1495
- global $wpdb, $s2nonce;
1496
-
1497
- //Get Registered Subscribers for bulk management
1498
- $registered = $this->get_registered();
1499
- $all_users = $this->get_all_registered();
1500
-
1501
- // was anything POSTed ?
1502
- if ( isset($_POST['s2_admin']) ) {
1503
- check_admin_referer('subscribe2-manage_subscribers' . $s2nonce);
1504
- if ( $_POST['addresses'] ) {
1505
- $sub_error = '';
1506
- $unsub_error = '';
1507
- foreach ( preg_split ("/[\s,]+/", $_POST['addresses']) as $email ) {
1508
- $email = $this->sanitize_email($email);
1509
- if ( is_email($email) && $_POST['subscribe'] ) {
1510
- if ( $this->is_public($email) !== false ) {
1511
- ('' == $sub_error) ? $sub_error = "$email" : $sub_error .= ", $email";
1512
- continue;
1513
- }
1514
- $this->activate($email);
1515
- $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) subscribed!', 'subscribe2') . "</strong></p></div>";
1516
- } elseif ( is_email($email) && $_POST['unsubscribe'] ) {
1517
- if ( $this->is_public($email) === false ) {
1518
- ('' == $unsub_error) ? $unsub_error = "$email" : $unsub_error .= ", $email";
1519
- continue;
1520
- }
1521
- $this->delete($email);
1522
- $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) unsubscribed!', 'subscribe2') . "</strong></p></div>";
1523
- }
1524
- }
1525
- if ( $sub_error != '' ) {
1526
- echo "<div id=\"message\" class=\"error\"><p><strong>" . __('Some emails were not processed, the following were already subscribed' , 'subscribe2') . ":<br />$sub_error</strong></p></div>";
1527
- }
1528
- if ( $unsub_error != '' ) {
1529
- echo "<div id=\"message\" class=\"error\"><p><strong>" . __('Some emails were not processed, the following were not in the database' , 'subscribe2') . ":<br />$unsub_error</strong></p></div>";
1530
- }
1531
- echo $message;
1532
- $_POST['what'] = 'confirmed';
1533
- } elseif ( $_POST['process'] ) {
1534
- if ( $_POST['delete'] ) {
1535
- foreach ( $_POST['delete'] as $address ) {
1536
- $this->delete($address);
1537
- }
1538
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Address(es) deleted!', 'subscribe2') . "</strong></p></div>";
1539
- }
1540
- if ( $_POST['confirm'] ) {
1541
- foreach ( $_POST['confirm'] as $address ) {
1542
- $this->toggle($this->sanitize_email($address));
1543
- }
1544
- $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>";
1545
- }
1546
- if ( $_POST['unconfirm'] ) {
1547
- foreach ( $_POST['unconfirm'] as $address ) {
1548
- $this->toggle($this->sanitize_email($address));
1549
- }
1550
- $message = "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Status changed!', 'subscribe2') . "</strong></p></div>";
1551
- }
1552
- echo $message;
1553
- } elseif ( $_POST['searchterm'] ) {
1554
- $confirmed = $this->get_public();
1555
- $unconfirmed = $this->get_public(0);
1556
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1557
- foreach ( $subscribers as $subscriber ) {
1558
- if ( is_numeric(stripos($subscriber, $_POST['searchterm'])) ) {
1559
- $result[] = $subscriber;
1560
- }
1561
- }
1562
- } elseif ( $_POST['remind'] ) {
1563
- $this->remind($_POST['reminderemails']);
1564
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Reminder Email(s) Sent!', 'subscribe2') . "</strong></p></div>";
1565
- } elseif ( $_POST['sub_categories'] && 'subscribe' == $_POST['manage'] ) {
1566
- $this->subscribe_registered_users($_POST['emails'], $_POST['category']);
1567
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Registered Users Subscribed!', 'subscribe2') . "</strong></p></div>";
1568
- } elseif ( $_POST['sub_categories'] && 'unsubscribe' == $_POST['manage'] ) {
1569
- $this->unsubscribe_registered_users($_POST['emails'], $_POST['category']);
1570
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Registered Users Unsubscribed!', 'subscribe2') . "</strong></p></div>";
1571
- } elseif ( $_POST['sub_format'] ) {
1572
- $this->format_change( $_POST['format'], $_POST['emails'] );
1573
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Format updated for Selected Registered Users!', 'subscribe2') . "</strong></p></div>";
1574
- }
1575
- }
1576
-
1577
- //Get Public Subscribers once for filter
1578
- $confirmed = $this->get_public();
1579
- $unconfirmed = $this->get_public(0);
1580
- // safety check for our arrays
1581
- if ( '' == $confirmed ) { $confirmed = array(); }
1582
- if ( '' == $unconfirmed ) { $unconfirmed = array(); }
1583
- if ( '' == $registered ) { $registered = array(); }
1584
- if ( '' == $all_users ) { $all_users = array(); }
1585
-
1586
- $reminderform = false;
1587
- $urlpath = str_replace("\\", "/", S2PATH);
1588
- $urlpath = trailingslashit(get_option('siteurl')) . substr($urlpath,strpos($urlpath, "wp-content/"));
1589
- if ( isset($_GET['s2page']) ) {
1590
- $page = (int) $_GET['s2page'];
1591
- } else {
1592
- $page = 1;
1593
- }
1594
-
1595
- if ( isset($_POST['what']) ) {
1596
- $page = 1;
1597
- if ( 'all' == $_POST['what'] ) {
1598
- $what = 'all';
1599
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1600
- } elseif ( 'public' == $_POST['what'] ) {
1601
- $what = 'public';
1602
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
1603
- } elseif ( 'confirmed' == $_POST['what'] ) {
1604
- $what = 'confirmed';
1605
- $subscribers = $confirmed;
1606
- } elseif ( 'unconfirmed' == $_POST['what'] ) {
1607
- $what = 'unconfirmed';
1608
- $subscribers = $unconfirmed;
1609
- if ( !empty($subscribers) ) {
1610
- $reminderemails = implode(",", $subscribers);
1611
- $reminderform = true;
1612
- }
1613
- } elseif ( is_numeric($_POST['what']) ) {
1614
- $what = intval($_POST['what']);
1615
- $subscribers = $this->get_registered("cats=$what");
1616
- } elseif ( 'registered' == $_POST['what'] ) {
1617
- $what = 'registered';
1618
- $subscribers = $registered;
1619
- } elseif ( 'all_users' == $_POST['what'] ) {
1620
- $what = 'all_users';
1621
- $subscribers = $all_users;
1622
- }
1623
- } elseif ( isset($_GET['what']) ) {
1624
- if ( 'all' == $_GET['what'] ) {
1625
- $what = 'all';
1626
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1627
- } elseif ( 'public' == $_GET['what'] ) {
1628
- $what = 'public';
1629
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed);
1630
- } elseif ( 'confirmed' == $_GET['what'] ) {
1631
- $what = 'confirmed';
1632
- $subscribers = $confirmed;
1633
- } elseif ( 'unconfirmed' == $_GET['what'] ) {
1634
- $what = 'unconfirmed';
1635
- $subscribers = $unconfirmed;
1636
- if ( !empty($subscribers) ) {
1637
- $reminderemails = implode(",", $subscribers);
1638
- $reminderform = true;
1639
- }
1640
- } elseif ( is_numeric($_GET['what']) ) {
1641
- $what = intval($_GET['what']);
1642
- $subscribers = $this->get_registered("cats=$what");
1643
- } elseif ( 'registered' == $_GET['what'] ) {
1644
- $what = 'registered';
1645
- $subscribers = $registered;
1646
- } elseif ( 'all_users' == $_GET['what'] ) {
1647
- $what = 'all_users';
1648
- $subscribers = $all_users;
1649
- }
1650
- } else {
1651
- $what = 'all';
1652
- $subscribers = array_merge((array)$confirmed, (array)$unconfirmed, (array)$all_users);
1653
- }
1654
- if ( $_POST['searchterm'] ) {
1655
- $subscribers = &$result;
1656
- $what = 'public';
1657
- }
1658
-
1659
- if ( !empty($subscribers) ) {
1660
- natcasesort($subscribers);
1661
- // Displays a page number strip - adapted from code in Akismet
1662
- $args['what'] = $what;
1663
- $total_subscribers = count($subscribers);
1664
- $total_pages = ceil($total_subscribers / $this->subscribe2_options['entries']);
1665
- $strip = '';
1666
- if ( $page > 1 ) {
1667
- $args['s2page'] = $page - 1;
1668
- $strip .= '<a class="prev" href="' . clean_url(add_query_arg($args)) . '">&laquo; '. __('Previous Page', 'subscribe2') .'</a>' . "\n";
1669
- }
1670
- if ( $total_pages > 1 ) {
1671
- for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) {
1672
- if ( $page == $page_num ) {
1673
- $strip .= "<strong>Page " . $page_num . "</strong>\n";
1674
- } else {
1675
- if ( $page_num < 3 || ( $page_num >= $page - 2 && $page_num <= $page + 2 ) || $page_num > $total_pages - 2 ) {
1676
- $args['s2page'] = $page_num;
1677
- $strip .= "<a class=\"page-numbers\" href=\"" . clean_url(add_query_arg($args)) . "\">" . $page_num . "</a>\n";
1678
- $trunc = true;
1679
- } elseif ( $trunc == true ) {
1680
- $strip .= "...\n";
1681
- $trunc = false;
1682
- }
1683
- }
1684
- }
1685
- }
1686
- if ( ( $page ) * $this->subscribe2_options['entries'] < $total_subscribers ) {
1687
- $args['s2page'] = $page + 1;
1688
- $strip .= "<a class=\"next\" href=\"" . clean_url(add_query_arg($args)) . "\">". __('Next Page', 'subscribe2') . " &raquo;</a>\n";
1689
- }
1690
- }
1691
-
1692
- // show our form
1693
- echo "<div class=\"wrap\">";
1694
- screen_icon();
1695
- echo "<h2>" . __('Manage Subscribers', 'subscribe2') . "</h2>\r\n";
1696
- echo "<form method=\"post\" action=\"\">\r\n";
1697
- if ( function_exists('wp_nonce_field') ) {
1698
- wp_nonce_field('subscribe2-manage_subscribers' . $s2nonce);
1699
- }
1700
- echo "<h2>" . __('Add/Remove Subscribers', 'subscribe2') . "</h2>\r\n";
1701
- echo "<p>" . __('Enter addresses, one per line or comma-separated', 'subscribe2') . "<br />\r\n";
1702
- echo "<textarea rows=\"2\" cols=\"80\" name=\"addresses\"></textarea></p>\r\n";
1703
- echo "<input type=\"hidden\" name=\"s2_admin\" />\r\n";
1704
- echo "<p class=\"submit\" style=\"border-top: none;\"><input type=\"submit\" class=\"button-primary\" name=\"subscribe\" value=\"" . __('Subscribe', 'subscribe2') . "\" />";
1705
- echo "&nbsp;<input type=\"submit\" class=\"button-primary\" name=\"unsubscribe\" value=\"" . __('Unsubscribe', 'subscribe2') . "\" /></p>\r\n";
1706
-
1707
- // subscriber lists
1708
- echo "<h2>" . __('Current Subscribers', 'subscribe2') . "</h2>\r\n";
1709
- echo "<br />";
1710
- $this->display_subscriber_dropdown($what, __('Filter', 'subscribe2'));
1711
- // show the selected subscribers
1712
- $alternate = '';
1713
- echo "<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
1714
- echo "<tr class=\"alternate\"><td width=\"50%\"><input type=\"text\" name=\"searchterm\" value=\"\" />&nbsp;\r\n";
1715
- echo "<input type=\"submit\" class=\"button-secondary\" name=\"search\" value=\"" . __('Search Subscribers', 'subscribe2') . "\" /></td>\r\n";
1716
- if ( $reminderform ) {
1717
- echo "<td width=\"25%\" align=\"right\"><input type=\"hidden\" name=\"reminderemails\" value=\"" . $reminderemails . "\" />\r\n";
1718
- echo "<input type=\"submit\" class=\"button-secondary\" name=\"remind\" value=\"" . __('Send Reminder Email', 'subscribe2') . "\" /></td>\r\n";
1719
- } else {
1720
- echo "<td width=\"25%\"></td>";
1721
- }
1722
- if ( !empty($subscribers) ) {
1723
- $exportcsv = implode(",\r\n", $subscribers);
1724
- echo "<td width=\"25%\" align=\"right\"><input type=\"hidden\" name=\"exportcsv\" value=\"" . $what . "\" />\r\n";
1725
- echo "<input type=\"submit\" class=\"button-secondary\" name=\"csv\" value=\"" . __('Save Emails to CSV File', 'subscribe2') . "\" /></td>\r\n";
1726
- }
1727
- echo "</tr></table>";
1728
-
1729
- echo "<table class=\"widefat\" cellpadding=\"2\" cellspacing=\"2\">";
1730
- if ( !empty($subscribers) ) {
1731
- echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n";
1732
- echo "<td align=\"right\">" . $strip . "</td></tr>\r\n";
1733
- }
1734
- if ( !empty($subscribers) ) {
1735
- if ( is_int($this->subscribe2_options['entries']) ) {
1736
- $subscriber_chunks = array_chunk($subscribers, $this->subscribe2_options['entries']);
1737
- } else {
1738
- $subscriber_chunks = array_chunk($subscribers, 25);
1739
- }
1740
- $chunk = $page - 1;
1741
- $subscribers = $subscriber_chunks[$chunk];
1742
- echo "<tr class=\"alternate\" style=\"height:1.5em;\">\r\n";
1743
- echo "<td width=\"4%\" align=\"center\">";
1744
- echo "<img src=\"" . $urlpath . "include/accept.png\" alt=\"&lt;\" title=\"" . __('Confirm this email address', 'subscribe2') . "\" /></td>\r\n";
1745
- echo "<td width=\"4%\" align=\"center\">";
1746
- echo "<img src=\"" . $urlpath . "include/exclamation.png\" alt=\"&gt;\" title=\"" . __('Unconfirm this email address', 'subscribe2') . "\" /></td>\r\n";
1747
- echo "<td width=\"4%\" align=\"center\">";
1748
- echo "<img src=\"" . $urlpath . "include/cross.png\" alt=\"X\" title=\"" . __('Delete this email address', 'subscribe2') . "\" /></td><td></td></tr>\r\n";
1749
- echo "<tr><td align=\"center\"><input type=\"checkbox\" name=\"checkall\" value=\"confirm_checkall\" /></td>\r\n";
1750
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"checkall\" value=\"unconfirm_checkall\" /></td>\r\n";
1751
- echo "<td align=\"center\"><input type=\"checkbox\" name=\"checkall\" value=\"delete_checkall\" /></td>\r\n";
1752
- echo "<td align=\"left\"><strong>" . __('Select / Unselect All', 'subscribe2') . "</strong></td></tr>\r\n";
1753
-
1754
- foreach ( $subscribers as $subscriber ) {
1755
- echo "<tr class=\"$alternate\" style=\"height:1.5em;\">";
1756
- echo "<td align=\"center\">\r\n";
1757
- if ( in_array($subscriber, $confirmed) ) {
1758
- echo "</td><td align=\"center\">\r\n";
1759
- echo "<input class=\"unconfirm_checkall\" title=\"" . __('Unconfirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"unconfirm[]\" value=\"" . $subscriber . "\" /></td>\r\n";
1760
- echo "<td align=\"center\">\r\n";
1761
- echo "<input class=\"delete_checkall\" title=\"" . __('Delete this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"delete[]\" value=\"" . $subscriber . "\" />\r\n";
1762
- echo "</td>\r\n";
1763
- echo "<td><span style=\"color:#006600\">&#x221A;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1764
- echo "(<span style=\"color:#006600\"><abbr title=\"" . $this->signup_ip($subscriber) . "\">" . $this->signup_date($subscriber) . "</abbr></span>)\r\n";
1765
- } elseif ( in_array($subscriber, $unconfirmed) ) {
1766
- echo "<input class=\"confirm_checkall\" title=\"" . __('Confirm this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"confirm[]\" value=\"" . $subscriber . "\" /></td>\r\n";
1767
- echo "<td align=\"center\"></td>\r\n";
1768
- echo "<td align=\"center\">\r\n";
1769
- echo "<input class=\"delete_checkall\" title=\"" . __('Delete this email address', 'subscribe2') . "\" type=\"checkbox\" name=\"delete[]\" value=\"" . $subscriber . "\" />\r\n";
1770
- echo "</td>\r\n";
1771
- echo "<td><span style=\"color:#FF0000\">&nbsp;!&nbsp;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1772
- echo "(<span style=\"color:#FF0000\"><abbr title=\"" . $this->signup_ip($subscriber) . "\">" . $this->signup_date($subscriber) . "</abbr></span>)\r\n";
1773
- } elseif ( in_array($subscriber, $all_users) ) {
1774
- echo "</td><td align=\"center\"></td><td align=\"center\"></td>\r\n";
1775
- echo "<td><span style=\"color:#006600\">&reg;&nbsp;&nbsp;</span><a href=\"mailto:" . $subscriber . "\">" . $subscriber . "</a>\r\n";
1776
- echo "(<a href=\"" . get_option('siteurl') . "/wp-admin/users.php?page=s2_users&amp;email=" . urlencode($subscriber) . "\">" . __('edit', 'subscribe2') . "</a>)\r\n";
1777
- }
1778
- echo "</td></tr>\r\n";
1779
- ('alternate' == $alternate) ? $alternate = '' : $alternate = 'alternate';
1780
- }
1781
- } else {
1782
- if ( $_POST['searchterm'] ) {
1783
- echo "<tr><td align=\"center\"><b>" . __('No matching subscribers found', 'subscribe2') . "</b></td></tr>\r\n";
1784
- } else {
1785
- echo "<tr><td align=\"center\"><b>" . __('NONE', 'subscribe2') . "</b></td></tr>\r\n";
1786
- }
1787
- }
1788
- if ( !empty($subscribers) ) {
1789
- echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" class=\"button-secondary\" name=\"process\" value=\"" . __('Process', 'subscribe2') . "\" /></td>\r\n";
1790
- echo "<td align=\"right\">" . $strip . "</td></tr>\r\n";
1791
- }
1792
- echo "</table>\r\n";
1793
-
1794
- // show bulk managment form if filtered in some Registered Users
1795
- if ( in_array($what, array('registered', 'all_users')) || is_numeric($what) ) {
1796
- $subscribers_string = implode(',', $subscribers);
1797
- echo "<h2>" . __('Categories', 'subscribe2') . "</h2>\r\n";
1798
- echo __('Preferences for Registered Users selected in the filter above can be changed using this section.', 'subscribe2') . "<br />\r\n";
1799
- echo "<strong><em style=\"color: red\">" . __('Consider User Privacy as changes cannot be undone', 'subscribe2') . "</em></strong><br />\r\n";
1800
- echo "<br />" . __('Action to perform', 'subscribe2') . ":\r\n";
1801
- echo "<label><input type=\"radio\" name=\"manage\" value=\"subscribe\" checked=\"checked\" /> " . __('Subscribe', 'subscribe2') . "</label>&nbsp;&nbsp;\r\n";
1802
- echo "<label><input type=\"radio\" name=\"manage\" value=\"unsubscribe\" /> " . __('Unsubscribe', 'subscribe2') . "</label><br /><br />\r\n";
1803
- echo "<input type=\"hidden\" name=\"emails\" value=\"$subscribers_string\" />\r\n";
1804
- $this->display_category_form();
1805
- echo "<p class=\"submit\"><input type=\"submit\" class=\"button-primary\" name=\"sub_categories\" value=\"" . __('Bulk Update Categories', 'subscribe2') . "\" /></p>";
1806
-
1807
- echo "<br />" . __('Send email as', 'subscribe2') . ":\r\n";
1808
- echo "<label><input type=\"radio\" name=\"format\" value=\"html\" /> " . __('HTML - Full', 'subscribe2') . "</label>&nbsp;&nbsp;\r\n";
1809
- echo "<label><input type=\"radio\" name=\"format\" value=\"html_excerpt\" /> " . __('HTML - Excerpt', 'subscribe2') . "</label>&nbsp;&nbsp;\r\n";
1810
- echo "<label><input type=\"radio\" name=\"format\" value=\"full\" /> " . __('Plain Text - Full', 'subscribe2') . "</label>&nbsp;&nbsp;\r\n";
1811
- echo "<label><input type=\"radio\" name=\"format\" value=\"excerpt\" checked=\"checked\" /> " . __('Plain Text - Excerpt', 'subscribe2') . "</label>\r\n";
1812
- echo "<p class=\"submit\"><input type=\"submit\" class=\"button-primary\" name=\"sub_format\" value=\"" . __('Bulk Update Format', 'subscribe2') . "\" /></p>";
1813
- }
1814
- echo "</form></div>\r\n";
1815
-
1816
- include(ABSPATH . 'wp-admin/admin-footer.php');
1817
- // just to be sure
1818
- die;
1819
- } // end manage_menu()
1820
-
1821
- /**
1822
- Our options page
1823
- */
1824
- function options_menu() {
1825
- global $s2nonce, $wpdb;
1826
-
1827
- // send error message if no WordPress page exists
1828
- $sql = "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' LIMIT 1";
1829
- $id = $wpdb->get_var($sql);
1830
- if ( empty($id) ) {
1831
- echo "<div id=\"message\" class=\"error\"><p><strong>$this->no_page</strong></p></div>";
1832
- }
1833
-
1834
- // was anything POSTed?
1835
- if ( isset( $_POST['s2_admin']) ) {
1836
- check_admin_referer('subscribe2-options_subscribers' . $s2nonce);
1837
- if ( $_POST['reset'] ) {
1838
- $this->reset();
1839
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>$this->options_reset</strong></p></div>";
1840
- } elseif ( $_POST['preview'] ) {
1841
- global $user_email;
1842
- $this->preview_email = true;
1843
- if ( 'never' == $this->subscribe2_options['email_freq'] ) {
1844
- $post = get_posts('numberposts=1');
1845
- $this->publish($post[0], $user_email);
1846
- } else {
1847
- $this->subscribe2_cron($user_email);
1848
- }
1849
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Preview message(s) sent to logged in user', 'subscribe2') . "</strong></p></div>";
1850
- } elseif ( $_POST['resend'] ) {
1851
- $status = $this->subscribe2_cron('', 'resend');
1852
- if ( $status === false ) {
1853
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('The Digest Notification email contained no post information. No email was sent', 'subscribe2') . "</strong></p></div>";
1854
- } else {
1855
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Attempt made to resend the Digest Notification email', 'subscribe2') . "</strong></p></div>";
1856
- }
1857
- } elseif ( $_POST['submit'] ) {
1858
- // BCClimit
1859
- if ( is_numeric($_POST['bcc']) && $_POST['bcc'] >= 0 ) {
1860
- $this->subscribe2_options['bcclimit'] = $_POST['bcc'];
1861
- }
1862
- // admin_email
1863
- $this->subscribe2_options['admin_email'] = $_POST['admin_email'];
1864
-
1865
- // send as author or admin?
1866
- $sender = 'author';
1867
- if ( is_numeric($_POST['sender']) ) {
1868
- $sender = $_POST['sender'];
1869
- }
1870
- $this->subscribe2_options['sender'] = $sender;
1871
-
1872
- // send email for pages, private and password protected posts
1873
- $this->subscribe2_options['stylesheet'] = $_POST['stylesheet'];
1874
- $this->subscribe2_options['pages'] = $_POST['pages'];
1875
- $this->subscribe2_options['password'] = $_POST['password'];
1876
- $this->subscribe2_options['private'] = $_POST['private'];
1877
- $this->subscribe2_options['cron_order'] = $_POST['cron_order'];
1878
-
1879
- // send per-post or digest emails
1880
- $email_freq = $_POST['email_freq'];
1881
- $scheduled_time = wp_next_scheduled('s2_digest_cron');
1882
- if ( $email_freq != $this->subscribe2_options['email_freq'] || $_POST['hour'] != date('H', $scheduled_time) ) {
1883
- $this->subscribe2_options['email_freq'] = $email_freq;
1884
- wp_clear_scheduled_hook('s2_digest_cron');
1885
- $scheds = (array)wp_get_schedules();
1886
- $interval = ( isset($scheds[$email_freq]['interval']) ) ? (int) $scheds[$email_freq]['interval'] : 0;
1887
- if ( $interval == 0 ) {
1888
- // if we are on per-post emails remove last_cron entry
1889
- unset($this->subscribe2_options['last_s2cron']);
1890
- } else {
1891
- // if we are using digest schedule the event and prime last_cron as now
1892
- $time = time() + $interval;
1893
- if ( $interval < 86400 ) {
1894
- // Schedule CRON events occurring less than daily starting now and periodically thereafter
1895
- $maybe_time = mktime($_POST['hour'], 0, 0, date('m', time()), date('d', time()), date('Y', time()));
1896
- // is maybe_time in the future
1897
- $offset = $maybe_time - time();
1898
- // is maybe_time + $interval in the future
1899
- $offset2 = ($maybe_time + $interval) - time();
1900
- if ( $offset < 0 ) {
1901
- if ( $offset2 < 0 ) {
1902
- $timestamp = &$time;
1903
- } else {
1904
- $timestamp = $maybe_time + $interval;
1905
- }
1906
- } else {
1907
- $timestamp = &$maybe_time;
1908
- }
1909
- } else {
1910
- // Schedule other CRON events starting at user defined hour and periodically thereafter
1911
- $timestamp = mktime($_POST['hour'], 0, 0, date('m', $time), date('d', $time), date('Y', $time));
1912
- }
1913
- wp_schedule_event($timestamp, $email_freq, 's2_digest_cron');
1914
- if ( !isset($this->subscribe2_options['last_s2cron']) ) {
1915
- $this->subscribe2_options['last_s2cron'] = current_time('mysql');
1916
- }
1917
- }
1918
- }
1919
-
1920
- // email subject and body templates
1921
- // ensure that are not empty before updating
1922
- if ( !empty($_POST['notification_subject']) ) {
1923
- $this->subscribe2_options['notification_subject'] = $_POST['notification_subject'];
1924
- }
1925
- if ( !empty($_POST['mailtext']) ) {
1926
- $this->subscribe2_options['mailtext'] = $_POST['mailtext'];
1927
- }
1928
- if ( !empty($_POST['confirm_subject']) ) {
1929
- $this->subscribe2_options['confirm_subject'] = $_POST['confirm_subject'];
1930
- }
1931
- if ( !empty($_POST['confirm_email']) ) {
1932
- $this->subscribe2_options['confirm_email'] = $_POST['confirm_email'];
1933
- }
1934
- if ( !empty($_POST['remind_subject']) ) {
1935
- $this->subscribe2_options['remind_subject'] = $_POST['remind_subject'];
1936
- }
1937
- if ( !empty($_POST['remind_email']) ) {
1938
- $this->subscribe2_options['remind_email'] = $_POST['remind_email'];
1939
- }
1940
-
1941
- // excluded categories
1942
- if ( !empty($_POST['category']) ) {
1943
- $exclude_cats = implode(',', $_POST['category']);
1944
- } else {
1945
- $exclude_cats = '';
1946
- }
1947
- $this->subscribe2_options['exclude'] = $exclude_cats;
1948
- // allow override?
1949
- ( isset($_POST['reg_override']) ) ? $override = '1' : $override = '0';
1950
- $this->subscribe2_options['reg_override'] = $override;
1951
-
1952
- // default WordPress page where Subscribe2 token is placed
1953
- if ( is_numeric($_POST['page']) && $_POST['page'] >= 0 ) {
1954
- $this->subscribe2_options['s2page'] = $_POST['page'];
1955
- }
1956
-
1957
- // Number of subscriber per page
1958
- if ( is_numeric($_POST['entries']) && $_POST['entries'] > 0 ) {
1959
- $this->subscribe2_options['entries'] = (int)$_POST['entries'];
1960
- }
1961
-
1962
- // show meta link?
1963
- ( $_POST['show_meta'] == '1' ) ? $showmeta = '1' : $showmeta = '0';
1964
- $this->subscribe2_options['show_meta'] = $showmeta;
1965
-
1966
- // show button?
1967
- ( $_POST['show_button'] == '1' ) ? $showbutton = '1' : $showbutton = '0';
1968
- $this->subscribe2_options['show_button'] = $showbutton;
1969
-
1970
- // show widget in Presentation->Widgets
1971
- ( $_POST['widget'] == '1' ) ? $showwidget = '1' : $showwidget = '0';
1972
- $this->subscribe2_options['widget'] = $showwidget;
1973
-
1974
- // show counterwidget in Presentation->Widgets
1975
- ( $_POST['counterwidget'] == '1' ) ? $showcounterwidget = '1' : $showcounterwidget = '0';
1976
- $this->subscribe2_options['counterwidget'] = $showcounterwidget;
1977
-
1978
- // Subscribe2 over ride postmeta checked by default
1979
- ( $_POST['s2meta_default'] == '1' ) ? $s2meta_default = '1' : $s2meta_default = '0';
1980
- $this->subscribe2_options['s2meta_default'] = $s2meta_default;
1981
-
1982
- //automatic subscription
1983
- $this->subscribe2_options['autosub'] = $_POST['autosub'];
1984
- $this->subscribe2_options['newreg_override'] = $_POST['newreg_override'];
1985
- $this->subscribe2_options['wpregdef'] = $_POST['wpregdef'];
1986
- $this->subscribe2_options['autoformat'] = $_POST['autoformat'];
1987
- $this->subscribe2_options['show_autosub'] = $_POST['show_autosub'];
1988
- $this->subscribe2_options['autosub_def'] = $_POST['autosub_def'];
1989
-
1990
- //barred domains
1991
- $this->subscribe2_options['barred'] = $_POST['barred'];
1992
-
1993
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>$this->options_saved</strong></p></div>";
1994
- update_option('subscribe2_options', $this->subscribe2_options);
1995
- }
1996
- }
1997
- // show our form
1998
- echo "<div class=\"wrap\">";
1999
- screen_icon();
2000
- echo "<h2>" . __('Subscribe2 Settings', 'subscribe2') . "</h2>\r\n";
2001
- echo "<a href=\"http://subscribe2.wordpress.com/\">" . __('Plugin Blog', 'subscribe2') . "</a> | ";
2002
- 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>";
2003
- echo "<form method=\"post\" action=\"\">\r\n";
2004
- if ( function_exists('wp_nonce_field') ) {
2005
- wp_nonce_field('subscribe2-options_subscribers' . $s2nonce);
2006
- }
2007
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"options\" />\r\n";
2008
- echo "<input type=\"hidden\" id=\"jsbcc\" value=\"" . $this->subscribe2_options['bcclimit'] . "\" />";
2009
- echo "<input type=\"hidden\" id=\"jspage\" value=\"" . $this->subscribe2_options['s2page'] . "\" />";
2010
- echo "<input type=\"hidden\" id=\"jsentries\" value=\"" . $this->subscribe2_options['entries'] . "\" />";
2011
-
2012
- // settings for outgoing emails
2013
- echo "<h2>" . __('Notification Settings', 'subscribe2') . "</h2>\r\n";
2014
- echo __('Restrict the number of recipients per email to (0 for unlimited)', 'subscribe2') . ': ';
2015
- echo "<span id=\"s2bcc_1\"><span id=\"s2bcc\" style=\"background-color: #FFFBCC\">" . $this->subscribe2_options['bcclimit'] . "</span> ";
2016
- echo "<a href=\"#\" onclick=\"s2_show('bcc'); return false;\">" . __('Edit', 'subscribe2') . "</a></span>\n";
2017
- echo "<span id=\"s2bcc_2\">\r\n";
2018
- echo "<input type=\"text\" name=\"bcc\" value=\"" . $this->subscribe2_options['bcclimit'] . "\" size=\"3\" />\r\n";
2019
- echo "<a href=\"#\" onclick=\"s2_update('bcc'); return false;\">". __('Update', 'subscribe2') . "</a>\n";
2020
- echo "<a href=\"#\" onclick=\"s2_revert('bcc'); return false;\">". __('Revert', 'subscribe2') . "</a></span>\n";
2021
-
2022
- echo "<br /><br />" . __('Send Admins notifications for new', 'subscribe2') . ': ';
2023
- echo "<label><input type=\"radio\" name=\"admin_email\" value=\"subs\"";
2024
- if ( 'subs' == $this->subscribe2_options['admin_email'] ) {
2025
- echo " checked=\"checked\"";
2026
- }
2027
- echo " /> " . __('Subscriptions', 'subscribe2') . "</label>&nbsp;&nbsp;";
2028
- echo "<label><input type=\"radio\" name=\"admin_email\" value=\"unsubs\"";
2029
- if ( 'unsubs' == $this->subscribe2_options['admin_email'] ) {
2030
- echo " checked=\"checked\"";
2031
- }
2032
- echo " /> " . __('Unsubscriptions', 'subscribe2') . "</label>&nbsp;&nbsp;";
2033
- echo "<label><input type=\"radio\" name=\"admin_email\" value=\"both\"";
2034
- if ( 'both' == $this->subscribe2_options['admin_email'] ) {
2035
- echo " checked=\"checked\"";
2036
- }
2037
- echo " /> " . __('Both', 'subscribe2') . "</label>&nbsp;&nbsp;";
2038
- echo "<label><input type=\"radio\" name=\"admin_email\" value=\"none\"";
2039
- if ( 'none' == $this->subscribe2_options['admin_email'] ) {
2040
- echo " checked=\"checked\"";
2041
- }
2042
- echo " /> " . __('Neither', 'subscribe2') . "</label><br /><br />\r\n";
2043
-
2044
- echo __('Include theme CSS stylesheet in HTML notifications', 'subscribe2') . ': ';
2045
- echo "<label><input type=\"radio\" name=\"stylesheet\" value=\"yes\"";
2046
- if ( 'yes' == $this->subscribe2_options['stylesheet'] ) {
2047
- echo " checked=\"checked\"";
2048
- }
2049
- echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2050
- echo "<label><input type=\"radio\" name=\"stylesheet\" value=\"no\"";
2051
- if ( 'no' == $this->subscribe2_options['stylesheet'] ) {
2052
- echo " checked=\"checked\"";
2053
- }
2054
- echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2055
-
2056
- echo __('Send Emails for Pages', 'subscribe2') . ': ';
2057
- echo "<label><input type=\"radio\" name=\"pages\" value=\"yes\"";
2058
- if ( 'yes' == $this->subscribe2_options['pages'] ) {
2059
- echo " checked=\"checked\"";
2060
- }
2061
- echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2062
- echo "<label><input type=\"radio\" name=\"pages\" value=\"no\"";
2063
- if ( 'no' == $this->subscribe2_options['pages'] ) {
2064
- echo " checked=\"checked\"";
2065
- }
2066
- echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2067
- echo __('Send Emails for Password Protected Posts', 'subscribe2') . ': ';
2068
- echo "<label><input type=\"radio\" name=\"password\" value=\"yes\"";
2069
- if ( 'yes' == $this->subscribe2_options['password'] ) {
2070
- echo " checked=\"checked\"";
2071
- }
2072
- echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2073
- echo "<label><input type=\"radio\" name=\"password\" value=\"no\"";
2074
- if ( 'no' == $this->subscribe2_options['password'] ) {
2075
- echo " checked=\"checked\"";
2076
- }
2077
- echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2078
- echo __('Send Emails for Private Posts', 'subscribe2') . ': ';
2079
- echo "<label><input type=\"radio\" name=\"private\" value=\"yes\"";
2080
- if ( 'yes' == $this->subscribe2_options['private'] ) {
2081
- echo " checked=\"checked\"";
2082
- }
2083
- echo " /> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2084
- echo "<label><input type=\"radio\" name=\"private\" value=\"no\"";
2085
- if ( 'no' == $this->subscribe2_options['private'] ) {
2086
- echo " checked=\"checked\"";
2087
- }
2088
- echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2089
- echo __('Send Email From', 'subscribe2') . ': ';
2090
- echo "<label>\r\n";
2091
- $this->admin_dropdown(true);
2092
- echo "</label><br /><br />\r\n";
2093
- if ( function_exists('wp_schedule_event') ) {
2094
- echo __('Send Emails', 'subscribe2') . ": <br /><br />\r\n";
2095
- $this->display_digest_choices();
2096
- echo __('For digest notifications, date order for posts is', 'subscribe2') . ": \r\n";
2097
- echo "<label><input type=\"radio\" name=\"cron_order\" value=\"desc\"";
2098
- if ( 'desc' == $this->subscribe2_options['cron_order'] ) {
2099
- echo " checked=\"checked\"";
2100
- }
2101
- echo " /> " . __('Descending', 'subscribe2') . "</label>&nbsp;&nbsp;";
2102
- echo "<label><input type=\"radio\" name=\"cron_order\" value=\"asc\"";
2103
- if ( 'asc' == $this->subscribe2_options['cron_order'] ) {
2104
- echo " checked=\"checked\"";
2105
- }
2106
- echo " /> " . __('Ascending', 'subscribe2') . "</label><br /><br />\r\n";
2107
- }
2108
-
2109
- // email templates
2110
- echo "<h2>" . __('Email Templates', 'subscribe2') . "</h2>\r\n";
2111
- echo"<br />";
2112
- echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"1\" class=\"editform\">\r\n";
2113
- echo "<tr><td>";
2114
- echo __('New Post email (must not be empty)', 'subscribe2') . ":<br />\r\n";
2115
- echo __('Subject Line', 'subscribe2') . ": ";
2116
- echo "<input type=\"text\" name=\"notification_subject\" value=\"" . stripslashes($this->subscribe2_options['notification_subject']) . "\" size=\"30\" />";
2117
- echo "<br />\r\n";
2118
- echo "<textarea rows=\"9\" cols=\"60\" name=\"mailtext\">" . stripslashes($this->subscribe2_options['mailtext']) . "</textarea><br /><br />\r\n";
2119
- echo "</td><td valign=\"top\" rowspan=\"3\">";
2120
- echo "<p class=\"submit\"><input type=\"submit\" class=\"button-secondary\" name=\"preview\" value=\"" . __('Send Email Preview', 'subscribe2') . "\" /></p>\r\n";
2121
- echo "<h3>" . __('Message substitions', 'subscribe2') . "</h3>\r\n";
2122
- echo "<dl>";
2123
- echo "<dt><b>BLOGNAME</b></dt><dd>" . get_option('blogname') . "</dd>\r\n";
2124
- echo "<dt><b>BLOGLINK</b></dt><dd>" . get_option('home') . "</dd>\r\n";
2125
- echo "<dt><b>TITLE</b></dt><dd>" . __("the post's title<br />(<i>for per-post emails only</i>)", 'subscribe2') . "</dd>\r\n";
2126
- echo "<dt><b>POST</b></dt><dd>" . __("the excerpt or the entire post<br />(<i>based on the subscriber's preferences</i>)", 'subscribe2') . "</dd>\r\n";
2127
- echo "<dt><b>POSTTIME</b></dt><dd>" . __("the excerpt of the post and the time it was posted<br />(<i>for digest emails only</i>)", 'subscribe2') . "</dd>\r\n";
2128
- echo "<dt><b>TABLE</b></dt><dd>" . __("a list of post titles<br />(<i>for digest emails only</i>)", 'subscribe2') . "</dd>\r\n";
2129
- echo "<dt><b>TABLELINKS</b></dt><dd>" . __("a list of post titles followed by links to the atricles<br />(<i>for digest emails only</i>)", 'subscribe2') . "</dd>\r\n";
2130
- echo "<dt><b>PERMALINK</b></dt><dd>" . __("the post's permalink<br />(<i>for per-post emails only</i>)", 'subscribe2') . "</dd>\r\n";
2131
- 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";
2132
- echo "<dt><b>DATE</b></dt><dd>" . __("the date the post was made<br />(<i>for per-post emails only</i>)", "subscribe2") . "</dd>\r\n";
2133
- echo "<dt><b>TIME</b></dt><dd>" . __("the time the post was made<br />(<i>for per-post emails only</i>)", "subscribe2") . "</dd>\r\n";
2134
- echo "<dt><b>MYNAME</b></dt><dd>" . __("the admin or post author's name", 'subscribe2') . "</dd>\r\n";
2135
- echo "<dt><b>EMAIL</b></dt><dd>" . __("the admin or post author's email", 'subscribe2') . "</dd>\r\n";
2136
- echo "<dt><b>AUTHORNAME</b></dt><dd>" . __("the post author's name", 'subscribe2') . "</dd>\r\n";
2137
- echo "<dt><b>LINK</b></dt><dd>" . __("the generated link to confirm a request<br />(<i>only used in the confirmation email template</i>)", 'subscribe2') . "</dd>\r\n";
2138
- echo "<dt><b>ACTION</b></dt><dd>" . __("Action performed by LINK in confirmation email<br />(<i>only used in the confirmation email template</i>)", 'subscribe2') . "</dd>\r\n";
2139
- echo "<dt><b>CATS</b></dt><dd>" . __("the post's assigned categories", 'subscribe2') . "</dd>\r\n";
2140
- echo "<dt><b>TAGS</b></dt><dd>" . __("the post's assigned Tags", 'subscribe2') . "</dd>\r\n";
2141
- echo "<dt><b>COUNT</b></dt><dd>" . __("the number of posts included in the digest email<br />(<i>for digest emails only</i>)", 'subscribe2') . "</dd>\r\n";
2142
- echo "</dl></td></tr><tr><td>";
2143
- echo __('Subscribe / Unsubscribe confirmation email', 'subscribe2') . ":<br />\r\n";
2144
- echo __('Subject Line', 'subscribe2') . ": ";
2145
- echo "<input type=\"text\" name=\"confirm_subject\" value=\"" . stripslashes($this->subscribe2_options['confirm_subject']) . "\" size=\"30\" /><br />\r\n";
2146
- echo "<textarea rows=\"9\" cols=\"60\" name=\"confirm_email\">" . stripslashes($this->subscribe2_options['confirm_email']) . "</textarea><br /><br />\r\n";
2147
- echo "</td></tr><tr valign=\"top\"><td>";
2148
- echo __('Reminder email to Unconfirmed Subscribers', 'subscribe2') . ":<br />\r\n";
2149
- echo __('Subject Line', 'subscribe2') . ": ";
2150
- echo "<input type=\"text\" name=\"remind_subject\" value=\"" . stripslashes($this->subscribe2_options['remind_subject']) . "\" size=\"30\" /><br />\r\n";
2151
- echo "<textarea rows=\"9\" cols=\"60\" name=\"remind_email\">" . stripslashes($this->subscribe2_options['remind_email']) . "</textarea><br /><br />\r\n";
2152
- echo "</td></tr></table><br />\r\n";
2153
-
2154
- // excluded categories
2155
- echo "<h2>" . __('Excluded Categories', 'subscribe2') . "</h2>\r\n";
2156
- echo"<p>";
2157
- echo "<strong><em style=\"color: red\">" . __('Posts assigned to any Excluded Category do not generate notifications and are not included in digest notifications', 'subscribe2') . "</em></strong><br />\r\n";
2158
- echo"</p>";
2159
- $this->display_category_form(explode(',', $this->subscribe2_options['exclude']));
2160
- echo "<center><label><input type=\"checkbox\" name=\"reg_override\" value=\"1\"";
2161
- if ( '1' == $this->subscribe2_options['reg_override'] ) {
2162
- echo " checked=\"checked\"";
2163
- }
2164
- echo " /> " . __('Allow registered users to subscribe to excluded categories?', 'subscribe2') . "</label></center><br />\r\n";
2165
-
2166
- // Appearance options
2167
- echo "<h2>" . __('Appearance', 'subscribe2') . "</h2>\r\n";
2168
- echo"<p>";
2169
-
2170
- // WordPress page ID where subscribe2 token is used
2171
- echo __('Set default Subscribe2 page as ID', 'subscribe2') . ': ';
2172
- $this->pages_dropdown();
2173
-
2174
- // Number of subscribers per page
2175
- echo "<br /><br />" . __('Set the number of Subscribers displayed per page', 'subscribe2') . ': ';
2176
- echo "<span id=\"s2entries_1\"><span id=\"s2entries\" style=\"background-color: #FFFBCC\">" . $this->subscribe2_options['entries'] . "</span> ";
2177
- echo "<a href=\"#\" onclick=\"s2_show('entries'); return false;\">" . __('Edit', 'subscribe2') . "</a></span>\n";
2178
- echo "<span id=\"s2entries_2\">\r\n";
2179
- echo "<input type=\"text\" name=\"entries\" value=\"" . $this->subscribe2_options['entries'] . "\" size=\"3\" />\r\n";
2180
- echo "<a href=\"#\" onclick=\"s2_update('entries'); return false;\">". __('Update', 'subscribe2') . "</a>\n";
2181
- echo "<a href=\"#\" onclick=\"s2_revert('entries'); return false;\">". __('Revert', 'subscribe2') . "</a></span>\n";
2182
-
2183
- // show link to WordPress page in meta
2184
- echo "<br /><br /><label><input type=\"checkbox\" name=\"show_meta\" value=\"1\"";
2185
- if ( '1' == $this->subscribe2_options['show_meta'] ) {
2186
- echo " checked=\"checked\"";
2187
- }
2188
- echo " /> " . __('Show a link to your subscription page in "meta"?', 'subscribe2') . "</label><br /><br />\r\n";
2189
-
2190
- // show QuickTag button
2191
- echo "<label><input type=\"checkbox\" name=\"show_button\" value=\"1\"";
2192
- if ( '1' == $this->subscribe2_options['show_button'] ) {
2193
- echo " checked=\"checked\"";
2194
- }
2195
- echo " /> " . __('Show the Subscribe2 button on the Write toolbar?', 'subscribe2') . "</label><br /><br />\r\n";
2196
-
2197
- // show Widget
2198
- echo "<label><input type=\"checkbox\" name=\"widget\" value=\"1\"";
2199
- if ( '1' == $this->subscribe2_options['widget'] ) {
2200
- echo " checked=\"checked\"";
2201
- }
2202
- echo " /> " . __('Enable Subscribe2 Widget?', 'subscribe2') . "</label><br /><br />\r\n";
2203
-
2204
- // show Counter Widget
2205
- echo "<label><input type=\"checkbox\" name=\"counterwidget\" value=\"1\"";
2206
- if ( '1' == $this->subscribe2_options['counterwidget'] ) {
2207
- echo " checked=\"checked\"";
2208
- }
2209
- echo " /> " . __('Enable Subscribe2 Counter Widget?', 'subscribe2') . "</label><br /><br />\r\n";
2210
-
2211
- // s2_meta checked by default
2212
- echo "<label><input type =\"checkbox\" name=\"s2meta_default\" value=\"1\"";
2213
- if ( "1" == $this->subscribe2_options['s2meta_default'] ) {
2214
- echo " checked=\"checked\"";
2215
- }
2216
- echo " /> " . __('Disable email notifications is checked by default on authoring pages?', 'subscribe2') . "</label>\r\n";
2217
- echo "</p>";
2218
-
2219
- //Auto Subscription for new registrations
2220
- echo "<h2>" . __('Auto Subscribe', 'subscribe2') . "</h2>\r\n";
2221
- echo"<p>";
2222
- echo __('Subscribe new users registering with your blog', 'subscribe2') . ":<br />\r\n";
2223
- echo "<label><input type=\"radio\" name=\"autosub\" value=\"yes\"";
2224
- if ( 'yes' == $this->subscribe2_options['autosub'] ) {
2225
- echo " checked=\"checked\"";
2226
- }
2227
- echo " /> " . __('Automatically', 'subscribe2') . "</label>&nbsp;&nbsp;";
2228
- echo "<label><input type=\"radio\" name=\"autosub\" value=\"wpreg\"";
2229
- if ( 'wpreg' == $this->subscribe2_options['autosub'] ) {
2230
- echo " checked=\"checked\"";
2231
- }
2232
- echo " /> " . __('Display option on Registration Form', 'subscribe2') . "</label>&nbsp;&nbsp;";
2233
- echo "<label><input type=\"radio\" name=\"autosub\" value=\"no\"";
2234
- if ( 'no' == $this->subscribe2_options['autosub'] ) {
2235
- echo " checked=\"checked\"";
2236
- }
2237
- echo " /> " . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2238
- echo __('Auto-subscribe includes any excluded categories', 'subscribe2') . ":<br />\r\n";
2239
- echo "<label><input type=\"radio\" name=\"newreg_override\" value=\"yes\"";
2240
- if ( 'yes' == $this->subscribe2_options['newreg_override'] ) {
2241
- echo " checked=\"checked\"";
2242
- }
2243
- echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2244
- echo "<label><input type=\"radio\" name=\"newreg_override\" value=\"no\"";
2245
- if ( 'no' == $this->subscribe2_options['newreg_override'] ) {
2246
- echo " checked=\"checked\"";
2247
- }
2248
- echo " />" . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2249
- echo __('Registration Form option is checked by default', 'subscribe2') . ":<br />\r\n";
2250
- echo "<label><input type=\"radio\" name=\"wpregdef\" value=\"yes\"";
2251
- if ( 'yes' == $this->subscribe2_options['wpregdef'] ) {
2252
- echo " checked=\"checked\"";
2253
- }
2254
- echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2255
- echo "<label><input type=\"radio\" name=\"wpregdef\" value=\"no\"";
2256
- if ( 'no' == $this->subscribe2_options['wpregdef'] ) {
2257
- echo " checked=\"checked\"";
2258
- }
2259
- echo " />" . __('No', 'subscribe2') . "</label><br /><br />\r\n";
2260
- echo __('Auto-subscribe users to receive email as', 'subscribe2') . ": <br />\r\n";
2261
- echo "<label><input type=\"radio\" name=\"autoformat\" value=\"html\"";
2262
- if ( 'html' == $this->subscribe2_options['autoformat'] ) {
2263
- echo "checked=\"checked\" ";
2264
- }
2265
- echo "/> " . __('HTML - Full', 'subscribe2') ."</label>&nbsp;&nbsp;";
2266
- echo "<label><input type=\"radio\" name=\"autoformat\" value=\"html_excerpt\"";
2267
- if ( 'html_excerpt' == $this->subscribe2_options['autoformat'] ) {
2268
- echo "checked=\"checked\" ";
2269
- }
2270
- echo "/> " . __('HTML - Excerpt', 'subscribe2') ."</label>&nbsp;&nbsp;";
2271
- echo "<label><input type=\"radio\" name=\"autoformat\" value=\"post\" ";
2272
- if ( 'post' == $this->subscribe2_options['autoformat'] ) {
2273
- echo "checked=\"checked\" ";
2274
- }
2275
- echo "/> " . __('Plain Text - Full', 'subscribe2') . "</label>&nbsp;&nbsp;";
2276
- echo "<label><input type=\"radio\" name=\"autoformat\" value=\"excerpt\" ";
2277
- if ( 'excerpt' == $this->subscribe2_options['autoformat'] ) {
2278
- echo "checked=\"checked\" ";
2279
- }
2280
- echo "/> " . __('Plain Text - Excerpt', 'subscribe2') . "</label><br /><br />";
2281
- echo __('Registered Users have the option to auto-subscribe to new categories', 'subscribe2') . ": <br />\r\n";
2282
- echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"yes\"";
2283
- if ( 'yes' == $this->subscribe2_options['show_autosub'] ) {
2284
- echo " checked=\"checked\"";
2285
- }
2286
- echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2287
- echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"no\"";
2288
- if ( 'no' == $this->subscribe2_options['show_autosub'] ) {
2289
- echo " checked=\"checked\"";
2290
- }
2291
- echo " />" . __('No', 'subscribe2') . "</label>&nbsp;&nbsp;";
2292
- echo "<label><input type=\"radio\" name=\"show_autosub\" value=\"exclude\"";
2293
- if ( 'exclude' == $this->subscribe2_options['show_autosub'] ) {
2294
- echo " checked=\"checked\"";
2295
- }
2296
- echo " />" .__('New categories are immediately excluded', 'subscribe2') . "</label><br /><br />";
2297
- echo __('Option for Registered Users to auto-subscribe to new categories is checked by default', 'subscribe2') . ": <br />\r\n";
2298
- echo "<label><input type=\"radio\" name=\"autosub_def\" value=\"yes\"";
2299
- if ( 'yes' == $this->subscribe2_options['autosub_def'] ) {
2300
- echo " checked=\"checked\"";
2301
- }
2302
- echo " />" . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2303
- echo "<label><input type=\"radio\" name=\"autosub_def\" value=\"no\"";
2304
- if ( 'no' == $this->subscribe2_options['autosub_def'] ) {
2305
- echo " checked=\"checked\"";
2306
- }
2307
- echo " />" . __('No', 'subscribe2');
2308
- echo"</label></p>";
2309
-
2310
- //barred domains
2311
- echo "<h2>" . __('Barred Domains', 'subscribe2') . "</h2>\r\n";
2312
- echo"<p>";
2313
- echo __('Enter domains to bar from public subscriptions: <br /> (Use a new line for each entry and omit the "@" symbol, for example email.com)', 'subscribe2');
2314
- echo "<br />\r\n<textarea style=\"width: 98%;\" rows=\"4\" cols=\"60\" name=\"barred\">" . $this->subscribe2_options['barred'] . "</textarea>";
2315
- echo"</p>";
2316
-
2317
- // submit
2318
- echo "<p class=\"submit\" align=\"center\"><input type=\"submit\" class=\"button-primary\" name=\"submit\" value=\"" . __('Submit', 'subscribe2') . "\" /></p>";
2319
-
2320
- // reset
2321
- echo "<h2>" . __('Reset Default', 'subscribe2') . "</h2>\r\n";
2322
- echo "<p>" . __('Use this to reset all options to their defaults. This <strong><em>will not</em></strong> modify your list of subscribers.', 'subscribe2') . "</p>\r\n";
2323
- echo "<p class=\"submit\" align=\"center\">";
2324
- echo "<input type=\"submit\" id=\"deletepost\" name=\"reset\" value=\"" . __('RESET', 'subscribe2') .
2325
- "\" />";
2326
- echo "</p></form></div>\r\n";
2327
-
2328
- include(ABSPATH . 'wp-admin/admin-footer.php');
2329
- // just to be sure
2330
- die;
2331
- } // end options_menu()
2332
-
2333
- /**
2334
- Our profile menu
2335
- */
2336
- function user_menu() {
2337
- global $user_ID, $s2nonce;
2338
-
2339
- if ( isset($_GET['email']) ) {
2340
- global $wpdb;
2341
- $user_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '" . urldecode($_GET['email']) . "'");
2342
- } else {
2343
- get_currentuserinfo();
2344
- }
2345
-
2346
- // was anything POSTed?
2347
- if ( isset($_POST['s2_admin']) && 'user' == $_POST['s2_admin'] ) {
2348
- check_admin_referer('subscribe2-user_subscribers' . $s2nonce);
2349
-
2350
- echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Subscription preferences updated.', 'subscribe2') . "</strong></p></div>\n";
2351
- update_usermeta($user_ID, 's2_format', $_POST['s2_format']);
2352
- update_usermeta($user_ID, 's2_autosub', $_POST['new_category']);
2353
-
2354
- $cats = $_POST['category'];
2355
-
2356
- if ( empty($cats) || $cats == '-1' ) {
2357
- $oldcats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
2358
- if ( $oldcats ) {
2359
- foreach ( $oldcats as $cat ) {
2360
- delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat);
2361
- }
2362
- }
2363
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), '');
2364
- } elseif ( $cats == 'digest' ) {
2365
- $all_cats = get_categories(array('hide_empty' => false));
2366
- foreach ( $all_cats as $cat ) {
2367
- ('' == $catids) ? $catids = "$cat->term_id" : $catids .= ",$cat->term_id";
2368
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat->term_id, $cat->term_id);
2369
- }
2370
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $catids);
2371
- } else {
2372
- if ( !is_array($cats) ) {
2373
- $cats = array($_POST['category']);
2374
- }
2375
- $old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')));
2376
- $remove = array_diff($old_cats, $cats);
2377
- $new = array_diff($cats, $old_cats);
2378
- if ( !empty($remove) ) {
2379
- // remove subscription to these cat IDs
2380
- foreach ( $remove as $id ) {
2381
- delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id);
2382
- }
2383
- }
2384
- if ( !empty($new) ) {
2385
- // add subscription to these cat IDs
2386
- foreach ( $new as $id ) {
2387
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id, $id);
2388
- }
2389
- }
2390
- update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $cats));
2391
- }
2392
- }
2393
-
2394
- // show our form
2395
- echo "<div class=\"wrap\">";
2396
- screen_icon();
2397
- echo "<h2>" . __('Notification Settings', 'subscribe2') . "</h2>\r\n";
2398
- if ( isset($_GET['email']) ) {
2399
- $user = get_userdata($user_ID);
2400
- echo "<span style=\"color: red;line-height: 300%;\">" . __('Editing Subscribe2 preferences for user', 'subscribe2') . ": " . $user->display_name . "</span>";
2401
- }
2402
- echo "<form method=\"post\" action=\"\">";
2403
- echo "<p>";
2404
- if ( function_exists('wp_nonce_field') ) {
2405
- wp_nonce_field('subscribe2-user_subscribers' . $s2nonce);
2406
- }
2407
- echo "<input type=\"hidden\" name=\"s2_admin\" value=\"user\" />";
2408
- if ( $this->subscribe2_options['email_freq'] == 'never' ) {
2409
- echo __('Receive email as', 'subscribe2') . ": &nbsp;&nbsp;";
2410
- echo "<label><input type=\"radio\" name=\"s2_format\" value=\"html\"";
2411
- if ( 'html' == get_usermeta($user_ID, 's2_format') ) {
2412
- echo "checked=\"checked\" ";
2413
- }
2414
- echo "/> " . __('HTML - Full', 'subscribe2') ."</label>&nbsp;&nbsp;";
2415
- echo "<label><input type=\"radio\" name=\"s2_format\" value=\"html_excerpt\" ";
2416
- if ( 'html_excerpt' == get_usermeta($user_ID, 's2_format') ) {
2417
- echo "checked=\"checked\" ";
2418
- }
2419
- echo "/> " . __('HTML - Excerpt', 'subscribe2') . "</label>&nbsp;&nbsp;";
2420
- echo "<label><input type=\"radio\" name=\"s2_format\" value=\"post\" ";
2421
- if ( 'post' == get_usermeta($user_ID, 's2_format') ) {
2422
- echo "checked=\"checked\" ";
2423
- }
2424
- echo "/> " . __('Plain Text - Full', 'subscribe2') . "</label>&nbsp;&nbsp;";
2425
- echo "<label><input type=\"radio\" name=\"s2_format\" value=\"excerpt\" ";
2426
- if ( 'excerpt' == get_usermeta($user_ID, 's2_format') ) {
2427
- echo "checked=\"checked\" ";
2428
- }
2429
- echo "/> " . __('Plain Text - Excerpt', 'subscribe2') . "</label><br /><br />\r\n";
2430
-
2431
- if ( $this->subscribe2_options['show_autosub'] == 'yes' ) {
2432
- echo __('Automatically subscribe me to newly created categories', 'subscribe2') . ': &nbsp;&nbsp;';
2433
- echo "<label><input type=\"radio\" name=\"new_category\" value=\"yes\" ";
2434
- if ( 'yes' == get_usermeta($user_ID, 's2_autosub') ) {
2435
- echo "checked=\"checked\" ";
2436
- }
2437
- echo "/> " . __('Yes', 'subscribe2') . "</label>&nbsp;&nbsp;";
2438
- echo "<label><input type=\"radio\" name=\"new_category\" value=\"no\" ";
2439
- if ( 'no' == get_usermeta($user_ID, 's2_autosub') ) {
2440
- echo "checked=\"checked\" ";
2441
- }
2442
- echo "/> " . __('No', 'subscribe2') . "</label>";
2443
- echo "</p>";
2444
- }
2445
-
2446
- // subscribed categories
2447
- if ( $this->s2_mu ) {
2448
- global $blog_id;
2449
- $subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
2450
- // if we are subscribed to the current blog display an "unsubscribe" link
2451
- if ( !empty($subscribed) ) {
2452
- $unsubscribe_link = get_option('home') . "/wp-admin/?s2mu_unsubscribe=". $blog_id;
2453
- echo "<p><a href=\"". $unsubscribe_link ."\" class=\"button\">" . __('Unsubscribe me from this blog', 'subscribe2') . "</a></p>";
2454
- } else {
2455
- // else we show a "subscribe" link
2456
- $subscribe_link = get_option('home') . "/wp-admin/?s2mu_subscribe=". $blog_id;
2457
- echo "<p><a href=\"". $subscribe_link ."\" class=\"button\">" . __('Subscribe to all categories', 'subscribe2') . "</a></p>";
2458
- }
2459
- echo "<h2>" . __('Subscribed Categories on', 'subscribe2') . " " . get_option('blogname') . " </h2>\r\n";
2460
- } else {
2461
- echo "<h2>" . __('Subscribed Categories', 'subscribe2') . "</h2>\r\n";
2462
- }
2463
- $this->display_category_form(explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))), $this->subscribe2_options['reg_override']);
2464
- } else {
2465
- // we're doing daily digests, so just show
2466
- // subscribe / unnsubscribe
2467
- echo __('Receive periodic summaries of new posts?', 'subscribe2') . ': &nbsp;&nbsp;';
2468
- echo "<label>";
2469
- echo "<input type=\"radio\" name=\"category\" value=\"digest\" ";
2470
- if ( get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')) ) {
2471
- echo "checked=\"checked\" ";
2472
- }
2473
- echo "/> " . __('Yes', 'subscribe2') . "</label> <label><input type=\"radio\" name=\"category\" value=\"-1\" ";
2474
- if ( !get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')) ) {
2475
- echo "checked=\"checked\" ";
2476
- }
2477
- echo "/> " . __('No', 'subscribe2');
2478
- echo "</label></p>";
2479
- }
2480
-
2481
- // submit
2482
- echo "<p class=\"submit\"><input type=\"submit\" class=\"button-primary\" name=\"submit\" value=\"" . __("Update Preferences", 'subscribe2') . " &raquo;\" /></p>";
2483
- echo "</form>\r\n";
2484
-
2485
- // list of subscribed blogs on wordpress mu
2486
- if ( $this->s2_mu && !isset($_GET['email']) ) {
2487
- global $blog_id;
2488
- $s2blog_id = $blog_id;
2489
- $blogs = $this->get_mu_blog_list();
2490
-
2491
- $blogs_subscribed = array();
2492
- $blogs_notsubscribed = array();
2493
-
2494
- foreach ( $blogs as $key => $blog ) {
2495
- // switch to blog
2496
- switch_to_blog($blog['blog_id']);
2497
-
2498
- // check that the plugin is active on the current blog
2499
- $current_plugins = get_option('active_plugins');
2500
- if ( !is_array($current_plugins) ) {
2501
- $current_plugins = (array)$current_plugins;
2502
- }
2503
- if ( !in_array(S2DIR . '/subscribe2.php', $current_plugins) ) {
2504
- continue;
2505