Subscribe To Comments Reloaded - Version 140220

Version Description

= v140220 =

Security Fix; PLEASE UPGRADE IMMEDIATELY. v140219 fixes an XSS/CSRF vulnerability that was discovered by Tom Adams and reported by a WordPress Plugin Repository moderator.

Download this release

Release Info

Developer reedyseth
Plugin Icon 128x128 Subscribe To Comments Reloaded
Version 140220
Comparing to
See all releases

Code changes from version 140219 to 140220

Files changed (3) hide show
  1. options/index.php +91 -90
  2. readme.txt +183 -179
  3. subscribe-to-comments-reloaded.php +1575 -1575
options/index.php CHANGED
@@ -1,90 +1,91 @@
1
- <?php
2
- // Avoid direct access to this piece of code
3
- if ( ! function_exists( 'is_admin' ) || ! is_admin() ) {
4
- header( 'Location: /' );
5
- exit;
6
- }
7
-
8
- function subscribe_reloaded_update_option( $_option = '', $_value = '', $_type = '' ) {
9
- if ( ! isset( $_value ) ) {
10
- return true;
11
- }
12
-
13
- // Prevent XSS/CSRF attacks
14
- $_value = esc_attr( $_value );
15
-
16
- switch ( $_type ) {
17
- case 'yesno':
18
- if ( $_value == 'yes' || $_value == 'no' ) {
19
- update_option( 'subscribe_reloaded_' . $_option, $_value );
20
-
21
- return true;
22
- }
23
- break;
24
-
25
- case 'integer':
26
- update_option( 'subscribe_reloaded_' . $_option, abs( intval( $_value ) ) );
27
-
28
- return true;
29
- break;
30
-
31
- case 'text-no-encode':
32
- update_option( 'subscribe_reloaded_' . $_option, $_value );
33
-
34
- return true;
35
- break;
36
-
37
- default:
38
- update_option( 'subscribe_reloaded_' . $_option, htmlentities( $_value, ENT_COMPAT, 'UTF-8' ) );
39
-
40
- return true;
41
- break;
42
- }
43
-
44
- return false;
45
- }
46
-
47
- function subscribe_reloaded_get_option( $_option = '', $_default = '' ) {
48
- $value = get_option( 'subscribe_reloaded_' . $_option, $_default );
49
-
50
- return stripslashes( $value );
51
- }
52
-
53
- // Load localization files
54
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
55
-
56
- // Define the panels
57
- $array_panels = array(
58
- __( 'Manage subscriptions', 'subscribe-reloaded' ),
59
- __( 'Comment Form', 'subscribe-reloaded' ),
60
- __( 'Management Page', 'subscribe-reloaded' ),
61
- __( 'Notifications', 'subscribe-reloaded' ),
62
- __( 'Options', 'subscribe-reloaded' ),
63
- __( 'You can help', 'subscribe-reloaded' )
64
- );
65
-
66
- // What panel to display
67
- $current_panel = empty( $_GET['subscribepanel'] ) ? 1 : intval( $_GET['subscribepanel'] );
68
-
69
- // Text direction
70
- if ( $wp_locale->text_direction != 'ltr' ) {
71
- $array_panels = array_reverse( $array_panels, true );
72
- }
73
-
74
- ?>
75
- <div class="wrap">
76
- <div id="subscribe-to-comments-icon" class="icon32 <?php echo $wp_locale->text_direction ?>"></div>
77
- <h2 class="medium">
78
- <?php
79
- foreach ( $array_panels as $a_panel_id => $a_panel_details ) {
80
- echo '<a class="nav-tab nav-tab';
81
- echo ( $current_panel == $a_panel_id + 1 ) ? '-active' : '-inactive';
82
- echo '" href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=' . ( $a_panel_id + 1 ) . '">' . $a_panel_details . '</a>';
83
- }
84
- ?>
85
- </h2>
86
-
87
- <?php if ( is_readable( WP_PLUGIN_DIR . "/subscribe-to-comments-reloaded/options/panel$current_panel.php" ) ) {
88
- require_once WP_PLUGIN_DIR . "/subscribe-to-comments-reloaded/options/panel$current_panel.php";
89
- } ?>
90
- </div>
 
