Scriptygoddess
Author: Mark Jaquith
Author URI: http://txfx.net/
*/
/* This is the code that is inserted into the comment form */
function show_subscription_checkbox ($id='0') {
global $sg_subscribe;
sg_subscribe_start();
if ( $sg_subscribe->checkbox_shown ) return $id;
if ( !$email = $sg_subscribe->current_viewer_subscription_status() ) :
$checked_status = ( !empty($_COOKIE['subscribe_checkbox_'.COOKIEHASH]) && 'checked' == $_COOKIE['subscribe_checkbox_'.COOKIEHASH] ) ? true : false;
?>
checkbox_shown = true;
return $id;
}
/* -------------------------------------------------------------------- */
/* This function outputs a "subscribe without commenting" form. */
/* Place this somewhere within "the loop", but NOT within another form */
/* This is NOT inserted automaticallly... you must place it yourself */
/* -------------------------------------------------------------------- */
function show_manual_subscription_form() {
global $id, $sg_subscribe, $user_email;
sg_subscribe_start();
$sg_subscribe->show_errors('solo_subscribe', '
', '
', __('Error: ', 'subscribe-to-comments'), ' ');
if ( !$sg_subscribe->current_viewer_subscription_status() ) :
get_currentuserinfo(); ?>
comment_subscribe == 'Y') {
return true;
} else {
return false;
}
}
/* ============================= */
/* DO NOT MODIFY BELOW THIS LINE */
/* ============================= */
class sg_subscribe_settings {
function options_page_contents() {
global $sg_subscribe;
sg_subscribe_start();
if ( isset($_POST['sg_subscribe_settings_submit']) ) {
check_admin_referer('subscribe-to-comments-update_options');
$update_settings = stripslashes_deep($_POST['sg_subscribe_settings']);
$sg_subscribe->update_settings($update_settings);
}
echo '
'.__('Subscribe to Comments Options','subscribe-to-comments').'
';
echo '
';
echo '';
echo '';
echo '';
echo '
';
echo '';
echo '';
}
function checkflag($optname) {
$options = get_settings('sg_subscribe_settings');
if ( $options[$optname] != $optname )
return;
return ' checked="checked"';
}
function form_setting($optname) {
$options = get_settings('sg_subscribe_settings');
return attribute_escape($options[$optname]);
}
function textarea_setting($optname) {
$options = get_settings('sg_subscribe_settings');
return wp_specialchars($options[$optname]);
}
function options_page() {
/** Display "saved" notification on post **/
if ( isset($_POST['sg_subscribe_settings_submit']) )
echo '
';
echo '';
}
}
class sg_subscribe {
var $errors;
var $messages;
var $post_subscriptions;
var $email_subscriptions;
var $subscriber_email;
var $site_email;
var $site_name;
var $standalone;
var $form_action;
var $checkbox_shown;
var $use_wp_style;
var $header;
var $sidebar;
var $footer;
var $clear_both;
var $before_manager;
var $after_manager;
var $email;
var $new_email;
var $ref;
var $key;
var $key_type;
var $action;
var $default_subscribed;
var $not_subscribed_text;
var $subscribed_text;
var $author_text;
var $salt;
var $settings;
var $version = '2.1.2';
function sg_subscribe() {
global $wpdb;
$this->db_upgrade_check();
$this->settings = get_settings('sg_subscribe_settings');
$this->salt = $this->settings['salt'];
$this->site_email = ( is_email($this->settings['email']) && $this->settings['email'] != 'email@example.com' ) ? $this->settings['email'] : get_bloginfo('admin_email');
$this->site_name = ( $this->settings['name'] != 'YOUR NAME' && !empty($this->settings['name']) ) ? $this->settings['name'] : get_bloginfo('name');
$this->default_subscribed = ($this->settings['default_subscribed']) ? true : false;
$this->not_subscribed_text = $this->settings['not_subscribed_text'];
$this->subscribed_text = $this->settings['subscribed_text'];
$this->author_text = $this->settings['author_text'];
$this->clear_both = $this->settings['clear_both'];
$this->errors = '';
$this->post_subscriptions = array();
$this->email_subscriptions = '';
}
function manager_init() {
$this->messages = '';
$this->use_wp_style = ( $this->settings['use_custom_style'] == 'use_custom_style' ) ? false : true;
if ( !$this->use_wp_style ) {
$this->header = str_replace('[theme_path]', get_template_directory(), $this->settings['header']);
$this->sidebar = str_replace('[theme_path]', get_template_directory(), $this->settings['sidebar']);
$this->footer = str_replace('[theme_path]', get_template_directory(), $this->settings['footer']);
$this->before_manager = $this->settings['before_manager'];
$this->after_manager = $this->settings['after_manager'];
}
foreach ( array('email', 'key', 'ref', 'new_email') as $var )
if ( isset($_REQUEST[$var]) && !empty($_REQUEST[$var]) )
$this->{$var} = attribute_escape(trim(stripslashes($_REQUEST[$var])));
if ( !$this->key )
$this->key = 'unset';
}
function add_error($text='generic error', $type='manager') {
$this->errors[$type][] = $text;
}
function show_errors($type='manager', $before_all='
', $after_all='
', $before_each='
', $after_each='
'){
if ( is_array($this->errors[$type]) ) {
echo $before_all;
foreach ($this->errors[$type] as $error)
echo $before_each . $error . $after_each;
echo $after_all;
}
unset($this->errors);
}
function add_message($text) {
$this->messages[] = $text;
}
function show_messages($before_all='', $after_all='', $before_each='
', $after_each='
'){
if ( is_array($this->messages) ) {
echo $before_all;
foreach ($this->messages as $message)
echo $before_each . $message . $after_each;
echo $after_all;
}
unset($this->messages);
}
function subscriptions_from_post($postid) {
if ( is_array($this->post_subscriptions[$postid]) )
return $this->post_subscriptions[$postid];
global $wpdb;
$postid = (int) $postid;
$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)");
$subscribed_without_comment = (array) get_post_meta($postid, '_sg_subscribe-to-comments');
$this->post_subscriptions[$postid] = array_merge((array) $this->post_subscriptions[$postid], (array) $subscribed_without_comment);
$this->post_subscriptions[$postid] = array_unique($this->post_subscriptions[$postid]);
return $this->post_subscriptions[$postid];
}
function subscriptions_from_email($email='') {
if ( is_array($this->email_subscriptions) )
return $this->email_subscriptions;
if ( !is_email($email) )
$email = $this->email;
global $wpdb;
$email = $wpdb->escape(strtolower($email));
$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");
foreach ( (array) $subscriptions as $subscription )
$this->email_subscriptions[] = $subscription->comment_post_ID;
$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");
foreach ( (array) $subscriptions as $subscription)
$this->email_subscriptions[] = $subscription->post_id;
if ( is_array($this->email_subscriptions) ) {
sort($this->email_subscriptions, SORT_NUMERIC);
return $this->email_subscriptions;
}
return false;
}
function solo_subscribe ($email, $postid) {
global $wpdb, $cache_userdata, $user_email;
$postid = (int) $postid;
$email = strtolower($email);
if ( !is_email($email) ) {
get_currentuserinfo();
if ( is_email($user_email) )
$email = strtolower($user_email);
else
$this->add_error(__('Please provide a valid e-mail address.', 'subscribe-to-comments'),'solo_subscribe');
}
if ( ( $email == $this->site_email && is_email($this->site_email) ) || ( $email == get_settings('admin_email') && is_email(get_settings('admin_email')) ) )
$this->add_error(__('This e-mail address may not be subscribed', 'subscribe-to-comments'),'solo_subscribe');
if ( is_array($this->subscriptions_from_email($email)) )
if (in_array($postid, (array) $this->subscriptions_from_email($email))) {
// already subscribed
setcookie('comment_author_email_' . COOKIEHASH, $email, time() + 30000000, COOKIEPATH);
$this->add_error(__('You appear to be already subscribed to this entry.', 'subscribe-to-comments'),'solo_subscribe');
}
$email = $wpdb->escape($email);
$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");
if ( !$post )
$this->add_error(__('Comments are not allowed on this entry.', 'subscribe-to-comments'),'solo_subscribe');
if ( empty($cache_userdata[$post->post_author]) && $post->post_author != 0) {
$cache_userdata[$post->post_author] = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $post->post_author");
$cache_userdata[$cache_userdata[$post->post_author]->user_login] =& $cache_userdata[$post->post_author];
}
$post_author = $cache_userdata[$post->post_author];
if ( strtolower($post_author->user_email) == ($email) )
$this->add_error(__('You appear to be already subscribed to this entry.', 'subscribe-to-comments'),'solo_subscribe');
if ( !is_array($this->errors['solo_subscribe']) ) {
add_post_meta($postid, '_sg_subscribe-to-comments', $email);
setcookie('comment_author_email_' . COOKIEHASH, $email, time() + 30000000, COOKIEPATH);
$location = $this->manage_link($email, false, false) . '&subscribeid=' . $postid;
header("Location: $location");
exit();
}
}
function add_subscriber($cid) {
global $wpdb;
$cid = (int) $cid;
$id = (int) $id;
$email = strtolower($wpdb->get_var("SELECT comment_author_email FROM $wpdb->comments WHERE comment_ID = '$cid'"));
$email_sql = $wpdb->escape($email);
$postid = $wpdb->get_var("SELECT comment_post_ID from $wpdb->comments WHERE comment_ID = '$cid'");
$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;
// If user wants to be notified or has previously subscribed, set the flag on this current comment
if (($_POST['subscribe'] == 'subscribe' && is_email($email)) || $previously_subscribed) {
delete_post_meta($postid, '_sg_subscribe-to-comments', $email);
$wpdb->query("UPDATE $wpdb->comments SET comment_subscribe = 'Y' where comment_post_ID = '$postid' AND LCASE(comment_author_email) = '$email'");
}
return $cid;
}
function is_blocked($email='') {
global $wpdb;
if ( !is_email($email) )
$email = $this->email;
if ( empty($email) )
return false;
$email = strtolower($email);
// add the option if it doesn't exist
add_option('do_not_mail', '');
$blocked = (array) explode (' ', get_settings('do_not_mail'));
if ( in_array($email, $blocked) )
return true;
return false;
}
function add_block($email='') {
if ( !is_email($email) )
$email = $this->email;
global $wpdb;
$email = strtolower($email);
// add the option if it doesn't exist
add_option('do_not_mail', '');
// check to make sure this email isn't already in there
if ( !$this->is_blocked($email) ) {
// email hasn't already been added - so add it
$blocked = get_settings('do_not_mail') . ' ' . $email;
update_option('do_not_mail', $blocked);
return true;
}
return false;
}
function remove_block($email='') {
if ( !is_email($email) )
$email = $this->email;
global $wpdb;
$email = strtolower($email);
if ( $this->is_blocked($email) ) {
// e-mail is in the list - so remove it
$blocked = str_replace (' ' . $email, '', explode (' ', get_settings('do_not_mail')));
update_option('do_not_mail', $blocked);
return true;
}
return false;
}
function has_subscribers() {
if ( count($this->get_unique_subscribers()) > 0 )
return true;
return false;
}
function get_unique_subscribers() {
global $comments, $comment, $sg_subscribers;
if ( isset($sg_subscribers) )
return $sg_subscribers;
$sg_subscribers = array();
$subscriber_emails = array();
// We run the comment loop, and put each unique subscriber into a new array
foreach ( (array) $comments as $comment ) {
if ( comment_subscription_status() && !in_array($comment->comment_author_email, $subscriber_emails) ) {
$sg_subscribers[] = $comment;
$subscriber_emails[] = $comment->comment_author_email;
}
}
return $sg_subscribers;
}
function hidden_form_fields() { ?>
settings['salt'] )
die('fatal error: corrupted salt');
return md5(md5($this->settings['salt'] . $data));
}
function validate_key() {
if ( $this->key == $this->generate_key($this->email) )
$this->key_type = 'normal';
elseif ( $this->key == $this->generate_key($this->email . $this->new_email) )
$this->key_type = 'change_email';
elseif ( $this->key == $this->generate_key($this->email . 'blockrequest') )
$this->key_type = 'block';
elseif ( current_user_can('manage_options') )
$this->key_type = 'admin';
else
return false;
return true;
}
function determine_action() {
// rather than check it a bunch of times
$is_email = is_email($this->email);
if ( is_email($this->new_email) && $is_email && $this->key_type == 'change_email' )
$this->action = 'change_email';
elseif ( isset($_POST['removesubscrips']) && $is_email )
$this->action = 'remove_subscriptions';
elseif ( isset($_POST['removeBlock']) && $is_email && current_user_can('manage_options') )
$this->action = 'remove_block';
elseif ( isset($_POST['changeemailrequest']) && $is_email && is_email($this->new_email) )
$this->action = 'email_change_request';
elseif ( $is_email && isset($_POST['blockemail']) )
$this->action = 'block_request';
elseif ( isset($_GET['subscribeid']) )
$this->action = 'solo_subscribe';
elseif ( $is_email && isset($_GET['blockemailconfirm']) && $this->key == $this->generate_key($this->email . 'blockrequest') )
$this->action = 'block';
else
$this->action = 'none';
}
function remove_subscriber($email, $postid) {
global $wpdb;
$postid = (int) $postid;
$email = strtolower($email);
$email_sql = $wpdb->escape($email);
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'") )
return true;
else
return false;
}
function remove_subscriptions ($postids) {
global $wpdb;
$removed = 0;
for ($i = 0; $i < count($postids); $i++) {
if ( $this->remove_subscriber($this->email, $postids[$i]) )
$removed++;
}
return $removed;
}
function send_notifications($cid) {
global $wpdb;
$cid = (int) $cid;
$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$cid' LIMIT 1");
$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
if ( $comment->comment_approved == '1' && $comment->comment_type == '' ) {
// Comment has been approved and isn't a trackback or a pingback, so we should send out notifications
$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));
$message .= sprintf(__("Author: %s\n", 'subscribe-to-comments'), $comment->comment_author);
$message .= __("Comment:\n", 'subscribe-to-comments') . $comment->comment_content . "\n\n";
$message .= __("See all comments on this post here:\n", 'subscribe-to-comments');
$message .= get_permalink($comment->comment_post_ID) . "#comments\n\n";
//add link to manage comment notifications
$message .= __("To manage your subscriptions or to block all notifications from this site, click the link below:\n", 'subscribe-to-comments');
$message .= get_settings('home') . '/?wp-subscription-manager=1&email=[email]&key=[key]';
$subject = sprintf(__('New Comment On: %s', 'subscribe-to-comments'), $post->post_title);
$subscriptions = $this->subscriptions_from_post($comment->comment_post_ID);
foreach ( (array) $subscriptions as $email ) {
if ( !$this->is_blocked($email) && $email != $comment->comment_author_email && is_email($email) ) {
$message_final = str_replace('[email]', urlencode($email), $message);
$message_final = str_replace('[key]', $this->generate_key($email), $message_final);
$this->send_mail($email, $subject, $message_final);
}
} // foreach subscription
} // end if comment approved
return $cid;
}
function change_email_request() {
if ( $this->is_blocked() )
return false;
$subject = __('E-mail change confirmation', 'subscribe-to-comments');
$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'));
$message .= sprintf(__("To change your e-mail address to %s, click this link:\n\n", 'subscribe-to-comments'), $this->new_email);
$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";
$message .= __('If you did not request this action, please disregard this message.', 'subscribe-to-comments');
return $this->send_mail($this->email, $subject, $message);
}
function block_email_request($email) {
if ( $this->is_blocked($email) )
return false;
$subject = __('E-mail block confirmation', 'subscribe-to-comments');
$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'));
$message .= __("To cancel all future notifications for this address, click this link:\n\n", 'subscribe-to-comments');
$message .= get_option('home') . "/?wp-subscription-manager=1&email=" . urlencode($email) . "&key=" . $this->generate_key($email . 'blockrequest') . "&blockemailconfirm=true" . ".\n\n";
$message .= __("If you did not request this action, please disregard this message.", 'subscribe-to-comments');
return $this->send_mail($email, $subject, $message);
}
function send_mail($to, $subject, $message) {
$subject = '[' . get_bloginfo('name') . '] ' . $subject;
// strip out some chars that might cause issues, and assemble vars
$site_name = str_replace('"', "'", $this->site_name);
$site_email = str_replace(array('<', '>'), array('', ''), $this->site_email);
$charset = get_settings('blog_charset');
$headers = "From: \"{$site_name}\" <{$site_email}>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"{$charset}\"\n";
return wp_mail($to, $subject, $message, $headers);
}
function change_email() {
global $wpdb;
$new_email = $wpdb->escape(strtolower($this->new_email));
$email = $wpdb->escape(strtolower($this->email));
if ( $wpdb->query("UPDATE $wpdb->comments SET comment_author_email = '$new_email' WHERE comment_author_email = '$email'") )
$return = true;
if ( $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$new_email' WHERE meta_value = '$email' AND meta_key = '_sg_subscribe-to-comments'") )
$return = true;
return $return;
}
function entry_link($postid, $uri='') {
if ( empty($uri) )
$uri = get_permalink($postid);
$postid = (int) $postid;
$title = get_the_title($postid);
if ( empty($title) )
$title = __('click here', 'subscribe-to-comments');
$output = ''.$title.'';
return $output;
}
function sg_wp_head() { ?>
'', 'email' => get_bloginfo('admin_email'), 'name' => get_bloginfo('name'), 'header' => '[theme_path]/header.php', 'sidebar' => '', 'footer' => '[theme_path]/footer.php', 'before_manager' => '
', 'after_manager' => '
', 'not_subscribed_text' => __('Notify me of followup comments via e-mail', 'subscribe-to-comments'), 'subscribed_text' => __('You are subscribed to this entry. Manage your subscriptions.', 'subscribe-to-comments'), 'author_text' => __('You are the author of this entry. Manage subscriptions.', 'subscribe-to-comments'), 'version' => $this->version));
$settings = get_option('sg_subscribe_settings');
if ( !$settings ) { // work around WP 2.2/2.2.1 bug
wp_redirect('http://' . $_SERVER['HTTP_HOST'] . add_query_arg('stcwpbug', '1'));
exit;
}
if ( !$settings['salt'] ) {
$settings['salt'] = md5(md5(uniqid(rand() . rand() . rand() . rand() . rand(), true))); // random MD5 hash
$update = true;
}
if ( !$settings['clear_both'] ) {
$settings['clear_both'] = 'clear_both';
$update = true;
}
if ( !$settings['version'] ) {
$settings = stripslashes_deep($settings);
$update = true;
}
if ( $settings['not_subscribed_text'] == '' || $settings['subscribed_text'] == '' ) { // recover from WP 2.2/2.2.1 bug
delete_option('sg_subscribe_settings');
wp_redirect('http://' . $_SERVER['HTTP_HOST'] . add_query_arg('stcwpbug', '2'));
exit;
}
if ( $update )
$this->update_settings($settings);
$column_name = 'comment_subscribe';
foreach ( (array) $wpdb->get_col("DESC $wpdb->comments", 0) as $column )
if ($column == $column_name)
return true;
// didn't find it... create it
$wpdb->query("ALTER TABLE $wpdb->comments ADD COLUMN comment_subscribe enum('Y','N') NOT NULL default 'N'");
}
function update_settings($settings) {
$settings['version'] = $this->version;
update_option('sg_subscribe_settings', $settings);
}
function current_viewer_subscription_status(){
global $wpdb, $post, $user_email;
$comment_author_email = ( isset($_COOKIE['comment_author_email_'. COOKIEHASH]) ) ? trim($_COOKIE['comment_author_email_'. COOKIEHASH]) : '';
get_currentuserinfo();
if ( is_email($user_email) ) {
$email = strtolower($user_email);
$loggedin = true;
} elseif ( is_email($comment_author_email) ) {
$email = strtolower($comment_author_email);
} else {
return false;
}
$post_author = get_userdata($post->post_author);
if ( strtolower($post_author->user_email) == $email && $loggedin )
return 'admin';
if ( is_array($this->subscriptions_from_email($email)) )
if ( in_array($post->ID, (array) $this->email_subscriptions) )
return $email;
return false;
}
function manage_link($email='', $html=true, $echo=true) {
$link = get_option('home') . '/?wp-subscription-manager=1';
if ( $email != 'admin' ) {
$link = add_query_arg('email', urlencode($email), $link);
$link = add_query_arg('key', $this->generate_key($email), $link);
}
$link = add_query_arg('ref', rawurlencode('http://' . $_SERVER['HTTP_HOST'] . attribute_escape($_SERVER['REQUEST_URI'])), $link);
//$link = str_replace('+', '%2B', $link);
if ( $html )
$link = htmlentities($link);
if ( !$echo )
return $link;
echo $link;
}
function on_edit($cid) {
global $wpdb;
$comment = &get_comment($cid);
if ( !is_email($comment->comment_author_email) && $comment->comment_subscribe == 'Y' )
$wpdb->query("UPDATE $wpdb->comments SET comment_subscribe = 'N' WHERE comment_ID = '$comment->comment_ID' LIMIT 1");
return $cid;
}
function add_admin_menu() {
add_management_page(__('Comment Subscription Manager', 'subscribe-to-comments'), __('Subscriptions', 'subscribe-to-comments'), 8, 'stc-management', 'sg_subscribe_admin');
add_options_page(__('Subscribe to Comments', 'subscribe-to-comments'), __('Subscribe to Comments', 'subscribe-to-comments'), 5, 'stc-options', array('sg_subscribe_settings', 'options_page'));
}
} // class sg_subscribe
function stc_checkbox_state($data) {
if ( isset($_POST['subscribe']) )
setcookie('subscribe_checkbox_'. COOKIEHASH, 'checked', time() + 30000000, COOKIEPATH);
else
setcookie('subscribe_checkbox_'. COOKIEHASH, 'unchecked', time() + 30000000, COOKIEPATH);
return $data;
}
function sg_subscribe_start() {
global $sg_subscribe;
if ( !$sg_subscribe ) {
load_plugin_textdomain('subscribe-to-comments');
$sg_subscribe = new sg_subscribe();
}
}
// This will be overridden if the user manually places the function
// in the comments form before the comment_form do_action() call
add_action('comment_form', 'show_subscription_checkbox');
// priority is very low (50) because we want to let anti-spam plugins have their way first.
add_action('comment_post', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->send_notifications($a);'), 50);
add_action('comment_post', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->add_subscriber($a);'));
add_action('wp_set_comment_status', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); return $sg_subscribe->send_notifications($a);'));
add_action('admin_menu', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); $sg_subscribe->add_admin_menu();'));
add_action('admin_head', create_function('$a', 'global $sg_subscribe; sg_subscribe_start(); $sg_subscribe->sg_wp_head();'));
add_action('edit_comment', array('sg_subscribe', 'on_edit'));
// save users' checkbox preference
add_filter('preprocess_comment', 'stc_checkbox_state', 1);
// detect "subscribe without commenting" attempts
add_action('init', create_function('$a','global $sg_subscribe; if ( $_POST[\'solo-comment-subscribe\'] == \'solo-comment-subscribe\' && is_numeric($_POST[\'postid\']) ) {
sg_subscribe_start();
$sg_subscribe->solo_subscribe(stripslashes($_POST[\'email\']), (int) $_POST[\'postid\']);
}')
);
if ( isset($_REQUEST['wp-subscription-manager']) )
add_action('template_redirect', 'sg_subscribe_admin_standalone');
function sg_subscribe_admin_standalone() {
sg_subscribe_admin(true);
}
function sg_subscribe_admin($standalone = false) {
global $wpdb, $sg_subscribe;
sg_subscribe_start();
if ( $standalone ) {
$sg_subscribe->form_action = get_option('home') . '/?wp-subscription-manager=1';
$sg_subscribe->standalone = true;
ob_start(create_function('$a', 'return str_replace("", " " . __("Subscription Manager", "subscribe-to-comments") . " » ", $a);'));
} else {
$sg_subscribe->form_action = 'edit.php?page=stc-management';
$sg_subscribe->standalone = false;
}
$sg_subscribe->manager_init();
get_currentuserinfo();
if ( !$sg_subscribe->validate_key() )
die ( __('You may not access this page without a valid key.', 'subscribe-to-comments') );
$sg_subscribe->determine_action();
switch ($sg_subscribe->action) :
case "change_email" :
if ( $sg_subscribe->change_email() ) {
$sg_subscribe->add_message(sprintf(__('All notifications that were formerly sent to %1$s will now be sent to %2$s!', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->new_email));
// change info to the new email
$sg_subscribe->email = $sg_subscribe->new_email;
unset($sg_subscribe->new_email);
$sg_subscribe->key = $sg_subscribe->generate_key($sg_subscribe->email);
$sg_subscribe->validate_key();
}
break;
case "remove_subscriptions" :
$postsremoved = $sg_subscribe->remove_subscriptions($_POST['subscrips']);
if ( $postsremoved > 0 )
$sg_subscribe->add_message(sprintf(__('%1$s %2$s removed successfully.', 'subscribe-to-comments'), $postsremoved, ($postsremoved != 1) ? __('subscriptions', 'subscribe-to-comments') : __('subscription', 'subscribe-to-comments')));
break;
case "remove_block" :
if ( $sg_subscribe->remove_block($sg_subscribe->email) )
$sg_subscribe->add_message(sprintf(__('The block on %s has been successfully removed.', 'subscribe-to-comments'), $sg_subscribe->email));
else
$sg_subscribe->add_error(sprintf(__('%s isn\'t blocked!', 'subscribe-to-comments'), $sg_subscribe->email), 'manager');
break;
case "email_change_request" :
if ( $sg_subscribe->is_blocked($sg_subscribe->email) )
$sg_subscribe->add_error(sprintf(__('%s 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));
else
if ($sg_subscribe->change_email_request($sg_subscribe->email, $sg_subscribe->new_email))
$sg_subscribe->add_message(sprintf(__('Your change of e-mail request was successfully received. Please check your old account (%s) in order to confirm the change.', 'subscribe-to-comments'), $sg_subscribe->email));
break;
case "block_request" :
if ($sg_subscribe->block_email_request($sg_subscribe->email ))
$sg_subscribe->add_message(sprintf(__('Your request to block %s 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));
break;
case "solo_subscribe" :
$sg_subscribe->add_message(sprintf(__('%1$s has been successfully subscribed to %2$s', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->entry_link($_GET['subscribeid'])));
break;
case "block" :
if ($sg_subscribe->add_block($sg_subscribe->email))
$sg_subscribe->add_message(sprintf(__('%1$s 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 site administrator to remove this block.', 'subscribe-to-comments'), $sg_subscribe->email, $sg_subscribe->site_email));
else
$sg_subscribe->add_error(sprintf(__('%s has already been blocked!', 'subscribe-to-comments'), $sg_subscribe->email), 'manager');
$sg_subscribe->key = $sg_subscribe->generate_key($sg_subscribe->email);
$sg_subscribe->validate_key();
break;
endswitch;
if ( $sg_subscribe->standalone ) {
if ( !$sg_subscribe->use_wp_style && !empty($sg_subscribe->header) ) {
@include($sg_subscribe->header);
echo $sg_subscribe->before_manager;
} else { ?>
sg_wp_head(); ?>
show_messages(); ?>
show_errors(); ?>
ref)) : ?>
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))); ?>
show_messages(); ?>
is_blocked() ) { ?>
subscriptions_from_email(); ?>
email) && !is_array($postlist) && $sg_subscribe->email != $sg_subscribe->site_email && $sg_subscribe->email != get_bloginfo('admin_email') ) {
if ( is_email($sg_subscribe->email) )
$sg_subscribe->add_error(sprintf(__('%s is not subscribed to any posts on this site.', 'subscribe-to-comments'), $sg_subscribe->email));
else
$sg_subscribe->add_error(sprintf(__('%s is not a valid e-mail address.', 'subscribe-to-comments'), $sg_subscribe->email));
}
?>
show_errors(); ?>
0 && is_array($postlist) ) { ?>
standalone ) : ?>
use_wp_style ) :
echo $sg_subscribe->after_manager;
if ( !empty($sg_subscribe->sidebar) )
@include_once($sg_subscribe->sidebar);
if ( !empty($sg_subscribe->footer) )
@include_once($sg_subscribe->footer);
?>