PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/plugins/subscribe-to-comments/subscribe-to-comments.php

https://github.com/prabhu/desistartups
PHP | 1241 lines | 914 code | 284 blank | 43 comment | 184 complexity | 2081adb1523169a57cf706bca83a4465 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: Subscribe To Comments
  4. Version: 2.1.2
  5. Plugin URI: http://txfx.net/code/wordpress/subscribe-to-comments/
  6. Description: Allows readers to receive notifications of new comments that are posted to an entry. Based on version 1 from <a href="http://scriptygoddess.com/">Scriptygoddess</a>
  7. Author: Mark Jaquith
  8. Author URI: http://txfx.net/
  9. */
  10. /* This is the code that is inserted into the comment form */
  11. function show_subscription_checkbox ($id='0') {
  12. global $sg_subscribe;
  13. sg_subscribe_start();
  14. if ( $sg_subscribe->checkbox_shown ) return $id;
  15. if ( !$email = $sg_subscribe->current_viewer_subscription_status() ) :
  16. $checked_status = ( !empty($_COOKIE['subscribe_checkbox_'.COOKIEHASH]) && 'checked' == $_COOKIE['subscribe_checkbox_'.COOKIEHASH] ) ? true : false;
  17. ?>
  18. <?php /* ------------------------------------------------------------------- */ ?>
  19. <?php /* This is the text that is displayed for users who are NOT subscribed */ ?>
  20. <?php /* ------------------------------------------------------------------- */ ?>
  21. <p <?php if ($sg_subscribe->clear_both) echo 'style="clear: both;" '; ?>class="subscribe-to-comments">
  22. <input type="checkbox" name="subscribe" id="subscribe" value="subscribe" style="width: auto;" <?php if ( $checked_status ) echo 'checked="checked" '; ?>/>
  23. <label for="subscribe"><?php echo $sg_subscribe->not_subscribed_text; ?></label>
  24. </p>
  25. <?php /* ------------------------------------------------------------------- */ ?>
  26. <?php elseif ( $email == 'admin' && current_user_can('manage_options') ) : ?>
  27. <?php /* ------------------------------------------------------------- */ ?>
  28. <?php /* This is the text that is displayed for the author of the post */ ?>
  29. <?php /* ------------------------------------------------------------- */ ?>
  30. <p <?php if ($sg_subscribe->clear_both) echo 'style="clear: both;" '; ?>class="subscribe-to-comments">
  31. <?php echo str_replace('[manager_link]', $sg_subscribe->manage_link($email, true, false), $sg_subscribe->author_text); ?>
  32. </p>
  33. <?php else : ?>
  34. <?php /* --------------------------------------------------------------- */ ?>
  35. <?php /* This is the text that is displayed for users who ARE subscribed */ ?>
  36. <?php /* --------------------------------------------------------------- */ ?>
  37. <p <?php if ($sg_subscribe->clear_both) echo 'style="clear: both;" '; ?>class="subscribe-to-comments">
  38. <?php echo str_replace('[manager_link]', $sg_subscribe->manage_link($email, true, false), $sg_subscribe->subscribed_text); ?>
  39. </p>
  40. <?php /* --------------------------------------------------------------- */ ?>
  41. <?php endif;
  42. $sg_subscribe->checkbox_shown = true;
  43. return $id;
  44. }
  45. /* -------------------------------------------------------------------- */
  46. /* This function outputs a "subscribe without commenting" form. */
  47. /* Place this somewhere within "the loop", but NOT within another form */
  48. /* This is NOT inserted automaticallly... you must place it yourself */
  49. /* -------------------------------------------------------------------- */
  50. function show_manual_subscription_form() {
  51. global $id, $sg_subscribe, $user_email;
  52. sg_subscribe_start();
  53. $sg_subscribe->show_errors('solo_subscribe', '<div class="solo-subscribe-errors">', '</div>', __('<strong>Error: </strong>', 'subscribe-to-comments'), '<br />');
  54. if ( !$sg_subscribe->current_viewer_subscription_status() ) :
  55. get_currentuserinfo(); ?>
  56. <?php /* ------------------------------------------------------------------- */ ?>
  57. <?php /* This is the text that is displayed for users who are NOT subscribed */ ?>
  58. <?php /* ------------------------------------------------------------------- */ ?>
  59. <form action="" method="post">
  60. <input type="hidden" name="solo-comment-subscribe" value="solo-comment-subscribe" />
  61. <input type="hidden" name="postid" value="<?php echo (int) $id; ?>" />
  62. <input type="hidden" name="ref" value="<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . attribute_escape($_SERVER['REQUEST_URI'])); ?>" />
  63. <p class="solo-subscribe-to-comments">
  64. <?php _e('Subscribe without commenting', 'subscribe-to-comments'); ?>
  65. <br />
  66. <label for="solo-subscribe-email"><?php _e('E-Mail:', 'subscribe-to-comments'); ?>
  67. <input type="text" name="email" id="solo-subscribe-email" size="22" value="<?php echo $user_email; ?>" /></label>
  68. <input type="submit" name="submit" value="<?php _e('Subscribe', 'subscribe-to-comments'); ?>" />
  69. </p>
  70. </form>
  71. <?php /* ------------------------------------------------------------------- */ ?>
  72. <?php endif;
  73. }
  74. /* -------------------------
  75. Use this function on your comments display - to show whether a user is subscribed to comments on the post or not.
  76. Note: this must be used within the comments loop! It will not work properly outside of it.
  77. ------------------------- */
  78. function comment_subscription_status() {
  79. global $comment;
  80. if ($comment->comment_subscribe == 'Y') {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }
  86. /* ============================= */
  87. /* DO NOT MODIFY BELOW THIS LINE */
  88. /* ============================= */
  89. class sg_subscribe_settings {
  90. function options_page_contents() {
  91. global $sg_subscribe;
  92. sg_subscribe_start();
  93. if ( isset($_POST['sg_subscribe_settings_submit']) ) {
  94. check_admin_referer('subscribe-to-comments-update_options');
  95. $update_settings = stripslashes_deep($_POST['sg_subscribe_settings']);
  96. $sg_subscribe->update_settings($update_settings);
  97. }
  98. echo '<h2>'.__('Subscribe to Comments Options','subscribe-to-comments').'</h2>';
  99. echo '<ul>';
  100. echo '<li><label for="name">' . __('"From" name for notifications:', 'subscribe-to-comments') . ' <input type="text" size="40" id="name" name="sg_subscribe_settings[name]" value="' . sg_subscribe_settings::form_setting('name') . '" /></label></li>';
  101. echo '<li><label for="email">' . __('"From" e-mail addresss for notifications:', 'subscribe-to-comments') . ' <input type="text" size="40" id="email" name="sg_subscribe_settings[email]" value="' . sg_subscribe_settings::form_setting('email') . '" /></label></li>';
  102. echo '<li><label for="clear_both"><input type="checkbox" id="clear_both" name="sg_subscribe_settings[clear_both]" value="clear_both"' . sg_subscribe_settings::checkflag('clear_both') . ' /> ' . __('Do a CSS "clear" on the subscription checkbox/message (uncheck this if the checkbox/message appears in a strange location in your theme)', 'subscribe-to-comments') . '</label></li>';
  103. echo '</ul>';
  104. echo '<fieldset><legend>' . __('Comment Form Text', 'subscribe-to-comments') . '</legend>';
  105. echo '<p>' . __('Customize the messages shown to different people. Use <code>[manager_link]</code> to insert the URI to the Subscription Manager.', 'subscribe-to-comments') . '</p>';
  106. echo '<ul>';
  107. echo '<li><label for="not_subscribed_text">' . __('Not subscribed', 'subscribe-to-comments') . '</label><br /><textarea style="width: 98%; font-size: 12px;" rows="2" cols="60" id="not_subscribed_text" name="sg_subscribe_settings[not_subscribed_text]">' . sg_subscribe_settings::textarea_setting('not_subscribed_text') . '</textarea></li>';
  108. echo '<li><label for="subscribed_text">' . __('Subscribed', 'subscribe-to-comments') . '</label><br /><textarea style="width: 98%; font-size: 12px;" rows="2" cols="60" id="subscribed_text" name="sg_subscribe_settings[subscribed_text]">' . sg_subscribe_settings::textarea_setting('subscribed_text') . '</textarea></li>';
  109. echo '<li><label for="author_text">' . __('Entry Author', 'subscribe-to-comments') . '</label><br /><textarea style="width: 98%; font-size: 12px;" rows="2" cols="60" id="author_text" name="sg_subscribe_settings[author_text]">' . sg_subscribe_settings::textarea_setting('author_text') . '</textarea></li>';
  110. echo '</ul></fieldset>';
  111. echo '<fieldset>';
  112. echo '<legend><input type="checkbox" id="use_custom_style" name="sg_subscribe_settings[use_custom_style]" value="use_custom_style"' . sg_subscribe_settings::checkflag('use_custom_style') . ' /> <label for="use_custom_style">' . __('Use custom style for Subscription Manager', 'subscribe-to-comments') . '</label></legend>';
  113. echo '<p>' . __('These settings only matter if you are using a custom style. <code>[theme_path]</code> will be replaced with the path to your current theme.', 'subscribe-to-comments') . '</p>';
  114. echo '<ul>';
  115. echo '<li><label for="sg_sub_header">' . __('Path to header:', 'subscribe-to-comments') . ' <input type="text" size="40" id="sg_sub_header" name="sg_subscribe_settings[header]" value="' . sg_subscribe_settings::form_setting('header') . '" /></label></li>';
  116. echo '<li><label for="sg_sub_sidebar">' . __('Path to sidebar:', 'subscribe-to-comments') . ' <input type="text" size="40" id="sg_sub_sidebar" name="sg_subscribe_settings[sidebar]" value="' . sg_subscribe_settings::form_setting('sidebar') . '" /></label></li>';
  117. echo '<li><label for="sg_sub_footer">' . __('Path to footer:', 'subscribe-to-comments') . ' <input type="text" size="40" id="sg_sub_footer" name="sg_subscribe_settings[footer]" value="' . sg_subscribe_settings::form_setting('footer') . '" /></label></li>';
  118. echo '<li><label for="before_manager">' . __('HTML for before the subscription manager:', 'subscribe-to-comments') . ' </label><br /><textarea style="width: 98%; font-size: 12px;" rows="2" cols="60" id="before_manager" name="sg_subscribe_settings[before_manager]">' . sg_subscribe_settings::textarea_setting('before_manager') . '</textarea></li>';
  119. echo '<li><label for="after_manager">' . __('HTML for after the subscription manager:', 'subscribe-to-comments') . ' </label><br /><textarea style="width: 98%; font-size: 12px;" rows="2" cols="60" id="after_manager" name="sg_subscribe_settings[after_manager]">' . sg_subscribe_settings::textarea_setting('after_manager') . '</textarea></li>';
  120. echo '</ul>';
  121. echo '</fieldset>';
  122. }
  123. function checkflag($optname) {
  124. $options = get_settings('sg_subscribe_settings');
  125. if ( $options[$optname] != $optname )
  126. return;
  127. return ' checked="checked"';
  128. }
  129. function form_setting($optname) {
  130. $options = get_settings('sg_subscribe_settings');
  131. return attribute_escape($options[$optname]);
  132. }
  133. function textarea_setting($optname) {
  134. $options = get_settings('sg_subscribe_settings');
  135. return wp_specialchars($options[$optname]);
  136. }
  137. function options_page() {
  138. /** Display "saved" notification on post **/
  139. if ( isset($_POST['sg_subscribe_settings_submit']) )
  140. echo '<div class="updated"><p><strong>' . __('Options saved.', 'subscribe-to-comments') . '</strong></p></div>';
  141. echo '<form method="post"><div class="wrap">';
  142. sg_subscribe_settings::options_page_contents();
  143. echo '<p class="submit"><input type="submit" name="sg_subscribe_settings_submit" value="';
  144. _e('Update Options &raquo;', 'subscribe-to-comments');
  145. echo '" /></p></div>';
  146. if ( function_exists('wp_nonce_field') )
  147. wp_nonce_field('subscribe-to-comments-update_options');
  148. echo '</form>';
  149. }
  150. }
  151. class sg_subscribe {
  152. var $errors;
  153. var $messages;
  154. var $post_subscriptions;
  155. var $email_subscriptions;
  156. var $subscriber_email;
  157. var $site_email;
  158. var $site_name;
  159. var $standalone;
  160. var $form_action;
  161. var $checkbox_shown;
  162. var $use_wp_style;
  163. var $header;
  164. var $sidebar;
  165. var $footer;
  166. var $clear_both;
  167. var $before_manager;
  168. var $after_manager;
  169. var $email;
  170. var $new_email;
  171. var $ref;
  172. var $key;
  173. var $key_type;
  174. var $action;
  175. var $default_subscribed;
  176. var $not_subscribed_text;
  177. var $subscribed_text;
  178. var $author_text;
  179. var $salt;
  180. var $settings;
  181. var $version = '2.1.2';
  182. function sg_subscribe() {
  183. global $wpdb;
  184. $this->db_upgrade_check();
  185. $this->settings = get_settings('sg_subscribe_settings');
  186. $this->salt = $this->settings['salt'];
  187. $this->site_email = ( is_email($this->settings['email']) && $this->settings['email'] != 'email@example.com' ) ? $this->settings['email'] : get_bloginfo('admin_email');
  188. $this->site_name = ( $this->settings['name'] != 'YOUR NAME' && !empty($this->settings['name']) ) ? $this->settings['name'] : get_bloginfo('name');
  189. $this->default_subscribed = ($this->settings['default_subscribed']) ? true : false;
  190. $this->not_subscribed_text = $this->settings['not_subscribed_text'];
  191. $this->subscribed_text = $this->settings['subscribed_text'];
  192. $this->author_text = $this->settings['author_text'];
  193. $this->clear_both = $this->settings['clear_both'];
  194. $this->errors = '';
  195. $this->post_subscriptions = array();
  196. $this->email_subscriptions = '';
  197. }
  198. function manager_init() {
  199. $this->messages = '';
  200. $this->use_wp_style = ( $this->settings['use_custom_style'] == 'use_custom_style' ) ? false : true;
  201. if ( !$this->use_wp_style ) {
  202. $this->header = str_replace('[theme_path]', get_template_directory(), $this->settings['header']);
  203. $this->sidebar = str_replace('[theme_path]', get_template_directory(), $this->settings['sidebar']);
  204. $this->footer = str_replace('[theme_path]', get_template_directory(), $this->settings['footer']);
  205. $this->before_manager = $this->settings['before_manager'];
  206. $this->after_manager = $this->settings['after_manager'];
  207. }
  208. foreach ( array('email', 'key', 'ref', 'new_email') as $var )
  209. if ( isset($_REQUEST[$var]) && !empty($_REQUEST[$var]) )
  210. $this->{$var} = attribute_escape(trim(stripslashes($_REQUEST[$var])));
  211. if ( !$this->key )
  212. $this->key = 'unset';
  213. }
  214. function add_error($text='generic error', $type='manager') {
  215. $this->errors[$type][] = $text;
  216. }
  217. function show_errors($type='manager', $before_all='<div class="updated updated-error">', $after_all='</div>', $before_each='<p>', $after_each='</p>'){
  218. if ( is_array($this->errors[$type]) ) {
  219. echo $before_all;
  220. foreach ($this->errors[$type] as $error)
  221. echo $before_each . $error . $after_each;
  222. echo $after_all;
  223. }
  224. unset($this->errors);
  225. }
  226. function add_message($text) {
  227. $this->messages[] = $text;
  228. }
  229. function show_messages($before_all='', $after_all='', $before_each='<div class="updated"><p>', $after_each='</p></div>'){
  230. if ( is_array($this->messages) ) {
  231. echo $before_all;
  232. foreach ($this->messages as $message)
  233. echo $before_each . $message . $after_each;
  234. echo $after_all;
  235. }
  236. unset($this->messages);
  237. }
  238. function subscriptions_from_post($postid) {
  239. if ( is_array($this->post_subscriptions[$postid]) )
  240. return $this->post_subscriptions[$postid];
  241. global $wpdb;
  242. $postid = (int) $postid;
  243. $this->post_subscriptions[$postid] = $wpdb->get_col("SELECT comment_author_email FROM $wpdb->comments WHERE comment_post_ID = '$postid' AND comment_subscribe='Y' AND comment_author_email != '' AND comment_approved = '1' GROUP BY LCASE(comment_author_email)");
  244. $subscribed_without_comment = (array) get_post_meta($postid, '_sg_subscribe-to-comments');
  245. $this->post_subscriptions[$postid] = array_merge((array) $this->post_subscriptions[$postid], (array) $subscribed_without_comment);
  246. $this->post_subscriptions[$postid] = array_unique($this->post_subscriptions[$postid]);
  247. return $this->post_subscriptions[$postid];
  248. }
  249. function subscriptions_from_email($email='') {
  250. if ( is_array($this->email_subscriptions) )
  251. return $this->email_subscriptions;
  252. if ( !is_email($email) )
  253. $email = $this->email;
  254. global $wpdb;
  255. $email = $wpdb->escape(strtolower($email));
  256. $subscriptions = $wpdb->get_results("SELECT comment_post_ID FROM $wpdb->comments WHERE LCASE(comment_author_email) = '$email' AND comment_subscribe='Y' AND comment_approved = '1' GROUP BY comment_post_ID");
  257. foreach ( (array) $subscriptions as $subscription )
  258. $this->email_subscriptions[] = $subscription->comment_post_ID;
  259. $subscriptions = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sg_subscribe-to-comments' AND LCASE(meta_value) = '$email' GROUP BY post_id");
  260. foreach ( (array) $subscriptions as $subscription)
  261. $this->email_subscriptions[] = $subscription->post_id;
  262. if ( is_array($this->email_subscriptions) ) {
  263. sort($this->email_subscriptions, SORT_NUMERIC);
  264. return $this->email_subscriptions;
  265. }
  266. return false;
  267. }
  268. function solo_subscribe ($email, $postid) {
  269. global $wpdb, $cache_userdata, $user_email;
  270. $postid = (int) $postid;
  271. $email = strtolower($email);
  272. if ( !is_email($email) ) {
  273. get_currentuserinfo();
  274. if ( is_email($user_email) )
  275. $email = strtolower($user_email);
  276. else
  277. $this->add_error(__('Please provide a valid e-mail address.', 'subscribe-to-comments'),'solo_subscribe');
  278. }
  279. if ( ( $email == $this->site_email && is_email($this->site_email) ) || ( $email == get_settings('admin_email') && is_email(get_settings('admin_email')) ) )
  280. $this->add_error(__('This e-mail address may not be subscribed', 'subscribe-to-comments'),'solo_subscribe');
  281. if ( is_array($this->subscriptions_from_email($email)) )
  282. if (in_array($postid, (array) $this->subscriptions_from_email($email))) {
  283. // already subscribed
  284. setcookie('comment_author_email_' . COOKIEHASH, $email, time() + 30000000, COOKIEPATH);
  285. $this->add_error(__('You appear to be already subscribed to this entry.', 'subscribe-to-comments'),'solo_subscribe');
  286. }
  287. $email = $wpdb->escape($email);
  288. $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$postid' AND comment_status <> 'closed' AND ( post_status = 'static' OR post_status = 'publish') LIMIT 1");
  289. if ( !$post )
  290. $this->add_error(__('Comments are not allowed on this entry.', 'subscribe-to-comments'),'solo_subscribe');
  291. if ( empty($cache_userdata[$post->post_author]) && $post->post_author != 0) {
  292. $cache_userdata[$post->post_author] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $post->post_author");
  293. $cache_userdata[$cache_userdata[$post->post_author]->user_login] =& $cache_userdata[$post->post_author];
  294. }
  295. $post_author = $cache_userdata[$post->post_author];
  296. if ( strtolower($post_author->user_email) == ($email) )
  297. $this->add_error(__('You appear to be already subscribed to this entry.', 'subscribe-to-comments'),'solo_subscribe');
  298. if ( !is_array($this->errors['solo_subscribe']) ) {
  299. add_post_meta($postid, '_sg_subscribe-to-comments', $email);
  300. setcookie('comment_author_email_' . COOKIEHASH, $email, time() + 30000000, COOKIEPATH);
  301. $location = $this->manage_link($email, false, false) . '&subscribeid=' . $postid;
  302. header("Location: $location");
  303. exit();
  304. }
  305. }
  306. function add_subscriber($cid) {
  307. global $wpdb;
  308. $cid = (int) $cid;
  309. $id = (int) $id;
  310. $email = strtolower($wpdb->get_var("SELECT comment_author_email FROM $wpdb->comments WHERE comment_ID = '$cid'"));
  311. $email_sql = $wpdb->escape($email);
  312. $postid = $wpdb->get_var("SELECT comment_post_ID from $wpdb->comments WHERE comment_ID = '$cid'");
  313. $previously_subscribed = ( $wpdb->get_var("SELECT comment_subscribe from $wpdb->comments WHERE comment_post_ID = '$postid' AND LCASE(comment_author_email) = '$email_sql' AND comment_subscribe = 'Y' LIMIT 1") || in_array($email, (array) get_post_meta($postid, '_sg_subscribe-to-comments')) ) ? true : false;
  314. // If user wants to be notified or has previously subscribed, set the flag on this current comment
  315. if (($_POST['subscribe'] == 'subscribe' && is_email($email)) || $previously_subscribed) {
  316. delete_post_meta($postid, '_sg_subscribe-to-comments', $email);
  317. $wpdb->query("UPDATE $wpdb->comments SET comment_subscribe = 'Y' where comment_post_ID = '$postid' AND LCASE(comment_author_email) = '$email'");
  318. }
  319. return $cid;
  320. }
  321. function is_blocked($email='') {
  322. global $wpdb;
  323. if ( !is_email($email) )
  324. $email = $this->email;
  325. if ( empty($email) )
  326. return false;
  327. $email = strtolower($email);
  328. // add the option if it doesn't exist
  329. add_option('do_not_mail', '');
  330. $blocked = (array) explode (' ', get_settings('do_not_mail'));
  331. if ( in_array($email, $blocked) )
  332. return true;
  333. return false;
  334. }
  335. function add_block($email='') {
  336. if ( !is_email($email) )
  337. $email = $this->email;
  338. global $wpdb;
  339. $email = strtolower($email);
  340. // add the option if it doesn't exist
  341. add_option('do_not_mail', '');
  342. // check to make sure this email isn't already in there
  343. if ( !$this->is_blocked($email) ) {
  344. // email hasn't already been added - so add it
  345. $blocked = get_settings('do_not_mail') . ' ' . $email;
  346. update_option('do_not_mail', $blocked);
  347. return true;
  348. }
  349. return false;
  350. }
  351. function remove_block($email='') {
  352. if ( !is_email($email) )
  353. $email = $this->email;
  354. global $wpdb;
  355. $email = strtolower($email);
  356. if ( $this->is_blocked($email) ) {
  357. // e-mail is in the list - so remove it
  358. $blocked = str_replace (' ' . $email, '', explode (' ', get_settings('do_not_mail')));
  359. update_option('do_not_mail', $blocked);
  360. return true;
  361. }
  362. return false;
  363. }
  364. function has_subscribers() {
  365. if ( count($this->get_unique_subscribers()) > 0 )
  366. return true;
  367. return false;
  368. }
  369. function get_unique_subscribers() {
  370. global $comments, $comment, $sg_subscribers;
  371. if ( isset($sg_subscribers) )
  372. return $sg_subscribers;
  373. $sg_subscribers = array();
  374. $subscriber_emails = array();
  375. // We run the comment loop, and put each unique subscriber into a new array
  376. foreach ( (array) $comments as $comment ) {
  377. if ( comment_subscription_status() && !in_array($comment->comment_author_email, $subscriber_emails) ) {
  378. $sg_subscribers[] = $comment;
  379. $subscriber_emails[] = $comment->comment_author_email;
  380. }
  381. }
  382. return $sg_subscribers;
  383. }
  384. function hidden_form_fields() { ?>
  385. <input type="hidden" name="ref" value="<?php echo $this->ref; ?>" />
  386. <input type="hidden" name="key" value="<?php echo $this->key; ?>" />
  387. <input type="hidden" name="email" value="<?php echo $this->email; ?>" />
  388. <?php
  389. }
  390. function generate_key($data='') {
  391. if ( '' == $data )
  392. return false;
  393. if ( !$this->settings['salt'] )
  394. die('fatal error: corrupted salt');
  395. return md5(md5($this->settings['salt'] . $data));
  396. }
  397. function validate_key() {
  398. if ( $this->key == $this->generate_key($this->email) )
  399. $this->key_type = 'normal';
  400. elseif ( $this->key == $this->generate_key($this->email . $this->new_email) )
  401. $this->key_type = 'change_email';
  402. elseif ( $this->key == $this->generate_key($this->email . 'blockrequest') )
  403. $this->key_type = 'block';
  404. elseif ( current_user_can('manage_options') )
  405. $this->key_type = 'admin';
  406. else
  407. return false;
  408. return true;
  409. }
  410. function determine_action() {
  411. // rather than check it a bunch of times
  412. $is_email = is_email($this->email);
  413. if ( is_email($this->new_email) && $is_email && $this->key_type == 'change_email' )
  414. $this->action = 'change_email';
  415. elseif ( isset($_POST['removesubscrips']) && $is_email )
  416. $this->action = 'remove_subscriptions';
  417. elseif ( isset($_POST['removeBlock']) && $is_email && current_user_can('manage_options') )
  418. $this->action = 'remove_block';
  419. elseif ( isset($_POST['changeemailrequest']) && $is_email && is_email($this->new_email) )
  420. $this->action = 'email_change_request';
  421. elseif ( $is_email && isset($_POST['blockemail']) )
  422. $this->action = 'block_request';
  423. elseif ( isset($_GET['subscribeid']) )
  424. $this->action = 'solo_subscribe';
  425. elseif ( $is_email && isset($_GET['blockemailconfirm']) && $this->key == $this->generate_key($this->email . 'blockrequest') )
  426. $this->action = 'block';
  427. else
  428. $this->action = 'none';
  429. }
  430. function remove_subscriber($email, $postid) {
  431. global $wpdb;
  432. $postid = (int) $postid;
  433. $email = strtolower($email);
  434. $email_sql = $wpdb->escape($email);
  435. if ( delete_post_meta($postid, '_sg_subscribe-to-comments', $email) || $wpdb->query("UPDATE $wpdb->comments SET comment_subscribe = 'N' WHERE comment_post_ID = '$postid' AND LCASE(comment_author_email) ='$email_sql'") )
  436. return true;
  437. else
  438. return false;
  439. }
  440. function remove_subscriptions ($postids) {
  441. global $wpdb;
  442. $removed = 0;
  443. for ($i = 0; $i < count($postids); $i++) {
  444. if ( $this->remove_subscriber($this->email, $postids[$i]) )
  445. $removed++;
  446. }
  447. return $removed;
  448. }
  449. function send_notifications($cid) {
  450. global $wpdb;
  451. $cid = (int) $cid;
  452. $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$cid' LIMIT 1");
  453. $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
  454. if ( $comment->comment_approved == '1' && $comment->comment_type == '' ) {
  455. // Comment has been approved and isn't a trackback or a pingback, so we should send out notifications
  456. $message = sprintf(__("There is a new comment on the post \"%s\"", 'subscribe-to-comments') . ". \n%s\n\n", $post->post_title, get_permalink($comment->comment_post_ID));
  457. $message .= sprintf(__("Author: %s\n", 'subscribe-to-comments'), $comment->comment_author);
  458. $message .= __("Comment:\n", 'subscribe-to-comments') . $comment->comment_content . "\n\n";
  459. $message .= __("See all comments on this post here:\n", 'subscribe-to-comments');
  460. $message .= get_permalink($comment->comment_post_ID) . "#comments\n\n";
  461. //add link to manage comment notifications
  462. $message .= __("To manage your subscriptions or to block all notifications from this site, click the link below:\n", 'subscribe-to-comments');
  463. $message .= get_settings('home') . '/?wp-subscription-manager=1&email=[email]&key=[key]';
  464. $subject = sprintf(__('New Comment On: %s', 'subscribe-to-comments'), $post->post_title);
  465. $subscriptions = $this->subscriptions_from_post($comment->comment_post_ID);
  466. foreach ( (array) $subscriptions as $email ) {
  467. if ( !$this->is_blocked($email) && $email != $comment->comment_author_email && is_email($email) ) {
  468. $message_final = str_replace('[email]', urlencode($email), $message);
  469. $message_final = str_replace('[key]', $this->generate_key($email), $message_final);
  470. $this->send_mail($email, $subject, $message_final);
  471. }
  472. } // foreach subscription
  473. } // end if comment approved
  474. return $cid;
  475. }
  476. function change_email_request() {
  477. if ( $this->is_blocked() )
  478. return false;
  479. $subject = __('E-mail change confirmation', 'subscribe-to-comments');
  480. $message = sprintf(__("You are receiving this message to confirm a change of e-mail address for your subscriptions at \"%s\"\n\n", 'subscribe-to-comments'), get_bloginfo('blogname'));
  481. $message .= sprintf(__("To change your e-mail address to %s, click this link:\n\n", 'subscribe-to-comments'), $this->new_email);
  482. $message .= get_option('home') . "/?wp-subscription-manager=1&email=" . urlencode($this->email) . "&new_email=" . urlencode($this->new_email) . "&key=" . $this->generate_key($this->email . $this->new_email) . ".\n\n";
  483. $message .= __('If you did not request this action, please disregard this message.', 'subscribe-to-comments');
  484. return $this->send_mail($this->email, $subject, $message);
  485. }
  486. function block_email_request($email) {
  487. if ( $this->is_blocked($email) )
  488. return false;
  489. $subject = __('E-mail block confirmation', 'subscribe-to-comments');
  490. $message = sprintf(__("You are receiving this message to confirm that you no longer wish to receive e-mail comment notifications from \"%s\"\n\n", 'subscribe-to-comments'), get_bloginfo('name'));
  491. $message .= __("To cancel all future notifications for this address, click this link:\n\n", 'subscribe-to-comments');
  492. $message .= get_option('home') . "/?wp-subscription-manager=1&email=" . urlencode($email) . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";
  493. $message .= __("If you did not request this action, please disregard this message.", 'subscribe-to-comments');
  494. return $this->send_mail($email, $subject, $message);
  495. }
  496. function send_mail($to, $subject, $message) {
  497. $subject = '[' . get_bloginfo('name') . '] ' . $subject;
  498. // strip out some chars that might cause issues, and assemble vars
  499. $site_name = str_replace('"', "'", $this->site_name);
  500. $site_email = str_replace(array('<', '>'), array('', ''), $this->site_email);
  501. $charset = get_settings('blog_charset');
  502. $headers = "From: \"{$site_name}\" <{$site_email}>\n";
  503. $headers .= "MIME-Version: 1.0\n";
  504. $headers .= "Content-Type: text/plain; charset=\"{$charset}\"\n";
  505. return wp_mail($to, $subject, $message, $headers);
  506. }
  507. function change_email() {
  508. global $wpdb;
  509. $new_email = $wpdb->escape(strtolower($this->new_email));
  510. $email = $wpdb->escape(strtolower($this->email));
  511. if ( $wpdb->query("UPDATE $wpdb->comments SET comment_author_email = '$new_email' WHERE comment_author_email = '$email'") )
  512. $return = true;
  513. if ( $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$new_email' WHERE meta_value = '$email' AND meta_key = '_sg_subscribe-to-comments'") )
  514. $return = true;
  515. return $return;
  516. }
  517. function entry_link($postid, $uri='') {
  518. if ( empty($uri) )
  519. $uri = get_permalink($postid);
  520. $postid = (int) $postid;
  521. $title = get_the_title($postid);
  522. if ( empty($title) )
  523. $title = __('click here', 'subscribe-to-comments');
  524. $output = '<a href="'.$uri.'">'.$title.'</a>';
  525. return $output;
  526. }
  527. function sg_wp_head() { ?>
  528. <style type="text/css" media="screen">
  529. .updated-error {
  530. background-color: #FF8080;
  531. border: 1px solid #F00;
  532. }
  533. </style>
  534. <?php
  535. return true;
  536. }
  537. function db_upgrade_check () {
  538. global $wpdb;
  539. // add the options
  540. add_option('sg_subscribe_settings', array('use_custom_style' => '', 'email' => get_bloginfo('admin_email'), 'name' => get_bloginfo('name'), 'header' => '[theme_path]/header.php', 'sidebar' => '', 'footer' => '[theme_path]/footer.php', 'before_manager' => '<div id="content" class="widecolumn subscription-manager">', 'after_manager' => '</div>', 'not_subscribed_text' => __('Notify me of followup comments via e-mail', 'subscribe-to-comments'), 'subscribed_text' => __('You are subscribed to this entry. <a href="[manager_link]">Manage your subscriptions</a>.', 'subscribe-to-comments'), 'author_text' => __('You are the author of this entry. <a href="[manager_link]">Manage subscriptions</a>.', 'subscribe-to-comments'), 'version' => $this->version));
  541. $settings = get_option('sg_subscribe_settings');
  542. if ( !$settings ) { // work around WP 2.2/2.2.1 bug
  543. wp_redirect('http://' . $_SERVER['HTTP_HOST'] . add_query_arg('stcwpbug', '1'));
  544. exit;
  545. }
  546. if ( !$settings['salt'] ) {
  547. $settings['salt'] = md5(md5(uniqid(rand() . rand() . rand() . rand() . rand(), true))); // random MD5 hash
  548. $update = true;
  549. }
  550. if ( !$settings['clear_both'] ) {
  551. $settings['clear_both'] = 'clear_both';
  552. $update = true;
  553. }
  554. if ( !$settings['version'] ) {
  555. $settings = stripslashes_deep($settings);
  556. $update = true;
  557. }
  558. if ( $settings['not_subscribed_text'] == '' || $settings['subscribed_text'] == '' ) { // recover from WP 2.2/2.2.1 bug
  559. delete_option('sg_subscribe_settings');
  560. wp_redirect('http://' . $_SERVER['HTTP_HOST'] . add_query_arg('stcwpbug', '2'));
  561. exit;
  562. }
  563. if ( $update )
  564. $this->update_settings($settings);
  565. $column_name = 'comment_subscribe';
  566. foreach ( (array) $wpdb->get_col("DESC $wpdb->comments", 0) as $column )
  567. if ($column == $column_name)
  568. return true;
  569. // didn't find it... create it
  570. $wpdb->query("ALTER TABLE $wpdb->comments ADD COLUMN comment_subscribe enum('Y','N') NOT NULL default 'N'");
  571. }
  572. function update_settings($settings) {
  573. $settings['version'] = $this->version;
  574. update_option('sg_subscribe_settings', $settings);
  575. }
  576. function current_viewer_subscription_status(){
  577. global $wpdb, $post, $user_email;
  578. $comment_author_email = ( isset($_COOKIE['comment_author_email_'. COOKIEHASH]) ) ? trim($_COOKIE['comment_author_email_'. COOKIEHASH]) : '';
  579. get_currentuserinfo();
  580. if ( is_email($user_email) ) {
  581. $email = strtolower($user_email);
  582. $loggedin = true;
  583. } elseif ( is_email($comment_author_email) ) {
  584. $email = strtolower($comment_author_email);
  585. } else {
  586. return false;
  587. }
  588. $post_author = get_userdata($post->post_author);
  589. if ( strtolower($post_author->user_email) == $email && $loggedin )
  590. return 'admin';
  591. if ( is_array($this->subscriptions_from_email($email)) )
  592. if ( in_array($post->ID, (array) $this->email_subscriptions) )
  593. return $email;
  594. return false;
  595. }
  596. function manage_link($email='', $html=true, $echo=true) {
  597. $link = get_option('home') . '/?wp-subscription-manager=1';
  598. if ( $email != 'admin' ) {
  599. $link = add_query_arg('email', urlencode($email), $link);
  600. $link = add_query_arg('key', $this->generate_key($email), $link);
  601. }
  602. $link = add_query_arg('ref', rawurlencode('http://' . $_SERVER['HTTP_HOST'] . attribute_escape($_SERVER['REQUEST_URI'])), $link);
  603. //$link = str_replace('+', '%2B', $link);
  604. if ( $html )
  605. $link = htmlentities($link);
  606. if ( !$echo )
  607. return $link;
  608. echo $link;
  609. }
  610. function on_edit($cid) {
  611. global $wpdb;
  612. $comment = &get_comment($cid);
  613. if ( !is_email($comment->comment_author_email) && $comment->comment_subscribe == 'Y' )
  614. $wpdb->query("UPDATE $wpdb->comments SET comment_subscribe = 'N' WHERE comment_ID = '$comment->comment_ID' LIMIT 1");
  615. return $cid;
  616. }
  617. function add_admin_menu() {
  618. add_management_page(__('Comment Subscription Manager', 'subscribe-to-comments'), __('Subscriptions', 'subscribe-to-comments'), 8, 'stc-management', 'sg_subscribe_admin');
  619. add_options_page(__('Subscribe to Comments', 'subscribe-to-comments'), __('Subscribe to Comments', 'subscribe-to-comments'), 5, 'stc-options', array('sg_subscribe_settings', 'options_page'));
  620. }
  621. } // class sg_subscribe
  622. function stc_checkbox_state($data) {
  623. if ( isset($_POST['subscribe']) )
  624. setcookie('subscribe_checkbox_'. COOKIEHASH, 'checked', time() + 30000000, COOKIEPATH);
  625. else
  626. setcookie('subscribe_checkbox_'. COOKIEHASH, 'unchecked', time() + 30000000, COOKIEPATH);
  627. return $data;
  628. }
  629. function sg_subscribe_start() {
  630. global $sg_subscribe;
  631. if ( !$sg_subscribe ) {
  632. load_plugin_textdomain('subscribe-to-comments');
  633. $sg_subscribe = new sg_subscribe();
  634. }
  635. }
  636. // This will be overridden if the user manually places the function
  637. // in the comments form before the comment_form do_action() call
  638. add_action('comment_form', 'show_subscription_checkbox');
  639. // priority is very low (50) because we want to let anti-spam plugins have their way first.
  640. add_action('comment_post', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->send_notifications($a);'), 50);
  641. add_action('comment_post', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->add_subscriber($a);'));
  642. add_action('wp_set_comment_status', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->send_notifications($a);'));
  643. add_action('admin_menu', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); $sg_subscribe->add_admin_menu();'));
  644. add_action('admin_head', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); $sg_subscribe->sg_wp_head();'));
  645. add_action('edit_comment', array('sg_subscribe', 'on_edit'));
  646. // save users' checkbox preference
  647. add_filter('preprocess_comment', 'stc_checkbox_state', 1);
  648. // detect "subscribe without commenting" attempts
  649. add_action('init', create_function('$a','global $sg_subscribe; if ( $_POST[\'solo-comment-subscribe\'] == \'solo-comment-subscribe\' && is_numeric($_POST[\'postid\']) ) {
  650. sg_subscribe_start();
  651. $sg_subscribe->solo_subscribe(stripslashes($_POST[\'email\']), (int) $_POST[\'postid\']);
  652. }')
  653. );
  654. if ( isset($_REQUEST['wp-subscription-manager']) )
  655. add_action('template_redirect', 'sg_subscribe_admin_standalone');
  656. function sg_subscribe_admin_standalone() {
  657. sg_subscribe_admin(true);
  658. }
  659. function sg_subscribe_admin($standalone = false) {
  660. global $wpdb, $sg_subscribe;
  661. sg_subscribe_start();
  662. if ( $standalone ) {
  663. $sg_subscribe->form_action = get_option('home') . '/?wp-subscription-manager=1';
  664. $sg_subscribe->standalone = true;
  665. ob_start(create_function('$a', 'return str_replace("<title>", "<title> " . __("Subscription Manager", "subscribe-to-comments") . " &raquo; ", $a);'));
  666. } else {
  667. $sg_subscribe->form_action = 'edit.php?page=stc-management';
  668. $sg_subscribe->standalone = false;
  669. }
  670. $sg_subscribe->manager_init();
  671. get_currentuserinfo();
  672. if ( !$sg_subscribe->validate_key() )
  673. die ( __('You may not access this page without a valid key.', 'subscribe-to-comments') );
  674. $sg_subscribe->determine_action();
  675. switch ($sg_subscribe->action) :
  676. case "change_email" :
  677. if ( $sg_subscribe->change_email() ) {
  678. $sg_subscribe->add_message(sprintf(__('All notifications that were formerly sent to <strong>%1$s</strong> will now be sent to <strong>%2$s</strong>!', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->new_email));
  679. // change info to the new email
  680. $sg_subscribe->email = $sg_subscribe->new_email;
  681. unset($sg_subscribe->new_email);
  682. $sg_subscribe->key = $sg_subscribe->generate_key($sg_subscribe->email);
  683. $sg_subscribe->validate_key();
  684. }
  685. break;
  686. case "remove_subscriptions" :
  687. $postsremoved = $sg_subscribe->remove_subscriptions($_POST['subscrips']);
  688. if ( $postsremoved > 0 )
  689. $sg_subscribe->add_message(sprintf(__('<strong>%1$s</strong> %2$s removed successfully.', 'subscribe-to-comments'), $postsremoved, ($postsremoved != 1) ? __('subscriptions', 'subscribe-to-comments') : __('subscription', 'subscribe-to-comments')));
  690. break;
  691. case "remove_block" :
  692. if ( $sg_subscribe->remove_block($sg_subscribe->email) )
  693. $sg_subscribe->add_message(sprintf(__('The block on <strong>%s</strong> has been successfully removed.', 'subscribe-to-comments'), $sg_subscribe->email));
  694. else
  695. $sg_subscribe->add_error(sprintf(__('<strong>%s</strong> isn\'t blocked!', 'subscribe-to-comments'), $sg_subscribe->email), 'manager');
  696. break;
  697. case "email_change_request" :
  698. if ( $sg_subscribe->is_blocked($sg_subscribe->email) )
  699. $sg_subscribe->add_error(sprintf(__('<strong>%s</strong> has been blocked from receiving notifications. You will have to have the administrator remove the block before you will be able to change your notification address.', 'subscribe-to-comments'), $sg_subscribe->email));
  700. else
  701. if ($sg_subscribe->change_email_request($sg_subscribe->email, $sg_subscribe->new_email))
  702. $sg_subscribe->add_message(sprintf(__('Your change of e-mail request was successfully received. Please check your old account (<strong>%s</strong>) in order to confirm the change.', 'subscribe-to-comments'), $sg_subscribe->email));
  703. break;
  704. case "block_request" :
  705. if ($sg_subscribe->block_email_request($sg_subscribe->email ))
  706. $sg_subscribe->add_message(sprintf(__('Your request to block <strong>%s</strong> from receiving any further notifications has been received. In order for you to complete the block, please check your e-mail and click on the link in the message that has been sent to you.', 'subscribe-to-comments'), $sg_subscribe->email));
  707. break;
  708. case "solo_subscribe" :
  709. $sg_subscribe->add_message(sprintf(__('<strong>%1$s</strong> has been successfully subscribed to %2$s', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->entry_link($_GET['subscribeid'])));
  710. break;
  711. case "block" :
  712. if ($sg_subscribe->add_block($sg_subscribe->email))
  713. $sg_subscribe->add_message(sprintf(__('<strong>%1$s</strong> has been added to the "do not mail" list. You will no longer receive any notifications from this site. If this was done in error, please contact the <a href="mailto:%2$s">site administrator</a> to remove this block.', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->site_email));
  714. else
  715. $sg_subscribe->add_error(sprintf(__('<strong>%s</strong> has already been blocked!', 'subscribe-to-comments'), $sg_subscribe->email), 'manager');
  716. $sg_subscribe->key = $sg_subscribe->generate_key($sg_subscribe->email);
  717. $sg_subscribe->validate_key();
  718. break;
  719. endswitch;
  720. if ( $sg_subscribe->standalone ) {
  721. if ( !$sg_subscribe->use_wp_style && !empty($sg_subscribe->header) ) {
  722. @include($sg_subscribe->header);
  723. echo $sg_subscribe->before_manager;
  724. } else { ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  725. <html>
  726. <head>
  727. <title><?php printf(__('%s Comment Subscription Manager', 'subscribe-to-comments'), bloginfo('name')); ?></title>
  728. <style type="text/css" media="screen">
  729. @import url( <?php echo get_settings('siteurl'); ?>/wp-admin/wp-admin.css );
  730. </style>
  731. <link rel="stylesheet" type="text/css" media="print" href="<?php echo get_settings('siteurl'); ?>/print.css" />
  732. <meta http-equiv="Content-Type" content="text/html;
  733. charset=<?php bloginfo('charset'); ?>" />
  734. <?php $sg_subscribe->sg_wp_head(); ?>
  735. </head>
  736. <body>
  737. <?php } ?>
  738. <?php } ?>
  739. <?php $sg_subscribe->show_messages(); ?>
  740. <?php $sg_subscribe->show_errors(); ?>
  741. <div class="wrap">
  742. <h2><?php printf(__('%s Comment Subscription Manager', 'subscribe-to-comments'), bloginfo('name')); ?></h2>
  743. <?php if (!empty($sg_subscribe->ref)) : ?>
  744. <?php $sg_subscribe->add_message(sprintf(__('Return to the page you were viewing: %s', 'subscribe-to-comments'), $sg_subscribe->entry_link(url_to_postid($sg_subscribe->ref), $sg_subscribe->ref))); ?>
  745. <?php $sg_subscribe->show_messages(); ?>
  746. <?php endif; ?>
  747. <?php if ( $sg_subscribe->is_blocked() ) { ?>
  748. <?php if ( current_user_can('manage_options') ) : ?>
  749. <fieldset class="options">
  750. <legend><?php _e('Remove Block', 'subscribe-to-comments'); ?></legend>
  751. <p>
  752. <?php printf(__('Click the button below to remove the block on <strong>%s</strong>. This should only be done if the user has specifically requested it.', 'subscribe-to-comments'), $sg_subscribe->email); ?>
  753. </p>
  754. <form name="removeBlock" method="post" action="<?php echo $sg_subscribe->form_action; ?>">
  755. <input type="hidden" name="removeBlock" value="removeBlock /">
  756. <?php $sg_subscribe->hidden_form_fields(); ?>
  757. <p class="submit">
  758. <input type="submit" name="submit" value="<?php _e('Remove Block &raquo;', 'subscribe-to-comments'); ?>" />
  759. </p>
  760. </form>
  761. </fieldset>
  762. <?php else : ?>
  763. <fieldset class="options">
  764. <legend><?php _e('Blocked', 'subscribe-to-comments'); ?></legend>
  765. <p>
  766. <?php printf(__('You have indicated that you do not wish to receive any notifications at <strong>%1$s</strong> from this site. If this is incorrect, or if you wish to have the block removed, please contact the <a href="mailto:%2$s">site administrator</a>.', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->site_email); ?>
  767. </p>
  768. </fieldset>
  769. <?php endif; ?>
  770. <?php } else { ?>
  771. <?php $postlist = $sg_subscribe->subscriptions_from_email(); ?>
  772. <?php
  773. if ( isset($sg_subscribe->email) && !is_array($postlist) && $sg_subscribe->email != $sg_subscribe->site_email && $sg_subscribe->email != get_bloginfo('admin_email') ) {
  774. if ( is_email($sg_subscribe->email) )
  775. $sg_subscribe->add_error(sprintf(__('<strong>%s</strong> is not subscribed to any posts on this site.', 'subscribe-to-comments'), $sg_subscribe->email));
  776. else
  777. $sg_subscribe->add_error(sprintf(__('<strong>%s</strong> is not a valid e-mail address.', 'subscribe-to-comments'), $sg_subscribe->email));
  778. }
  779. ?>
  780. <?php $sg_subscribe->show_errors(); ?>
  781. <?php if ( current_user_can('manage_options') ) { ?>
  782. <fieldset class="options">
  783. <?php if ( $_REQUEST['email'] ) : ?>
  784. <p><a href="<?php echo $sg_subscribe->form_action; ?>"><?php _e('&laquo; Back'); ?></a></p>
  785. <?php endif; ?>
  786. <legend><?php _e('Find Subscriptions', 'subscribe-to-comments'); ?></legend>
  787. <p>
  788. <?php _e('Enter an e-mail address to view its subscriptions or undo a block.', 'subscribe-to-comments'); ?>
  789. </p>
  790. <form name="getemail" method="post" action="<?php echo $sg_subscribe->form_action; ?>">
  791. <input type="hidden" name="ref" value="<?php echo $sg_subscribe->ref; ?>" />
  792. <p>
  793. <input name="email" type="text" id="email" size="40" />
  794. <input type="submit" value="<?php _e('Search &raquo;', 'subscribe-to-comments'); ?>" />
  795. </p>
  796. </form>
  797. </fieldset>
  798. <?php if ( !$_REQUEST['email'] ) : ?>
  799. <fieldset class="options">
  800. <?php if ( !$_REQUEST['showallsubscribers'] ) : ?>
  801. <legend><?php _e('Top Subscriber List', 'subscribe-to-comments'); ?></legend>
  802. <?php else : ?>
  803. <legend><?php _e('Subscriber List', 'subscribe-to-comments'); ?></legend>
  804. <?php endif; ?>
  805. <?php
  806. $stc_limit = ( !$_REQUEST['showallsubscribers'] ) ? 'LIMIT 25' : '';
  807. $all_ct_subscriptions = $wpdb->get_results("SELECT distinct LCASE(comment_author_email) as email, count(distinct comment_post_ID) as ccount FROM $wpdb->comments WHERE comment_subscribe='Y' AND comment_approved = '1' GROUP BY email ORDER BY ccount DESC $stc_limit");
  808. $all_pm_subscriptions = $wpdb->get_results("SELECT distinct LCASE(meta_value) as email, count(post_id) as ccount FROM $wpdb->postmeta WHERE meta_key = '_sg_subscribe-to-comments' GROUP BY email ORDER BY ccount DESC $stc_limit");
  809. $all_subscriptions = array();
  810. foreach ( array('all_ct_subscriptions', 'all_pm_subscriptions') as $each ) {
  811. foreach ( (array) $$each as $sub ) {
  812. if ( !isset($all_subscriptions[$sub->email]) )
  813. $all_subscriptions[$sub->email] = (int) $sub->ccount;
  814. else
  815. $all_subscriptions[$sub->email] += (int) $sub->ccount;
  816. }
  817. }
  818. if ( !$_REQUEST['showallsubscribers'] ) : ?>
  819. <p><a href="<?php echo attribute_escape(add_query_arg('showallsubscribers', '1', $sg_subscribe->form_action)); ?>"><?php _e('Show all subscribers', 'subscribe-to-comments'); ?></a></p>
  820. <?php elseif ( !$_REQUEST['showccfield'] ) : ?>
  821. <p><a href="<?php echo add_query_arg('showccfield', '1'); ?>"><?php _e('Show list of subscribers in <code>CC:</code>-field format (for bulk e-mailing)', 'subscribe-to-comments'); ?></a></p>
  822. <?php else : ?>
  823. <p><a href="<?php echo attribute_escape($sg_subscribe->form_action); ?>"><?php _e('&laquo; Back to regular view'); ?></a></p>
  824. <p><textarea cols="60" rows="10"><?php echo implode(', ', array_keys($all_subscriptions) ); ?></textarea></p>
  825. <?php endif;
  826. if ( $all_subscriptions ) {
  827. if ( !$_REQUEST['showccfield'] ) {
  828. echo "<ul>\n";
  829. foreach ( (array) $all_subscriptions as $email => $ccount ) {
  830. $enc_email = urlencode($email);
  831. echo "<li>($ccount) <a href='" . attribute_escape($sg_subscribe->form_action . "&email=$enc_email") . "'>" . wp_specialchars($email) . "</a></li>\n";
  832. }
  833. echo "</ul>\n";
  834. }
  835. ?>
  836. <legend><?php _e('Top Subscribed Posts', 'subscribe-to-comments'); ?></legend>
  837. <?php
  838. $top_subscribed_posts1 = $wpdb->get_results("SELECT distinct comment_post_ID as post_id, count(distinct comment_author_email) as ccount FROM $wpdb->comments WHERE comment_subscribe='Y' AND comment_approved = '1' GROUP BY post_id ORDER BY ccount DESC LIMIT 25");
  839. $top_subscribed_posts2 = $wpdb->get_results("SELECT distinct post_id, count(distinct meta_value) as ccount FROM $wpdb->postmeta WHERE meta_key = '_sg_subscribe-to-comments' GROUP BY post_id ORDER BY ccount DESC LIMIT 25");
  840. $all_top_posts = array();
  841. foreach ( array('top_subscribed_posts1', 'top_subscribed_posts2') as $each ) {
  842. foreach ( (array) $$each as $pid ) {
  843. if ( !isset($all_top_posts[$pid->post_id]) )
  844. $all_top_posts[$pid->post_id] = (int) $pid->ccount;
  845. else
  846. $all_top_posts[$pid->post_id] += (int) $pid->ccount;
  847. }
  848. }
  849. arsort($all_top_posts);
  850. echo "<ul>\n";
  851. foreach ( $all_top_posts as $pid => $ccount ) {
  852. echo "<li>($ccount) <a href='" . get_permalink($pid) . "'>" . get_the_title($pid) . "</a></li>\n";
  853. }
  854. echo "</ul>";
  855. ?>
  856. <?php } ?>
  857. </fieldset>
  858. <?php endif; ?>
  859. <?php } ?>
  860. <?php if ( count($postlist) > 0 && is_array($postlist) ) { ?>
  861. <script type="text/javascript">
  862. <!--
  863. function checkAll(form) {
  864. for ( i = 0, n = form.elements.length; i < n; i++ ) {
  865. if ( form.elements[i].type == "checkbox" ) {
  866. if ( form.elements[i].checked == true )
  867. form.elements[i].checked = false;
  868. else
  869. form.elements[i].checked = true;
  870. }
  871. }
  872. }
  873. //-->
  874. </script>
  875. <fieldset class="options">
  876. <legend><?php _e('Subscriptions', 'subscribe-to-comments'); ?></legend>
  877. <p>
  878. <?php printf(__('<strong>%s</strong> is subscribed to the posts listed below. To unsubscribe to one or more posts, click the checkbox next to the title, then click "Remove Selected Subscription(s)" at the bottom of the list.', 'subscribe-to-comments'), $sg_subscribe->email); ?>
  879. </p>
  880. <form name="removeSubscription" id="removeSubscription" method="post" action="<?php echo $sg_subscribe->form_action; ?>">
  881. <input type="hidden" name="removesubscrips" value="removesubscrips" />
  882. <?php $sg_subscribe->hidden_form_fields(); ?>
  883. <ol>
  884. <?php for ($i = 0; $i < count($postlist); $i++) { ?>
  885. <li><label for="subscrip-<?php echo $i; ?>"><input id="subscrip-<?php echo $i; ?>" type="checkbox" name="subscrips[]" value="<?php echo $postlist[$i]; ?>" /> <?php echo $sg_subscribe->entry_link($postlist[$i]); ?></label></li>
  886. <?php } ?>
  887. </ol>
  888. <p>

Large files files are truncated, but you can click here to view the full file