1
+ <?php
2
+ // Avoid direct access to this piece of code
3
+ if ( ! function_exists( 'is_admin' ) || ! is_admin() ) {
4
+ header( 'Location: /' );
5
+ exit;
6
+ }
7
+
8
+ function subscribe_reloaded_update_option( $_option = '', $_value = '', $_type = '' ) {
9
+ if ( ! isset( $_value ) ) {
10
+ return true;
11
+ }
12
+
13
+ // Prevent XSS/CSRF attacks
14
+ $_value = esc_attr( $_value );
15
+
16
+ switch ( $_type ) {
17
+ case 'yesno':
18
+ if ( $_value == 'yes' || $_value == 'no' ) {
19
+ update_option( 'subscribe_reloaded_' . $_option, $_value );
20
+
21
+ return true;
22
+ }
23
+ break;
24
+
25
+ case 'integer':
26
+ update_option( 'subscribe_reloaded_' . $_option, abs( intval( $_value ) ) );
27
+
28
+ return true;
29
+ break;
30
+
31
+ case 'text-no-encode':
32
+ update_option( 'subscribe_reloaded_' . $_option, $_value );
33
+
34
+ return true;
35
+ break;
36
+
37
+ default:
38
+ update_option( 'subscribe_reloaded_' . $_option, htmlentities( $_value, ENT_COMPAT, 'UTF-8' ) );
39
+
40
+ return true;
41
+ break;
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ function subscribe_reloaded_get_option( $_option = '', $_default = '' ) {
48
+ $value = get_option( 'subscribe_reloaded_' . $_option, $_default );
49
+ $value = html_entity_decode( stripslashes( $value ), ENT_COMPAT, 'UTF-8' );
50
+
51
+ return stripslashes( $value );
52
+ }
53
+
54
+ // Load localization files
55
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
56
+
57
+ // Define the panels
58
+ $array_panels = array(
59
+ __( 'Manage subscriptions', 'subscribe-reloaded' ),
60
+ __( 'Comment Form', 'subscribe-reloaded' ),
61
+ __( 'Management Page', 'subscribe-reloaded' ),
62
+ __( 'Notifications', 'subscribe-reloaded' ),
63
+ __( 'Options', 'subscribe-reloaded' ),
64
+ __( 'You can help', 'subscribe-reloaded' )
65
+ );
66
+
67
+ // What panel to display
68
+ $current_panel = empty( $_GET['subscribepanel'] ) ? 1 : intval( $_GET['subscribepanel'] );
69
+
70
+ // Text direction
71
+ if ( $wp_locale->text_direction != 'ltr' ) {
72
+ $array_panels = array_reverse( $array_panels, true );
73
+ }
74
+
75
+ ?>
76
+ <div class="wrap">
77
+ <div id="subscribe-to-comments-icon" class="icon32 <?php echo $wp_locale->text_direction ?>"></div>
78
+ <h2 class="medium">
79
+ <?php
80
+ foreach ( $array_panels as $a_panel_id => $a_panel_details ) {
81
+ echo '<a class="nav-tab nav-tab';
82
+ echo ( $current_panel == $a_panel_id + 1 ) ? '-active' : '-inactive';
83
+ echo '" href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=' . ( $a_panel_id + 1 ) . '">' . $a_panel_details . '</a>';
84
+ }
85
+ ?>
86
+ </h2>
87
+
88
+ <?php if ( is_readable( WP_PLUGIN_DIR . "/subscribe-to-comments-reloaded/options/panel$current_panel.php" ) ) {
89
+ require_once WP_PLUGIN_DIR . "/subscribe-to-comments-reloaded/options/panel$current_panel.php";
90
+ } ?>
91
+ </div>
readme.txt CHANGED
@@ -1,179 +1,183 @@
1
- === Subscribe To Comments Reloaded ===
2
- Author: camu, Reedyseth, andreasbo, raamdev
3
- Contributors: coolmann, Reedyseth, raamdev
4
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=XF86X93FDCGYA&lc=US&item_name=Datasoft%20Engineering&item_number=DI%2dSTCR&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted
5
- Tags: subscribe, comments, notification, subscription, manage, double check-in, follow, commenting
6
- Requires at least: 2.9.2
7
- Tested up to: 3.8.1
8
- Stable tag: 140219
9
-
10
- Subscribe to Comments Reloaded allows commenters to sign up for e-mail notifications of subsequent replies.
11
-
12
- == Description ==
13
- Subscribe to Comments Reloaded is a robust plugin that enables commenters to sign up for e-mail notification of subsequent entries. The plugin includes a full-featured subscription manager that your commenters can use to unsubscribe to certain posts or suspend all notifications. It solves most of the issues that affect Mark Jaquith's version, using the latest Wordpress features and functionality. Plus, allows administrators to enable a double opt-in mechanism, requiring users to confirm their subscription clicking on a link they will receive via email.
14
-
15
- ## Requirements
16
- * Wordpress 2.9.2 or higher
17
- * PHP 5.1 or higher
18
- * MySQL 5.x or higher
19
-
20
- ## Main Features
21
- * Does not modify Wordpress core tables
22
- * Easily manage and search among your subscriptions
23
- * Imports Mark Jaquith's Subscribe To Comments (and its clones) data
24
- * Messages are fully customizable, no poEdit required (and you can use HTML!)
25
- * Disable subscriptions for specific posts
26
- * Compatible with [Fluency Admin](http://deanjrobinson.com/projects/fluency-admin/) and [QTranslate](http://wordpress.org/extend/plugins/qtranslate/)
27
-
28
- == Installation ==
29
-
30
- 1. If you are using Subscribe To Comments by Mark Jaquith, disable it (no need to uninstall it, though)
31
- 2. Upload the entire folder and all the subfolders to your Wordpress plugins' folder
32
- 3. Activate it
33
- 5. Customize the Permalink value under Settings > Subscribe to Comments > Management Page > Management URL. It **must** reflect your permalinks' structure
34
- 5. If you don't see the checkbox to subscribe, you will have to manually edit your template, and add `<?php if (function_exists('subscribe_reloaded_show')) subscribe_reloaded_show(); ?>` somewhere in your `comments.php`
35
- 6. If you're upgrading from a previous version, please **make sure to deactivate/activate** StCR
36
-
37
- == Frequently Asked Questions ==
38
-
39
- = Aaargh! Were did all my subscriptions go? =
40
- No panic. If you upgraded from 1.6 or earlier to 2.0+, you need to deactivate/activate StCR, in order to update the DB structure
41
-
42
- = How do I create a 'real' management page? =
43
- Please refer to [this page](http://lab.duechiacchiere.it/index.php?topic=71.0) for a detailed step-by-step description on how to do that
44
-
45
- = Can I customize the layout of the management page? =
46
- Yes, each HTML tag has a CSS class or ID that you can use to change its position or look-and-feel
47
-
48
- = How do I disable subscriptions for a given post? =
49
- Add a custom field called `stcr_disable_subscriptions` to it, with value 'yes'
50
-
51
- = How do I add the management page URL to my posts? =
52
- Use the shortcode `[subscribe-url]`, or use the following code in your theme:
53
- `if(function_exists('subscribe_reloaded_show')) echo '<a href="'.do_shortcode('[subscribe-url]').'">Subscribe</a>";`
54
-
55
- = Can I move the subscription checkbox to another position? =
56
- Yes! Just disable the corresponding option under Settings > Comment Form and then add the following code where you want to display the checkbox:
57
- `<?php if (function_exists('subscribe_reloaded_show')) subscribe_reloaded_show(); ?>`
58
-
59
- == Screenshots ==
60
-
61
- 1. Manage your subscriptions
62
- 2. Use your own messages to interact with your users
63
- 3. Configure the Virtual Management page
64
- 4. Customize the notification messages
65
- 5. Customize the plugin's behavior
66
-
67
- == Upgrade Notice ==
68
-
69
- = v140219 =
70
-
71
- **Security Fix; PLEASE UPGRADE IMMEDIATELY**. v140219 fixes an XSS/CSRF vulnerability that was discovered by Tom Adams and reported by a WordPress Plugin Repository moderator.
72
-
73
- == Changelog ==
74
-
75
- = v140219 =
76
-
77
- * **Security Fix; PLEASE UPGRADE IMMEDIATELY**. Fixes XSS/CSRF vulnerability that was discovered by Tom Adams and reported by a WordPress Plugin Repository moderator.
78
- * **Translations**. Updated French translation (thanks to Jean-Michel MEYER).
79
- * Improvements to translation support (thanks to Carlos Alberto Lopez Perez).
80
- * Add trailing slash to comment-subscriptions page to avoid unnecessary redirections (thanks to Carlos Alberto Lopez Perez).
81
-
82
- = v140204 =
83
-
84
- * **New Feature**. There is a new Option that Sets the default Subscription Type when the Chechbox 'Checked by default' is enable *Settings -> Subscribe to Comments -> Comment Form -> Default Checkbox Value*.
85
- * Corrected reference to the language translation files. If you find something fuzzy please open a Issue on GitHub <https://github.com/stcr/subscribe-to-comments-reloaded/issues/new?title=Bug%20Report:%20%3Cshort%20description%3E&labels=bug>
86
-
87
- = v140129 =
88
-
89
- * **Bug Fix**. Fixed `Notice: Undefined variable: post_id` that was sometimes causing issues with creating a new subscription when WordPres Debug mode was enabled. See: <https://github.com/stcr/subscribe-to-comments-reloaded/issues/2>
90
- * Added missing `.mo` files for translations in `lang/`. See: <https://github.com/stcr/subscribe-to-comments-reloaded/issues/13>
91
-
92
- = v140128 =
93
-
94
- * **New Feature**. There is now an option to BCC the admin on all Notifications. This is very useful when troubleshooting email delivery issues.
95
- * **New Option**. There is a new 'HTMLify links in emails' Option. When using HTML emails for messages you can now choose to have StCR automatically HTMLify the links for you (*Settings -> Subscribe to Comments -> Options -> HTMLify links in emails*). You can, of course, leave this option disabled and add your own HTML to the messages if you prefer.
96
- * **New Option**. There is a new 'default subscription type' Option. If you're using Advanced subscriptions, you can now specify the Advanced default subscription type ("None", "All new comments", or "Replies to this comment") in *Settings -> Subscribe to Comments -> Comment Form -> Advanced default*. This will be the default option shown on the comment form.
97
- * **Bug Fix**. Paragraph tags are now properly added to the comment content when sending HTML emails with `[comment_content]`
98
- * **Bug Fix**. Partial fix for the broken Subscribe to Replies Only feature. The Replies Only feature has not been working as intended. Instead of only receiving notificaitons for replies to their own comment, subscribers were receiving notifications for all new comments on the post. This fix makes sure they only receiving replies to their own comment thread.
99
- * **Bug Fix**. Fix duplicate `MIME-Version` header bug resulting in unsent emails. Fixes a bug where using StCR with other plugins, like WP-Mail-SMTP, results in a quiet duplicate header error. `wp_mail()` already takes care of setting the `MIME-Version` header so this doesn't need to be done again.
100
- * **Bug Fix**. Fixed `Fatal Error: Cannot redeclare class Helper` when visiting the `[subscribe_link]`. See also: <http://wordpress.org/support/topic/bug-fatal-error-in-classeshelperclassphp>
101
- * New import routine for WP Comment Subscriptions plugin. If subscription data and options are found for WP Comment Subscriptions, StCR will import those upon activation. Options and data are only imported if there is no existing StCR subscription data.
102
- * New admin notices to improve messaging and indicate when data is imported from an existing plugin.
103
- * New `stcr_confirmation_email_message` hook to modify the message that is sent to confirm a subscription. (Thanks to ziofix!)
104
- * New `stcr_notify_user_message` hook to modify the notification message that is sent to a user. (Thanks to ziofix!)
105
- * New plugin versioning format of YYMMDD.
106
- * Plugin development is now actively happening over at the new GitHub Repository for Subscribe to Comments Reloaded. If you have a bug to report or want to make a feature request, please post a new Issue over at GitHub. If you're a programmer, you're welcome to submit a Pull Request! See: <https://github.com/stcr/subscribe-to-comments-reloaded>
107
- * Added WPML language configuration file.
108
- * Added Raam Dev (`raamdev`) to the contributors list.
109
-
110
- = 2.0.6 =
111
- * Updated: Updated the contact information on every laguage file, some links were missing.
112
- * Fixed: The Spanish translation had some missing text.
113
-
114
- = 2.0.5 =
115
- * Added: Since the authorship of the plugin has changed I added the correct information of the contact in order to have a faster response to the issues.
116
-
117
- = 2.0.4 =
118
- * Added: Dutch translation fixes provided by [Martijn Chel](http://www.martijnchel.com)
119
- * Fixed: There was vulnerability in the form where the URI was added.
120
-
121
- = 2.0.3 =
122
- * I would like to thank Andreas for contributing to the project and fixing some issues with the plugin
123
-
124
- = 2.0.2 =
125
- * Added: option to automatically subscribe authors to their posts (improves Wordpress' default alert system, thank you [Julius](http://wordpress.org/support/topic/plugin-subscribe-to-comments-reloaded-does-the-post-author-automatically-get-subscribed-to-comments))
126
- * Added: number of subscriptions per post in the Posts page
127
- * Added: Serbian and Indonesian localization (thank you [Anna](http://www.sneg.iz.rs/) and [The Masked Cat](http://themaskedcat.tk))
128
- * Fixed: bug in daily purge SQL command
129
- * Fixed: bug with international characters (thank you Pascal)
130
- * Updated: you can now edit a single subscription's status without having to change the email address
131
- * Updated: more localizations are now up-to-date, thank you!
132
-
133
- = 2.0.1 =
134
- * Maintenance release: 2.0 shipped with a bunch of annoying bugs, sorry about that!
135
- * Added: option to not subscribe in 'advanced mode' (thank you [LincolnAdams](http://wordpress.org/support/topic/replies-only-broken))
136
- * Added: subscriptions count for each post (All Posts panel)
137
- * Added: option to disable the virtual management page, for those [having problems](http://lab.duechiacchiere.it/index.php?topic=71.0) with their theme
138
- * Fixed: subscriptions to replies only were not working properly, fixed (thank you [LincolnAdams](http://wordpress.org/support/topic/replies-only-broken))
139
- * Fixed: some warning popping up with WP_DEBUG mode enabled
140
- * Updated: most localizations are now up-to-date, thank you everybody!
141
-
142
- = 2.0 =
143
- * StCR does not use a separate table anymore, making it fully compatible with Wordpress 'network' environments! YAY!
144
- * Added: option to prevent StCR from adding the subscription checkbox to the comment form (useful for those who want to display the box in different place on the page)
145
- * Added: you can now disable subscriptions on specific posts, by adding a custom filed `stcr_disable_subscriptions` set to 'yes'
146
- * Added: double opt-in is only required once, users with at least one active subscription will automatically get approved
147
- * Added: administrators can add new subscriptions on-the-fly
148
- * Added: if Akismet is detected, it will now be used to check those who subscribe without commenting
149
- * Added: new shortcode to add the management page URL to your posts/widgets (thank you [Greg](http://wordpress.org/support/topic/plugin-subscribe-to-comments-reloaded-plugin-does-not-create-table))
150
- * Added: option to enable "advanced" subscription mode, where users can choose what kind of subscription they want to activate (all, replies only)
151
- * Added: new localizations
152
- * Added: security checks when uninstalling the plugin
153
- * Updated: reorganized and polished the CSS classes and ID's on the management page
154
- * Updated: registered users are not required to confirm their subscriptions anymore (if double opt-in is enabled)
155
- * Fixed: a problem with Gmail addresses containing a + sign in them
156
- * Fixed: a bug with HTML attributes in the field "custom HTML for the checkbox" (thank you [travelvice](http://wordpress.org/support/topic/custom-html-quotes-problem-php-ecape-characters))
157
- * Fixed: a bug causing some themes to not display the management page
158
-
159
- == Language Localization ==
160
-
161
- Subscribe to Comments Reloaded can speak your language! If you want to provide a localized file in your
162
- language, use the template files (.pot) you'll find inside the `langs` folder,
163
- and [contact me](http://behstant.com/negocio/contact.php) once your
164
- localization is ready. Currently, we support the following languages:
165
-
166
- * Danish - [Torben Bendixen](http://www.freelancekonsulenten.dk/)
167
- * Dutch - [Martijn Chel](http://mcpnetwork.nl/),[Muratje](http://www.muromedia.nl/)
168
- * French - [Anthony](http://imnotgeek.com/), Goormand, Maxime
169
- * German - [derhenry](http://www.derhenry.net/2010/subscribe-to-comments-reloaded/), [Stefan](http://www.beedy.de/)
170
- * Indonesian - [The Masked Cat](http://themaskedcat.tk)
171
- * Italian - myself
172
- * Norwegian - [Odd Henriksen](http://www.oddhenriksen.net/)
173
- * Polish - [Robert Koeseling](http://www.katalogpodkastow.pl), [Filip Cierpich](http://keepmind.eu/)
174
- * Portuguese, Brazil - [Ronaldo Richieri](http://richieri.com), [ClassiNoiva](http://www.classinoiva.com.br), [Luciano](http://litemind.com/)
175
- * Portuguese, Portugal
176
- * Russian - [Marika Bukvonka](http://violetnotes.com)
177
- * Serbian - [Anna Swedziol](http://www.sneg.iz.rs/)
178
- * Spanish - [TodoWordPress team](http://www.todowp.org/), [Juan Luis Perez](http://www.juanluperez.com/)
179
- * Turkish - [MaD, Kali](http://www.dusunsel.com/)
 
 
 
 
1
+ === Subscribe To Comments Reloaded ===
2
+ Author: camu, Reedyseth, andreasbo, raamdev
3
+ Contributors: coolmann, Reedyseth, raamdev
4
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=XF86X93FDCGYA&lc=US&item_name=Datasoft%20Engineering&item_number=DI%2dSTCR&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted
5
+ Tags: subscribe, comments, notification, subscription, manage, double check-in, follow, commenting
6
+ Requires at least: 2.9.2
7
+ Tested up to: 3.8.1
8
+ Stable tag: 140220
9
+
10
+ Subscribe to Comments Reloaded allows commenters to sign up for e-mail notifications of subsequent replies.
11
+
12
+ == Description ==
13
+ Subscribe to Comments Reloaded is a robust plugin that enables commenters to sign up for e-mail notification of subsequent entries. The plugin includes a full-featured subscription manager that your commenters can use to unsubscribe to certain posts or suspend all notifications. It solves most of the issues that affect Mark Jaquith's version, using the latest Wordpress features and functionality. Plus, allows administrators to enable a double opt-in mechanism, requiring users to confirm their subscription clicking on a link they will receive via email.
14
+
15
+ ## Requirements
16
+ * Wordpress 2.9.2 or higher
17
+ * PHP 5.1 or higher
18
+ * MySQL 5.x or higher
19
+
20
+ ## Main Features
21
+ * Does not modify Wordpress core tables
22
+ * Easily manage and search among your subscriptions
23
+ * Imports Mark Jaquith's Subscribe To Comments (and its clones) data
24
+ * Messages are fully customizable, no poEdit required (and you can use HTML!)
25
+ * Disable subscriptions for specific posts
26
+ * Compatible with [Fluency Admin](http://deanjrobinson.com/projects/fluency-admin/) and [QTranslate](http://wordpress.org/extend/plugins/qtranslate/)
27
+
28
+ == Installation ==
29
+
30
+ 1. If you are using Subscribe To Comments by Mark Jaquith, disable it (no need to uninstall it, though)
31
+ 2. Upload the entire folder and all the subfolders to your Wordpress plugins' folder
32
+ 3. Activate it
33
+ 5. Customize the Permalink value under Settings > Subscribe to Comments > Management Page > Management URL. It **must** reflect your permalinks' structure
34
+ 5. If you don't see the checkbox to subscribe, you will have to manually edit your template, and add `<?php if (function_exists('subscribe_reloaded_show')) subscribe_reloaded_show(); ?>` somewhere in your `comments.php`
35
+ 6. If you're upgrading from a previous version, please **make sure to deactivate/activate** StCR
36
+
37
+ == Frequently Asked Questions ==
38
+
39
+ = Aaargh! Were did all my subscriptions go? =
40
+ No panic. If you upgraded from 1.6 or earlier to 2.0+, you need to deactivate/activate StCR, in order to update the DB structure
41
+
42
+ = How do I create a 'real' management page? =
43
+ Please refer to [this page](http://lab.duechiacchiere.it/index.php?topic=71.0) for a detailed step-by-step description on how to do that
44
+
45
+ = Can I customize the layout of the management page? =
46
+ Yes, each HTML tag has a CSS class or ID that you can use to change its position or look-and-feel
47
+
48
+ = How do I disable subscriptions for a given post? =
49
+ Add a custom field called `stcr_disable_subscriptions` to it, with value 'yes'
50
+
51
+ = How do I add the management page URL to my posts? =
52
+ Use the shortcode `[subscribe-url]`, or use the following code in your theme:
53
+ `if(function_exists('subscribe_reloaded_show')) echo '<a href="'.do_shortcode('[subscribe-url]').'">Subscribe</a>";`
54
+
55
+ = Can I move the subscription checkbox to another position? =
56
+ Yes! Just disable the corresponding option under Settings > Comment Form and then add the following code where you want to display the checkbox:
57
+ `<?php if (function_exists('subscribe_reloaded_show')) subscribe_reloaded_show(); ?>`
58
+
59
+ == Screenshots ==
60
+
61
+ 1. Manage your subscriptions
62
+ 2. Use your own messages to interact with your users
63
+ 3. Configure the Virtual Management page
64
+ 4. Customize the notification messages
65
+ 5. Customize the plugin's behavior
66
+
67
+ == Upgrade Notice ==
68
+
69
+ = v140220 =
70
+
71
+ **Security Fix; PLEASE UPGRADE IMMEDIATELY**. v140219 fixes an XSS/CSRF vulnerability that was discovered by Tom Adams and reported by a WordPress Plugin Repository moderator.
72
+
73
+ == Changelog ==
74
+
75
+ = v140220 =
76
+
77
+ **Bug Fix**. Fixes an encoding bug that broke HTML output after patching XSS vulnerability. If you started seeing raw HTML output at the bottom of your comment forms after upgrading to v140219, this update should fix that.
78
+
79
+ = v140219 =
80
+
81
+ * **Security Fix; PLEASE UPGRADE IMMEDIATELY**. Fixes XSS/CSRF vulnerability that was discovered by Tom Adams and reported by a WordPress Plugin Repository moderator.
82
+ * **Translations**. Updated French translation (thanks to Jean-Michel MEYER).
83
+ * Improvements to translation support (thanks to Carlos Alberto Lopez Perez).
84
+ * Add trailing slash to comment-subscriptions page to avoid unnecessary redirections (thanks to Carlos Alberto Lopez Perez).
85
+
86
+ = v140204 =
87
+
88
+ * **New Feature**. There is a new Option that Sets the default Subscription Type when the Chechbox 'Checked by default' is enable *Settings -> Subscribe to Comments -> Comment Form -> Default Checkbox Value*.
89
+ * Corrected reference to the language translation files. If you find something fuzzy please open a Issue on GitHub <https://github.com/stcr/subscribe-to-comments-reloaded/issues/new?title=Bug%20Report:%20%3Cshort%20description%3E&labels=bug>
90
+
91
+ = v140129 =
92
+
93
+ * **Bug Fix**. Fixed `Notice: Undefined variable: post_id` that was sometimes causing issues with creating a new subscription when WordPres Debug mode was enabled. See: <https://github.com/stcr/subscribe-to-comments-reloaded/issues/2>
94
+ * Added missing `.mo` files for translations in `lang/`. See: <https://github.com/stcr/subscribe-to-comments-reloaded/issues/13>
95
+
96
+ = v140128 =
97
+
98
+ * **New Feature**. There is now an option to BCC the admin on all Notifications. This is very useful when troubleshooting email delivery issues.
99
+ * **New Option**. There is a new 'HTMLify links in emails' Option. When using HTML emails for messages you can now choose to have StCR automatically HTMLify the links for you (*Settings -> Subscribe to Comments -> Options -> HTMLify links in emails*). You can, of course, leave this option disabled and add your own HTML to the messages if you prefer.
100
+ * **New Option**. There is a new 'default subscription type' Option. If you're using Advanced subscriptions, you can now specify the Advanced default subscription type ("None", "All new comments", or "Replies to this comment") in *Settings -> Subscribe to Comments -> Comment Form -> Advanced default*. This will be the default option shown on the comment form.
101
+ * **Bug Fix**. Paragraph tags are now properly added to the comment content when sending HTML emails with `[comment_content]`
102
+ * **Bug Fix**. Partial fix for the broken Subscribe to Replies Only feature. The Replies Only feature has not been working as intended. Instead of only receiving notificaitons for replies to their own comment, subscribers were receiving notifications for all new comments on the post. This fix makes sure they only receiving replies to their own comment thread.
103
+ * **Bug Fix**. Fix duplicate `MIME-Version` header bug resulting in unsent emails. Fixes a bug where using StCR with other plugins, like WP-Mail-SMTP, results in a quiet duplicate header error. `wp_mail()` already takes care of setting the `MIME-Version` header so this doesn't need to be done again.
104
+ * **Bug Fix**. Fixed `Fatal Error: Cannot redeclare class Helper` when visiting the `[subscribe_link]`. See also: <http://wordpress.org/support/topic/bug-fatal-error-in-classeshelperclassphp>
105
+ * New import routine for WP Comment Subscriptions plugin. If subscription data and options are found for WP Comment Subscriptions, StCR will import those upon activation. Options and data are only imported if there is no existing StCR subscription data.
106
+ * New admin notices to improve messaging and indicate when data is imported from an existing plugin.
107
+ * New `stcr_confirmation_email_message` hook to modify the message that is sent to confirm a subscription. (Thanks to ziofix!)
108
+ * New `stcr_notify_user_message` hook to modify the notification message that is sent to a user. (Thanks to ziofix!)
109
+ * New plugin versioning format of YYMMDD.
110
+ * Plugin development is now actively happening over at the new GitHub Repository for Subscribe to Comments Reloaded. If you have a bug to report or want to make a feature request, please post a new Issue over at GitHub. If you're a programmer, you're welcome to submit a Pull Request! See: <https://github.com/stcr/subscribe-to-comments-reloaded>
111
+ * Added WPML language configuration file.
112
+ * Added Raam Dev (`raamdev`) to the contributors list.
113
+
114
+ = 2.0.6 =
115
+ * Updated: Updated the contact information on every laguage file, some links were missing.
116
+ * Fixed: The Spanish translation had some missing text.
117
+
118
+ = 2.0.5 =
119
+ * Added: Since the authorship of the plugin has changed I added the correct information of the contact in order to have a faster response to the issues.
120
+
121
+ = 2.0.4 =
122
+ * Added: Dutch translation fixes provided by [Martijn Chel](http://www.martijnchel.com)
123
+ * Fixed: There was vulnerability in the form where the URI was added.
124
+
125
+ = 2.0.3 =
126
+ * I would like to thank Andreas for contributing to the project and fixing some issues with the plugin
127
+
128
+ = 2.0.2 =
129
+ * Added: option to automatically subscribe authors to their posts (improves Wordpress' default alert system, thank you [Julius](http://wordpress.org/support/topic/plugin-subscribe-to-comments-reloaded-does-the-post-author-automatically-get-subscribed-to-comments))
130
+ * Added: number of subscriptions per post in the Posts page
131
+ * Added: Serbian and Indonesian localization (thank you [Anna](http://www.sneg.iz.rs/) and [The Masked Cat](http://themaskedcat.tk))
132
+ * Fixed: bug in daily purge SQL command
133
+ * Fixed: bug with international characters (thank you Pascal)
134
+ * Updated: you can now edit a single subscription's status without having to change the email address
135
+ * Updated: more localizations are now up-to-date, thank you!
136
+
137
+ = 2.0.1 =
138
+ * Maintenance release: 2.0 shipped with a bunch of annoying bugs, sorry about that!
139
+ * Added: option to not subscribe in 'advanced mode' (thank you [LincolnAdams](http://wordpress.org/support/topic/replies-only-broken))
140
+ * Added: subscriptions count for each post (All Posts panel)
141
+ * Added: option to disable the virtual management page, for those [having problems](http://lab.duechiacchiere.it/index.php?topic=71.0) with their theme
142
+ * Fixed: subscriptions to replies only were not working properly, fixed (thank you [LincolnAdams](http://wordpress.org/support/topic/replies-only-broken))
143
+ * Fixed: some warning popping up with WP_DEBUG mode enabled
144
+ * Updated: most localizations are now up-to-date, thank you everybody!
145
+
146
+ = 2.0 =
147
+ * StCR does not use a separate table anymore, making it fully compatible with Wordpress 'network' environments! YAY!
148
+ * Added: option to prevent StCR from adding the subscription checkbox to the comment form (useful for those who want to display the box in different place on the page)
149
+ * Added: you can now disable subscriptions on specific posts, by adding a custom filed `stcr_disable_subscriptions` set to 'yes'
150
+ * Added: double opt-in is only required once, users with at least one active subscription will automatically get approved
151
+ * Added: administrators can add new subscriptions on-the-fly
152
+ * Added: if Akismet is detected, it will now be used to check those who subscribe without commenting
153
+ * Added: new shortcode to add the management page URL to your posts/widgets (thank you [Greg](http://wordpress.org/support/topic/plugin-subscribe-to-comments-reloaded-plugin-does-not-create-table))
154
+ * Added: option to enable "advanced" subscription mode, where users can choose what kind of subscription they want to activate (all, replies only)
155
+ * Added: new localizations
156
+ * Added: security checks when uninstalling the plugin
157
+ * Updated: reorganized and polished the CSS classes and ID's on the management page
158
+ * Updated: registered users are not required to confirm their subscriptions anymore (if double opt-in is enabled)
159
+ * Fixed: a problem with Gmail addresses containing a + sign in them
160
+ * Fixed: a bug with HTML attributes in the field "custom HTML for the checkbox" (thank you [travelvice](http://wordpress.org/support/topic/custom-html-quotes-problem-php-ecape-characters))
161
+ * Fixed: a bug causing some themes to not display the management page
162
+
163
+ == Language Localization ==
164
+
165
+ Subscribe to Comments Reloaded can speak your language! If you want to provide a localized file in your
166
+ language, use the template files (.pot) you'll find inside the `langs` folder,
167
+ and [contact me](http://behstant.com/negocio/contact.php) once your
168
+ localization is ready. Currently, we support the following languages:
169
+
170
+ * Danish - [Torben Bendixen](http://www.freelancekonsulenten.dk/)
171
+ * Dutch - [Martijn Chel](http://mcpnetwork.nl/),[Muratje](http://www.muromedia.nl/)
172
+ * French - [Anthony](http://imnotgeek.com/), Goormand, Maxime
173
+ * German - [derhenry](http://www.derhenry.net/2010/subscribe-to-comments-reloaded/), [Stefan](http://www.beedy.de/)
174
+ * Indonesian - [The Masked Cat](http://themaskedcat.tk)
175
+ * Italian - myself
176
+ * Norwegian - [Odd Henriksen](http://www.oddhenriksen.net/)
177
+ * Polish - [Robert Koeseling](http://www.katalogpodkastow.pl), [Filip Cierpich](http://keepmind.eu/)
178
+ * Portuguese, Brazil - [Ronaldo Richieri](http://richieri.com), [ClassiNoiva](http://www.classinoiva.com.br), [Luciano](http://litemind.com/)
179
+ * Portuguese, Portugal
180
+ * Russian - [Marika Bukvonka](http://violetnotes.com)
181
+ * Serbian - [Anna Swedziol](http://www.sneg.iz.rs/)
182
+ * Spanish - [TodoWordPress team](http://www.todowp.org/), [Juan Luis Perez](http://www.juanluperez.com/)
183
+ * Turkish - [MaD, Kali](http://www.dusunsel.com/)
subscribe-to-comments-reloaded.php CHANGED
@@ -1,1575 +1,1575 @@
1
- <?php
2
- /*
3
- Plugin Name: Subscribe to Comments Reloaded
4
-
5
- Version: 140219
6
- Stable tag: 140219
7
- Requires at least: 2.9.2
8
- Tested up to: 3.8.1
9
-
10
- Plugin URI: http://wordpress.org/extend/plugins/subscribe-to-comments-reloaded/
11
- Description: Subscribe to Comments Reloaded is a robust plugin that enables commenters to sign up for e-mail notifications. It includes a full-featured subscription manager that your commenters can use to unsubscribe to certain posts or suspend all notifications.
12
- Contributors: camu, Reedyseth, andreasbo, raamdev
13
- Author: camu, Reedyseth, Raam Dev
14
- */
15
-
16
- // Avoid direct access to this piece of code
17
- if ( ! function_exists( 'add_action' ) ) {
18
- header( 'Location: /' );
19
- exit;
20
- }
21
-
22
- /**
23
- * Displays the checkbox to allow visitors to subscribe
24
- */
25
- function subscribe_reloaded_show() {
26
- global $post, $wp_subscribe_reloaded;
27
- $checkbox_subscription_type;
28
-
29
- $is_disabled = get_post_meta( $post->ID, 'stcr_disable_subscriptions', true );
30
- if ( ! empty( $is_disabled ) ) {
31
- return $_comment_ID;
32
- }
33
-
34
- $show_subscription_box = true;
35
- $html_to_show = '';
36
- $user_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '' );
37
-
38
- if ( function_exists( 'qtrans_convertURL' ) ) {
39
- $user_link = qtrans_convertURL( $user_link );
40
- }
41
-
42
- $manager_link = ( strpos( $user_link, '?' ) !== false ) ? "$user_link&amp;srp=$post->ID" : "$user_link?srp=$post->ID";
43
-
44
- // Load localization files
45
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
46
-
47
- if ( $wp_subscribe_reloaded->is_user_subscribed( $post->ID, '', 'C' ) ) {
48
- $html_to_show = str_replace(
49
- '[manager_link]', $user_link,
50
- __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_subscribed_waiting_label', "Your subscription to this post needs to be confirmed. <a href='[manager_link]'>Manage your subscriptions</a>." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
51
- );
52
- $show_subscription_box = false;
53
- } elseif ( $wp_subscribe_reloaded->is_user_subscribed( $post->ID, '' ) ) {
54
- $html_to_show = str_replace(
55
- '[manager_link]', $user_link,
56
- __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_subscribed_label', "You are subscribed to this post. <a href='[manager_link]'>Manage</a> your subscriptions." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
57
- );
58
- $show_subscription_box = false;
59
- }
60
-
61
- if ( $wp_subscribe_reloaded->is_author( $post->post_author ) ) { // when the second parameter is empty, cookie value will be used
62
- if ( get_option( 'subscribe_reloaded_admin_subscribe', 'no' ) == 'no' ) {
63
- $show_subscription_box = false;
64
- }
65
- $html_to_show .= str_replace(
66
- '[manager_link]', $manager_link,
67
- __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_author_label', "You can <a href='[manager_link]'>manage the subscriptions</a> of this post." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
68
- );
69
- }
70
-
71
- if ( $show_subscription_box ) {
72
- $checkbox_label = str_replace(
73
- '[subscribe_link]', "$manager_link&amp;sra=s",
74
- __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_checkbox_label', "Notify me of followup comments via e-mail. You can also <a href='[subscribe_link]'>subscribe</a> without commenting." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
75
- );
76
- $checkbox_inline_style = get_option( 'subscribe_reloaded_checkbox_inline_style', 'width:30px' );
77
- if ( ! empty( $checkbox_inline_style ) ) {
78
- $checkbox_inline_style = " style='$checkbox_inline_style'";
79
- }
80
- $checkbox_html_wrap = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_checkbox_html', '' ) ), ENT_COMPAT, 'UTF-8' );
81
- if ( get_option( 'subscribe_reloaded_enable_advanced_subscriptions', 'no' ) == 'no' ) {
82
- switch ( get_option('subscribe_reloaded_checked_by_default_value') ) {
83
- case '0':
84
- $checkbox_subscription_type = 'yes';
85
- break;
86
- case '1':
87
- $checkbox_subscription_type = 'replies';
88
- break;
89
- }
90
- $checkbox_field = "<input$checkbox_inline_style type='checkbox' name='subscribe-reloaded' id='subscribe-reloaded' value='$checkbox_subscription_type'" . ( ( get_option( 'subscribe_reloaded_checked_by_default', 'no' ) == 'yes' ) ? " checked='checked'" : '' ) . " />";
91
- } else {
92
- $checkbox_field = "<select name='subscribe-reloaded' id='subscribe-reloaded'>
93
- <option value='none'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '0' ) ? "selected='selected'" : '' ) . ">" . __( "Don't subscribe", 'subscribe-reloaded' ) . "</option>
94
- <option value='yes'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '1' ) ? "selected='selected'" : '' ) . ">" . __( "All", 'subscribe-reloaded' ) . "</option>
95
- <option value='replies'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '2' ) ? "selected='selected'" : '' ) . ">" . __( "Replies to my comments", 'subscribe-reloaded' ) . "</option>
96
- </select>";
97
- }
98
- if ( empty( $checkbox_html_wrap ) ) {
99
- $html_to_show = "$checkbox_field <label for='subscribe-reloaded'>$checkbox_label</label>" . $html_to_show;
100
- } else {
101
- $checkbox_html_wrap = str_replace( '[checkbox_field]', $checkbox_field, $checkbox_html_wrap );
102
- $html_to_show = str_replace( '[checkbox_label]', $checkbox_label, $checkbox_html_wrap ) . $html_to_show;
103
- }
104
- }
105
- if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
106
- $html_to_show = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $html_to_show );
107
- }
108
- echo "<!-- BEGIN: subscribe to comments reloaded -->$html_to_show<!-- END: subscribe to comments reloaded -->";
109
- }
110
-
111
- // Show the checkbox - You can manually override this by adding the corresponding function in your template
112
- if ( get_option( 'subscribe_reloaded_show_subscription_box', 'yes' ) == 'yes' ) {
113
- add_action( 'comment_form', 'subscribe_reloaded_show' );
114
- }
115
-
116
- class wp_subscribe_reloaded {
117
-
118
- public $current_version = '140219';
119
-
120
- /**
121
- * Constructor -- Sets things up.
122
- */
123
- public function __construct() {
124
- $this->salt = defined( 'NONCE_KEY' ) ? NONCE_KEY : 'please create a unique key in your wp-config.php';
125
-
126
- // What to do when a new comment is posted
127
- add_action( 'comment_post', array( &$this, 'new_comment_posted' ), 12, 2 );
128
-
129
- // Provide content for the management page using WP filters
130
- if ( ! is_admin() ) {
131
- $manager_page_permalink = get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
132
- if ( function_exists( 'qtrans_convertURL' ) ) {
133
- $manager_page_permalink = qtrans_convertURL( $manager_page_permalink );
134
- }
135
- if ( empty( $manager_page_permalink ) ) {
136
- $manager_page_permalink = get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
137
- }
138
- if ( ( strpos( $_SERVER["REQUEST_URI"], $manager_page_permalink ) !== false ) && get_option( 'subscribe_reloaded_manager_page_enabled', 'yes' ) == 'yes' ) {
139
- add_filter( 'the_posts', array( &$this, 'subscribe_reloaded_manage' ), 10, 2 );
140
- }
141
-
142
- // Create a hook to use with the daily cron job
143
- add_action( 'subscribe_reloaded_purge', array( &$this, 'subscribe_reloaded_purge' ) );
144
- } else {
145
- // Initialization routines that should be executed on activation/deactivation
146
- register_activation_hook( __FILE__, array( &$this, 'activate' ) );
147
- register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
148
-
149
- // Hook for WPMU - New blog created
150
- add_action( 'wpmu_new_blog', array( &$this, 'new_blog' ), 10, 1 );
151
-
152
- // Remove subscriptions attached to a post that is being deleted
153
- add_action( 'delete_post', array( &$this, 'delete_subscriptions' ), 10, 2 );
154
-
155
- // Monitor actions on existing comments
156
- add_action( 'deleted_comment', array( &$this, 'comment_deleted' ) );
157
- add_action( 'wp_set_comment_status', array( &$this, 'comment_status_changed' ) );
158
-
159
- // Subscribe post authors, if the case
160
- if ( get_option( 'subscribe_reloaded_notify_authors', 'no' ) == 'yes' ) {
161
- add_action( 'publish_post', array( &$this, 'subscribe_post_author' ) );
162
- }
163
-
164
- // Add a new column to the Edit Comments panel
165
- add_filter( 'manage_edit-comments_columns', array( &$this, 'add_column_header' ) );
166
- add_filter( 'manage_posts_columns', array( &$this, 'add_column_header' ) );
167
- add_action( 'manage_comments_custom_column', array( &$this, 'add_comment_column' ) );
168
- add_action( 'manage_posts_custom_column', array( &$this, 'add_post_column' ) );
169
-
170
- // Add appropriate entries in the admin menu
171
- add_action( 'admin_menu', array( &$this, 'add_config_menu' ) );
172
- add_action(
173
- 'admin_print_styles-subscribe-to-comments-reloaded/options/index.php', array(
174
- &$this,
175
- 'add_options_stylesheet'
176
- )
177
- );
178
- add_action( 'admin_print_styles-edit-comments.php', array( &$this, 'add_post_comments_stylesheet' ) );
179
- add_action( 'admin_print_styles-edit.php', array( &$this, 'add_post_comments_stylesheet' ) );
180
-
181
- // Admin notices
182
- add_action( 'admin_init', array( &$this, 'admin_init' ) );
183
- add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
184
-
185
- // Contextual help
186
- add_action( 'contextual_help', array( &$this, 'contextual_help' ), 10, 3 );
187
-
188
- // Shortcodes to use the management URL sitewide
189
- add_shortcode( 'subscribe-url', array( &$this, 'subscribe_url_shortcode' ) );
190
-
191
- // Settings link for plugin on plugins page
192
- add_filter( 'plugin_action_links', array( &$this, 'plugin_settings_link' ), 10, 2 );
193
- }
194
- }
195
-
196
- // end __construct
197
-
198
- public function admin_init() {
199
-
200
- $version = get_option( 'subscribe_reloaded_version' );
201
- if ( $version != $this->current_version ) {
202
- // Do whatever upgrades needed here.
203
- update_option( 'subscribe_reloaded_version', $this->current_version );
204
- }
205
- }
206
-
207
- public function admin_notices() {
208
- if ( $notices = get_option( 'subscribe_reloaded_deferred_admin_notices' ) ) {
209
- foreach ( $notices as $notice ) {
210
- echo $notice;
211
- }
212
- delete_option( 'subscribe_reloaded_deferred_admin_notices' );
213
- }
214
- }
215
-
216
- /**
217
- * Support for WP MU network activations (experimental)
218
- */
219
- public function activate() {
220
- global $wpdb;
221
-
222
- if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) {
223
- $blogids = $wpdb->get_col(
224
- $wpdb->prepare(
225
- "
226
- SELECT blog_id
227
- FROM $wpdb->blogs
228
- WHERE site_id = %d
229
- AND deleted = 0
230
- AND spam = 0", $wpdb->siteid
231
- )
232
- );
233
-
234
- foreach ( $blogids as $blog_id ) {
235
- switch_to_blog( $blog_id );
236
- $this->_activate();
237
- }
238
- restore_current_blog();
239
- } else {
240
- $this->_activate();
241
- }
242
- }
243
- // end activate
244
-
245
- /**
246
- * Support for WP MU network activations (experimental)
247
- */
248
- public function new_blog( $_blog_id ) {
249
- switch_to_blog( $_blog_id );
250
- $this->_activate();
251
- restore_current_blog();
252
- }
253
- // end new_blog
254
-
255
- /**
256
- * Adds the options to the database and imports the data from other plugins
257
- */
258
- private function _activate() {
259
-
260
- // Load localization files
261
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
262
-
263
- // Import data from the WP Comment Subscriptions plugin, if needed
264
- $this->_import_wpcs_data();
265
-
266
- // Import data from Subscribe to Comments & Co., if needed
267
- $this->_import_stc_data();
268
-
269
- // Starting from version 2.0 StCR uses Wordpress' tables to store the information about subscriptions
270
- $this->_update_db();
271
-
272
- // Messages related to the management page
273
- global $wp_rewrite;
274
-
275
- if ( empty( $wp_rewrite->permalink_structure ) ) {
276
- add_option( 'subscribe_reloaded_manager_page', '/?page_id=99999', '', 'no' );
277
- } else {
278
- add_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/', '', 'no' );
279
- }
280
-
281
- add_option( 'subscribe_reloaded_show_subscription_box', 'yes', '', 'no' );
282
- add_option( 'subscribe_reloaded_checked_by_default', 'no', '', 'no' );
283
- add_option( 'subscribe_reloaded_enable_advanced_subscriptions', 'no', '', 'no' );
284
- add_option( 'subscribe_reloaded_default_subscription_type', '2', '', 'no' );
285
- add_option( 'subscribe_reloaded_checked_by_default_value', '0', '', 'no' );
286
- add_option( 'subscribe_reloaded_checkbox_inline_style', 'width:30px', '', 'no' );
287
- add_option( 'subscribe_reloaded_checkbox_html', "<p class='comment-form-subscriptions'><label for='subscribe-reloaded'>[checkbox_field] [checkbox_label]</label></p>", '', 'no' );
288
- add_option( 'subscribe_reloaded_checkbox_label', __( "Notify me of followup comments via e-mail. You can also <a href='[subscribe_link]'>subscribe</a> without commenting.", 'subscribe-reloaded' ), '', 'no' );
289
- add_option( 'subscribe_reloaded_subscribed_label', __( "You are subscribed to this post. <a href='[manager_link]'>Manage</a> your subscriptions.", 'subscribe-reloaded' ), '', 'no' );
290
- add_option( 'subscribe_reloaded_subscribed_waiting_label', __( "Your subscription to this post needs to be confirmed. <a href='[manager_link]'>Manage your subscriptions</a>.", 'subscribe-reloaded' ), '', 'no' );
291
- add_option( 'subscribe_reloaded_author_label', __( "You can <a href='[manager_link]'>manage the subscriptions</a> of this post.", 'subscribe-reloaded' ), '', 'no' );
292
-
293
- add_option( 'subscribe_reloaded_manager_page_enabled', 'yes', '', 'no' );
294
- add_option( 'subscribe_reloaded_manager_page_title', __( 'Manage subscriptions', 'subscribe-reloaded' ), '', 'no' );
295
- add_option( 'subscribe_reloaded_custom_header_meta', "<meta name='robots' content='noindex,nofollow'>", '', 'no' );
296
- add_option( 'subscribe_reloaded_request_mgmt_link', __( 'To manage your subscriptions, please enter your email address here below. We will send you a message containing the link to access your personal management page.', 'subscribe-reloaded' ), '', 'no' );
297
- add_option( 'subscribe_reloaded_request_mgmt_link_thankyou', __( 'Thank you for using our subscription service. Your request has been completed, and you should receive an email with the management link in a few minutes.', 'subscribe-reloaded' ), '', 'no' );
298
- add_option( 'subscribe_reloaded_subscribe_without_commenting', __( "You can follow the discussion on <strong>[post_title]</strong> without having to leave a comment. Cool, huh? Just enter your email address in the form here below and you're all set.", 'subscribe-reloaded' ), '', 'no' );
299
- add_option( 'subscribe_reloaded_subscription_confirmed', __( "Thank you for using our subscription service. Your request has been completed. You will receive a notification email every time a new comment to this article is approved and posted by the administrator.", 'subscribe-reloaded' ), '', 'no' );
300
- add_option( 'subscribe_reloaded_subscription_confirmed_dci', __( "Thank you for using our subscription service. In order to confirm your request, please check your email for the verification message and follow the instructions.", 'subscribe-reloaded' ), '', 'no' );
301
- add_option( 'subscribe_reloaded_author_text', __( "In order to cancel or suspend one or more notifications, select the corresponding checkbox(es) and click on the button at the end of the list.", 'subscribe-reloaded' ), '', 'no' );
302
- add_option( 'subscribe_reloaded_user_text', __( "In order to cancel or suspend one or more notifications, select the corresponding checkbox(es) and click on the button at the end of the list. You are currently subscribed to:", 'subscribe-reloaded' ), '', 'no' );
303
-
304
- add_option( 'subscribe_reloaded_from_name', get_bloginfo( 'name' ), '', 'no' );
305
- add_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ), '', 'no' );
306
- add_option( 'subscribe_reloaded_notification_subject', __( 'There is a new comment to [post_title]', 'subscribe-reloaded' ), '', 'no' );
307
- add_option( 'subscribe_reloaded_notification_content', __( "There is a new comment to [post_title].\nComment Link: [comment_permalink]\nAuthor: [comment_author]\nComment:\n[comment_content]\nPermalink: [post_permalink]\nManage your subscriptions: [manager_link]", 'subscribe-reloaded' ), '', 'no' );
308
- add_option( 'subscribe_reloaded_double_check_subject', __( 'Please confirm your subscription to [post_title]', 'subscribe-reloaded' ), '', 'no' );
309
- add_option( 'subscribe_reloaded_double_check_content', __( "You have requested to be notified every time a new comment is added to:\n[post_permalink]\n\nPlease confirm your request by clicking on this link:\n[confirm_link]", 'subscribe-reloaded' ), '', 'no' );
310
- add_option( 'subscribe_reloaded_management_subject', __( 'Manage your subscriptions on [blog_name]', 'subscribe-reloaded' ) );
311
- add_option( 'subscribe_reloaded_management_content', __( "You have requested to manage your subscriptions to the articles on [blog_name]. Follow this link to access your personal page:\n[manager_link]", 'subscribe-reloaded' ) );
312
-
313
- add_option( 'subscribe_reloaded_purge_days', '30', '', 'no' );
314
- add_option( 'subscribe_reloaded_enable_double_check', 'no', '', 'no' );
315
- add_option( 'subscribe_reloaded_notify_authors', 'no', '', 'no' );
316
- add_option( 'subscribe_reloaded_enable_html_emails', 'no', '', 'no' );
317
- add_option( 'subscribe_reloaded_htmlify_message_links', 'no', '', 'no' );
318
- add_option( 'subscribe_reloaded_process_trackbacks', 'no', '', 'no' );
319
- add_option( 'subscribe_reloaded_enable_admin_messages', 'no', '', 'no' );
320
- add_option( 'subscribe_reloaded_admin_subscribe', 'no', '', 'no' );
321
- add_option( 'subscribe_reloaded_admin_bcc', 'no', '', 'no' );
322
-
323
- // Schedule the autopurge hook
324
- if ( ! wp_next_scheduled( 'subscribe_reloaded_purge' ) ) {
325
- wp_schedule_event( time(), 'daily', 'subscribe_reloaded_purge' );
326
- }
327
- }
328
- // end _activate
329
-
330
- /**
331
- * Performs some clean-up maintenance (disable cron job).
332
- */
333
- public function deactivate() {
334
- global $wpdb;
335
- if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) {
336
- $blogids = $wpdb->get_col(
337
- $wpdb->prepare(
338
- "
339
- SELECT blog_id
340
- FROM $wpdb->blogs
341
- WHERE site_id = %d
342
- AND deleted = 0
343
- AND spam = 0", $wpdb->siteid
344
- )
345
- );
346
-
347
- foreach ( $blogids as $blog_id ) {
348
- switch_to_blog( $blog_id );
349
- wp_clear_scheduled_hook( 'subscribe_reloaded_purge' );
350
- }
351
- restore_current_blog();
352
- } else {
353
- wp_clear_scheduled_hook( 'subscribe_reloaded_purge' );
354
- }
355
-
356
- delete_option( 'subscribe_reloaded_version' );
357
- delete_option( 'subscribe_reloaded_deferred_admin_notices' );
358
- }
359
- // end deactivate
360
-
361
- /*
362
- * Add Settings link to plugin on plugins page
363
- */
364
- public function plugin_settings_link( $links, $file ) {
365
- if ( $file == 'subscribe-to-comments-reloaded/subscribe-to-comments-reloaded.php' ) {
366
- $links['settings'] = sprintf( '<a href="%s"> %s </a>', admin_url( 'options-general.php?page=subscribe-to-comments-reloaded/options/index.php' ), __( 'Settings', 'subscribe-reloaded' ) );
367
- }
368
-
369
- return $links;
370
- }
371
-
372
- /**
373
- * Takes the appropriate action, when a new comment is posted
374
- */
375
- public function new_comment_posted( $_comment_ID = 0, $_comment_status = 0 ) {
376
- // Retrieve the information about the new comment
377
- $info = $this->_get_comment_object( $_comment_ID );
378
-
379
- if ( empty( $info ) || $info->comment_approved == 'spam' ) {
380
- return $_comment_ID;
381
- }
382
-
383
- // Are subscriptions allowed for this post?
384
- $is_disabled = get_post_meta( $info->comment_post_ID, 'stcr_disable_subscriptions', true );
385
- if ( ! empty( $is_disabled ) ) {
386
- return $_comment_ID;
387
- }
388
-
389
- // Process trackbacks and pingbacks?
390
- if ( ( get_option( 'subscribe_reloaded_process_trackbacks', 'no' ) == 'no' ) && ( $info->comment_type == 'trackback' || $info->comment_type == 'pingback' ) ) {
391
- return $_comment_ID;
392
- }
393
-
394
- // Did this visitor request to be subscribed to the discussion? (and s/he is not subscribed)
395
- if ( ! empty( $_POST['subscribe-reloaded'] ) && ! empty( $info->comment_author_email ) ) {
396
- if ( ! in_array( $_POST['subscribe-reloaded'], array( 'replies', 'digest', 'yes' ) ) ) {
397
- return $_comment_ID;
398
- }
399
-
400
- switch ( $_POST['subscribe-reloaded'] ) {
401
- case 'replies':
402
- $status = 'R';
403
- break;
404
- case 'digest':
405
- $status = 'D';
406
- break;
407
- default:
408
- $status = 'Y';
409
- break;
410
- }
411
-
412
- if ( ! $this->is_user_subscribed( $info->comment_post_ID, $info->comment_author_email ) ) {
413
- if ( $this->isDoubleCheckinEnabled( $info ) ) {
414
- $this->sendConfirmationEMail( $info );
415
- $status = "{$status}C";
416
- }
417
- $this->add_subscription( $info->comment_post_ID, $info->comment_author_email, $status );
418
-
419
- // If comment is in the moderation queue
420
- if ( $info->comment_approved == 0 ) {
421
- //don't send notification-emails to all subscribed users
422
- return $_comment_ID;
423
- }
424
- }
425
- }
426
-
427
- // Send a notification to all the users subscribed to this post
428
- if ( $info->comment_approved == 1 ) {
429
- $subscriptions = $this->get_subscriptions(
430
- array(
431
- 'post_id',
432
- 'status'
433
- ), array(
434
- 'equals',
435
- 'equals'
436
- ), array(
437
- $info->comment_post_ID,
438
- 'Y'
439
- )
440
- );
441
- if ( ! empty( $info->comment_parent ) ) {
442
- $subscriptions = array_merge(
443
- $subscriptions, $this->get_subscriptions(
444
- 'parent', 'equals', array(
445
- $info->comment_parent,
446
- $info->comment_post_ID
447
- )
448
- )
449
- );
450
- }
451
-
452
- foreach ( $subscriptions as $a_subscription ) {
453
- // Skip the user who posted this new comment
454
- if ( $a_subscription->email != $info->comment_author_email ) {
455
- $this->notify_user( $info->comment_post_ID, $a_subscription->email, $_comment_ID );
456
- }
457
- }
458
- }
459
-
460
- // If the case, notify the author
461
- if ( get_option( 'subscribe_reloaded_notify_authors', 'no' ) == 'yes' ) {
462
- $this->notify_user( $info->comment_post_ID, get_bloginfo( 'admin_email' ), $_comment_ID );
463
- }
464
-
465
- return $_comment_ID;
466
- }
467
-
468
- // end new_comment_posted
469
-
470
- public function isDoubleCheckinEnabled( $info ) {
471
- $approved_subscriptions = $this->get_subscriptions(
472
- array(
473
- 'status',
474
- 'email'
475
- ), array(
476
- 'equals',
477
- 'equals'
478
- ), array(
479
- 'Y',
480
- $info->comment_author_email
481
- )
482
- );
483
- if ( ( get_option( 'subscribe_reloaded_enable_double_check', 'no' ) == 'yes' ) && ! is_user_logged_in() && empty( $approved_subscriptions ) ) {
484
- return true;
485
- } else {
486
- return false;
487
- }
488
- }
489
-
490
- public function sendConfirmationEMail( $info ) {
491
- // Retrieve the information about the new comment
492
- $this->confirmation_email( $info->comment_post_ID, $info->comment_author_email );
493
- }
494
-
495
- /**
496
- * Performs the appropriate action when the status of a given comment changes
497
- */
498
- public function comment_status_changed( $_comment_ID = 0, $_comment_status = 0 ) {
499
- // Retrieve the information about the comment
500
- $info = $this->_get_comment_object( $_comment_ID );
501
- if ( empty( $info ) ) {
502
- return $_comment_ID;
503
- }
504
-
505
- switch ( $info->comment_approved ) {
506
- case '0': // Unapproved: change the status of the corresponding subscription (if exists) to 'pending'
507
- $this->update_subscription_status( $info->comment_post_ID, $info->comment_author_email, 'C' );
508
- break;
509
-
510
- case '1': // Approved
511
- $this->update_subscription_status( $info->comment_post_ID, $info->comment_author_email, '-C' );
512
- $subscriptions = $this->get_subscriptions(
513
- array(
514
- 'post_id',
515
- 'status'
516
- ), array(
517
- 'equals',
518
- 'equals'
519
- ), array(
520
- $info->comment_post_ID,
521
- 'Y'
522
- )
523
- );
524
- if ( ! empty( $info->comment_parent ) ) {
525
- $subscriptions = array_merge(
526
- $subscriptions, $this->get_subscriptions(
527
- 'parent', 'equals', array(
528
- $info->comment_parent,
529
- $info->comment_post_ID
530
- )
531
- )
532
- );
533
- }
534
-
535
- foreach ( $subscriptions as $a_subscription ) {
536
- if ( $a_subscription->email != $info->comment_author_email ) // Skip the user who posted this new comment
537
- {
538
- $this->notify_user( $info->comment_post_ID, $a_subscription->email, $_comment_ID );
539
- }
540
- }
541
- break;
542
-
543
- case 'trash':
544
- case 'spam':
545
- $this->comment_deleted( $_comment_ID );
546
- break;
547
-
548
- default:
549
- break;
550
- }
551
-
552
- return $_comment_ID;
553
- }
554
- // end comment_status
555
-
556
- /**
557
- * Performs the appropriate action when a comment is deleted
558
- */
559
- public function comment_deleted( $_comment_ID ) {
560
- global $wpdb;
561
-
562
- $info = $this->_get_comment_object( $_comment_ID );
563
- if ( empty( $info ) ) {
564
- return $_comment_ID;
565
- }
566
-
567
- // Are there any other approved comments sent by this user?
568
- $count_approved_comments = $wpdb->get_var(
569
- "
570
- SELECT COUNT(*)
571
- FROM $wpdb->comments
572
- WHERE comment_post_ID = '$info->comment_post_ID' AND comment_author_email = '$info->comment_author_email' AND comment_approved = 1"
573
- );
574
- if ( intval( $count_approved_comments ) == 0 ) {
575
- $this->delete_subscriptions( $info->comment_post_ID, $info->comment_author_email );
576
- }
577
-
578
- return $_comment_ID;
579
- }
580
- // end comment_deleted
581
-
582
- /**
583
- * Subscribes the post author, if the corresponding option is set
584
- */
585
- public function subscribe_post_author( $_post_ID ) {
586
- $new_post = get_post( $_post_ID );
587
- $author_email = get_the_author_meta( 'user_email', $new_post->post_author );
588
- if ( ! empty( $author_email ) ) {
589
- $this->add_subscription( $_post_ID, $author_email, 'Y' );
590
- }
591
- }
592
- // end subscribe_post_author
593
-
594
- /**
595
- * Displays the appropriate management page
596
- */
597
- public function subscribe_reloaded_manage( $_posts = '', $_query = '' ) {
598
- global $current_user;
599
-
600
- if ( ! empty( $_posts ) ) {
601
- return $_posts;
602
- }
603
-
604
- $post_ID = ! empty( $_POST['srp'] ) ? intval( $_POST['srp'] ) : ( ! empty( $_GET['srp'] ) ? intval( $_GET['srp'] ) : 0 );
605
-
606
- // Is the post_id passed in the query string valid?
607
- $target_post = get_post( $post_ID );
608
- if ( ( $post_ID > 0 ) && ! is_object( $target_post ) ) {
609
- return $_posts;
610
- }
611
-
612
- // Load localization files
613
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
614
-
615
- $action = ! empty( $_POST['sra'] ) ? $_POST['sra'] : ( ! empty( $_GET['sra'] ) ? $_GET['sra'] : 0 );
616
- $key = ! empty( $_POST['srk'] ) ? $_POST['srk'] : ( ! empty( $_GET['srk'] ) ? $_GET['srk'] : 0 );
617
-
618
- $email = $this->clean_email( ! empty( $_POST['sre'] ) ? urldecode( $_POST['sre'] ) : ( ! empty( $_GET['sre'] ) ? $_GET['sre'] : '' ) );
619
- if ( empty( $email ) && ! empty( $current_user->user_email ) ) {
620
- $email = $this->clean_email( $current_user->user_email );
621
- }
622
-
623
- // Subscribe without commenting
624
- if ( ! empty( $action ) && ( $action == 's' ) && ( $post_ID > 0 ) ) {
625
- $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/subscribe.php';
626
- } // Management page for post authors
627
- elseif ( ( $post_ID > 0 ) && $this->is_author( $target_post->post_author ) ) {
628
- $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/author.php';
629
- } // Confirm your subscription (double check-in)
630
- elseif ( ( $post_ID > 0 ) && ! empty( $email ) && ! empty( $key ) && ! empty( $action ) &&
631
- $this->is_user_subscribed( $post_ID, $email, 'C' ) &&
632
- $this->_is_valid_key( $key, $email ) &&
633
- ( $action == 'c' )
634
- ) {
635
- $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/confirm.php';
636
- } // Manage your subscriptions (user)
637
- elseif ( ! empty( $email ) && ( ( ! empty( $key ) && $this->_is_valid_key( $key, $email ) ) || current_user_can( 'read' ) ) ) {
638
- $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/user.php';
639
- }
640
-
641
- if ( empty( $include_post_content ) ) {
642
- $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/request-management-link.php';
643
- }
644
-
645
- global $wp_query;
646
-
647
- $manager_page_title = html_entity_decode( get_option( 'subscribe_reloaded_manager_page_title', 'Manage subscriptions' ), ENT_COMPAT, 'UTF-8' );
648
- if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
649
- $manager_page_title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $manager_page_title );
650
- }
651
-
652
- $posts[] =
653
- (object) array(
654
- 'ID' => '9999999',
655
- 'post_author' => '1',
656
- 'post_date' => '2001-01-01 11:38:56',
657
- 'post_date_gmt' => '2001-01-01 00:38:56',
658
- 'post_content' => $include_post_content,
659
- 'post_title' => $manager_page_title,
660
- 'post_excerpt' => '',
661
- 'post_status' => 'publish',
662
- 'comment_status' => 'closed',
663
- 'ping_status' => 'closed',
664
- 'post_password' => '',
665
- 'to_ping' => '',
666
- 'pinged' => '',
667
- 'post_modified' => '2001-01-01 11:00:01',
668
- 'post_modified_gmt' => '2001-01-01 00:00:01',
669
- 'post_content_filtered' => '',
670
- 'post_parent' => '0',
671
- 'menu_order' => '0',
672
- 'post_type' => 'page',
673
- 'post_mime_type' => '',
674
- 'post_category' => '0',
675
- 'comment_count' => '0',
676
- 'filter' => 'raw',
677
- 'guid' => get_bloginfo( 'url' ) . '/?page_id=9999999',
678
- 'post_name' => get_bloginfo( 'url' ) . '/?page_id=9999999',
679
- 'ancestors' => array()
680
- );
681
-
682
- // Make WP believe this is a real page, with no comments attached
683
- $wp_query->is_page = true;
684
- $wp_query->is_single = false;
685
- $wp_query->is_home = false;
686
- $wp_query->comments = false;
687
-
688
- // Discard 404 errors thrown by other checks
689
- unset( $wp_query->query["error"] );
690
- $wp_query->query_vars["error"] = "";
691
- $wp_query->is_404 = false;
692
-
693
- // Seems like WP adds its own HTML formatting code to the content, we don't need that here
694
- remove_filter( 'the_content', 'wpautop' );
695
- add_action( 'wp_head', array( &$this, 'add_custom_header_meta' ) );
696
-
697
- return $posts;
698
- }
699
- // end subscribe_reloaded_manage
700
-
701
- /**
702
- * Removes old entries from the database
703
- */
704
- public function subscribe_reloaded_purge() {
705
- global $wpdb;
706
-
707
- if ( ( $autopurge_interval = intval( get_option( 'subscribe_reloaded_purge_days', 0 ) ) ) <= 0 ) {
708
- return true;
709
- }
710
-
711
- // Delete old entries
712
- $wpdb->query(
713
- "
714
- DELETE FROM $wpdb->postmeta
715
- WHERE meta_key LIKE '\_stcr@\_%'
716
- AND STR_TO_DATE(meta_value, '%Y-%m-%d %H:%i:%s') <= DATE_SUB(NOW(), INTERVAL $autopurge_interval DAY) AND meta_value LIKE '%C'"
717
- );
718
- }
719
- // end subscribe_reloaded_purge
720
-
721
- /**
722
- * Checks if current logged in user is the author of this post
723
- */
724
- public function is_author( $_post_author ) {
725
- global $current_user;
726
-
727
- return ! empty( $current_user ) && ( ( $_post_author == $current_user->ID ) || current_user_can( 'manage_options' ) );
728
- }
729
- // end is_author
730
-
731
- /**
732
- * Checks if a given email address is subscribed to a post
733
- */
734
- public function is_user_subscribed( $_post_ID = 0, $_email = '', $_status = '' ) {
735
- global $current_user;
736
-
737
- if ( ( empty( $current_user->user_email ) && empty( $_COOKIE['comment_author_email_' . COOKIEHASH] ) && empty( $_email ) ) || empty( $_post_ID ) ) {
738
- return false;
739
- }
740
-
741
- $operator = ( $_status != '' ) ? 'equals' : 'contains';
742
- $subscriptions = $this->get_subscriptions(
743
- array(
744
- 'post_id',
745
- 'status'
746
- ), array(
747
- 'equals',
748
- $operator
749
- ), array(
750
- $_post_ID,
751
- $_status
752
- )
753
- );
754
-
755
- if ( empty( $_email ) ) {
756
- $user_email = ! empty( $current_user->user_email ) ? $current_user->user_email : ( ! empty( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ? stripslashes( esc_attr( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) : '#undefined#' );
757
- } else {
758
- $user_email = $_email;
759
- }
760
-
761
- foreach ( $subscriptions as $a_subscription ) {
762
- if ( $user_email == $a_subscription->email ) {
763
- return true;
764
- }
765
- }
766
-
767
- return false;
768
- }
769
- // end is_user_subscribed
770
-
771
- /**
772
- * Adds a new subscription
773
- */
774
- public function add_subscription( $_post_id = 0, $_email = '', $_status = 'Y' ) {
775
- global $wpdb;
776
- // Does the post exist?
777
- $target_post = get_post( $_post_id );
778
- if ( ( $_post_id > 0 ) && ! is_object( $target_post ) ) {
779
- return;
780
- }
781
-
782
- // Filter unwanted statuses
783
- if ( ! in_array( $_status, array( 'Y', 'YC', 'R', 'RC', 'C', '-C' ) ) || empty( $_status ) ) {
784
- return;
785
- }
786
-
787
- // Using Wordpress local time
788
- $dt = date_i18n( 'Y-m-d H:i:s' );
789
-
790
- $clean_email = $this->clean_email( $_email );
791
- $wpdb->query(
792
- $wpdb->prepare(
793
- "
794
- INSERT IGNORE INTO $wpdb->postmeta (post_id, meta_key, meta_value)
795
- SELECT %d, %s, %s
796
- FROM DUAL
797
- WHERE NOT EXISTS (
798
- SELECT post_id
799
- FROM $wpdb->postmeta
800
- WHERE post_id = %d
801
- AND meta_key = %s
802
- LIMIT 0,1
803
- )", $_post_id, "_stcr@_$clean_email", "$dt|$_status", $_post_id, "_stcr@_$clean_email"
804
- )
805
- );
806
- }
807
- // end add_subscription
808
-
809
- /**
810
- * Deletes one or more subscriptions from the database
811
- */
812
- public function delete_subscriptions( $_post_id = 0, $_email = '' ) {
813
- global $wpdb;
814
-
815
- if ( empty( $_post_id ) ) {
816
- return 0;
817
- }
818
-
819
- $posts_where = '';
820
- if ( ! is_array( $_post_id ) ) {
821
- $posts_where = "post_id = " . intval( $_post_id );
822
- } else {
823
- foreach ( $_post_id as $a_post_id ) {
824
- $posts_where .= "post_id = '" . intval( $a_post_id ) . "' OR ";
825
- }
826
-
827
- $posts_where = substr( $posts_where, 0, - 4 );
828
- }
829
-
830
- if ( ! empty( $_email ) ) {
831
- $emails_where = '';
832
- if ( ! is_array( $_email ) ) {
833
- $emails_where = "meta_key = '_stcr@_" . $this->clean_email( $_email ) . "'";
834
- } else {
835
- foreach ( $_email as $a_email ) {
836
- $emails_where .= "meta_key = '_stcr@_" . $this->clean_email( $a_email ) . "' OR ";
837
- }
838
-
839
- $emails_where = substr( $emails_where, 0, - 4 );
840
- }
841
-
842
- return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE ($posts_where) AND ($emails_where)" );
843
- } else {
844
- return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%' AND ($posts_where)" );
845
- }
846
- }
847
- // end delete_subscriptions
848
-
849
- /**
850
- * Updates the status of an existing subscription
851
- */
852
- public function update_subscription_status( $_post_id = 0, $_email = '', $_new_status = 'C' ) {
853
- global $wpdb;
854
-
855
- // Filter unwanted statuses
856
- if ( empty( $_new_status ) || ! in_array( $_new_status, array( 'Y', 'R', 'C', '-C' ) ) || empty( $_email ) ) {
857
- return 0;
858
- }
859
-
860
- if ( ! empty( $_post_id ) ) {
861
- $posts_where = '';
862
- if ( ! is_array( $_post_id ) ) {
863
- $posts_where = "post_id = " . intval( $_post_id );
864
- } else {
865
- foreach ( $_post_id as $a_post_id ) {
866
- $posts_where .= "post_id = '" . intval( $a_post_id ) . "' OR ";
867
- }
868
-
869
- $posts_where = substr( $posts_where, 0, - 4 );
870
- }
871
- } else { // Mass update subscriptions
872
- $posts_where = '1=1';
873
- }
874
-
875
- $emails_where = '';
876
- if ( ! is_array( $_email ) ) {
877
- $emails_where = "meta_key = '_stcr@_" . $this->clean_email( $_email ) . "'";
878
- } else {
879
- foreach ( $_email as $a_email ) {
880
- $emails_where .= "meta_key = '_stcr@_" . $this->clean_email( $a_email ) . "' OR ";
881
- }
882
-
883
- $emails_where = substr( $emails_where, 0, - 4 );
884
- }
885
-
886
- $meta_length = ( strpos( $_new_status, 'C' ) !== false ) ? 21 : 20;
887
- $new_status = ( $_new_status == '-C' ) ? '' : $_new_status;
888
-
889
- return $wpdb->query(
890
- "
891
- UPDATE $wpdb->postmeta
892
- SET meta_value = CONCAT(SUBSTRING(meta_value, 1, $meta_length), '$new_status')
893
- WHERE ($posts_where) AND ($emails_where)"
894
- );
895
- }
896
- // end update_subscription_status
897
-
898
- /**
899
- * Updates the email address of an existing subscription
900
- */
901
- public function update_subscription_email( $_post_id = 0, $_email = '', $_new_email = '' ) {
902
- global $wpdb;
903
-
904
- // Nothing to do if the new email hasn't been specified
905
- if ( empty( $_email ) || empty( $_new_email ) || strpos( $_new_email, '@' ) == 0 ) {
906
- return;
907
- }
908
-
909
- $clean_values[] = "_stcr@_" . $this->clean_email( $_new_email );
910
- $clean_values[] = "_stcr@_" . $this->clean_email( $_email );
911
- $post_where = '';
912
- if ( ! empty( $_post_id ) ) {
913
- $post_where = ' AND post_id = %d';
914
- $clean_values[] = $_post_id;
915
- }
916
-
917
- return $wpdb->query(
918
- $wpdb->prepare(
919
- "
920
- UPDATE $wpdb->postmeta
921
- SET meta_key = %s
922
- WHERE meta_key = %s $post_where", $clean_values
923
- )
924
- );
925
- }
926
- // end update_subscription_email
927
-
928
- /**
929
- * Retrieves a list of emails subscribed to this post
930
- */
931
- public function get_subscriptions( $_search_field = array( 'email' ), $_operator = array( 'equals' ), $_search_value = array( '' ), $_order_by = 'dt', $_order = 'ASC', $_offset = 0, $_limit_results = 0 ) {
932
- global $wpdb;
933
-
934
- // Type adjustments
935
- $search_fields = ( ! is_array( $_search_field ) ) ? array( $_search_field ) : $_search_field;
936
- $operators = ( ! is_array( $_operator ) ) ? array( $_operator ) : $_operator;
937
- $search_values = ( ! is_array( $_search_value ) ) ? array( $_search_value ) : $_search_value;
938
-
939
- // Find if exists a 'replies only' subscription for the parent comment
940
- if ( $search_fields[0] == 'parent' ) {
941
-
942
- $parent_comment_id = $search_values[0];
943
- $comment_post_id = $search_values[1];
944
-
945
- // Get the parent comment author email so we can search for any Replies Only subscriptions
946
- $parent_comment_author_email_query = mysql_query( "SELECT `comment_author_email` FROM $wpdb->comments WHERE `comment_ID` = '$parent_comment_id'" );
947
- $parent_comment_author_email = mysql_fetch_row( $parent_comment_author_email_query );
948
- $parent_comment_author_email = "\_stcr@\_" . $parent_comment_author_email[0];
949
-
950
- // Check if $parent_comment_author_email has any Replies Only (R) subscriptions for $comment_post_id
951
-
952
- /*
953
- Heads up: this will return Replies Only subscriptions for a given post, *not* for a given comment.
954
- This plugin does not track subscriptions for specific comments but rather for entire posts, so there
955
- is no way to figure out if a specific parent comment has a subscription (of any type). To make the
956
- Replies Only feature half-work, we check if a parent comment author has *any* Replies Only subscriptions
957
- for a given post. If they do, we assume that they must want to get notified of replies to *any* of their
958
- comments on *that* post.
959
- */
960
-
961
- return $wpdb->get_results(
962
- $wpdb->prepare(
963
- "
964
- SELECT pm.meta_id, REPLACE(pm.meta_key, '_stcr@_', '') AS email, pm.post_id, SUBSTRING(pm.meta_value, 1, 19) AS dt, SUBSTRING(pm.meta_value, 21) AS status
965
- FROM $wpdb->postmeta pm
966
- WHERE pm.meta_key LIKE %s
967
- AND pm.meta_value LIKE '%%R'
968
- AND pm.post_id = %d", $parent_comment_author_email, $comment_post_id
969
- ), OBJECT
970
- );
971
- } else {
972
- $where_clause = '';
973
- foreach ( $search_fields as $a_idx => $a_field ) {
974
- $where_clause .= ' AND';
975
- $offset_status = ( $a_field == 'status' && $search_values[$a_idx] == 'C' ) ? 22 : 21;
976
- switch ( $a_field ) {
977
- case 'status':
978
- $where_clause .= " SUBSTRING(meta_value, $offset_status)";
979
- break;
980
- case 'post_id':
981
- $where_clause .= ' post_id';
982
- break;
983
- default:
984
- $where_clause .= ' SUBSTRING(meta_key, 8)';
985
- }
986
- switch ( $operators[$a_idx] ) {
987
- case 'equals':
988
- $where_clause .= " = %s";
989
- $where_values[] = $search_values[$a_idx];
990
- break;
991
- case 'does not contain':
992
- $where_clause .= " NOT LIKE %s";
993
- $where_values[] = "%{$search_values[$a_idx]}%";
994
- break;
995
- case 'starts with':
996
- $where_clause .= " LIKE %s";
997
- $where_values[] = "${$search_values[$a_idx]}%";
998
- break;
999
- case 'ends with':
1000
- $where_clause .= " LIKE %s";
1001
- $where_values[] = "%{$search_values[$a_idx]}";
1002
- break;
1003
- default: // contains
1004
- $where_clause .= " LIKE %s";
1005
- $where_values[] = "%{$search_values[$a_idx]}%";
1006
- }
1007
- }
1008
- switch ( $_order_by ) {
1009
- case 'status':
1010
- $order_by = "status";
1011
- break;
1012
- case 'email':
1013
- $order_by = 'meta_key';
1014
- break;
1015
- case 'dt':
1016
- $order_by = 'dt';
1017
- break;
1018
- default:
1019
- $order_by = 'post_id';
1020
- }
1021
- $order = ( $_order != 'ASC' && $_order != 'DESC' ) ? 'DESC' : $_order;
1022
-
1023
- // This is the 'official' way to have an offset without a limit
1024
- $row_count = ( $_limit_results <= 0 ) ? '18446744073709551610' : $_limit_results;
1025
-
1026
- return $wpdb->get_results(
1027
- $wpdb->prepare(
1028
- "
1029
- SELECT meta_id, REPLACE(meta_key, '_stcr@_', '') AS email, post_id, SUBSTRING(meta_value, 1, 19) AS dt, SUBSTRING(meta_value, 21) AS status
1030
- FROM $wpdb->postmeta
1031
- WHERE meta_key LIKE '\_stcr@\_%%' $where_clause
1032
- ORDER BY $order_by $order
1033
- LIMIT $_offset,$row_count", $where_values
1034
- ), OBJECT
1035
- );
1036
- }
1037
- }
1038
- // end get_subscriptions
1039
-
1040
- /**
1041
- * Sends a message to confirm a subscription
1042
- */
1043
- public function confirmation_email( $_post_ID = 0, $_email = '' ) {
1044
- // Retrieve the options from the database
1045
- $from_name = stripslashes( get_option( 'subscribe_reloaded_from_name', 'admin' ) );
1046
- $from_email = get_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ) );
1047
- $subject = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_double_check_subject', 'Please confirm your subscribtion to [post_title]' ) ), ENT_COMPAT, 'UTF-8' );
1048
- $message = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_double_check_content', '' ) ), ENT_COMPAT, 'UTF-8' );
1049
- $manager_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
1050
- if ( function_exists( 'qtrans_convertURL' ) ) {
1051
- $manager_link = qtrans_convertURL( $manager_link );
1052
- }
1053
-
1054
- $clean_email = $this->clean_email( $_email );
1055
- $subscriber_salt = $this->generate_key( $clean_email );
1056
-
1057
- $manager_link .= ( ( strpos( $manager_link, '?' ) !== false ) ? '&' : '?' ) . "sre=" . urlencode( $clean_email ) . "&srk=$subscriber_salt";
1058
- $confirm_link = "$manager_link&srp=$_post_ID&sra=c";
1059
-
1060
- $headers = "From: $from_name <$from_email>\n";
1061
- $content_type = ( get_option( 'subscribe_reloaded_enable_html_emails', 'no' ) == 'yes' ) ? 'text/html' : 'text/plain';
1062
- $headers .= "Content-Type: $content_type; charset=" . get_bloginfo( 'charset' ) . "\n";
1063
-
1064
- $post = get_post( $_post_ID );
1065
- $post_permalink = get_permalink( $_post_ID );
1066
-
1067
- // Replace tags with their actual values
1068
- $subject = str_replace( '[post_title]', $post->post_title, $subject );
1069
-
1070
- $message = str_replace( '[post_permalink]', $post_permalink, $message );
1071
- $message = str_replace( '[confirm_link]', $confirm_link, $message );
1072
- $message = str_replace( '[manager_link]', $manager_link, $message );
1073
-
1074
- // QTranslate support
1075
- if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
1076
- $subject = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $subject );
1077
- $message = str_replace( '[post_title]', qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post->post_title ), $message );
1078
- $message = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $message );
1079
- } else {
1080
- $message = str_replace( '[post_title]', $post->post_title, $message );
1081
- }
1082
- $message = apply_filters( 'stcr_confirmation_email_message', $message, $_post_ID, $email );
1083
- if ( $content_type == 'text/html' ) {
1084
- $message = $this->wrap_html_message( $message, $subject );
1085
- }
1086
-
1087
- wp_mail( $clean_email, $subject, $message, $headers );
1088
- }
1089
- // end confirmation_email
1090
-
1091
- /**
1092
- * Sends the notification message to a given user
1093
- */
1094
- public function notify_user( $_post_ID = 0, $_email = '', $_comment_ID = 0 ) {
1095
- // Retrieve the options from the database
1096
- $from_name = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_from_name', 'admin' ) ), ENT_COMPAT, 'UTF-8' );
1097
- $from_email = get_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ) );
1098
- $subject = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_notification_subject', 'There is a new comment on the post [post_title]' ) ), ENT_COMPAT, 'UTF-8' );
1099
- $message = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_notification_content', '' ) ), ENT_COMPAT, 'UTF-8' );
1100
- $manager_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
1101
- if ( function_exists( 'qtrans_convertURL' ) ) {
1102
- $manager_link = qtrans_convertURL( $manager_link );
1103
- }
1104
-
1105
- $clean_email = $this->clean_email( $_email );
1106
- $subscriber_salt = $this->generate_key( $clean_email );
1107
-
1108
- $manager_link .= ( ( strpos( $manager_link, '?' ) !== false ) ? '&' : '?' ) . "sre=" . urlencode( $clean_email ) . "&srk=$subscriber_salt";
1109
-
1110
- $headers = "From: $from_name <$from_email>\n";
1111
- $content_type = ( get_option( 'subscribe_reloaded_enable_html_emails', 'no' ) == 'yes' ) ? 'text/html' : 'text/plain';
1112
- $headers .= "Content-Type: $content_type; charset=" . get_bloginfo( 'charset' ) . "\n";
1113
-
1114
- if ( get_option( 'subscribe_reloaded_admin_bcc', 'no' ) == 'yes' ) {
1115
- $headers .= "Bcc: $from_name <$from_email>\n";
1116
- }
1117
-
1118
- $post = get_post( $_post_ID );
1119
- $comment = get_comment( $_comment_ID );
1120
- $post_permalink = get_permalink( $_post_ID );
1121
- $comment_permalink = get_comment_link( $_comment_ID );
1122
- $comment_reply_permalink = get_permalink( $_post_ID ) . '?replytocom=' . $_comment_ID . '#respond';
1123
-
1124
- $comment_content = $comment->comment_content;
1125
-
1126
- // Add HTML paragraph tags to comment
1127
- // See wp-includes/formatting.php for details on the wpautop() function
1128
- if ( $content_type == 'text/html' ) {
1129
- $comment_content = wpautop( $comment->comment_content );
1130
- }
1131
-
1132
- // Replace tags with their actual values
1133
- $subject = str_replace( '[post_title]', $post->post_title, $subject );
1134
-
1135
- $message = str_replace( '[post_permalink]', $post_permalink, $message );
1136
- $message = str_replace( '[comment_permalink]', $comment_permalink, $message );
1137
- $message = str_replace( '[comment_reply_permalink]', $comment_reply_permalink, $message );
1138
- $message = str_replace( '[comment_author]', $comment->comment_author, $message );
1139
- $message = str_replace( '[comment_content]', $comment_content, $message );
1140
- $message = str_replace( '[manager_link]', $manager_link, $message );
1141
-
1142
- // QTranslate support
1143
- if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
1144
- $subject = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $subject );
1145
- $message = str_replace( '[post_title]', qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post->post_title ), $message );
1146
- $message = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $message );
1147
- } else {
1148
- $message = str_replace( '[post_title]', $post->post_title, $message );
1149
- }
1150
- $message = apply_filters( 'stcr_notify_user_message', $message, $_post_ID, $_email, $_comment_ID );
1151
- if ( $content_type == 'text/html' ) {
1152
- if ( get_option( 'subscribe_reloaded_htmlify_message_links' ) == 'yes' ) {
1153
- $message = $this->htmlify_message_links( $message );
1154
- }
1155
- $message = $this->wrap_html_message( $message, $subject );
1156
- }
1157
-
1158
- wp_mail( $clean_email, $subject, $message, $headers );
1159
- }
1160
- // end notify_user
1161
-
1162
- /**
1163
- * Finds all links in text and wraps them with an HTML anchor tag
1164
- *
1165
- * @param unknown $text
1166
- *
1167
- * @return string Text with all links wrapped in HTML anchor tags
1168
- *
1169
- */
1170
- public function htmlify_message_links( $text ) {
1171
- return preg_replace( '!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text );
1172
- }
1173
-
1174
- /**
1175
- * Generate a unique key to allow users to manage their subscriptions
1176
- */
1177
- public function generate_key( $_email ) {
1178
- $day = date_i18n( 'Ymd' );
1179
-
1180
- return md5( $day . $this->salt . $_email );
1181
- }
1182
- // end generate_key
1183
-
1184
- /**
1185
- * Creates the HTML structure to properly handle HTML messages
1186
- */
1187
- public function wrap_html_message( $_message = '', $_subject = '' ) {
1188
- return "<html><head><title>$_subject</title></head><body>$_message</body></html>";
1189
- }
1190
- // end _wrap_html_message
1191
-
1192
- /**
1193
- * Returns an email address where some possible 'offending' strings have been removed
1194
- */
1195
- public function clean_email( $_email ) {
1196
- $offending_strings = array(
1197
- "/to\:/i",
1198
- "/from\:/i",
1199
- "/bcc\:/i",
1200
- "/cc\:/i",
1201
- "/content\-transfer\-encoding\:/i",
1202
- "/content\-type\:/i",
1203
- "/mime\-version\:/i"
1204
- );
1205
-
1206
- return esc_attr( stripslashes( strip_tags( preg_replace( $offending_strings, '', $_email ) ) ) );
1207
- }
1208
- // end clean_email
1209
-
1210
- /**
1211
- * Adds a new entry in the admin menu, to manage this plugin's options
1212
- */
1213
- public function add_config_menu( $_s ) {
1214
- global $current_user;
1215
-
1216
- if ( current_user_can( 'manage_options' ) ) {
1217
- add_options_page( 'Subscribe to Comments', 'Subscribe to Comments', 'manage_options', WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/options/index.php' );
1218
- }
1219
-
1220
- return $_s;
1221
- }
1222
- // end add_config_menu
1223
-
1224
- /**
1225
- * Adds a custom stylesheet file to the admin interface
1226
- */
1227
- public function add_options_stylesheet() {
1228
- // It looks like WP_PLUGIN_URL doesn't honor the HTTPS setting in wp-config.php
1229
- $stylesheet_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/style.css';
1230
- wp_register_style( 'subscribe-to-comments', $stylesheet_url );
1231
- wp_enqueue_style( 'subscribe-to-comments' );
1232
- }
1233
-
1234
- public function add_post_comments_stylesheet() {
1235
- // It looks like WP_PLUGIN_URL doesn't honor the HTTPS setting in wp-config.php
1236
- $stylesheet_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/post-and-comments.css';
1237
- wp_register_style( 'subscribe-to-comments', $stylesheet_url );
1238
- wp_enqueue_style( 'subscribe-to-comments' );
1239
- }
1240
- // end add_stylesheet
1241
-
1242
- /**
1243
- * Adds custom HTML code to the HEAD section of the management page
1244
- */
1245
- public function add_custom_header_meta() {
1246
- echo html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_custom_header_meta', '' ) ), ENT_COMPAT, 'UTF-8' );
1247
- }
1248
- // end add_custom_header_meta
1249
-
1250
- /**
1251
- * Adds a new column header to the Edit Comments panel
1252
- */
1253
- public function add_column_header( $_columns ) {
1254
- $image_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/images';
1255
- $_columns['subscribe-reloaded'] = "<img src='$image_url/subscribe-to-comments-small.png' width='17' height='12' alt='Subscriptions' />";
1256
-
1257
- return $_columns;
1258
- }
1259
- // end add_comment_column_header
1260
-
1261
- /**
1262
- * Adds a new column to the Edit Comments panel
1263
- */
1264
- public function add_comment_column( $_column_name ) {
1265
- if ( 'subscribe-reloaded' != $_column_name ) {
1266
- return;
1267
- }
1268
-
1269
- global $comment;
1270
- $subscription = $this->get_subscriptions(
1271
- array(
1272
- 'post_id',
1273
- 'email'
1274
- ), array(
1275
- 'equals',
1276
- 'equals'
1277
- ), array(
1278
- $comment->comment_post_ID,
1279
- $comment->comment_author_email
1280
- ), 'dt', 'DESC', 0, 1
1281
- );
1282
- if ( count( $subscription ) == 0 ) {
1283
- _e( 'No', 'subscribe-reloaded' );
1284
- } else {
1285
- echo '<a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=1&amp;srf=email&amp;srt=equals&amp;srv=' . urlencode( $comment->comment_author_email ) . '">' . $subscription[0]->status . '</a>';
1286
- }
1287
- }
1288
- // end add_column
1289
-
1290
- /**
1291
- * Adds a new column to the Posts management panel
1292
- */
1293
- public function add_post_column( $_column_name ) {
1294
- if ( 'subscribe-reloaded' != $_column_name ) {
1295
- return;
1296
- }
1297
-
1298
- global $post;
1299
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
1300
- echo '<a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=1&amp;srf=post_id&amp;srt=equals&amp;srv=' . $post->ID . '">' . count( $this->get_subscriptions( 'post_id', 'equals', $post->ID ) ) . '</a>';
1301
- }
1302
- // end add_column
1303
-
1304
- /**
1305
- * Contextual help (link to the support forum)
1306
- */
1307
- public function contextual_help( $contextual_help, $screen_id, $screen ) {
1308
- if ( $screen_id == 'subscribe-to-comments-reloaded/options/index' ) {
1309
- load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
1310
- $contextual_help = __( 'Need help on how to use Subscribe to Comments Reloaded? Visit the official', 'subscribe-reloaded' ) . ' <a href="http://wordpress.org/tags/subscribe-to-comments-reloaded?forum_id=10" target="_blank">' . __( 'support forum', 'subscribe-reloaded' ) . '</a>. ';
1311
- $contextual_help .= __( 'Feeling generous?', 'subscribe-reloaded' ) . ' <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=XF86X93FDCGYA&lc=US&item_name=Datasoft%20Engineering&item_number=DI%2dSTCR&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank">' . __( 'Donate a few bucks!', 'subscribe-reloaded' ) . '</a>';
1312
- }
1313
-
1314
- return $contextual_help;
1315
- }
1316
- // end contextual_help
1317
-
1318
- /**
1319
- * Returns the URL of the management page as a shortcode
1320
- */
1321
- public function subscribe_url_shortcode() {
1322
- global $post;
1323
- $user_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '' );
1324
- if ( function_exists( 'qtrans_convertURL' ) ) {
1325
- $user_link = qtrans_convertURL( $user_link );
1326
- }
1327
- if ( strpos( $user_link, '?' ) !== false ) {
1328
- return "$user_link&amp;srp=$post->ID&amp;sra=s";
1329
- } else {
1330
- return "$user_link?srp=$post->ID&amp;sra=s";
1331
- }
1332
- }
1333
- // end subscribe_url_shortcode
1334
-
1335
- /**
1336
- * Copies the information from the stand-alone table to WP's core table
1337
- */
1338
- private function _update_db() {
1339
- global $wpdb;
1340
- $stcr_table = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}subscribe_reloaded'" );
1341
-
1342
- // Perform the import only if the target table does not contain any subscriptions
1343
- $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1344
- if ( ! empty( $stcr_table ) && $count_postmeta_rows == 0 ) {
1345
- $wpdb->query(
1346
- "
1347
- INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1348
- SELECT post_ID, CONCAT('_stcr@_', email), CONCAT(dt, '|Y')
1349
- FROM {$wpdb->prefix}subscribe_reloaded
1350
- WHERE email LIKE '%@%.%' AND status = 'Y'
1351
- GROUP BY email, post_ID"
1352
- );
1353
- }
1354
- }
1355
- // end _update_db
1356
-
1357
- /**
1358
- * Imports subscription data created with the Subscribe to Comments plugin
1359
- */
1360
- private function _import_stc_data() {
1361
- global $wpdb;
1362
-
1363
- // Import the information collected by Subscribe to Comments, if needed
1364
- $result = $wpdb->get_row( "DESC $wpdb->comments comment_subscribe", ARRAY_A );
1365
-
1366
- // Perform the import only if the target table does not contain any subscriptions
1367
- $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1368
-
1369
- if ( ! empty( $result ) && is_array( $result ) && $count_postmeta_rows == 0 ) {
1370
- $wpdb->query(
1371
- "
1372
- INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1373
- SELECT comment_post_ID, CONCAT('_stcr@_', comment_author_email), CONCAT(comment_date, '|Y')
1374
- FROM $wpdb->comments
1375
- WHERE comment_author_email LIKE '%@%.%' AND comment_subscribe = 'Y'
1376
- GROUP BY comment_post_ID, comment_author_email"
1377
- );
1378
-
1379
- $notices = get_option( 'subscribe_reloaded_deferred_admin_notices', array() );
1380
- $notices[] = '<div class="updated"><h3>' . __( 'Important Notice', 'subscribe-reloaded' ) . '</h3>' .
1381
- '<p>' . __( 'Comment subscription data from the <strong>Subscribe to Comments</strong> plugin was detected and automatically imported into <strong>Subscribe to Comments Reloaded</strong>.', 'subscribe-reloaded' ) . ( is_plugin_active( 'subscribe-to-comments/subscribe-to-comments.php' ) ? __( ' It is recommended that you now <strong>deactivate</strong> Subscribe to Comments to prevent confusion between the two plugins.', 'subscribe-reloaded' ) : '' ) . '</p>' .
1382
- '<p>' . __( 'If you have subscription data from Subscribe to Comments Reloaded < v2.0 that you want to import, you\'ll need to import that data manually, as only one import routine will ever run to prevent data loss.', 'subscribe-reloaded' ) . '</p>' .
1383
- '<p>' . __( 'Please visit <a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php">Settings -> Subscribe to Comments</a> to review your configuration.', 'subscribe-reloaded' ) . '</p></div>';
1384
- update_option( 'subscribe_reloaded_deferred_admin_notices', $notices );
1385
- }
1386
- }
1387
- // end _import_stc_data
1388
-
1389
- /**
1390
- * Imports options and subscription data created with the WP Comment Subscriptions plugin
1391
- */
1392
- private function _import_wpcs_data() {
1393
- global $wpdb;
1394
-
1395
- // Import the information collected by WP Comment Subscriptions, if needed
1396
- $wpcs_data_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_wpcs@\_%'" );
1397
-
1398
- // Perform the import only if the target table does not contain any subscriptions
1399
- $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1400
-
1401
- if ( ! empty( $wpcs_data_count ) && $count_postmeta_rows == 0 ) {
1402
- $wpdb->query(
1403
- "
1404
- INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1405
- SELECT post_id, REPLACE(meta_key, '_wpcs@_', '_stcr@_') meta_key, meta_value
1406
- FROM $wpdb->postmeta
1407
- WHERE meta_key LIKE '%_wpcs@_%'"
1408
- );
1409
-
1410
- if ( $option = get_option( 'wp_comment_subscriptions_manager_page' ) ) {
1411
- add_option( 'subscribe_reloaded_manager_page', $option );
1412
- }
1413
- if ( $option = get_option( 'wp_comment_subscriptions_show_subscription_box' ) ) {
1414
- add_option( 'subscribe_reloaded_show_subscription_box', $option );
1415
- }
1416
- if ( $option = get_option( 'wp_comment_subscriptions_checked_by_default' ) ) {
1417
- add_option( 'subscribe_reloaded_checked_by_default', $option );
1418
- }
1419
- if ( $option = get_option( 'wp_comment_subscriptions_enable_advanced_subscriptions' ) ) {
1420
- add_option( 'subscribe_reloaded_enable_advanced_subscriptions', $option );
1421
- }
1422
- if ( $option = get_option( 'wp_comment_subscriptions_checkbox_inline_style' ) ) {
1423
- add_option( 'subscribe_reloaded_checkbox_inline_style', $option );
1424
- }
1425
- if ( $option = get_option( 'wp_comment_subscriptions_checkbox_html' ) ) {
1426
- add_option( 'subscribe_reloaded_checkbox_html', $option );
1427
- }
1428
- if ( $option = get_option( 'wp_comment_subscriptions_checkbox_label' ) ) {
1429
- add_option( 'subscribe_reloaded_checkbox_label', $option );
1430
- }
1431
- if ( $option = get_option( 'wp_comment_subscriptions_subscribed_label' ) ) {
1432
- add_option( 'subscribe_reloaded_subscribed_label', $option );
1433
- }
1434
- if ( $option = get_option( 'wp_comment_subscriptions_subscribed_waiting_label' ) ) {
1435
- add_option( 'subscribe_reloaded_subscribed_waiting_label', $option );
1436
- }
1437
- if ( $option = get_option( 'wp_comment_subscriptions_author_label' ) ) {
1438
- add_option( 'subscribe_reloaded_author_label', $option );
1439
- }
1440
- if ( $option = get_option( 'wp_comment_subscriptions_htmlify_message_links' ) ) {
1441
- add_option( 'subscribe_reloaded_htmlify_message_links', $option );
1442
- }
1443
-
1444
- if ( $option = get_option( 'wp_comment_subscriptions_manager_page_enabled' ) ) {
1445
- add_option( 'subscribe_reloaded_manager_page_enabled', $option );
1446
- }
1447
- if ( $option = get_option( 'wp_comment_subscriptions_manager_page_title' ) ) {
1448
- add_option( 'subscribe_reloaded_manager_page_title', $option );
1449
- }
1450
- if ( $option = get_option( 'wp_comment_subscriptions_custom_header_meta' ) ) {
1451
- add_option( 'subscribe_reloaded_custom_header_meta', $option );
1452
- }
1453
- if ( $option = get_option( 'wp_comment_subscriptions_request_mgmt_link' ) ) {
1454
- add_option( 'subscribe_reloaded_request_mgmt_link', $option );
1455
- }
1456
- if ( $option = get_option( 'wp_comment_subscriptions_request_mgmt_link_thankyou' ) ) {
1457
- add_option( 'subscribe_reloaded_request_mgmt_link_thankyou', $option );
1458
- }
1459
- if ( $option = get_option( 'wp_comment_subscriptions_subscribe_without_commenting' ) ) {
1460
- add_option( 'subscribe_reloaded_subscribe_without_commenting', $option );
1461
- }
1462
- if ( $option = get_option( 'wp_comment_subscriptions_subscription_confirmed' ) ) {
1463
- add_option( 'subscribe_reloaded_subscription_confirmed', $option );
1464
- }
1465
- if ( $option = get_option( 'wp_comment_subscriptions_subscription_confirmed_dci' ) ) {
1466
- add_option( 'subscribe_reloaded_subscription_confirmed_dci', $option );
1467
- }
1468
- if ( $option = get_option( 'wp_comment_subscriptions_author_text' ) ) {
1469
- add_option( 'subscribe_reloaded_author_text', $option );
1470
- }
1471
- if ( $option = get_option( 'wp_comment_subscriptions_user_text' ) ) {
1472
- add_option( 'subscribe_reloaded_user_text', $option );
1473
- }
1474
-
1475
- if ( $option = get_option( 'wp_comment_subscriptions_from_name' ) ) {
1476
- add_option( 'subscribe_reloaded_from_name', $option );
1477
- }
1478
- if ( $option = get_option( 'wp_comment_subscriptions_from_email' ) ) {
1479
- add_option( 'subscribe_reloaded_from_email', $option );
1480
- }
1481
- if ( $option = get_option( 'wp_comment_subscriptions_notification_subject' ) ) {
1482
- add_option( 'subscribe_reloaded_notification_subject', $option );
1483
- }
1484
- if ( $option = get_option( 'wp_comment_subscriptions_notification_content' ) ) {
1485
- add_option( 'subscribe_reloaded_notification_content', $option );
1486
- }
1487
- if ( $option = get_option( 'wp_comment_subscriptions_double_check_subject' ) ) {
1488
- add_option( 'subscribe_reloaded_double_check_subject', $option );
1489
- }
1490
- if ( $option = get_option( 'wp_comment_subscriptions_double_check_content' ) ) {
1491
- add_option( 'subscribe_reloaded_double_check_content', $option );
1492
- }
1493
- if ( $option = get_option( 'wp_comment_subscriptions_management_subject' ) ) {
1494
- add_option( 'subscribe_reloaded_management_subject', $option );
1495
- }
1496
- if ( $option = get_option( 'wp_comment_subscriptions_management_content' ) ) {
1497
- add_option( 'subscribe_reloaded_management_content', $option );
1498
- }
1499
-
1500
- if ( $option = get_option( 'wp_comment_subscriptions_purge_days' ) ) {
1501
- add_option( 'subscribe_reloaded_purge_days', $option );
1502
- }
1503
- if ( $option = get_option( 'wp_comment_subscriptions_enable_double_check' ) ) {
1504
- add_option( 'subscribe_reloaded_enable_double_check', $option );
1505
- }
1506
- if ( $option = get_option( 'wp_comment_subscriptions_notify_authors' ) ) {
1507
- add_option( 'subscribe_reloaded_notify_authors', $option );
1508
- }
1509
- if ( $option = get_option( 'wp_comment_subscriptions_enable_html_emails' ) ) {
1510
- add_option( 'subscribe_reloaded_enable_html_emails', $option );
1511
- }
1512
- if ( $option = get_option( 'wp_comment_subscriptions_process_trackbacks' ) ) {
1513
- add_option( 'subscribe_reloaded_process_trackbacks', $option );
1514
- }
1515
- if ( $option = get_option( 'wp_comment_subscriptions_enable_admin_messages' ) ) {
1516
- add_option( 'subscribe_reloaded_enable_admin_messages', $option );
1517
- }
1518
- if ( $option = get_option( 'wp_comment_subscriptions_admin_subscribe' ) ) {
1519
- add_option( 'subscribe_reloaded_admin_subscribe', $option );
1520
- }
1521
- if ( $option = get_option( 'wp_comment_subscriptions_admin_bcc' ) ) {
1522
- add_option( 'subscribe_reloaded_admin_bcc', $option );
1523
- }
1524
-
1525
- $notices = get_option( 'subscribe_reloaded_deferred_admin_notices', array() );
1526
- $notices[] = '<div class="updated"><h3>' . __( 'Important Notice', 'subscribe-reloaded' ) . '</h3>' .
1527
- '<p>' . __( 'Plugin options and comment subscription data from the <strong>WP Comment Subscriptions</strong> plugin were detected and automatically imported into <strong>Subscribe to Comments Reloaded</strong>.', 'subscribe-reloaded' ) . ( is_plugin_active( 'wp-comment-subscriptions/wp-comment-subscriptions.php' ) ? __( ' It is recommended that you now <strong>deactivate</strong> WP Comment Subscriptions to prevent confusion between the two plugins.', 'subscribe-reloaded' ) : '' ) . '</p>' .
1528
- '<p>' . __( 'If you have subscription data from another plugin (such as Subscribe to Comments or Subscribe to Comments Reloaded < v2.0) that you want to import, you\'ll need to import that data manually, as only one import routine will ever run to prevent data loss.', 'subscribe-reloaded' ) . '</p>' .
1529
- '<p>' . __( '<strong>Note:</strong> If you were previously using the <code>wp_comment_subscriptions_show()</code> function or the <code>[wpcs-subscribe-url]</code> shortcode, you\'ll need to replace those with <code>subscribe_reloaded_show()</code> and <code>[subscribe-url]</code> respectively.', 'subscribe-reloaded' ) . '</p>' .
1530
- '<p>' . __( 'Please visit <a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php">Settings -> Subscribe to Comments</a> to review your configuration.', 'subscribe-reloaded' ) . '</p></div>';
1531
- update_option( 'subscribe_reloaded_deferred_admin_notices', $notices );
1532
- }
1533
- }
1534
- // end _import_wpcs_data
1535
-
1536
- /**
1537
- * Retrieves the comment information from the databse
1538
- */
1539
- private function _get_comment_object( $_comment_ID ) {
1540
- global $wpdb;
1541
-
1542
- return $wpdb->get_row(
1543
- $wpdb->prepare(
1544
- "
1545
- SELECT comment_post_ID, comment_author_email, comment_approved, comment_type, comment_parent
1546
- FROM $wpdb->comments
1547
- WHERE comment_ID = %d LIMIT 1", $_comment_ID
1548
- ), OBJECT
1549
- );
1550
- }
1551
- // end _get_comment_object
1552
-
1553
- /**
1554
- * Checks if a key is valid for a given email address
1555
- */
1556
- private function _is_valid_key( $_key, $_email ) {
1557
- return $this->generate_key( $_email ) == $_key;
1558
- }
1559
- // end _is_valid_key
1560
- }
1561
-
1562
- // end of class declaration
1563
-
1564
- // Bootstrap the whole thing
1565
- $wp_subscribe_reloaded = new wp_subscribe_reloaded();
1566
- // Set a cookie if the user just subscribed without commenting
1567
- $subscribe_to_comments_action = ! empty( $_POST['sra'] ) ? $_POST['sra'] : ( ! empty( $_GET['sra'] ) ? $_GET['sra'] : 0 );
1568
- $subscribe_to_comments_post_ID = ! empty( $_POST['srp'] ) ? intval( $_POST['srp'] ) : ( ! empty( $_GET['srp'] ) ? intval( $_GET['srp'] ) : 0 );
1569
-
1570
- if ( ! empty( $subscribe_to_comments_action ) && ! empty( $_POST['subscribe_reloaded_email'] ) &&
1571
- ( $subscribe_to_comments_action == 's' ) && ( $subscribe_to_comments_post_ID > 0 )
1572
- ) {
1573
- $subscribe_to_comments_clean_email = $wp_subscribe_reloaded->clean_email( $_POST['subscribe_reloaded_email'] );
1574
- setcookie( 'comment_author_email' . COOKIEHASH, $subscribe_to_comments_clean_email, time() + 1209600, '/' );
1575
- }
1
+ <?php
2
+ /*
3
+ Plugin Name: Subscribe to Comments Reloaded
4
+
5
+ Version: 140220
6
+ Stable tag: 140220
7
+ Requires at least: 2.9.2
8
+ Tested up to: 3.8.1
9
+
10
+ Plugin URI: http://wordpress.org/extend/plugins/subscribe-to-comments-reloaded/
11
+ Description: Subscribe to Comments Reloaded is a robust plugin that enables commenters to sign up for e-mail notifications. It includes a full-featured subscription manager that your commenters can use to unsubscribe to certain posts or suspend all notifications.
12
+ Contributors: camu, Reedyseth, andreasbo, raamdev
13
+ Author: camu, Reedyseth, Raam Dev
14
+ */
15
+
16
+ // Avoid direct access to this piece of code
17
+ if ( ! function_exists( 'add_action' ) ) {
18
+ header( 'Location: /' );
19
+ exit;
20
+ }
21
+
22
+ /**
23
+ * Displays the checkbox to allow visitors to subscribe
24
+ */
25
+ function subscribe_reloaded_show() {
26
+ global $post, $wp_subscribe_reloaded;
27
+ $checkbox_subscription_type;
28
+
29
+ $is_disabled = get_post_meta( $post->ID, 'stcr_disable_subscriptions', true );
30
+ if ( ! empty( $is_disabled ) ) {
31
+ return $_comment_ID;
32
+ }
33
+
34
+ $show_subscription_box = true;
35
+ $html_to_show = '';
36
+ $user_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '' );
37
+
38
+ if ( function_exists( 'qtrans_convertURL' ) ) {
39
+ $user_link = qtrans_convertURL( $user_link );
40
+ }
41
+
42
+ $manager_link = ( strpos( $user_link, '?' ) !== false ) ? "$user_link&amp;srp=$post->ID" : "$user_link?srp=$post->ID";
43
+
44
+ // Load localization files
45
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
46
+
47
+ if ( $wp_subscribe_reloaded->is_user_subscribed( $post->ID, '', 'C' ) ) {
48
+ $html_to_show = str_replace(
49
+ '[manager_link]', $user_link,
50
+ __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_subscribed_waiting_label', "Your subscription to this post needs to be confirmed. <a href='[manager_link]'>Manage your subscriptions</a>." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
51
+ );
52
+ $show_subscription_box = false;
53
+ } elseif ( $wp_subscribe_reloaded->is_user_subscribed( $post->ID, '' ) ) {
54
+ $html_to_show = str_replace(
55
+ '[manager_link]', $user_link,
56
+ __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_subscribed_label', "You are subscribed to this post. <a href='[manager_link]'>Manage</a> your subscriptions." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
57
+ );
58
+ $show_subscription_box = false;
59
+ }
60
+
61
+ if ( $wp_subscribe_reloaded->is_author( $post->post_author ) ) { // when the second parameter is empty, cookie value will be used
62
+ if ( get_option( 'subscribe_reloaded_admin_subscribe', 'no' ) == 'no' ) {
63
+ $show_subscription_box = false;
64
+ }
65
+ $html_to_show .= str_replace(
66
+ '[manager_link]', $manager_link,
67
+ __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_author_label', "You can <a href='[manager_link]'>manage the subscriptions</a> of this post." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
68
+ );
69
+ }
70
+
71
+ if ( $show_subscription_box ) {
72
+ $checkbox_label = str_replace(
73
+ '[subscribe_link]', "$manager_link&amp;sra=s",
74
+ __( html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_checkbox_label', "Notify me of followup comments via e-mail. You can also <a href='[subscribe_link]'>subscribe</a> without commenting." ) ), ENT_COMPAT, 'UTF-8' ), 'subscribe-reloaded' )
75
+ );
76
+ $checkbox_inline_style = get_option( 'subscribe_reloaded_checkbox_inline_style', 'width:30px' );
77
+ if ( ! empty( $checkbox_inline_style ) ) {
78
+ $checkbox_inline_style = " style='$checkbox_inline_style'";
79
+ }
80
+ $checkbox_html_wrap = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_checkbox_html', '' ) ), ENT_COMPAT, 'UTF-8' );
81
+ if ( get_option( 'subscribe_reloaded_enable_advanced_subscriptions', 'no' ) == 'no' ) {
82
+ switch ( get_option('subscribe_reloaded_checked_by_default_value') ) {
83
+ case '0':
84
+ $checkbox_subscription_type = 'yes';
85
+ break;
86
+ case '1':
87
+ $checkbox_subscription_type = 'replies';
88
+ break;
89
+ }
90
+ $checkbox_field = "<input$checkbox_inline_style type='checkbox' name='subscribe-reloaded' id='subscribe-reloaded' value='$checkbox_subscription_type'" . ( ( get_option( 'subscribe_reloaded_checked_by_default', 'no' ) == 'yes' ) ? " checked='checked'" : '' ) . " />";
91
+ } else {
92
+ $checkbox_field = "<select name='subscribe-reloaded' id='subscribe-reloaded'>
93
+ <option value='none'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '0' ) ? "selected='selected'" : '' ) . ">" . __( "Don't subscribe", 'subscribe-reloaded' ) . "</option>
94
+ <option value='yes'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '1' ) ? "selected='selected'" : '' ) . ">" . __( "All", 'subscribe-reloaded' ) . "</option>
95
+ <option value='replies'" . ( ( get_option( 'subscribe_reloaded_default_subscription_type' ) === '2' ) ? "selected='selected'" : '' ) . ">" . __( "Replies to my comments", 'subscribe-reloaded' ) . "</option>
96
+ </select>";
97
+ }
98
+ if ( empty( $checkbox_html_wrap ) ) {
99
+ $html_to_show = "$checkbox_field <label for='subscribe-reloaded'>$checkbox_label</label>" . $html_to_show;
100
+ } else {
101
+ $checkbox_html_wrap = str_replace( '[checkbox_field]', $checkbox_field, $checkbox_html_wrap );
102
+ $html_to_show = str_replace( '[checkbox_label]', $checkbox_label, $checkbox_html_wrap ) . $html_to_show;
103
+ }
104
+ }
105
+ if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
106
+ $html_to_show = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $html_to_show );
107
+ }
108
+ echo "<!-- BEGIN: subscribe to comments reloaded -->" . html_entity_decode( stripslashes( $html_to_show ), ENT_QUOTES, 'UTF-8' ) ."<!-- END: subscribe to comments reloaded -->";
109
+ }
110
+
111
+ // Show the checkbox - You can manually override this by adding the corresponding function in your template
112
+ if ( get_option( 'subscribe_reloaded_show_subscription_box', 'yes' ) == 'yes' ) {
113
+ add_action( 'comment_form', 'subscribe_reloaded_show' );
114
+ }
115
+
116
+ class wp_subscribe_reloaded {
117
+
118
+ public $current_version = '140220';
119
+
120
+ /**
121
+ * Constructor -- Sets things up.
122
+ */
123
+ public function __construct() {
124
+ $this->salt = defined( 'NONCE_KEY' ) ? NONCE_KEY : 'please create a unique key in your wp-config.php';
125
+
126
+ // What to do when a new comment is posted
127
+ add_action( 'comment_post', array( &$this, 'new_comment_posted' ), 12, 2 );
128
+
129
+ // Provide content for the management page using WP filters
130
+ if ( ! is_admin() ) {
131
+ $manager_page_permalink = get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
132
+ if ( function_exists( 'qtrans_convertURL' ) ) {
133
+ $manager_page_permalink = qtrans_convertURL( $manager_page_permalink );
134
+ }
135
+ if ( empty( $manager_page_permalink ) ) {
136
+ $manager_page_permalink = get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
137
+ }
138
+ if ( ( strpos( $_SERVER["REQUEST_URI"], $manager_page_permalink ) !== false ) && get_option( 'subscribe_reloaded_manager_page_enabled', 'yes' ) == 'yes' ) {
139
+ add_filter( 'the_posts', array( &$this, 'subscribe_reloaded_manage' ), 10, 2 );
140
+ }
141
+
142
+ // Create a hook to use with the daily cron job
143
+ add_action( 'subscribe_reloaded_purge', array( &$this, 'subscribe_reloaded_purge' ) );
144
+ } else {
145
+ // Initialization routines that should be executed on activation/deactivation
146
+ register_activation_hook( __FILE__, array( &$this, 'activate' ) );
147
+ register_deactivation_hook( __FILE__, array( &$this, 'deactivate' ) );
148
+
149
+ // Hook for WPMU - New blog created
150
+ add_action( 'wpmu_new_blog', array( &$this, 'new_blog' ), 10, 1 );
151
+
152
+ // Remove subscriptions attached to a post that is being deleted
153
+ add_action( 'delete_post', array( &$this, 'delete_subscriptions' ), 10, 2 );
154
+
155
+ // Monitor actions on existing comments
156
+ add_action( 'deleted_comment', array( &$this, 'comment_deleted' ) );
157
+ add_action( 'wp_set_comment_status', array( &$this, 'comment_status_changed' ) );
158
+
159
+ // Subscribe post authors, if the case
160
+ if ( get_option( 'subscribe_reloaded_notify_authors', 'no' ) == 'yes' ) {
161
+ add_action( 'publish_post', array( &$this, 'subscribe_post_author' ) );
162
+ }
163
+
164
+ // Add a new column to the Edit Comments panel
165
+ add_filter( 'manage_edit-comments_columns', array( &$this, 'add_column_header' ) );
166
+ add_filter( 'manage_posts_columns', array( &$this, 'add_column_header' ) );
167
+ add_action( 'manage_comments_custom_column', array( &$this, 'add_comment_column' ) );
168
+ add_action( 'manage_posts_custom_column', array( &$this, 'add_post_column' ) );
169
+
170
+ // Add appropriate entries in the admin menu
171
+ add_action( 'admin_menu', array( &$this, 'add_config_menu' ) );
172
+ add_action(
173
+ 'admin_print_styles-subscribe-to-comments-reloaded/options/index.php', array(
174
+ &$this,
175
+ 'add_options_stylesheet'
176
+ )
177
+ );
178
+ add_action( 'admin_print_styles-edit-comments.php', array( &$this, 'add_post_comments_stylesheet' ) );
179
+ add_action( 'admin_print_styles-edit.php', array( &$this, 'add_post_comments_stylesheet' ) );
180
+
181
+ // Admin notices
182
+ add_action( 'admin_init', array( &$this, 'admin_init' ) );
183
+ add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
184
+
185
+ // Contextual help
186
+ add_action( 'contextual_help', array( &$this, 'contextual_help' ), 10, 3 );
187
+
188
+ // Shortcodes to use the management URL sitewide
189
+ add_shortcode( 'subscribe-url', array( &$this, 'subscribe_url_shortcode' ) );
190
+
191
+ // Settings link for plugin on plugins page
192
+ add_filter( 'plugin_action_links', array( &$this, 'plugin_settings_link' ), 10, 2 );
193
+ }
194
+ }
195
+
196
+ // end __construct
197
+
198
+ public function admin_init() {
199
+
200
+ $version = get_option( 'subscribe_reloaded_version' );
201
+ if ( $version != $this->current_version ) {
202
+ // Do whatever upgrades needed here.
203
+ update_option( 'subscribe_reloaded_version', $this->current_version );
204
+ }
205
+ }
206
+
207
+ public function admin_notices() {
208
+ if ( $notices = get_option( 'subscribe_reloaded_deferred_admin_notices' ) ) {
209
+ foreach ( $notices as $notice ) {
210
+ echo $notice;
211
+ }
212
+ delete_option( 'subscribe_reloaded_deferred_admin_notices' );
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Support for WP MU network activations (experimental)
218
+ */
219
+ public function activate() {
220
+ global $wpdb;
221
+
222
+ if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) {
223
+ $blogids = $wpdb->get_col(
224
+ $wpdb->prepare(
225
+ "
226
+ SELECT blog_id
227
+ FROM $wpdb->blogs
228
+ WHERE site_id = %d
229
+ AND deleted = 0
230
+ AND spam = 0", $wpdb->siteid
231
+ )
232
+ );
233
+
234
+ foreach ( $blogids as $blog_id ) {
235
+ switch_to_blog( $blog_id );
236
+ $this->_activate();
237
+ }
238
+ restore_current_blog();
239
+ } else {
240
+ $this->_activate();
241
+ }
242
+ }
243
+ // end activate
244
+
245
+ /**
246
+ * Support for WP MU network activations (experimental)
247
+ */
248
+ public function new_blog( $_blog_id ) {
249
+ switch_to_blog( $_blog_id );
250
+ $this->_activate();
251
+ restore_current_blog();
252
+ }
253
+ // end new_blog
254
+
255
+ /**
256
+ * Adds the options to the database and imports the data from other plugins
257
+ */
258
+ private function _activate() {
259
+
260
+ // Load localization files
261
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
262
+
263
+ // Import data from the WP Comment Subscriptions plugin, if needed
264
+ $this->_import_wpcs_data();
265
+
266
+ // Import data from Subscribe to Comments & Co., if needed
267
+ $this->_import_stc_data();
268
+
269
+ // Starting from version 2.0 StCR uses Wordpress' tables to store the information about subscriptions
270
+ $this->_update_db();
271
+
272
+ // Messages related to the management page
273
+ global $wp_rewrite;
274
+
275
+ if ( empty( $wp_rewrite->permalink_structure ) ) {
276
+ add_option( 'subscribe_reloaded_manager_page', '/?page_id=99999', '', 'no' );
277
+ } else {
278
+ add_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/', '', 'no' );
279
+ }
280
+
281
+ add_option( 'subscribe_reloaded_show_subscription_box', 'yes', '', 'no' );
282
+ add_option( 'subscribe_reloaded_checked_by_default', 'no', '', 'no' );
283
+ add_option( 'subscribe_reloaded_enable_advanced_subscriptions', 'no', '', 'no' );
284
+ add_option( 'subscribe_reloaded_default_subscription_type', '2', '', 'no' );
285
+ add_option( 'subscribe_reloaded_checked_by_default_value', '0', '', 'no' );
286
+ add_option( 'subscribe_reloaded_checkbox_inline_style', 'width:30px', '', 'no' );
287
+ add_option( 'subscribe_reloaded_checkbox_html', "<p class='comment-form-subscriptions'><label for='subscribe-reloaded'>[checkbox_field] [checkbox_label]</label></p>", '', 'no' );
288
+ add_option( 'subscribe_reloaded_checkbox_label', __( "Notify me of followup comments via e-mail. You can also <a href='[subscribe_link]'>subscribe</a> without commenting.", 'subscribe-reloaded' ), '', 'no' );
289
+ add_option( 'subscribe_reloaded_subscribed_label', __( "You are subscribed to this post. <a href='[manager_link]'>Manage</a> your subscriptions.", 'subscribe-reloaded' ), '', 'no' );
290
+ add_option( 'subscribe_reloaded_subscribed_waiting_label', __( "Your subscription to this post needs to be confirmed. <a href='[manager_link]'>Manage your subscriptions</a>.", 'subscribe-reloaded' ), '', 'no' );
291
+ add_option( 'subscribe_reloaded_author_label', __( "You can <a href='[manager_link]'>manage the subscriptions</a> of this post.", 'subscribe-reloaded' ), '', 'no' );
292
+
293
+ add_option( 'subscribe_reloaded_manager_page_enabled', 'yes', '', 'no' );
294
+ add_option( 'subscribe_reloaded_manager_page_title', __( 'Manage subscriptions', 'subscribe-reloaded' ), '', 'no' );
295
+ add_option( 'subscribe_reloaded_custom_header_meta', "<meta name='robots' content='noindex,nofollow'>", '', 'no' );
296
+ add_option( 'subscribe_reloaded_request_mgmt_link', __( 'To manage your subscriptions, please enter your email address here below. We will send you a message containing the link to access your personal management page.', 'subscribe-reloaded' ), '', 'no' );
297
+ add_option( 'subscribe_reloaded_request_mgmt_link_thankyou', __( 'Thank you for using our subscription service. Your request has been completed, and you should receive an email with the management link in a few minutes.', 'subscribe-reloaded' ), '', 'no' );
298
+ add_option( 'subscribe_reloaded_subscribe_without_commenting', __( "You can follow the discussion on <strong>[post_title]</strong> without having to leave a comment. Cool, huh? Just enter your email address in the form here below and you're all set.", 'subscribe-reloaded' ), '', 'no' );
299
+ add_option( 'subscribe_reloaded_subscription_confirmed', __( "Thank you for using our subscription service. Your request has been completed. You will receive a notification email every time a new comment to this article is approved and posted by the administrator.", 'subscribe-reloaded' ), '', 'no' );
300
+ add_option( 'subscribe_reloaded_subscription_confirmed_dci', __( "Thank you for using our subscription service. In order to confirm your request, please check your email for the verification message and follow the instructions.", 'subscribe-reloaded' ), '', 'no' );
301
+ add_option( 'subscribe_reloaded_author_text', __( "In order to cancel or suspend one or more notifications, select the corresponding checkbox(es) and click on the button at the end of the list.", 'subscribe-reloaded' ), '', 'no' );
302
+ add_option( 'subscribe_reloaded_user_text', __( "In order to cancel or suspend one or more notifications, select the corresponding checkbox(es) and click on the button at the end of the list. You are currently subscribed to:", 'subscribe-reloaded' ), '', 'no' );
303
+
304
+ add_option( 'subscribe_reloaded_from_name', get_bloginfo( 'name' ), '', 'no' );
305
+ add_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ), '', 'no' );
306
+ add_option( 'subscribe_reloaded_notification_subject', __( 'There is a new comment to [post_title]', 'subscribe-reloaded' ), '', 'no' );
307
+ add_option( 'subscribe_reloaded_notification_content', __( "There is a new comment to [post_title].\nComment Link: [comment_permalink]\nAuthor: [comment_author]\nComment:\n[comment_content]\nPermalink: [post_permalink]\nManage your subscriptions: [manager_link]", 'subscribe-reloaded' ), '', 'no' );
308
+ add_option( 'subscribe_reloaded_double_check_subject', __( 'Please confirm your subscription to [post_title]', 'subscribe-reloaded' ), '', 'no' );
309
+ add_option( 'subscribe_reloaded_double_check_content', __( "You have requested to be notified every time a new comment is added to:\n[post_permalink]\n\nPlease confirm your request by clicking on this link:\n[confirm_link]", 'subscribe-reloaded' ), '', 'no' );
310
+ add_option( 'subscribe_reloaded_management_subject', __( 'Manage your subscriptions on [blog_name]', 'subscribe-reloaded' ) );
311
+ add_option( 'subscribe_reloaded_management_content', __( "You have requested to manage your subscriptions to the articles on [blog_name]. Follow this link to access your personal page:\n[manager_link]", 'subscribe-reloaded' ) );
312
+
313
+ add_option( 'subscribe_reloaded_purge_days', '30', '', 'no' );
314
+ add_option( 'subscribe_reloaded_enable_double_check', 'no', '', 'no' );
315
+ add_option( 'subscribe_reloaded_notify_authors', 'no', '', 'no' );
316
+ add_option( 'subscribe_reloaded_enable_html_emails', 'no', '', 'no' );
317
+ add_option( 'subscribe_reloaded_htmlify_message_links', 'no', '', 'no' );
318
+ add_option( 'subscribe_reloaded_process_trackbacks', 'no', '', 'no' );
319
+ add_option( 'subscribe_reloaded_enable_admin_messages', 'no', '', 'no' );
320
+ add_option( 'subscribe_reloaded_admin_subscribe', 'no', '', 'no' );
321
+ add_option( 'subscribe_reloaded_admin_bcc', 'no', '', 'no' );
322
+
323
+ // Schedule the autopurge hook
324
+ if ( ! wp_next_scheduled( 'subscribe_reloaded_purge' ) ) {
325
+ wp_schedule_event( time(), 'daily', 'subscribe_reloaded_purge' );
326
+ }
327
+ }
328
+ // end _activate
329
+
330
+ /**
331
+ * Performs some clean-up maintenance (disable cron job).
332
+ */
333
+ public function deactivate() {
334
+ global $wpdb;
335
+ if ( function_exists( 'is_multisite' ) && is_multisite() && isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) {
336
+ $blogids = $wpdb->get_col(
337
+ $wpdb->prepare(
338
+ "
339
+ SELECT blog_id
340
+ FROM $wpdb->blogs
341
+ WHERE site_id = %d
342
+ AND deleted = 0
343
+ AND spam = 0", $wpdb->siteid
344
+ )
345
+ );
346
+
347
+ foreach ( $blogids as $blog_id ) {
348
+ switch_to_blog( $blog_id );
349
+ wp_clear_scheduled_hook( 'subscribe_reloaded_purge' );
350
+ }
351
+ restore_current_blog();
352
+ } else {
353
+ wp_clear_scheduled_hook( 'subscribe_reloaded_purge' );
354
+ }
355
+
356
+ delete_option( 'subscribe_reloaded_version' );
357
+ delete_option( 'subscribe_reloaded_deferred_admin_notices' );
358
+ }
359
+ // end deactivate
360
+
361
+ /*
362
+ * Add Settings link to plugin on plugins page
363
+ */
364
+ public function plugin_settings_link( $links, $file ) {
365
+ if ( $file == 'subscribe-to-comments-reloaded/subscribe-to-comments-reloaded.php' ) {
366
+ $links['settings'] = sprintf( '<a href="%s"> %s </a>', admin_url( 'options-general.php?page=subscribe-to-comments-reloaded/options/index.php' ), __( 'Settings', 'subscribe-reloaded' ) );
367
+ }
368
+
369
+ return $links;
370
+ }
371
+
372
+ /**
373
+ * Takes the appropriate action, when a new comment is posted
374
+ */
375
+ public function new_comment_posted( $_comment_ID = 0, $_comment_status = 0 ) {
376
+ // Retrieve the information about the new comment
377
+ $info = $this->_get_comment_object( $_comment_ID );
378
+
379
+ if ( empty( $info ) || $info->comment_approved == 'spam' ) {
380
+ return $_comment_ID;
381
+ }
382
+
383
+ // Are subscriptions allowed for this post?
384
+ $is_disabled = get_post_meta( $info->comment_post_ID, 'stcr_disable_subscriptions', true );
385
+ if ( ! empty( $is_disabled ) ) {
386
+ return $_comment_ID;
387
+ }
388
+
389
+ // Process trackbacks and pingbacks?
390
+ if ( ( get_option( 'subscribe_reloaded_process_trackbacks', 'no' ) == 'no' ) && ( $info->comment_type == 'trackback' || $info->comment_type == 'pingback' ) ) {
391
+ return $_comment_ID;
392
+ }
393
+
394
+ // Did this visitor request to be subscribed to the discussion? (and s/he is not subscribed)
395
+ if ( ! empty( $_POST['subscribe-reloaded'] ) && ! empty( $info->comment_author_email ) ) {
396
+ if ( ! in_array( $_POST['subscribe-reloaded'], array( 'replies', 'digest', 'yes' ) ) ) {
397
+ return $_comment_ID;
398
+ }
399
+
400
+ switch ( $_POST['subscribe-reloaded'] ) {
401
+ case 'replies':
402
+ $status = 'R';
403
+ break;
404
+ case 'digest':
405
+ $status = 'D';
406
+ break;
407
+ default:
408
+ $status = 'Y';
409
+ break;
410
+ }
411
+
412
+ if ( ! $this->is_user_subscribed( $info->comment_post_ID, $info->comment_author_email ) ) {
413
+ if ( $this->isDoubleCheckinEnabled( $info ) ) {
414
+ $this->sendConfirmationEMail( $info );
415
+ $status = "{$status}C";
416
+ }
417
+ $this->add_subscription( $info->comment_post_ID, $info->comment_author_email, $status );
418
+
419
+ // If comment is in the moderation queue
420
+ if ( $info->comment_approved == 0 ) {
421
+ //don't send notification-emails to all subscribed users
422
+ return $_comment_ID;
423
+ }
424
+ }
425
+ }
426
+
427
+ // Send a notification to all the users subscribed to this post
428
+ if ( $info->comment_approved == 1 ) {
429
+ $subscriptions = $this->get_subscriptions(
430
+ array(
431
+ 'post_id',
432
+ 'status'
433
+ ), array(
434
+ 'equals',
435
+ 'equals'
436
+ ), array(
437
+ $info->comment_post_ID,
438
+ 'Y'
439
+ )
440
+ );
441
+ if ( ! empty( $info->comment_parent ) ) {
442
+ $subscriptions = array_merge(
443
+ $subscriptions, $this->get_subscriptions(
444
+ 'parent', 'equals', array(
445
+ $info->comment_parent,
446
+ $info->comment_post_ID
447
+ )
448
+ )
449
+ );
450
+ }
451
+
452
+ foreach ( $subscriptions as $a_subscription ) {
453
+ // Skip the user who posted this new comment
454
+ if ( $a_subscription->email != $info->comment_author_email ) {
455
+ $this->notify_user( $info->comment_post_ID, $a_subscription->email, $_comment_ID );
456
+ }
457
+ }
458
+ }
459
+
460
+ // If the case, notify the author
461
+ if ( get_option( 'subscribe_reloaded_notify_authors', 'no' ) == 'yes' ) {
462
+ $this->notify_user( $info->comment_post_ID, get_bloginfo( 'admin_email' ), $_comment_ID );
463
+ }
464
+
465
+ return $_comment_ID;
466
+ }
467
+
468
+ // end new_comment_posted
469
+
470
+ public function isDoubleCheckinEnabled( $info ) {
471
+ $approved_subscriptions = $this->get_subscriptions(
472
+ array(
473
+ 'status',
474
+ 'email'
475
+ ), array(
476
+ 'equals',
477
+ 'equals'
478
+ ), array(
479
+ 'Y',
480
+ $info->comment_author_email
481
+ )
482
+ );
483
+ if ( ( get_option( 'subscribe_reloaded_enable_double_check', 'no' ) == 'yes' ) && ! is_user_logged_in() && empty( $approved_subscriptions ) ) {
484
+ return true;
485
+ } else {
486
+ return false;
487
+ }
488
+ }
489
+
490
+ public function sendConfirmationEMail( $info ) {
491
+ // Retrieve the information about the new comment
492
+ $this->confirmation_email( $info->comment_post_ID, $info->comment_author_email );
493
+ }
494
+
495
+ /**
496
+ * Performs the appropriate action when the status of a given comment changes
497
+ */
498
+ public function comment_status_changed( $_comment_ID = 0, $_comment_status = 0 ) {
499
+ // Retrieve the information about the comment
500
+ $info = $this->_get_comment_object( $_comment_ID );
501
+ if ( empty( $info ) ) {
502
+ return $_comment_ID;
503
+ }
504
+
505
+ switch ( $info->comment_approved ) {
506
+ case '0': // Unapproved: change the status of the corresponding subscription (if exists) to 'pending'
507
+ $this->update_subscription_status( $info->comment_post_ID, $info->comment_author_email, 'C' );
508
+ break;
509
+
510
+ case '1': // Approved
511
+ $this->update_subscription_status( $info->comment_post_ID, $info->comment_author_email, '-C' );
512
+ $subscriptions = $this->get_subscriptions(
513
+ array(
514
+ 'post_id',
515
+ 'status'
516
+ ), array(
517
+ 'equals',
518
+ 'equals'
519
+ ), array(
520
+ $info->comment_post_ID,
521
+ 'Y'
522
+ )
523
+ );
524
+ if ( ! empty( $info->comment_parent ) ) {
525
+ $subscriptions = array_merge(
526
+ $subscriptions, $this->get_subscriptions(
527
+ 'parent', 'equals', array(
528
+ $info->comment_parent,
529
+ $info->comment_post_ID
530
+ )
531
+ )
532
+ );
533
+ }
534
+
535
+ foreach ( $subscriptions as $a_subscription ) {
536
+ if ( $a_subscription->email != $info->comment_author_email ) // Skip the user who posted this new comment
537
+ {
538
+ $this->notify_user( $info->comment_post_ID, $a_subscription->email, $_comment_ID );
539
+ }
540
+ }
541
+ break;
542
+
543
+ case 'trash':
544
+ case 'spam':
545
+ $this->comment_deleted( $_comment_ID );
546
+ break;
547
+
548
+ default:
549
+ break;
550
+ }
551
+
552
+ return $_comment_ID;
553
+ }
554
+ // end comment_status
555
+
556
+ /**
557
+ * Performs the appropriate action when a comment is deleted
558
+ */
559
+ public function comment_deleted( $_comment_ID ) {
560
+ global $wpdb;
561
+
562
+ $info = $this->_get_comment_object( $_comment_ID );
563
+ if ( empty( $info ) ) {
564
+ return $_comment_ID;
565
+ }
566
+
567
+ // Are there any other approved comments sent by this user?
568
+ $count_approved_comments = $wpdb->get_var(
569
+ "
570
+ SELECT COUNT(*)
571
+ FROM $wpdb->comments
572
+ WHERE comment_post_ID = '$info->comment_post_ID' AND comment_author_email = '$info->comment_author_email' AND comment_approved = 1"
573
+ );
574
+ if ( intval( $count_approved_comments ) == 0 ) {
575
+ $this->delete_subscriptions( $info->comment_post_ID, $info->comment_author_email );
576
+ }
577
+
578
+ return $_comment_ID;
579
+ }
580
+ // end comment_deleted
581
+
582
+ /**
583
+ * Subscribes the post author, if the corresponding option is set
584
+ */
585
+ public function subscribe_post_author( $_post_ID ) {
586
+ $new_post = get_post( $_post_ID );
587
+ $author_email = get_the_author_meta( 'user_email', $new_post->post_author );
588
+ if ( ! empty( $author_email ) ) {
589
+ $this->add_subscription( $_post_ID, $author_email, 'Y' );
590
+ }
591
+ }
592
+ // end subscribe_post_author
593
+
594
+ /**
595
+ * Displays the appropriate management page
596
+ */
597
+ public function subscribe_reloaded_manage( $_posts = '', $_query = '' ) {
598
+ global $current_user;
599
+
600
+ if ( ! empty( $_posts ) ) {
601
+ return $_posts;
602
+ }
603
+
604
+ $post_ID = ! empty( $_POST['srp'] ) ? intval( $_POST['srp'] ) : ( ! empty( $_GET['srp'] ) ? intval( $_GET['srp'] ) : 0 );
605
+
606
+ // Is the post_id passed in the query string valid?
607
+ $target_post = get_post( $post_ID );
608
+ if ( ( $post_ID > 0 ) && ! is_object( $target_post ) ) {
609
+ return $_posts;
610
+ }
611
+
612
+ // Load localization files
613
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
614
+
615
+ $action = ! empty( $_POST['sra'] ) ? $_POST['sra'] : ( ! empty( $_GET['sra'] ) ? $_GET['sra'] : 0 );
616
+ $key = ! empty( $_POST['srk'] ) ? $_POST['srk'] : ( ! empty( $_GET['srk'] ) ? $_GET['srk'] : 0 );
617
+
618
+ $email = $this->clean_email( ! empty( $_POST['sre'] ) ? urldecode( $_POST['sre'] ) : ( ! empty( $_GET['sre'] ) ? $_GET['sre'] : '' ) );
619
+ if ( empty( $email ) && ! empty( $current_user->user_email ) ) {
620
+ $email = $this->clean_email( $current_user->user_email );
621
+ }
622
+
623
+ // Subscribe without commenting
624
+ if ( ! empty( $action ) && ( $action == 's' ) && ( $post_ID > 0 ) ) {
625
+ $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/subscribe.php';
626
+ } // Management page for post authors
627
+ elseif ( ( $post_ID > 0 ) && $this->is_author( $target_post->post_author ) ) {
628
+ $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/author.php';
629
+ } // Confirm your subscription (double check-in)
630
+ elseif ( ( $post_ID > 0 ) && ! empty( $email ) && ! empty( $key ) && ! empty( $action ) &&
631
+ $this->is_user_subscribed( $post_ID, $email, 'C' ) &&
632
+ $this->_is_valid_key( $key, $email ) &&
633
+ ( $action == 'c' )
634
+ ) {
635
+ $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/confirm.php';
636
+ } // Manage your subscriptions (user)
637
+ elseif ( ! empty( $email ) && ( ( ! empty( $key ) && $this->_is_valid_key( $key, $email ) ) || current_user_can( 'read' ) ) ) {
638
+ $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/user.php';
639
+ }
640
+
641
+ if ( empty( $include_post_content ) ) {
642
+ $include_post_content = include WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/templates/request-management-link.php';
643
+ }
644
+
645
+ global $wp_query;
646
+
647
+ $manager_page_title = html_entity_decode( get_option( 'subscribe_reloaded_manager_page_title', 'Manage subscriptions' ), ENT_COMPAT, 'UTF-8' );
648
+ if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
649
+ $manager_page_title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $manager_page_title );
650
+ }
651
+
652
+ $posts[] =
653
+ (object) array(
654
+ 'ID' => '9999999',
655
+ 'post_author' => '1',
656
+ 'post_date' => '2001-01-01 11:38:56',
657
+ 'post_date_gmt' => '2001-01-01 00:38:56',
658
+ 'post_content' => $include_post_content,
659
+ 'post_title' => $manager_page_title,
660
+ 'post_excerpt' => '',
661
+ 'post_status' => 'publish',
662
+ 'comment_status' => 'closed',
663
+ 'ping_status' => 'closed',
664
+ 'post_password' => '',
665
+ 'to_ping' => '',
666
+ 'pinged' => '',
667
+ 'post_modified' => '2001-01-01 11:00:01',
668
+ 'post_modified_gmt' => '2001-01-01 00:00:01',
669
+ 'post_content_filtered' => '',
670
+ 'post_parent' => '0',
671
+ 'menu_order' => '0',
672
+ 'post_type' => 'page',
673
+ 'post_mime_type' => '',
674
+ 'post_category' => '0',
675
+ 'comment_count' => '0',
676
+ 'filter' => 'raw',
677
+ 'guid' => get_bloginfo( 'url' ) . '/?page_id=9999999',
678
+ 'post_name' => get_bloginfo( 'url' ) . '/?page_id=9999999',
679
+ 'ancestors' => array()
680
+ );
681
+
682
+ // Make WP believe this is a real page, with no comments attached
683
+ $wp_query->is_page = true;
684
+ $wp_query->is_single = false;
685
+ $wp_query->is_home = false;
686
+ $wp_query->comments = false;
687
+
688
+ // Discard 404 errors thrown by other checks
689
+ unset( $wp_query->query["error"] );
690
+ $wp_query->query_vars["error"] = "";
691
+ $wp_query->is_404 = false;
692
+
693
+ // Seems like WP adds its own HTML formatting code to the content, we don't need that here
694
+ remove_filter( 'the_content', 'wpautop' );
695
+ add_action( 'wp_head', array( &$this, 'add_custom_header_meta' ) );
696
+
697
+ return $posts;
698
+ }
699
+ // end subscribe_reloaded_manage
700
+
701
+ /**
702
+ * Removes old entries from the database
703
+ */
704
+ public function subscribe_reloaded_purge() {
705
+ global $wpdb;
706
+
707
+ if ( ( $autopurge_interval = intval( get_option( 'subscribe_reloaded_purge_days', 0 ) ) ) <= 0 ) {
708
+ return true;
709
+ }
710
+
711
+ // Delete old entries
712
+ $wpdb->query(
713
+ "
714
+ DELETE FROM $wpdb->postmeta
715
+ WHERE meta_key LIKE '\_stcr@\_%'
716
+ AND STR_TO_DATE(meta_value, '%Y-%m-%d %H:%i:%s') <= DATE_SUB(NOW(), INTERVAL $autopurge_interval DAY) AND meta_value LIKE '%C'"
717
+ );
718
+ }
719
+ // end subscribe_reloaded_purge
720
+
721
+ /**
722
+ * Checks if current logged in user is the author of this post
723
+ */
724
+ public function is_author( $_post_author ) {
725
+ global $current_user;
726
+
727
+ return ! empty( $current_user ) && ( ( $_post_author == $current_user->ID ) || current_user_can( 'manage_options' ) );
728
+ }
729
+ // end is_author
730
+
731
+ /**
732
+ * Checks if a given email address is subscribed to a post
733
+ */
734
+ public function is_user_subscribed( $_post_ID = 0, $_email = '', $_status = '' ) {
735
+ global $current_user;
736
+
737
+ if ( ( empty( $current_user->user_email ) && empty( $_COOKIE['comment_author_email_' . COOKIEHASH] ) && empty( $_email ) ) || empty( $_post_ID ) ) {
738
+ return false;
739
+ }
740
+
741
+ $operator = ( $_status != '' ) ? 'equals' : 'contains';
742
+ $subscriptions = $this->get_subscriptions(
743
+ array(
744
+ 'post_id',
745
+ 'status'
746
+ ), array(
747
+ 'equals',
748
+ $operator
749
+ ), array(
750
+ $_post_ID,
751
+ $_status
752
+ )
753
+ );
754
+
755
+ if ( empty( $_email ) ) {
756
+ $user_email = ! empty( $current_user->user_email ) ? $current_user->user_email : ( ! empty( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ? stripslashes( esc_attr( $_COOKIE['comment_author_email_' . COOKIEHASH] ) ) : '#undefined#' );
757
+ } else {
758
+ $user_email = $_email;
759
+ }
760
+
761
+ foreach ( $subscriptions as $a_subscription ) {
762
+ if ( $user_email == $a_subscription->email ) {
763
+ return true;
764
+ }
765
+ }
766
+
767
+ return false;
768
+ }
769
+ // end is_user_subscribed
770
+
771
+ /**
772
+ * Adds a new subscription
773
+ */
774
+ public function add_subscription( $_post_id = 0, $_email = '', $_status = 'Y' ) {
775
+ global $wpdb;
776
+ // Does the post exist?
777
+ $target_post = get_post( $_post_id );
778
+ if ( ( $_post_id > 0 ) && ! is_object( $target_post ) ) {
779
+ return;
780
+ }
781
+
782
+ // Filter unwanted statuses
783
+ if ( ! in_array( $_status, array( 'Y', 'YC', 'R', 'RC', 'C', '-C' ) ) || empty( $_status ) ) {
784
+ return;
785
+ }
786
+
787
+ // Using Wordpress local time
788
+ $dt = date_i18n( 'Y-m-d H:i:s' );
789
+
790
+ $clean_email = $this->clean_email( $_email );
791
+ $wpdb->query(
792
+ $wpdb->prepare(
793
+ "
794
+ INSERT IGNORE INTO $wpdb->postmeta (post_id, meta_key, meta_value)
795
+ SELECT %d, %s, %s
796
+ FROM DUAL
797
+ WHERE NOT EXISTS (
798
+ SELECT post_id
799
+ FROM $wpdb->postmeta
800
+ WHERE post_id = %d
801
+ AND meta_key = %s
802
+ LIMIT 0,1
803
+ )", $_post_id, "_stcr@_$clean_email", "$dt|$_status", $_post_id, "_stcr@_$clean_email"
804
+ )
805
+ );
806
+ }
807
+ // end add_subscription
808
+
809
+ /**
810
+ * Deletes one or more subscriptions from the database
811
+ */
812
+ public function delete_subscriptions( $_post_id = 0, $_email = '' ) {
813
+ global $wpdb;
814
+
815
+ if ( empty( $_post_id ) ) {
816
+ return 0;
817
+ }
818
+
819
+ $posts_where = '';
820
+ if ( ! is_array( $_post_id ) ) {
821
+ $posts_where = "post_id = " . intval( $_post_id );
822
+ } else {
823
+ foreach ( $_post_id as $a_post_id ) {
824
+ $posts_where .= "post_id = '" . intval( $a_post_id ) . "' OR ";
825
+ }
826
+
827
+ $posts_where = substr( $posts_where, 0, - 4 );
828
+ }
829
+
830
+ if ( ! empty( $_email ) ) {
831
+ $emails_where = '';
832
+ if ( ! is_array( $_email ) ) {
833
+ $emails_where = "meta_key = '_stcr@_" . $this->clean_email( $_email ) . "'";
834
+ } else {
835
+ foreach ( $_email as $a_email ) {
836
+ $emails_where .= "meta_key = '_stcr@_" . $this->clean_email( $a_email ) . "' OR ";
837
+ }
838
+
839
+ $emails_where = substr( $emails_where, 0, - 4 );
840
+ }
841
+
842
+ return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE ($posts_where) AND ($emails_where)" );
843
+ } else {
844
+ return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%' AND ($posts_where)" );
845
+ }
846
+ }
847
+ // end delete_subscriptions
848
+
849
+ /**
850
+ * Updates the status of an existing subscription
851
+ */
852
+ public function update_subscription_status( $_post_id = 0, $_email = '', $_new_status = 'C' ) {
853
+ global $wpdb;
854
+
855
+ // Filter unwanted statuses
856
+ if ( empty( $_new_status ) || ! in_array( $_new_status, array( 'Y', 'R', 'C', '-C' ) ) || empty( $_email ) ) {
857
+ return 0;
858
+ }
859
+
860
+ if ( ! empty( $_post_id ) ) {
861
+ $posts_where = '';
862
+ if ( ! is_array( $_post_id ) ) {
863
+ $posts_where = "post_id = " . intval( $_post_id );
864
+ } else {
865
+ foreach ( $_post_id as $a_post_id ) {
866
+ $posts_where .= "post_id = '" . intval( $a_post_id ) . "' OR ";
867
+ }
868
+
869
+ $posts_where = substr( $posts_where, 0, - 4 );
870
+ }
871
+ } else { // Mass update subscriptions
872
+ $posts_where = '1=1';
873
+ }
874
+
875
+ $emails_where = '';
876
+ if ( ! is_array( $_email ) ) {
877
+ $emails_where = "meta_key = '_stcr@_" . $this->clean_email( $_email ) . "'";
878
+ } else {
879
+ foreach ( $_email as $a_email ) {
880
+ $emails_where .= "meta_key = '_stcr@_" . $this->clean_email( $a_email ) . "' OR ";
881
+ }
882
+
883
+ $emails_where = substr( $emails_where, 0, - 4 );
884
+ }
885
+
886
+ $meta_length = ( strpos( $_new_status, 'C' ) !== false ) ? 21 : 20;
887
+ $new_status = ( $_new_status == '-C' ) ? '' : $_new_status;
888
+
889
+ return $wpdb->query(
890
+ "
891
+ UPDATE $wpdb->postmeta
892
+ SET meta_value = CONCAT(SUBSTRING(meta_value, 1, $meta_length), '$new_status')
893
+ WHERE ($posts_where) AND ($emails_where)"
894
+ );
895
+ }
896
+ // end update_subscription_status
897
+
898
+ /**
899
+ * Updates the email address of an existing subscription
900
+ */
901
+ public function update_subscription_email( $_post_id = 0, $_email = '', $_new_email = '' ) {
902
+ global $wpdb;
903
+
904
+ // Nothing to do if the new email hasn't been specified
905
+ if ( empty( $_email ) || empty( $_new_email ) || strpos( $_new_email, '@' ) == 0 ) {
906
+ return;
907
+ }
908
+
909
+ $clean_values[] = "_stcr@_" . $this->clean_email( $_new_email );
910
+ $clean_values[] = "_stcr@_" . $this->clean_email( $_email );
911
+ $post_where = '';
912
+ if ( ! empty( $_post_id ) ) {
913
+ $post_where = ' AND post_id = %d';
914
+ $clean_values[] = $_post_id;
915
+ }
916
+
917
+ return $wpdb->query(
918
+ $wpdb->prepare(
919
+ "
920
+ UPDATE $wpdb->postmeta
921
+ SET meta_key = %s
922
+ WHERE meta_key = %s $post_where", $clean_values
923
+ )
924
+ );
925
+ }
926
+ // end update_subscription_email
927
+
928
+ /**
929
+ * Retrieves a list of emails subscribed to this post
930
+ */
931
+ public function get_subscriptions( $_search_field = array( 'email' ), $_operator = array( 'equals' ), $_search_value = array( '' ), $_order_by = 'dt', $_order = 'ASC', $_offset = 0, $_limit_results = 0 ) {
932
+ global $wpdb;
933
+
934
+ // Type adjustments
935
+ $search_fields = ( ! is_array( $_search_field ) ) ? array( $_search_field ) : $_search_field;
936
+ $operators = ( ! is_array( $_operator ) ) ? array( $_operator ) : $_operator;
937
+ $search_values = ( ! is_array( $_search_value ) ) ? array( $_search_value ) : $_search_value;
938
+
939
+ // Find if exists a 'replies only' subscription for the parent comment
940
+ if ( $search_fields[0] == 'parent' ) {
941
+
942
+ $parent_comment_id = $search_values[0];
943
+ $comment_post_id = $search_values[1];
944
+
945
+ // Get the parent comment author email so we can search for any Replies Only subscriptions
946
+ $parent_comment_author_email_query = mysql_query( "SELECT `comment_author_email` FROM $wpdb->comments WHERE `comment_ID` = '$parent_comment_id'" );
947
+ $parent_comment_author_email = mysql_fetch_row( $parent_comment_author_email_query );
948
+ $parent_comment_author_email = "\_stcr@\_" . $parent_comment_author_email[0];
949
+
950
+ // Check if $parent_comment_author_email has any Replies Only (R) subscriptions for $comment_post_id
951
+
952
+ /*
953
+ Heads up: this will return Replies Only subscriptions for a given post, *not* for a given comment.
954
+ This plugin does not track subscriptions for specific comments but rather for entire posts, so there
955
+ is no way to figure out if a specific parent comment has a subscription (of any type). To make the
956
+ Replies Only feature half-work, we check if a parent comment author has *any* Replies Only subscriptions
957
+ for a given post. If they do, we assume that they must want to get notified of replies to *any* of their
958
+ comments on *that* post.
959
+ */
960
+
961
+ return $wpdb->get_results(
962
+ $wpdb->prepare(
963
+ "
964
+ SELECT pm.meta_id, REPLACE(pm.meta_key, '_stcr@_', '') AS email, pm.post_id, SUBSTRING(pm.meta_value, 1, 19) AS dt, SUBSTRING(pm.meta_value, 21) AS status
965
+ FROM $wpdb->postmeta pm
966
+ WHERE pm.meta_key LIKE %s
967
+ AND pm.meta_value LIKE '%%R'
968
+ AND pm.post_id = %d", $parent_comment_author_email, $comment_post_id
969
+ ), OBJECT
970
+ );
971
+ } else {
972
+ $where_clause = '';
973
+ foreach ( $search_fields as $a_idx => $a_field ) {
974
+ $where_clause .= ' AND';
975
+ $offset_status = ( $a_field == 'status' && $search_values[$a_idx] == 'C' ) ? 22 : 21;
976
+ switch ( $a_field ) {
977
+ case 'status':
978
+ $where_clause .= " SUBSTRING(meta_value, $offset_status)";
979
+ break;
980
+ case 'post_id':
981
+ $where_clause .= ' post_id';
982
+ break;
983
+ default:
984
+ $where_clause .= ' SUBSTRING(meta_key, 8)';
985
+ }
986
+ switch ( $operators[$a_idx] ) {
987
+ case 'equals':
988
+ $where_clause .= " = %s";
989
+ $where_values[] = $search_values[$a_idx];
990
+ break;
991
+ case 'does not contain':
992
+ $where_clause .= " NOT LIKE %s";
993
+ $where_values[] = "%{$search_values[$a_idx]}%";
994
+ break;
995
+ case 'starts with':
996
+ $where_clause .= " LIKE %s";
997
+ $where_values[] = "${$search_values[$a_idx]}%";
998
+ break;
999
+ case 'ends with':
1000
+ $where_clause .= " LIKE %s";
1001
+ $where_values[] = "%{$search_values[$a_idx]}";
1002
+ break;
1003
+ default: // contains
1004
+ $where_clause .= " LIKE %s";
1005
+ $where_values[] = "%{$search_values[$a_idx]}%";
1006
+ }
1007
+ }
1008
+ switch ( $_order_by ) {
1009
+ case 'status':
1010
+ $order_by = "status";
1011
+ break;
1012
+ case 'email':
1013
+ $order_by = 'meta_key';
1014
+ break;
1015
+ case 'dt':
1016
+ $order_by = 'dt';
1017
+ break;
1018
+ default:
1019
+ $order_by = 'post_id';
1020
+ }
1021
+ $order = ( $_order != 'ASC' && $_order != 'DESC' ) ? 'DESC' : $_order;
1022
+
1023
+ // This is the 'official' way to have an offset without a limit
1024
+ $row_count = ( $_limit_results <= 0 ) ? '18446744073709551610' : $_limit_results;
1025
+
1026
+ return $wpdb->get_results(
1027
+ $wpdb->prepare(
1028
+ "
1029
+ SELECT meta_id, REPLACE(meta_key, '_stcr@_', '') AS email, post_id, SUBSTRING(meta_value, 1, 19) AS dt, SUBSTRING(meta_value, 21) AS status
1030
+ FROM $wpdb->postmeta
1031
+ WHERE meta_key LIKE '\_stcr@\_%%' $where_clause
1032
+ ORDER BY $order_by $order
1033
+ LIMIT $_offset,$row_count", $where_values
1034
+ ), OBJECT
1035
+ );
1036
+ }
1037
+ }
1038
+ // end get_subscriptions
1039
+
1040
+ /**
1041
+ * Sends a message to confirm a subscription
1042
+ */
1043
+ public function confirmation_email( $_post_ID = 0, $_email = '' ) {
1044
+ // Retrieve the options from the database
1045
+ $from_name = stripslashes( get_option( 'subscribe_reloaded_from_name', 'admin' ) );
1046
+ $from_email = get_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ) );
1047
+ $subject = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_double_check_subject', 'Please confirm your subscribtion to [post_title]' ) ), ENT_COMPAT, 'UTF-8' );
1048
+ $message = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_double_check_content', '' ) ), ENT_COMPAT, 'UTF-8' );
1049
+ $manager_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
1050
+ if ( function_exists( 'qtrans_convertURL' ) ) {
1051
+ $manager_link = qtrans_convertURL( $manager_link );
1052
+ }
1053
+
1054
+ $clean_email = $this->clean_email( $_email );
1055
+ $subscriber_salt = $this->generate_key( $clean_email );
1056
+
1057
+ $manager_link .= ( ( strpos( $manager_link, '?' ) !== false ) ? '&' : '?' ) . "sre=" . urlencode( $clean_email ) . "&srk=$subscriber_salt";
1058
+ $confirm_link = "$manager_link&srp=$_post_ID&sra=c";
1059
+
1060
+ $headers = "From: $from_name <$from_email>\n";
1061
+ $content_type = ( get_option( 'subscribe_reloaded_enable_html_emails', 'no' ) == 'yes' ) ? 'text/html' : 'text/plain';
1062
+ $headers .= "Content-Type: $content_type; charset=" . get_bloginfo( 'charset' ) . "\n";
1063
+
1064
+ $post = get_post( $_post_ID );
1065
+ $post_permalink = get_permalink( $_post_ID );
1066
+
1067
+ // Replace tags with their actual values
1068
+ $subject = str_replace( '[post_title]', $post->post_title, $subject );
1069
+
1070
+ $message = str_replace( '[post_permalink]', $post_permalink, $message );
1071
+ $message = str_replace( '[confirm_link]', $confirm_link, $message );
1072
+ $message = str_replace( '[manager_link]', $manager_link, $message );
1073
+
1074
+ // QTranslate support
1075
+ if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
1076
+ $subject = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $subject );
1077
+ $message = str_replace( '[post_title]', qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post->post_title ), $message );
1078
+ $message = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $message );
1079
+ } else {
1080
+ $message = str_replace( '[post_title]', $post->post_title, $message );
1081
+ }
1082
+ $message = apply_filters( 'stcr_confirmation_email_message', $message, $_post_ID, $email );
1083
+ if ( $content_type == 'text/html' ) {
1084
+ $message = $this->wrap_html_message( $message, $subject );
1085
+ }
1086
+
1087
+ wp_mail( $clean_email, $subject, $message, $headers );
1088
+ }
1089
+ // end confirmation_email
1090
+
1091
+ /**
1092
+ * Sends the notification message to a given user
1093
+ */
1094
+ public function notify_user( $_post_ID = 0, $_email = '', $_comment_ID = 0 ) {
1095
+ // Retrieve the options from the database
1096
+ $from_name = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_from_name', 'admin' ) ), ENT_COMPAT, 'UTF-8' );
1097
+ $from_email = get_option( 'subscribe_reloaded_from_email', get_bloginfo( 'admin_email' ) );
1098
+ $subject = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_notification_subject', 'There is a new comment on the post [post_title]' ) ), ENT_COMPAT, 'UTF-8' );
1099
+ $message = html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_notification_content', '' ) ), ENT_COMPAT, 'UTF-8' );
1100
+ $manager_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '/comment-subscriptions/' );
1101
+ if ( function_exists( 'qtrans_convertURL' ) ) {
1102
+ $manager_link = qtrans_convertURL( $manager_link );
1103
+ }
1104
+
1105
+ $clean_email = $this->clean_email( $_email );
1106
+ $subscriber_salt = $this->generate_key( $clean_email );
1107
+
1108
+ $manager_link .= ( ( strpos( $manager_link, '?' ) !== false ) ? '&' : '?' ) . "sre=" . urlencode( $clean_email ) . "&srk=$subscriber_salt";
1109
+
1110
+ $headers = "From: $from_name <$from_email>\n";
1111
+ $content_type = ( get_option( 'subscribe_reloaded_enable_html_emails', 'no' ) == 'yes' ) ? 'text/html' : 'text/plain';
1112
+ $headers .= "Content-Type: $content_type; charset=" . get_bloginfo( 'charset' ) . "\n";
1113
+
1114
+ if ( get_option( 'subscribe_reloaded_admin_bcc', 'no' ) == 'yes' ) {
1115
+ $headers .= "Bcc: $from_name <$from_email>\n";
1116
+ }
1117
+
1118
+ $post = get_post( $_post_ID );
1119
+ $comment = get_comment( $_comment_ID );
1120
+ $post_permalink = get_permalink( $_post_ID );
1121
+ $comment_permalink = get_comment_link( $_comment_ID );
1122
+ $comment_reply_permalink = get_permalink( $_post_ID ) . '?replytocom=' . $_comment_ID . '#respond';
1123
+
1124
+ $comment_content = $comment->comment_content;
1125
+
1126
+ // Add HTML paragraph tags to comment
1127
+ // See wp-includes/formatting.php for details on the wpautop() function
1128
+ if ( $content_type == 'text/html' ) {
1129
+ $comment_content = wpautop( $comment->comment_content );
1130
+ }
1131
+
1132
+ // Replace tags with their actual values
1133
+ $subject = str_replace( '[post_title]', $post->post_title, $subject );
1134
+
1135
+ $message = str_replace( '[post_permalink]', $post_permalink, $message );
1136
+ $message = str_replace( '[comment_permalink]', $comment_permalink, $message );
1137
+ $message = str_replace( '[comment_reply_permalink]', $comment_reply_permalink, $message );
1138
+ $message = str_replace( '[comment_author]', $comment->comment_author, $message );
1139
+ $message = str_replace( '[comment_content]', $comment_content, $message );
1140
+ $message = str_replace( '[manager_link]', $manager_link, $message );
1141
+
1142
+ // QTranslate support
1143
+ if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
1144
+ $subject = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $subject );
1145
+ $message = str_replace( '[post_title]', qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post->post_title ), $message );
1146
+ $message = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $message );
1147
+ } else {
1148
+ $message = str_replace( '[post_title]', $post->post_title, $message );
1149
+ }
1150
+ $message = apply_filters( 'stcr_notify_user_message', $message, $_post_ID, $_email, $_comment_ID );
1151
+ if ( $content_type == 'text/html' ) {
1152
+ if ( get_option( 'subscribe_reloaded_htmlify_message_links' ) == 'yes' ) {
1153
+ $message = $this->htmlify_message_links( $message );
1154
+ }
1155
+ $message = $this->wrap_html_message( $message, $subject );
1156
+ }
1157
+
1158
+ wp_mail( $clean_email, $subject, $message, $headers );
1159
+ }
1160
+ // end notify_user
1161
+
1162
+ /**
1163
+ * Finds all links in text and wraps them with an HTML anchor tag
1164
+ *
1165
+ * @param unknown $text
1166
+ *
1167
+ * @return string Text with all links wrapped in HTML anchor tags
1168
+ *
1169
+ */
1170
+ public function htmlify_message_links( $text ) {
1171
+ return preg_replace( '!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text );
1172
+ }
1173
+
1174
+ /**
1175
+ * Generate a unique key to allow users to manage their subscriptions
1176
+ */
1177
+ public function generate_key( $_email ) {
1178
+ $day = date_i18n( 'Ymd' );
1179
+
1180
+ return md5( $day . $this->salt . $_email );
1181
+ }
1182
+ // end generate_key
1183
+
1184
+ /**
1185
+ * Creates the HTML structure to properly handle HTML messages
1186
+ */
1187
+ public function wrap_html_message( $_message = '', $_subject = '' ) {
1188
+ return "<html><head><title>$_subject</title></head><body>$_message</body></html>";
1189
+ }
1190
+ // end _wrap_html_message
1191
+
1192
+ /**
1193
+ * Returns an email address where some possible 'offending' strings have been removed
1194
+ */
1195
+ public function clean_email( $_email ) {
1196
+ $offending_strings = array(
1197
+ "/to\:/i",
1198
+ "/from\:/i",
1199
+ "/bcc\:/i",
1200
+ "/cc\:/i",
1201
+ "/content\-transfer\-encoding\:/i",
1202
+ "/content\-type\:/i",
1203
+ "/mime\-version\:/i"
1204
+ );
1205
+
1206
+ return esc_attr( stripslashes( strip_tags( preg_replace( $offending_strings, '', $_email ) ) ) );
1207
+ }
1208
+ // end clean_email
1209
+
1210
+ /**
1211
+ * Adds a new entry in the admin menu, to manage this plugin's options
1212
+ */
1213
+ public function add_config_menu( $_s ) {
1214
+ global $current_user;
1215
+
1216
+ if ( current_user_can( 'manage_options' ) ) {
1217
+ add_options_page( 'Subscribe to Comments', 'Subscribe to Comments', 'manage_options', WP_PLUGIN_DIR . '/subscribe-to-comments-reloaded/options/index.php' );
1218
+ }
1219
+
1220
+ return $_s;
1221
+ }
1222
+ // end add_config_menu
1223
+
1224
+ /**
1225
+ * Adds a custom stylesheet file to the admin interface
1226
+ */
1227
+ public function add_options_stylesheet() {
1228
+ // It looks like WP_PLUGIN_URL doesn't honor the HTTPS setting in wp-config.php
1229
+ $stylesheet_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/style.css';
1230
+ wp_register_style( 'subscribe-to-comments', $stylesheet_url );
1231
+ wp_enqueue_style( 'subscribe-to-comments' );
1232
+ }
1233
+
1234
+ public function add_post_comments_stylesheet() {
1235
+ // It looks like WP_PLUGIN_URL doesn't honor the HTTPS setting in wp-config.php
1236
+ $stylesheet_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/post-and-comments.css';
1237
+ wp_register_style( 'subscribe-to-comments', $stylesheet_url );
1238
+ wp_enqueue_style( 'subscribe-to-comments' );
1239
+ }
1240
+ // end add_stylesheet
1241
+
1242
+ /**
1243
+ * Adds custom HTML code to the HEAD section of the management page
1244
+ */
1245
+ public function add_custom_header_meta() {
1246
+ echo html_entity_decode( stripslashes( get_option( 'subscribe_reloaded_custom_header_meta', '' ) ), ENT_COMPAT, 'UTF-8' );
1247
+ }
1248
+ // end add_custom_header_meta
1249
+
1250
+ /**
1251
+ * Adds a new column header to the Edit Comments panel
1252
+ */
1253
+ public function add_column_header( $_columns ) {
1254
+ $image_url = ( is_ssl() ? str_replace( 'http://', 'https://', WP_PLUGIN_URL ) : WP_PLUGIN_URL ) . '/subscribe-to-comments-reloaded/images';
1255
+ $_columns['subscribe-reloaded'] = "<img src='$image_url/subscribe-to-comments-small.png' width='17' height='12' alt='Subscriptions' />";
1256
+
1257
+ return $_columns;
1258
+ }
1259
+ // end add_comment_column_header
1260
+
1261
+ /**
1262
+ * Adds a new column to the Edit Comments panel
1263
+ */
1264
+ public function add_comment_column( $_column_name ) {
1265
+ if ( 'subscribe-reloaded' != $_column_name ) {
1266
+ return;
1267
+ }
1268
+
1269
+ global $comment;
1270
+ $subscription = $this->get_subscriptions(
1271
+ array(
1272
+ 'post_id',
1273
+ 'email'
1274
+ ), array(
1275
+ 'equals',
1276
+ 'equals'
1277
+ ), array(
1278
+ $comment->comment_post_ID,
1279
+ $comment->comment_author_email
1280
+ ), 'dt', 'DESC', 0, 1
1281
+ );
1282
+ if ( count( $subscription ) == 0 ) {
1283
+ _e( 'No', 'subscribe-reloaded' );
1284
+ } else {
1285
+ echo '<a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=1&amp;srf=email&amp;srt=equals&amp;srv=' . urlencode( $comment->comment_author_email ) . '">' . $subscription[0]->status . '</a>';
1286
+ }
1287
+ }
1288
+ // end add_column
1289
+
1290
+ /**
1291
+ * Adds a new column to the Posts management panel
1292
+ */
1293
+ public function add_post_column( $_column_name ) {
1294
+ if ( 'subscribe-reloaded' != $_column_name ) {
1295
+ return;
1296
+ }
1297
+
1298
+ global $post;
1299
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
1300
+ echo '<a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php&subscribepanel=1&amp;srf=post_id&amp;srt=equals&amp;srv=' . $post->ID . '">' . count( $this->get_subscriptions( 'post_id', 'equals', $post->ID ) ) . '</a>';
1301
+ }
1302
+ // end add_column
1303
+
1304
+ /**
1305
+ * Contextual help (link to the support forum)
1306
+ */
1307
+ public function contextual_help( $contextual_help, $screen_id, $screen ) {
1308
+ if ( $screen_id == 'subscribe-to-comments-reloaded/options/index' ) {
1309
+ load_plugin_textdomain( 'subscribe-reloaded', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
1310
+ $contextual_help = __( 'Need help on how to use Subscribe to Comments Reloaded? Visit the official', 'subscribe-reloaded' ) . ' <a href="http://wordpress.org/tags/subscribe-to-comments-reloaded?forum_id=10" target="_blank">' . __( 'support forum', 'subscribe-reloaded' ) . '</a>. ';
1311
+ $contextual_help .= __( 'Feeling generous?', 'subscribe-reloaded' ) . ' <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=XF86X93FDCGYA&lc=US&item_name=Datasoft%20Engineering&item_number=DI%2dSTCR&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank">' . __( 'Donate a few bucks!', 'subscribe-reloaded' ) . '</a>';
1312
+ }
1313
+
1314
+ return $contextual_help;
1315
+ }
1316
+ // end contextual_help
1317
+
1318
+ /**
1319
+ * Returns the URL of the management page as a shortcode
1320
+ */
1321
+ public function subscribe_url_shortcode() {
1322
+ global $post;
1323
+ $user_link = get_bloginfo( 'url' ) . get_option( 'subscribe_reloaded_manager_page', '' );
1324
+ if ( function_exists( 'qtrans_convertURL' ) ) {
1325
+ $user_link = qtrans_convertURL( $user_link );
1326
+ }
1327
+ if ( strpos( $user_link, '?' ) !== false ) {
1328
+ return "$user_link&amp;srp=$post->ID&amp;sra=s";
1329
+ } else {
1330
+ return "$user_link?srp=$post->ID&amp;sra=s";
1331
+ }
1332
+ }
1333
+ // end subscribe_url_shortcode
1334
+
1335
+ /**
1336
+ * Copies the information from the stand-alone table to WP's core table
1337
+ */
1338
+ private function _update_db() {
1339
+ global $wpdb;
1340
+ $stcr_table = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}subscribe_reloaded'" );
1341
+
1342
+ // Perform the import only if the target table does not contain any subscriptions
1343
+ $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1344
+ if ( ! empty( $stcr_table ) && $count_postmeta_rows == 0 ) {
1345
+ $wpdb->query(
1346
+ "
1347
+ INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1348
+ SELECT post_ID, CONCAT('_stcr@_', email), CONCAT(dt, '|Y')
1349
+ FROM {$wpdb->prefix}subscribe_reloaded
1350
+ WHERE email LIKE '%@%.%' AND status = 'Y'
1351
+ GROUP BY email, post_ID"
1352
+ );
1353
+ }
1354
+ }
1355
+ // end _update_db
1356
+
1357
+ /**
1358
+ * Imports subscription data created with the Subscribe to Comments plugin
1359
+ */
1360
+ private function _import_stc_data() {
1361
+ global $wpdb;
1362
+
1363
+ // Import the information collected by Subscribe to Comments, if needed
1364
+ $result = $wpdb->get_row( "DESC $wpdb->comments comment_subscribe", ARRAY_A );
1365
+
1366
+ // Perform the import only if the target table does not contain any subscriptions
1367
+ $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1368
+
1369
+ if ( ! empty( $result ) && is_array( $result ) && $count_postmeta_rows == 0 ) {
1370
+ $wpdb->query(
1371
+ "
1372
+ INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1373
+ SELECT comment_post_ID, CONCAT('_stcr@_', comment_author_email), CONCAT(comment_date, '|Y')
1374
+ FROM $wpdb->comments
1375
+ WHERE comment_author_email LIKE '%@%.%' AND comment_subscribe = 'Y'
1376
+ GROUP BY comment_post_ID, comment_author_email"
1377
+ );
1378
+
1379
+ $notices = get_option( 'subscribe_reloaded_deferred_admin_notices', array() );
1380
+ $notices[] = '<div class="updated"><h3>' . __( 'Important Notice', 'subscribe-reloaded' ) . '</h3>' .
1381
+ '<p>' . __( 'Comment subscription data from the <strong>Subscribe to Comments</strong> plugin was detected and automatically imported into <strong>Subscribe to Comments Reloaded</strong>.', 'subscribe-reloaded' ) . ( is_plugin_active( 'subscribe-to-comments/subscribe-to-comments.php' ) ? __( ' It is recommended that you now <strong>deactivate</strong> Subscribe to Comments to prevent confusion between the two plugins.', 'subscribe-reloaded' ) : '' ) . '</p>' .
1382
+ '<p>' . __( 'If you have subscription data from Subscribe to Comments Reloaded < v2.0 that you want to import, you\'ll need to import that data manually, as only one import routine will ever run to prevent data loss.', 'subscribe-reloaded' ) . '</p>' .
1383
+ '<p>' . __( 'Please visit <a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php">Settings -> Subscribe to Comments</a> to review your configuration.', 'subscribe-reloaded' ) . '</p></div>';
1384
+ update_option( 'subscribe_reloaded_deferred_admin_notices', $notices );
1385
+ }
1386
+ }
1387
+ // end _import_stc_data
1388
+
1389
+ /**
1390
+ * Imports options and subscription data created with the WP Comment Subscriptions plugin
1391
+ */
1392
+ private function _import_wpcs_data() {
1393
+ global $wpdb;
1394
+
1395
+ // Import the information collected by WP Comment Subscriptions, if needed
1396
+ $wpcs_data_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_wpcs@\_%'" );
1397
+
1398
+ // Perform the import only if the target table does not contain any subscriptions
1399
+ $count_postmeta_rows = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key LIKE '\_stcr@\_%'" );
1400
+
1401
+ if ( ! empty( $wpcs_data_count ) && $count_postmeta_rows == 0 ) {
1402
+ $wpdb->query(
1403
+ "
1404
+ INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value)
1405
+ SELECT post_id, REPLACE(meta_key, '_wpcs@_', '_stcr@_') meta_key, meta_value
1406
+ FROM $wpdb->postmeta
1407
+ WHERE meta_key LIKE '%_wpcs@_%'"
1408
+ );
1409
+
1410
+ if ( $option = get_option( 'wp_comment_subscriptions_manager_page' ) ) {
1411
+ add_option( 'subscribe_reloaded_manager_page', $option );
1412
+ }
1413
+ if ( $option = get_option( 'wp_comment_subscriptions_show_subscription_box' ) ) {
1414
+ add_option( 'subscribe_reloaded_show_subscription_box', $option );
1415
+ }
1416
+ if ( $option = get_option( 'wp_comment_subscriptions_checked_by_default' ) ) {
1417
+ add_option( 'subscribe_reloaded_checked_by_default', $option );
1418
+ }
1419
+ if ( $option = get_option( 'wp_comment_subscriptions_enable_advanced_subscriptions' ) ) {
1420
+ add_option( 'subscribe_reloaded_enable_advanced_subscriptions', $option );
1421
+ }
1422
+ if ( $option = get_option( 'wp_comment_subscriptions_checkbox_inline_style' ) ) {
1423
+ add_option( 'subscribe_reloaded_checkbox_inline_style', $option );
1424
+ }
1425
+ if ( $option = get_option( 'wp_comment_subscriptions_checkbox_html' ) ) {
1426
+ add_option( 'subscribe_reloaded_checkbox_html', $option );
1427
+ }
1428
+ if ( $option = get_option( 'wp_comment_subscriptions_checkbox_label' ) ) {
1429
+ add_option( 'subscribe_reloaded_checkbox_label', $option );
1430
+ }
1431
+ if ( $option = get_option( 'wp_comment_subscriptions_subscribed_label' ) ) {
1432
+ add_option( 'subscribe_reloaded_subscribed_label', $option );
1433
+ }
1434
+ if ( $option = get_option( 'wp_comment_subscriptions_subscribed_waiting_label' ) ) {
1435
+ add_option( 'subscribe_reloaded_subscribed_waiting_label', $option );
1436
+ }
1437
+ if ( $option = get_option( 'wp_comment_subscriptions_author_label' ) ) {
1438
+ add_option( 'subscribe_reloaded_author_label', $option );
1439
+ }
1440
+ if ( $option = get_option( 'wp_comment_subscriptions_htmlify_message_links' ) ) {
1441
+ add_option( 'subscribe_reloaded_htmlify_message_links', $option );
1442
+ }
1443
+
1444
+ if ( $option = get_option( 'wp_comment_subscriptions_manager_page_enabled' ) ) {
1445
+ add_option( 'subscribe_reloaded_manager_page_enabled', $option );
1446
+ }
1447
+ if ( $option = get_option( 'wp_comment_subscriptions_manager_page_title' ) ) {
1448
+ add_option( 'subscribe_reloaded_manager_page_title', $option );
1449
+ }
1450
+ if ( $option = get_option( 'wp_comment_subscriptions_custom_header_meta' ) ) {
1451
+ add_option( 'subscribe_reloaded_custom_header_meta', $option );
1452
+ }
1453
+ if ( $option = get_option( 'wp_comment_subscriptions_request_mgmt_link' ) ) {
1454
+ add_option( 'subscribe_reloaded_request_mgmt_link', $option );
1455
+ }
1456
+ if ( $option = get_option( 'wp_comment_subscriptions_request_mgmt_link_thankyou' ) ) {
1457
+ add_option( 'subscribe_reloaded_request_mgmt_link_thankyou', $option );
1458
+ }
1459
+ if ( $option = get_option( 'wp_comment_subscriptions_subscribe_without_commenting' ) ) {
1460
+ add_option( 'subscribe_reloaded_subscribe_without_commenting', $option );
1461
+ }
1462
+ if ( $option = get_option( 'wp_comment_subscriptions_subscription_confirmed' ) ) {
1463
+ add_option( 'subscribe_reloaded_subscription_confirmed', $option );
1464
+ }
1465
+ if ( $option = get_option( 'wp_comment_subscriptions_subscription_confirmed_dci' ) ) {
1466
+ add_option( 'subscribe_reloaded_subscription_confirmed_dci', $option );
1467
+ }
1468
+ if ( $option = get_option( 'wp_comment_subscriptions_author_text' ) ) {
1469
+ add_option( 'subscribe_reloaded_author_text', $option );
1470
+ }
1471
+ if ( $option = get_option( 'wp_comment_subscriptions_user_text' ) ) {
1472
+ add_option( 'subscribe_reloaded_user_text', $option );
1473
+ }
1474
+
1475
+ if ( $option = get_option( 'wp_comment_subscriptions_from_name' ) ) {
1476
+ add_option( 'subscribe_reloaded_from_name', $option );
1477
+ }
1478
+ if ( $option = get_option( 'wp_comment_subscriptions_from_email' ) ) {
1479
+ add_option( 'subscribe_reloaded_from_email', $option );
1480
+ }
1481
+ if ( $option = get_option( 'wp_comment_subscriptions_notification_subject' ) ) {
1482
+ add_option( 'subscribe_reloaded_notification_subject', $option );
1483
+ }
1484
+ if ( $option = get_option( 'wp_comment_subscriptions_notification_content' ) ) {
1485
+ add_option( 'subscribe_reloaded_notification_content', $option );
1486
+ }
1487
+ if ( $option = get_option( 'wp_comment_subscriptions_double_check_subject' ) ) {
1488
+ add_option( 'subscribe_reloaded_double_check_subject', $option );
1489
+ }
1490
+ if ( $option = get_option( 'wp_comment_subscriptions_double_check_content' ) ) {
1491
+ add_option( 'subscribe_reloaded_double_check_content', $option );
1492
+ }
1493
+ if ( $option = get_option( 'wp_comment_subscriptions_management_subject' ) ) {
1494
+ add_option( 'subscribe_reloaded_management_subject', $option );
1495
+ }
1496
+ if ( $option = get_option( 'wp_comment_subscriptions_management_content' ) ) {
1497
+ add_option( 'subscribe_reloaded_management_content', $option );
1498
+ }
1499
+
1500
+ if ( $option = get_option( 'wp_comment_subscriptions_purge_days' ) ) {
1501
+ add_option( 'subscribe_reloaded_purge_days', $option );
1502
+ }
1503
+ if ( $option = get_option( 'wp_comment_subscriptions_enable_double_check' ) ) {
1504
+ add_option( 'subscribe_reloaded_enable_double_check', $option );
1505
+ }
1506
+ if ( $option = get_option( 'wp_comment_subscriptions_notify_authors' ) ) {
1507
+ add_option( 'subscribe_reloaded_notify_authors', $option );
1508
+ }
1509
+ if ( $option = get_option( 'wp_comment_subscriptions_enable_html_emails' ) ) {
1510
+ add_option( 'subscribe_reloaded_enable_html_emails', $option );
1511
+ }
1512
+ if ( $option = get_option( 'wp_comment_subscriptions_process_trackbacks' ) ) {
1513
+ add_option( 'subscribe_reloaded_process_trackbacks', $option );
1514
+ }
1515
+ if ( $option = get_option( 'wp_comment_subscriptions_enable_admin_messages' ) ) {
1516
+ add_option( 'subscribe_reloaded_enable_admin_messages', $option );
1517
+ }
1518
+ if ( $option = get_option( 'wp_comment_subscriptions_admin_subscribe' ) ) {
1519
+ add_option( 'subscribe_reloaded_admin_subscribe', $option );
1520
+ }
1521
+ if ( $option = get_option( 'wp_comment_subscriptions_admin_bcc' ) ) {
1522
+ add_option( 'subscribe_reloaded_admin_bcc', $option );
1523
+ }
1524
+
1525
+ $notices = get_option( 'subscribe_reloaded_deferred_admin_notices', array() );
1526
+ $notices[] = '<div class="updated"><h3>' . __( 'Important Notice', 'subscribe-reloaded' ) . '</h3>' .
1527
+ '<p>' . __( 'Plugin options and comment subscription data from the <strong>WP Comment Subscriptions</strong> plugin were detected and automatically imported into <strong>Subscribe to Comments Reloaded</strong>.', 'subscribe-reloaded' ) . ( is_plugin_active( 'wp-comment-subscriptions/wp-comment-subscriptions.php' ) ? __( ' It is recommended that you now <strong>deactivate</strong> WP Comment Subscriptions to prevent confusion between the two plugins.', 'subscribe-reloaded' ) : '' ) . '</p>' .
1528
+ '<p>' . __( 'If you have subscription data from another plugin (such as Subscribe to Comments or Subscribe to Comments Reloaded < v2.0) that you want to import, you\'ll need to import that data manually, as only one import routine will ever run to prevent data loss.', 'subscribe-reloaded' ) . '</p>' .
1529
+ '<p>' . __( '<strong>Note:</strong> If you were previously using the <code>wp_comment_subscriptions_show()</code> function or the <code>[wpcs-subscribe-url]</code> shortcode, you\'ll need to replace those with <code>subscribe_reloaded_show()</code> and <code>[subscribe-url]</code> respectively.', 'subscribe-reloaded' ) . '</p>' .
1530
+ '<p>' . __( 'Please visit <a href="options-general.php?page=subscribe-to-comments-reloaded/options/index.php">Settings -> Subscribe to Comments</a> to review your configuration.', 'subscribe-reloaded' ) . '</p></div>';
1531
+ update_option( 'subscribe_reloaded_deferred_admin_notices', $notices );
1532
+ }
1533
+ }
1534
+ // end _import_wpcs_data
1535
+
1536
+ /**
1537
+ * Retrieves the comment information from the databse
1538
+ */
1539
+ private function _get_comment_object( $_comment_ID ) {
1540
+ global $wpdb;
1541
+
1542
+ return $wpdb->get_row(
1543
+ $wpdb->prepare(
1544
+ "
1545
+ SELECT comment_post_ID, comment_author_email, comment_approved, comment_type, comment_parent
1546
+ FROM $wpdb->comments
1547
+ WHERE comment_ID = %d LIMIT 1", $_comment_ID
1548
+ ), OBJECT
1549
+ );
1550
+ }
1551
+ // end _get_comment_object
1552
+
1553
+ /**
1554
+ * Checks if a key is valid for a given email address
1555
+ */
1556
+ private function _is_valid_key( $_key, $_email ) {
1557
+ return $this->generate_key( $_email ) == $_key;
1558
+ }
1559
+ // end _is_valid_key
1560
+ }
1561
+
1562
+ // end of class declaration
1563
+
1564
+ // Bootstrap the whole thing
1565
+ $wp_subscribe_reloaded = new wp_subscribe_reloaded();
1566
+ // Set a cookie if the user just subscribed without commenting
1567
+ $subscribe_to_comments_action = ! empty( $_POST['sra'] ) ? $_POST['sra'] : ( ! empty( $_GET['sra'] ) ? $_GET['sra'] : 0 );
1568
+ $subscribe_to_comments_post_ID = ! empty( $_POST['srp'] ) ? intval( $_POST['srp'] ) : ( ! empty( $_GET['srp'] ) ? intval( $_GET['srp'] ) : 0 );
1569
+
1570
+ if ( ! empty( $subscribe_to_comments_action ) && ! empty( $_POST['subscribe_reloaded_email'] ) &&
1571
+ ( $subscribe_to_comments_action == 's' ) && ( $subscribe_to_comments_post_ID > 0 )
1572
+ ) {
1573
+ $subscribe_to_comments_clean_email = $wp_subscribe_reloaded->clean_email( $_POST['subscribe_reloaded_email'] );
1574
+ setcookie( 'comment_author_email' . COOKIEHASH, $subscribe_to_comments_clean_email, time() + 1209600, '/' );
1575
+ }