<?php
class s2class {
function load_translations() {
load_plugin_textdomain('subscribe2', false, S2DIR);
load_plugin_textdomain('subscribe2', false, S2DIR . "languages/");
$mofile = WP_LANG_DIR . '/subscribe2-' . apply_filters('plugin_locale', get_locale(), 'subscribe2') . '.mo';
load_textdomain('subscribe2', $mofile);
}
function install() {
$this->load_translations();
if ( !function_exists('maybe_create_table') ) {
require_once(ABSPATH . 'wp-admin/install-helper.php');
}
$date = date('Y-m-d');
$sql = "CREATE TABLE $this->public (
id int(11) NOT NULL auto_increment,
email varchar(64) NOT NULL default '',
active tinyint(1) default 0,
date DATE default '$date' NOT NULL,
time TIME DEFAULT '00:00:00' NOT NULL,
ip char(64) NOT NULL default 'admin',
conf_date DATE,
conf_time TIME,
conf_ip char(64),
PRIMARY KEY (id) )";
maybe_create_table($this->public, $sql);
$users = $this->get_all_registered('ID');
if ( !empty($users) ) {
foreach ( $users as $user_ID ) {
$check_format = get_user_meta($user_ID, $this->get_usermeta_keyname('s2_format'), true);
if ( empty($check_format) ) {
$this->register($user_ID);
}
}
}
if ( !is_array($this->subscribe2_options) ) {
$this->reset();
}
}
function upgrade() {
$this->load_translations();
require(S2PATH . "classes/class-s2-upgrade.php");
global $s2_upgrade;
$s2_upgrade = new s2class_upgrade;
require(S2PATH . "include/options.php");
if ( !isset($this->subscribe2_options['version']) ) {
$this->subscribe2_options['version'] = '2.0';
}
$s2_upgrade->upgrade_core();
if ( version_compare($this->subscribe2_options['version'], '2.3', '<') ) {
$s2_upgrade->upgrade23();
$this->subscribe2_options['version'] = '2.3';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '5.1', '<') ) {
$s2_upgrade->upgrade51();
$this->subscribe2_options['version'] = '5.1';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '5.6', '<') ) {
$s2_upgrade->upgrade56();
$this->subscribe2_options['version'] = '5.6';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '5.9', '<') ) {
$s2_upgrade->upgrade59();
$this->subscribe2_options['version'] = '5.9';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '6.4', '<') ) {
$s2_upgrade->upgrade64();
$this->subscribe2_options['version'] = '6.4';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '7.0', '<') ) {
$s2_upgrade->upgrade70();
$this->subscribe2_options['version'] = '7.0';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '8.5', '<') ) {
$s2_upgrade->upgrade85();
$this->subscribe2_options['version'] = '8.5';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '8.6', '<') ) {
$s2_upgrade->upgrade86();
$this->subscribe2_options['version'] = '8.6';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '8.8', '<') ) {
$s2_upgrade->upgrade88();
$this->subscribe2_options['version'] = '8.8';
update_option('subscribe2_options', $this->subscribe2_options);
}
if ( version_compare($this->subscribe2_options['version'], '10.0', '<') ) {
$s2_upgrade->upgrade100();
$this->subscribe2_options['version'] = '10.0';
}
$this->subscribe2_options['version'] = S2VERSION;
update_option('subscribe2_options', $this->subscribe2_options);
return;
}
function reset() {
$this->load_translations();
delete_option('subscribe2_options');
wp_clear_scheduled_hook('s2_digest_cron');
unset($this->subscribe2_options);
require(S2PATH . "include/options.php");
$this->subscribe2_options['version'] = S2VERSION;
update_option('subscribe2_options', $this->subscribe2_options);
}
function substitute($string = '') {
if ( '' == $string ) {
return;
}
$string = str_replace("{BLOGNAME}", html_entity_decode(get_option('blogname'), ENT_QUOTES), $string);
$string = str_replace("{BLOGLINK}", get_option('home'), $string);
$string = str_replace("{TITLE}", stripslashes($this->post_title), $string);
$link = "<a href=\"" . $this->get_tracking_link($this->permalink) . "\">" . $this->get_tracking_link($this->permalink) . "</a>";
$string = str_replace("{PERMALINK}", $link, $string);
if ( strstr($string, "{TINYLINK}") ) {
$tinylink = file_get_contents('http:
if ( $tinylink !== 'Error' && $tinylink != false ) {
$tlink = "<a href=\"" . $tinylink . "\">" . $tinylink . "</a>";
$string = str_replace("{TINYLINK}", $tlink, $string);
} else {
$string = str_replace("{TINYLINK}", $link, $string);
}
}
$string = str_replace("{DATE}", $this->post_date, $string);
$string = str_replace("{TIME}", $this->post_time, $string);
$string = str_replace("{MYNAME}", stripslashes($this->myname), $string);
$string = str_replace("{EMAIL}", $this->myemail, $string);
$string = str_replace("{AUTHORNAME}", stripslashes($this->authorname), $string);
$string = str_replace("{CATS}", $this->post_cat_names, $string);
$string = str_replace("{TAGS}", $this->post_tag_names, $string);
$string = str_replace("{COUNT}", $this->post_count, $string);
return apply_filters('s2_custom_keywords', $string);
}
function mail($recipients = array(), $subject = '', $message = '', $type = 'text', $attachments = array()) {
if ( empty($recipients) || '' == $message ) { return; }
$subject = strip_tags(html_entity_decode($subject, ENT_QUOTES));
$subject = apply_filters('s2_email_subject', $subject);
if ( 'html' == $type ) {
$headers = $this->headers('html', $attachments);
if ( 'yes' == $this->subscribe2_options['stylesheet'] ) {
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title><link rel=\"stylesheet\" href=\"" . get_stylesheet_uri() . "\" type=\"text/css\" media=\"screen\" /></head><body>" . $message . "</body></html>", $subject, $message);
} else {
$mailtext = apply_filters('s2_html_email', "<html><head><title>" . $subject . "</title></head><body>" . $message . "</body></html>", $subject, $message);
}
} else {
$headers = $this->headers('text', $attachments);
$message = html_entity_decode($message, ENT_NOQUOTES, 'UTF-8');
$message = wordwrap(strip_tags($message), $this->word_wrap, "\n");
$mailtext = apply_filters('s2_plain_email', $message);
}
$bcc = '';
natcasesort($recipients);
if ( function_exists('wpmq_mail') || $this->subscribe2_options['bcclimit'] == 1 || count($recipients) == 1 ) {
foreach ( $recipients as $recipient ) {
$recipient = trim($recipient);
if ( !is_email($recipient) || empty($recipient) ) { continue; }
if ( function_exists('wpmq_mail') && !$this->preview_email ) {
@wp_mail($recipient, $subject, $mailtext, $headers, $attachments, 0);
} else {
@wp_mail($recipient, $subject, $mailtext, $headers, $attachments);
}
}
return true;
} elseif ( $this->subscribe2_options['bcclimit'] == 0 ) {
foreach ( $recipients as $recipient ) {
$recipient = trim($recipient);
if ( !is_email($recipient) ) { continue; }
if ( !empty($recipient) && $this->myemail != $recipient ) {
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
}
}
$headers .= "$bcc\n";
} else {
$count = 1;
$batch = array();
foreach ( $recipients as $recipient ) {
$recipient = trim($recipient);
if ( !is_email($recipient) ) { continue; }
if ( !empty($recipient) && $this->myemail != $recipient ) {
('' == $bcc) ? $bcc = "Bcc: $recipient" : $bcc .= ", $recipient";
}
if ( $this->subscribe2_options['bcclimit'] == $count ) {
$count = 0;
$batch[] = $bcc;
$bcc = '';
}
$count++;
}
if ( '' != $bcc ) {
$batch[] = $bcc;
}
}
reset($recipients);
if ( isset($batch) && !empty($batch) ) {
foreach ( $batch as $bcc ) {
$newheaders = $headers . "$bcc\n";
$status = @wp_mail($this->myemail, $subject, $mailtext, $newheaders, $attachments);
}
} else {
$status = @wp_mail($this->myemail, $subject, $mailtext, $headers, $attachments);
}
return $status;
}
function headers($type = 'text', $attachments = array()) {
if ( empty($this->myname) || empty($this->myemail) ) {
if ( $this->subscribe2_options['sender'] == 'blogname' ) {
$this->myname = html_entity_decode(get_option('blogname'), ENT_QUOTES);
$this->myemail = get_option('admin_email');
} else {
$admin = $this->get_userdata($this->subscribe2_options['sender']);
$this->myname = html_entity_decode($admin->display_name, ENT_QUOTES);
$this->myemail = $admin->user_email;
if ( empty($this->myname) ) {
$this->myname = html_entity_decode(get_option('blogname'), ENT_QUOTES);
}
if ( empty($this->myemail) ) {
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
$this->myemail = 'wordpress@' . $sitename;
}
}
}
$char_set = get_option('blog_charset');
if ( function_exists('mb_encode_mimeheader') ) {
$header['From'] = mb_encode_mimeheader($this->myname, $char_set, 'Q') . " <" . $this->myemail . ">";
$header['Reply-To'] = mb_encode_mimeheader($this->myname, $char_set, 'Q') . " <" . $this->myemail . ">";
} else {
$header['From'] = $this->myname. " <" . $this->myemail . ">";
$header['Reply-To'] = $this->myname . " <" . $this->myemail . ">";
}
$header['Return-path'] = "<" . $this->myemail . ">";
$header['Precedence'] = "list\nList-Id: " . html_entity_decode(get_option('blogname'), ENT_QUOTES) . "";
if ( empty($attachments) && $type == 'html' ) {
$header['Content-Type'] = get_option('html_type') . "; charset=\"". $char_set . "\"";
} elseif ( empty($attachments) && $type == 'text' ) {
$header['Content-Type'] = "text/plain; charset=\"". $char_set . "\"";
}
$header = apply_filters('s2_email_headers', $header);
foreach ( $header as $key => $value ) {
$headers[$key] = $key . ": " . $value;
}
$headers = implode("\n", $headers);
$headers .= "\n";
return $headers;
}
function get_tracking_link($link) {
if ( empty($link) ) { return; }
if ( !empty($this->subscribe2_options['tracking']) ) {
(strpos($link, '?') > 0) ? $delimiter .= '&' : $delimiter = '?';
$tracking = $this->subscribe2_options['tracking'];
if ( strpos($tracking, "{ID}") ) {
$id = url_to_postid($link);
$tracking = str_replace("{ID}", $id, $tracking);
}
if ( strpos($tracking, "{TITLE}") ) {
$id = url_to_postid($link);
$title = urlencode(htmlentities(get_the_title($id), 1));
$tracking = str_replace("{TITLE}", $title, $tracking);
}
return $link . $delimiter . $tracking;
} else {
return $link;
}
}
function publish($post, $preview = '') {
if ( !$post ) { return $post; }
if ( $this->s2_mu && !apply_filters('s2_allow_site_switching', $this->site_switching) ) {
global $switched;
if ( $switched ) { return; }
}
if ( $preview == '' ) {
$s2mail = get_post_meta($post->ID, '_s2mail', true);
if ( (isset($_POST['s2_meta_field']) && $_POST['s2_meta_field'] == 'no') || strtolower(trim($s2mail)) == 'no' ) { return $post; }
if ( $this->subscribe2_options['email_freq'] != 'never' ) { return $post; }
if ( $this->subscribe2_options['pages'] == 'yes' ) {
$s2_post_types = array('page', 'post');
} else {
$s2_post_types = array('post');
}
$s2_post_types = apply_filters('s2_post_types', $s2_post_types);
if ( !in_array($post->post_type, $s2_post_types) ) {
return $post;
}
if ( $this->subscribe2_options['password'] == "no" && $post->post_password != '' ) {
return $post;
}
$post_format = get_post_format($post->ID);
$excluded_formats = explode(', ', $this->subscribe2_options['exclude_formats']);
if ( $post_format !== false && in_array($post_format, $excluded_formats) ) {
return $post;
}
$s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
$post_cats = wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'ids'));
$check = false;
foreach ( explode(', ', $this->subscribe2_options['exclude']) as $cat ) {
if ( in_array($cat, $post_cats) ) {
$check = true;
}
}
if ( $check ) {
if ( '0' == $this->subscribe2_options['reg_override'] ) {
return $post;
}
}
if ( $this->subscribe2_options['private'] == "yes" && $post->post_status == 'private' ) {
$check = true;
}
$public = array();
if ( !$check ) {
$public = $this->get_public();
}
if ( $post->post_type == 'page' ) {
$post_cats_string = implode(', ', get_all_category_ids());
} else {
$post_cats_string = implode(', ', $post_cats);
}
$registered = $this->get_registered("cats=$post_cats_string");
if ( empty($public) && empty($registered) ) {
return $post;
}
} else {
$s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
}
$this->post_title = "<a href=\"" . get_permalink($post->ID) . "\">" . html_entity_decode($post->post_title, ENT_QUOTES) . "</a>";
$this->permalink = get_permalink($post->ID);
$this->post_date = get_the_time(get_option('date_format'), $post);
$this->post_time = get_the_time('', $post);
$author = get_userdata($post->post_author);
$this->authorname = html_entity_decode(apply_filters('the_author', $author->display_name), ENT_QUOTES);
if ( 'author' == $this->subscribe2_options['sender'] ) {
$user = &$author;
$this->myemail = $user->user_email;
$this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
} elseif ( 'blogname' == $this->subscribe2_options['sender'] ) {
$this->myemail = get_option('admin_email');
$this->myname = html_entity_decode(get_option('blogname'), ENT_QUOTES);
} else {
$user = $this->get_userdata($this->subscribe2_options['sender']);
$this->myemail = $user->user_email;
$this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
}
$this->post_cat_names = implode(', ', wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'names')));
$this->post_tag_names = implode(', ', wp_get_post_tags($post->ID, array('fields' => 'names')));
$subject = html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), '')));
$mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
$mailtext = stripslashes($this->substitute($mailtext));
$plaintext = $post->post_content;
$plaintext = strip_shortcodes($plaintext);
$plaintext = preg_replace('|<s[^>]*>(.*)<\/s>|Ui', '', $plaintext);
$plaintext = preg_replace('|<strike[^>]*>(.*)<\/strike>|Ui', '', $plaintext);
$plaintext = preg_replace('|<del[^>]*>(.*)<\/del>|Ui', '', $plaintext);
$excerpttext = $plaintext;
if ( strstr($mailtext, "{REFERENCELINKS}") ) {
$mailtext = str_replace("{REFERENCELINKS}", '', $mailtext);
$plaintext_links = '';
$i = 0;
while ( preg_match('|<a([^>]*)>(.*)<\/a>|Ui', $plaintext, $matches) ) {
if ( preg_match('|href="([^"]*)"|', $matches[1], $link_matches) ) {
$plaintext_links .= sprintf( "[%d] %s\r\n", ++$i, $link_matches[1] );
$link_replacement = sprintf( "%s [%d]", $matches[2], $i );
} else {
$link_replacement = $matches[2];
}
$plaintext = preg_replace('|<a[^>]*>(.*)<\/a>|Ui', $link_replacement, $plaintext, 1);
}
}
$plaintext = trim(strip_tags($plaintext));
if ( strstr($mailtext, "{REFERENCELINKS}") && $plaintext_links != '' ) {
$plaintext .= "\r\n\r\n" . trim($plaintext_links);
}
$gallid = ']>", "]]>", $content);
$excerpt = trim($post->post_excerpt);
if ( '' == $excerpt ) {
if ( false !== strpos($excerpttext, '<!--more-->') ) {
list($excerpt, $more) = explode('<!--more-->', $excerpttext, 2);
$excerpt = trim(strip_tags($excerpt));
} else {
$excerpt = trim(strip_tags($excerpttext));
$words = explode(' ', $excerpt, $this->excerpt_length + 1);
if (count($words) > $this->excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$excerpt = implode(' ', $words);
}
}
}
$html_excerpt = trim($post->post_excerpt);
if ( '' == $html_excerpt ) {
if ( false !== strpos($content, '<!--more-->') ) {
list($html_excerpt, $more) = explode('<!--more-->', $content, 2);
$html_excerpt = trim(balanceTags($html_excerpt, true));
} else {
$words = explode(' ', $content, $this->excerpt_length + 1);
if (count($words) > $this->excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$html_excerpt = implode(' ', $words);
$html_excerpt = trim(balanceTags($html_excerpt, true));
} else {
$html_excerpt = $content;
}
}
}
$social = apply_filters('s2_social_links', array('facebook', 'twitter'));
if ( !empty($social) ) {
$social_buttons = $this->social_buttons($social);
$content .= $social_buttons;
$html_excerpt .= $social_buttons;
}
$excerpt = preg_replace('|[ ]+|', ' ', $excerpt);
$plaintext = preg_replace('|[ ]+|', ' ', $plaintext);
$plain_excerpt_body = str_replace("{POST}", $excerpt, $mailtext);
$plain_body = str_replace("{POST}", $plaintext, $mailtext);
$html_body = str_replace("\r\n", "<br />\r\n", $mailtext);
$html_body = str_replace("{POST}", $content, $html_body);
$html_excerpt_body = str_replace("\r\n", "<br />\r\n", $mailtext);
$html_excerpt_body = str_replace("{POST}", $html_excerpt, $html_excerpt_body);
if ( $preview != '' ) {
$this->myemail = $preview;
$this->myname = __('Plain Text Excerpt Preview', 'subscribe2');
$this->mail(array($preview), $subject, $plain_excerpt_body);
$this->myname = __('Plain Text Full Preview', 'subscribe2');
$this->mail(array($preview), $subject, $plain_body);
$this->myname = __('HTML Excerpt Preview', 'subscribe2');
$this->mail(array($preview), $subject, $html_excerpt_body, 'html');
$this->myname = __('HTML Full Preview', 'subscribe2');
$this->mail(array($preview), $subject, $html_body, 'html');
} else {
$recipients = $this->get_registered("cats=$post_cats_string&format=excerpt&author=$post->post_author");
$recipients = apply_filters('s2_send_plain_excerpt_subscribers', $recipients, $post->ID);
$this->mail($recipients, $subject, $plain_excerpt_body);
$recipients = $this->get_registered("cats=$post_cats_string&format=post&author=$post->post_author");
$recipients = apply_filters('s2_send_plain_fullcontent_subscribers', $recipients, $post->ID);
$this->mail($recipients, $subject, $plain_body);
$recipients = $this->get_registered("cats=$post_cats_string&format=html_excerpt&author=$post->post_author");
$recipients = apply_filters('s2_send_html_excerpt_subscribers', $recipients, $post->ID);
$this->mail($recipients, $subject, $html_excerpt_body, 'html');
$recipients = $this->get_registered("cats=$post_cats_string&format=html&author=$post->post_author");
$recipients = apply_filters('s2_send_html_fullcontent_subscribers', $recipients, $post->ID);
$this->mail($recipients, $subject, $html_body, 'html');
$recipients = apply_filters('s2_send_public_subscribers', $public, $post->ID);
$this->mail($recipients, $subject, $plain_excerpt_body, 'text');
}
}
function social_buttons($social) {
$social_buttons = '';
if ( in_array('facebook', $social) ) {
$social_buttons .= '<a href="http:
}
if ( in_array('twitter', $social) ) {
$social_buttons .= '<a href="http:
}
if ( in_array('google', $social) ) {
$social_buttons .= '<a href="http:
}
return apply_filters('s2_social_buttons', $social_buttons);
}
function send_confirm($what = '', $is_remind = false) {
if ( $this->filtered == 1 ) { return true; }
if ( !$this->email || !$what ) { return false; }
$id = $this->get_id($this->email);
if ( !$id ) {
return false;
}
$link = apply_filters('s2_confirm_link', get_option('home')) . "/?s2=";
if ( 'add' == $what ) {
$link .= '1';
} elseif ( 'del' == $what ) {
$link .= '0';
}
$link .= wp_hash($this->email);
$link .= $id;
$mailheaders = $this->headers();
if ( $is_remind == true ) {
$body = $this->substitute(stripslashes($this->subscribe2_options['remind_email']));
$subject = $this->substitute(stripslashes($this->subscribe2_options['remind_subject']));
} else {
$body = apply_filters('s2_confirm_email', stripslashes($this->subscribe2_options['confirm_email']), $what);
$body = $this->substitute($body);
if ( 'add' == $what ) {
$body = str_replace("{ACTION}", $this->subscribe, $body);
$subject = str_replace("{ACTION}", $this->subscribe, $this->subscribe2_options['confirm_subject']);
} elseif ( 'del' == $what ) {
$body = str_replace("{ACTION}", $this->unsubscribe, $body);
$subject = str_replace("{ACTION}", $this->unsubscribe, $this->subscribe2_options['confirm_subject']);
}
$subject = html_entity_decode($this->substitute(stripslashes($subject)), ENT_QUOTES);
}
$body = str_replace("{LINK}", $link, $body);
if ( $is_remind == true && function_exists('wpmq_mail') ) {
@wp_mail($this->email, $subject, $body, $mailheaders, '', 0);
} else {
return @wp_mail($this->email, $subject, $body, $mailheaders);
}
}
function get_public($confirmed = 1) {
global $wpdb;
if ( 1 == $confirmed ) {
if ( '' == $this->all_confirmed ) {
$this->all_confirmed = $wpdb->get_col("SELECT email FROM $this->public WHERE active='1'");
}
return $this->all_confirmed;
} else {
if ( '' == $this->all_unconfirmed ) {
$this->all_unconfirmed = $wpdb->get_col("SELECT email FROM $this->public WHERE active='0'");
}
return $this->all_unconfirmed;
}
}
function get_email($id = 0) {
global $wpdb;
if ( !$id ) {
return false;
}
return $wpdb->get_var($wpdb->prepare("SELECT email FROM $this->public WHERE id=%d", $id));
}
function get_id($email = '') {
global $wpdb;
if ( !$email ) {
return false;
}
return $wpdb->get_var($wpdb->prepare("SELECT id FROM $this->public WHERE email=%s", $email));
}
function add($email = '', $confirm = false) {
if ( $this->filtered == 1 ) { return; }
global $wpdb;
if ( !is_email($email) ) { return false; }
if ( false !== $this->is_public($email) ) {
$check = $wpdb->get_var($wpdb->prepare("SELECT user_email FROM $wpdb->users WHERE user_email=%s", $this->email));
if ( $check ) { return; }
if ( $confirm ) {
$wpdb->query($wpdb->prepare("UPDATE $this->public SET active='1', ip=%s WHERE CAST(email as binary)=%s", $this->ip, $email));
} else {
$wpdb->query($wpdb->prepare("UPDATE $this->public SET date=CURDATE(), time=CURTIME() WHERE CAST(email as binary)=%s", $email));
}
} else {
if ( $confirm ) {
global $current_user;
$wpdb->query($wpdb->prepare("INSERT INTO $this->public (email, active, date, time, ip) VALUES (%s, %d, CURDATE(), CURTIME(), %s)", $email, 1, $current_user->user_login));
} else {
$wpdb->query($wpdb->prepare("INSERT INTO $this->public (email, active, date, time, ip) VALUES (%s, %d, CURDATE(), CURTIME(), %s)", $email, 0, $this->ip));
}
}
}
function delete($email = '') {
global $wpdb;
if ( !is_email($email) ) { return false; }
$wpdb->query($wpdb->prepare("DELETE FROM $this->public WHERE CAST(email as binary)=%s", $email));
}
function toggle($email = '') {
global $wpdb;
if ( '' == $email || !is_email($email) ) { return false; }
$status = $this->is_public($email);
if ( false === $status ) { return false; }
if ( '0' == $status ) {
$wpdb->query($wpdb->prepare("UPDATE $this->public SET active='1', conf_date=CURDATE(), conf_time=CURTIME(), conf_ip=%s WHERE CAST(email as binary)=%s", $this->ip, $email));
} else {
$wpdb->query($wpdb->prepare("UPDATE $this->public SET active='0', conf_date=CURDATE(), conf_time=CURTIME(), conf_ip=%s WHERE CAST(email as binary)=%s", $this->ip, $email));
}
}
function remind($emails = '') {
if ( '' == $emails ) { return false; }
$recipients = explode(", ", $emails);
if ( !is_array($recipients) ) { $recipients = (array)$recipients; }
foreach ( $recipients as $recipient ) {
$this->email = $recipient;
$this->send_confirm('add', true);
}
}
function is_public($email = '') {
global $wpdb;
if ( '' == $email ) { return false; }
$check = $wpdb->get_var($wpdb->prepare("SELECT active FROM $this->public WHERE CAST(email as binary)=%s", $email));
if ( '0' == $check || '1' == $check ) {
return $check;
} else {
return false;
}
}
function is_registered($email = '') {
global $wpdb;
if ( '' == $email ) { return false; }
$check = $wpdb->get_var($wpdb->prepare("SELECT user_email FROM $wpdb->users WHERE user_email=%s", $email));
if ( $check ) {
return true;
} else {
return false;
}
}
function get_user_id($email = '') {
global $wpdb;
if ( '' == $email ) { return false; }
$id = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wpdb->users WHERE user_email=%s", $email));
return $id;
}
function get_all_registered($return = 'email') {
global $wpdb;
if ( $this->s2_mu ) {
if ( $return === 'ID' ) {
if ( $this->all_registered_id === '' ) {
$this->all_registered_id = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='" . $wpdb->prefix . "capabilities'");
}
return $this->all_registered_id;
} else {
if ( $this->all_registered_email === '' ) {
$this->all_registered_email = $wpdb->get_col("SELECT a.user_email FROM $wpdb->users AS a INNER JOIN $wpdb->usermeta AS b ON a.ID = b.user_id WHERE b.meta_key='" . $wpdb->prefix . "capabilities'");
}
return $this->all_registered_email;
}
} else {
if ( $return === 'ID' ) {
if ( $this->all_registered_id === '' ) {
$this->all_registered_id = $wpdb->get_col("SELECT ID FROM $wpdb->users");
}
return $this->all_registered_id;
} else {
if ( $this->all_registered_email === '' ) {
$this->all_registered_email = $wpdb->get_col("SELECT user_email FROM $wpdb->users");
}
return $this->all_registered_email;
}
}
}
function get_registered($args = '') {
global $wpdb;
parse_str($args, $r);
if ( !isset($r['format']) )
$r['format'] = 'all';
if ( !isset($r['cats']) )
$r['cats'] = '';
if ( !isset($r['author']) )
$r['author'] = '';
$compulsory = explode(', ', $this->subscribe2_options['compulsory']);
foreach ( explode(', ', $r['cats']) as $cat ) {
if ( in_array($cat, $compulsory) ) {
$r['cats'] = '';
}
}
$JOIN = ''; $AND = '';
if ( 'all' != $r['format'] ) {
$JOIN .= "INNER JOIN $wpdb->usermeta AS b ON a.user_id = b.user_id ";
$AND .= $wpdb->prepare(" AND b.meta_key=%s AND b.meta_value=", $this->get_usermeta_keyname('s2_format'));
if ( 'html' == $r['format'] ) {
$AND .= "'html'";
} elseif ( 'html_excerpt' == $r['format'] ) {
$AND .= "'html_excerpt'";
} elseif ( 'post' == $r['format'] ) {
$AND .= "'post'";
} elseif ( 'excerpt' == $r['format'] ) {
$AND .= "'excerpt'";
}
}
if ( '' != $r['cats'] ) {
$JOIN .= "INNER JOIN $wpdb->usermeta AS c ON a.user_id = c.user_id ";
$and = '';
foreach ( explode(', ', $r['cats']) as $cat ) {
('' == $and) ? $and = $wpdb->prepare("c.meta_key=%s", $this->get_usermeta_keyname('s2_cat') . $cat) : $and .= $wpdb->prepare(" OR c.meta_key=%s", $this->get_usermeta_keyname('s2_cat') . $cat);
}
$AND .= " AND ($and)";
}
if ( '' != $r['author'] ) {
$JOIN .= "INNER JOIN $wpdb->usermeta AS d ON a.user_id = d.user_id ";
$AND .= $wpdb->prepare(" AND (d.meta_key=%s AND NOT FIND_IN_SET(%s, d.meta_value))", $this->get_usermeta_keyname('s2_authors'), $r['author']);
}
if ( $this->s2_mu ) {
$sql = $wpdb->prepare("SELECT a.user_id FROM $wpdb->usermeta AS a INNER JOIN $wpdb->usermeta AS e ON a.user_id = e.user_id " . $JOIN . "WHERE a.meta_key='" . $wpdb->prefix . "capabilities' AND e.meta_key=%s AND e.meta_value <> ''" . $AND, $this->get_usermeta_keyname('s2_subscribed'));
} else {
$sql = $wpdb->prepare("SELECT a.user_id FROM $wpdb->usermeta AS a " . $JOIN . "WHERE a.meta_key=%s AND a.meta_value <> ''" . $AND, $this->get_usermeta_keyname('s2_subscribed'));
}
$result = $wpdb->get_col($sql);
if ( $result ) {
$ids = implode(', ', array_map(array($this, 'prepare_in_data'), $result));
$registered = $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE ID IN ($ids)");
}
if ( empty($registered) ) { return array(); }
$registered = apply_filters('s2_registered_subscribers', $registered, $args);
return $registered;
}
function sanitize_email($email) {
$email = trim($email);
if ( !is_email($email) ) { return; }
list($name, $domain) = explode('@', $email, 2);
return $name . "@" . strtolower($domain);
}
function register($user_ID = 0, $consent = false) {
global $wpdb;
if ( 0 == $user_ID ) { return $user_ID; }
$user = get_userdata($user_ID);
if ( 0 == $this->subscribe2_options['reg_override'] || 'no' == $this->subscribe2_options['newreg_override'] ) {
$all_cats = $this->all_cats(true, 'ID');
} else {
$all_cats = $this->all_cats(false, 'ID');
}
$cats = '';
foreach ( $all_cats as $cat ) {
('' == $cats) ? $cats = "$cat->term_id" : $cats .= ", $cat->term_id";
}
if ( '' == $cats ) {
return $user_ID;
}
if ( false !== $this->is_public($this->sanitize_email($user->user_email)) ) {
$this->delete($user->user_email);
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
foreach ( explode(', ', $cats) as $cat ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, $cat);
}
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_format'), 'excerpt');
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_autosub'), $this->subscribe2_options['autosub_def']);
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_authors'), '');
} else {
if ( in_array($this->subscribe2_options['autoformat'], array('html', 'html_excerpt', 'post', 'excerpt')) ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_format'), $this->subscribe2_options['autoformat']);
} else {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_format'), 'excerpt');
}
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_autosub'), $this->subscribe2_options['autosub_def']);
if ( true === $consent ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $cats);
foreach ( explode(', ', $cats) as $cat ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat, $cat);
}
}
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_authors'), '');
}
return $user_ID;
}
function get_userdata($admin_id) {
global $wpdb, $userdata;
if ( is_numeric($admin_id) ) {
$admin = get_userdata($admin_id);
} elseif ( $admin_id == 'admin' ) {
$admin = get_userdata('1');
} else {
$admin = &$userdata;
}
if ( empty($admin) || $admin->ID == 0 ) {
$role = array('role' => 'administrator');
$wp_user_query = get_users( $role );
$admin = $wp_user_query[0];
}
return $admin;
}
function one_click_handler($user_ID, $action) {
if ( !isset($user_ID) || !isset($action) ) { return; }
$all_cats = $this->all_cats(true);
if ( 'subscribe' == $action ) {
$new_cats = array();
foreach ( $all_cats as $cat ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat->term_id, $cat->term_id);
$new_cats[] = $cat->term_id;
}
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(', ', $new_cats));
if ( 'yes' == $this->subscribe2_options['show_autosub'] && 'no' != get_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), true) ) {
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_autosub'), 'yes');
}
} elseif ( 'unsubscribe' == $action ) {
foreach ( $all_cats as $cat ) {
delete_user_meta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat->term_id);
}
delete_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'));
update_user_meta($user_ID, $this->get_usermeta_keyname('s2_autosub'), 'no');
}
}
function all_cats($exclude = false, $orderby = 'slug') {
$all_cats = array();
$s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
foreach ( $s2_taxonomies as $taxonomy ) {
if ( taxonomy_exists($taxonomy) ) {
$all_cats = array_merge($all_cats, get_categories(array('hide_empty' => false, 'orderby' => $orderby, 'taxonomy' => $taxonomy)));
}
}
if ( $exclude === true ) {
$excluded = explode(', ', $this->subscribe2_options['exclude']);
$id = 0;
foreach ( $all_cats as $cat) {
if ( in_array($cat->term_id, $excluded) ) {
unset($all_cats[$id]);
}
$id++;
}
}
return $all_cats;
}
function prepare_in_data($data) {
global $wpdb;
return $wpdb->prepare('%s', $data);
}
function get_usermeta_keyname($metaname) {
global $wpdb;
if ( $this->s2_mu === true ) {
switch( $metaname ) {
case 's2_subscribed':
case 's2_cat':
case 's2_format':
case 's2_autosub':
case 's2_authors':
return $wpdb->prefix . $metaname;
break;
}
}
return $metaname;
}
function register_form() {
if ( 'no' == $this->subscribe2_options['autosub'] ) { return; }
if ( 'wpreg' == $this->subscribe2_options['autosub'] ) {
echo "<p>\r\n<label>";
echo __('Check here to Subscribe to email notifications for new posts', 'subscribe2') . ":<br />\r\n";
echo "<input type=\"checkbox\" name=\"reg_subscribe\"" . checked($this->subscribe2_options['wpregdef'], 'yes', false) . " />";
echo "</label>\r\n";
echo "</p>\r\n";
} elseif ( 'yes' == $this->subscribe2_options['autosub'] ) {
echo "<p>\r\n<center>\r\n";
echo __('By registering with this blog you are also agreeing to receive email notifications for new posts but you can unsubscribe at anytime', 'subscribe2') . ".<br />\r\n";
echo "</center></p>\r\n";
}
}
function register_post($user_ID = 0) {
global $_POST;
if ( 0 == $user_ID ) { return; }
if ( 'yes' == $this->subscribe2_options['autosub'] || ( isset($_POST['reg_subscribe']) && 'on' == $_POST['reg_subscribe'] && 'wpreg' == $this->subscribe2_options['autosub'] ) ) {
$this->register($user_ID, true);
} else {
$this->register($user_ID, false);
}
}
function s2_comment_meta_form() {
if ( is_user_logged_in() ) {
echo $this->profile;
} else {
echo "<p style=\"width: auto;\"><label><input type=\"checkbox\" name=\"s2_comment_request\" value=\"1\" " . checked($this->subscribe2_options['comment_def'], 'yes', false) . "/> " . __('Check here to Subscribe to notifications for new posts', 'subscribe2') . "</label></p>";
}
}
function s2_comment_meta($comment_ID, $approved = 0) {
if ( $_POST['s2_comment_request'] == '1' ) {
switch ($approved) {
case '0':
add_comment_meta($comment_ID, 's2_comment_request', $_POST['s2_comment_request']);
break;
case '1':
$comment = get_comment($comment_ID);
$is_public = $this->is_public($comment->comment_author_email);
if ( $is_public == 0 ) {
$this->toggle($comment->comment_author_email);
}
$is_registered = $this->is_registered($comment->comment_author_email);
if ( !$is_public && !$is_registered ) {
$this->add($comment->comment_author_email, true);
}
break;
default :
break;
}
}
}
function comment_status($comment_ID = 0) {
global $wpdb;
$subscribe = get_comment_meta($comment_ID, 's2_comment_request', true);
if ( $subscribe != '1' ) { return $comment_ID; }
$sql = $wpdb->prepare("SELECT comment_author_email, comment_approved FROM $wpdb->comments WHERE comment_ID=%s LIMIT 1", $comment_ID);
$comment = $wpdb->get_row($sql, OBJECT);
if ( empty($comment) ) { return $comment_ID; }
switch ($comment->comment_approved) {
case '0':
break;
case '1':
$is_public = $this->is_public($comment->comment_author_email);
if ( $is_public == 0 ) {
$this->toggle($comment->comment_author_email);
}
$is_registered = $this->is_registered($comment->comment_author_email);
if ( !$is_public && !$is_registered ) {
$this->add($comment->comment_author_email, true);
}
delete_comment_meta($comment_ID, 's2_comment_request');
break;
default:
delete_comment_meta($comment_ID, 's2_comment_request');
break;
}
return $comment_ID;
}
function subscribe2_widget() {
require_once( S2PATH . 'include/widget.php');
register_widget('S2_Form_widget');
}
function counter_widget() {
require_once( S2PATH . 'include/counterwidget.php');
register_widget('S2_Counter_widget');
}
function add_weekly_sched($scheds) {
$exists = false;
foreach ( $scheds as $sched ) {
if ( array_search(604800, $sched) ) {
$exists = true;
}
}
if ( !$exists ) {
$scheds['weekly'] = array('interval' => 604800, 'display' => __('Weekly', 'subscribe2'));
}
return $scheds;
}
function digest_post_transitions($new_status, $old_status, $post) {
if ( $new_status === $old_status ) { return; }
if ( $this->subscribe2_options['pages'] == 'yes' ) {
$s2_post_types = array('page', 'post');
} else {
$s2_post_types = array('post');
}
$s2_post_types = apply_filters('s2_post_types', $s2_post_types);
if ( !in_array($post->post_type, $s2_post_types) ) { return; }
update_post_meta( $post->ID, '_s2_digest_post_status', ( 'publish' === $new_status ) ? 'pending' : 'draft' );
}
function subscribe2_cron($preview = '', $resend = '') {
if ( defined('DOING_S2_CRON') && DOING_S2_CRON ) { return; }
define( 'DOING_S2_CRON', true );
global $wpdb, $post;
if ( '' == $preview ) {
if ( $this->subscribe2_options['private'] == 'yes' ) {
$status = "'publish', 'private'";
} else {
$status = "'publish'";
}
if ( $this->subscribe2_options['pages'] == 'yes' ) {
$s2_post_types = array('page', 'post');
} else {
$s2_post_types = array('post');
}
$s2_post_types = apply_filters('s2_post_types', $s2_post_types);
foreach ( $s2_post_types as $post_type ) {
if ( !isset($type) ) {
$type = $wpdb->prepare("%s", $post_type);
} else {
$type .= $wpdb->prepare(", %s", $post_type);
}
}
if ( $resend == 'resend' ) {
$query = new WP_Query( array(
'post__in' => explode(', ', $this->subscribe2_options['last_s2cron']),
'ignore_sticky_posts' => 1,
'order' => ($this->subscribe2_options['cron_order'] === 'desc') ? "DESC" : "ASC"
) );
$posts = $query->posts;
} else {
$sql = "SELECT ID, post_title, post_excerpt, post_content, post_type, post_password, post_date, post_author FROM $wpdb->posts AS a INNER JOIN $wpdb->postmeta AS b ON b.post_id = a.ID";
$sql .= " AND b.meta_key = '_s2_digest_post_status' AND b.meta_value = 'pending' WHERE post_status IN ($status) AND post_type IN ($type) ORDER BY post_date " . (($this->subscribe2_options['cron_order'] === 'desc') ? 'DESC' : 'ASC');
$posts = $wpdb->get_results($sql);
}
} else {
$posts = get_posts('numberposts=1');
}
if ( $this->subscribe2_options['stickies'] == 'yes' ) {
$sticky_ids = get_option('sticky_posts');
if ( !empty($sticky_ids) ) {
$sticky_posts = get_posts( array('post__in' => $sticky_ids) );
$posts = array_merge((array)$sticky_posts, (array)$posts);
}
}
if ( empty($posts) && !has_filter('s2_digest_email') ) { return false; }
$this->post_count = count($posts);
$datetime = get_option('date_format') . ' @ ' . get_option('time_format');
$all_post_cats = array();
$ids = array();
$mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
$table = '';
$tablelinks = '';
$message_post= '';
$message_posttime = '';
$digest_post_ids = array();
$s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
foreach ( $posts as $post ) {
if ( in_array($post->ID, $ids) ) { continue; }
$ids[] = $post->ID;
$post_cats = wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'ids'));
$post_cats_string = implode(', ', $post_cats);
$all_post_cats = array_unique(array_merge($all_post_cats, $post_cats));
$check = false;
if ( $post->post_type != 'page' ) {
foreach ( explode(', ', $this->subscribe2_options['exclude']) as $cat ) {
if ( in_array($cat, $post_cats) ) {
$check = true;
}
}
}
$s2mail = get_post_meta($post->ID, '_s2mail', true);
if ( strtolower(trim($s2mail)) == 'no' ) {
$check = true;
}
if ( $this->subscribe2_options['password'] == 'no' && $post->post_password != '' ) {
$check = true;
}
$post_format = get_post_format($post->ID);
$excluded_formats = explode(', ', $this->subscribe2_options['exclude_formats']);
if ( $post_format !== false && in_array($post_format, $excluded_formats) ) {
$check = true;
}
if ( $check ) {
continue;
}
if ( isset($sticky_ids) && !in_array($post->ID, $sticky_ids) ) {
$digest_post_ids[] = $post->ID;
} else {
$digest_post_ids[] = $post->ID;
}
$post_title = html_entity_decode($post->post_title, ENT_QUOTES);
('' == $table) ? $table .= "* " . $post_title : $table .= "\r\n* " . $post_title;
('' == $tablelinks) ? $tablelinks .= "* " . $post_title : $tablelinks .= "\r\n* " . $post_title;
$message_post .= $post_title;
$message_posttime .= $post_title;
if ( strstr($mailtext, "{AUTHORNAME}") ) {
$author = get_userdata($post->post_author);
if ( $author->display_name != '' ) {
$message_post .= " (" . __('Author', 'subscribe2') . ": " . html_entity_decode(apply_filters('the_author', $author->display_name), ENT_QUOTES) . ")";
$message_posttime .= " (" . __('Author', 'subscribe2') . ": " . html_entity_decode(apply_filters('the_author', $author->display_name), ENT_QUOTES) . ")";
}
}
$message_post .= "\r\n";
$message_posttime .= "\r\n";
$message_posttime .= __('Posted on', 'subscribe2') . ": " . mysql2date($datetime, $post->post_date) . "\r\n";
if ( strstr($mailtext, "{TINYLINK}") ) {
$tinylink = file_get_contents('http:
} else {
$tinylink = false;
}
if ( strstr($mailtext, "{TINYLINK}") && $tinylink !== 'Error' && $tinylink !== false ) {
$tablelinks .= "\r\n" . $tinylink . "\r\n";
$message_post .= $tinylink . "\r\n";
$message_posttime .= $tinylink . "\r\n";
} else {
$tablelinks .= "\r\n" . $this->get_tracking_link(get_permalink($post->ID)) . "\r\n";
$message_post .= $this->get_tracking_link(get_permalink($post->ID)) . "\r\n";
$message_posttime .= $this->get_tracking_link(get_permalink($post->ID)) . "\r\n";
}
if ( strstr($mailtext, "{CATS}") ) {
$post_cat_names = implode(', ', wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'names')));
$message_post .= __('Posted in', 'subscribe2') . ": " . $post_cat_names . "\r\n";
$message_posttime .= __('Posted in', 'subscribe2') . ": " . $post_cat_names . "\r\n";
}
if ( strstr($mailtext, "{TAGS}") ) {
$post_tag_names = implode(', ', wp_get_post_tags($post->ID, array('fields' => 'names')));
if ( $post_tag_names != '' ) {
$message_post .= __('Tagged as', 'subscribe2') . ": " . $post_tag_names . "\r\n";
$message_posttime .= __('Tagged as', 'subscribe2') . ": " . $post_tag_names . "\r\n";
}
}
$message_post .= "\r\n";
$message_posttime .= "\r\n";
( !empty($post->post_excerpt) ) ? $excerpt = trim($post->post_excerpt) : $excerpt = '';
if ( '' == $excerpt ) {
if ( false !== strpos($post->post_content, '<!--more-->') ) {
list($excerpt, $more) = explode('<!--more-->', $post->post_content, 2);
$excerpt = strip_tags($excerpt);
$excerpt = strip_shortcodes($excerpt);
} else {
$excerpt = strip_tags($post->post_content);
$excerpt = strip_shortcodes($excerpt);
$words = explode(' ', $excerpt, $this->excerpt_length + 1);
if ( count($words) > $this->excerpt_length ) {
array_pop($words);
array_push($words, '[...]');
$excerpt = implode(' ', $words);
}
}
$excerpt = trim($excerpt);
}
$message_post .= $excerpt . "\r\n\r\n";
$message_posttime .= $excerpt . "\r\n\r\n";
}
foreach ( $digest_post_ids as $digest_post_id ) {
update_post_meta($digest_post_id, '_s2_digest_post_status', 'done');
}
$this->subscribe2_options['last_s2cron'] = implode(', ', $digest_post_ids);
update_option('subscribe2_options', $this->subscribe2_options);
$message_post = trim($message_post);
$message_posttime = trim($message_posttime);
$message_post = preg_replace('|[ ]+|', ' ', $message_post);
$message_posttime = preg_replace('|[ ]+|', ' ', $message_posttime);
$message_post = preg_replace("|[\r\n]{3, }|", "\r\n\r\n", $message_post);
$message_posttime = preg_replace("|[\r\n]{3, }|", "\r\n\r\n", $message_posttime);
$message_post = apply_filters('s2_custom_keywords', $message_post, $digest_post_ids);
$message_posttime = apply_filters('s2_custom_keywords', $message_posttime, $digest_post_ids);
$message_post = apply_filters('s2_digest_email', $message_post);
$message_posttime = apply_filters('s2_digest_email', $message_posttime);
if ( !$message_post && !$message_posttime && !$table && !$tablelinks ) {
return;
}
if ( $this->subscribe2_options['sender'] == 'blogname' ) {
$this->myname = html_entity_decode(get_option('blogname'), ENT_QUOTES);
$this->myemail = get_bloginfo('admin_email');
} else {
$user = $this->get_userdata($this->subscribe2_options['sender']);
$this->myemail = $user->user_email;
$this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
}
$scheds = (array)wp_get_schedules();
$email_freq = $this->subscribe2_options['email_freq'];
$display = $scheds[$email_freq]['display'];
( '' == get_option('blogname') ) ? $subject = "" : $subject = "[" . stripslashes(html_entity_decode(get_option('blogname'), ENT_QUOTES)) . "] ";
$subject .= $display . " " . __('Digest Email', 'subscribe2');
$mailtext = str_replace("{TABLELINKS}", $tablelinks, $mailtext);
$mailtext = str_replace("{TABLE}", $table, $mailtext);
$mailtext = str_replace("{POSTTIME}", $message_posttime, $mailtext);
$mailtext = str_replace("{POST}", $message_post, $mailtext);
$mailtext = stripslashes($this->substitute($mailtext));
if ( $preview != '' ) {
$this->myemail = $preview;
$this->myname = __('Digest Preview', 'subscribe2');
$this->mail(array($preview), $subject, $mailtext);
} else {
$public = $this->get_public();
$all_post_cats_string = implode(', ', $all_post_cats);
$registered = $this->get_registered("cats=$all_post_cats_string");
$recipients = array_merge((array)$public, (array)$registered);
$this->mail($recipients, $subject, $mailtext);
}
}
function s2cleaner_task() {
$unconfirmed = $this->get_public('0');
if ( empty($unconfirmed) ) { return; }
global $wpdb;
$sql = "SELECT email FROM $this->public WHERE active='0' AND date < DATE_SUB(CURDATE(), INTERVAL " . $this->clean_interval . " DAY)";
$old_unconfirmed = $wpdb->get_col( $sql );
if ( empty($old_unconfirmed) ) {
return;
} else {
foreach ( $old_unconfirmed as $email ) {
$this->delete($email);
}
}
return;
}
function s2_hide_jetpack_comments($modules) {
unset($modules['comments']);
return $modules;
}
function s2init() {
global $wpdb, $wp_version, $wpmu_version;
$this->subscribe2_options = get_option('subscribe2_options');
$this->script_debug = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min';
$tmp = explode('-', $wp_version, 2);
$this->wp_release = $tmp[0];
if ( isset($wpmu_version) || strpos($wp_version, 'wordpress-mu') ) {
$this->s2_mu = true;
}
if ( function_exists('is_multisite') && is_multisite() ) {
$this->s2_mu = true;
}
if ( $this->s2_mu === true ) {
require_once(S2PATH . "classes/class-s2-multisite.php");
global $s2class_multisite;
$s2class_multisite = new s2_multisite;
if ( isset($_GET['s2mu_subscribe']) || isset($_GET['s2mu_unsubscribe']) ) {
add_action('init', array(&$s2class_multisite, 'wpmu_subscribe'));
}
}
add_action('plugins_loaded', array(&$this, 'load_translations'));
$this->public = $wpdb->prefix . "subscribe2";
if ( $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $this->public)) != $this->public ) { $this->install(); }
if ( $this->subscribe2_options === false || is_array($this->subscribe2_options) && $this->subscribe2_options['version'] !== S2VERSION ) {
add_action('shutdown', array(&$this, 'upgrade'));
}
add_filter('cron_schedules', array(&$this, 'add_weekly_sched'), 20);
if ( $this->s2_mu ) {
add_action('wpmu_activate_user', array(&$s2class_multisite, 'wpmu_add_user'));
add_action('add_user_to_blog', array(&$s2class_multisite, 'wpmu_add_user'), 10);
add_action('remove_user_from_blog', array(&$s2class_multisite, 'wpmu_remove_user'), 10);
} else {
add_action('register_form', array(&$this, 'register_form'));
add_action('user_register', array(&$this, 'register_post'));
}
if ( $this->subscribe2_options['email_freq'] != 'never' ) {
add_action('s2_digest_cron', array(&$this, 'subscribe2_cron'));
add_action('transition_post_status', array(&$this, 'digest_post_transitions'), 10, 3);
} else {
$statuses = apply_filters('s2_post_statuses', array('new', 'draft', 'auto-draft', 'pending'));
if ( $this->subscribe2_options['private'] == 'yes' ) {
foreach ( $statuses as $status ) {
add_action("{$status}_to_private", array(&$this, 'publish'));
}
}
array_push($statuses, 'private', 'future');
foreach ( $statuses as $status ) {
add_action("{$status}_to_publish", array(&$this, 'publish'));
}
}
if ( 'no' !== $this->subscribe2_options['comment_subs'] ) {
add_filter('jetpack_get_available_modules', array(&$this, 's2_hide_jetpack_comments'));
if ( 'before' == $this->subscribe2_options['comment_subs'] ) {
add_action('comment_form_after_fields', array(&$this, 's2_comment_meta_form'));
} else {
add_action('comment_form', array(&$this, 's2_comment_meta_form'));
}
add_action('comment_post', array(&$this, 's2_comment_meta'), 1, 2);
add_action('wp_set_comment_status', array(&$this, 'comment_status'));
}
if ( '1' == $this->subscribe2_options['widget'] ) {
add_action('widgets_init', array(&$this, 'subscribe2_widget'));
}
if ( '1' == $this->subscribe2_options['counterwidget'] ) {
add_action('widgets_init', array(&$this, 'counter_widget'));
}
if ( $this->clean_interval > 0 ) {
add_action('wp_scheduled_delete', array(&$this, 's2cleaner_task'));
}
if ( is_admin() ) {
add_action('admin_menu', array(&$this, 'admin_menu'));
add_action('admin_menu', array(&$this, 's2_meta_init'));
add_action('save_post', array(&$this, 's2_meta_handler'));
add_action('create_category', array(&$this, 'new_category'));
add_action('delete_category', array(&$this, 'delete_category'));
if ( function_exists('wp_ozh_adminmenu') ) {
add_filter('ozh_adminmenu_icon_s2_posts', array(&$this, 'ozh_s2_icon'));
add_filter('ozh_adminmenu_icon_s2_users', array(&$this, 'ozh_s2_icon'));
add_filter('ozh_adminmenu_icon_s2_tools', array(&$this, 'ozh_s2_icon'));
add_filter('ozh_adminmenu_icon_s2_settings', array(&$this, 'ozh_s2_icon'));
}
if ( '1' == $this->subscribe2_options['show_button'] ) {
add_action('admin_init', array(&$this, 'button_init'));
}
if ( '1' == $this->subscribe2_options['counterwidget'] ) {
add_action('admin_init', array(&$this, 'widget_s2counter_css_and_js'));
}
if ( 'yes' == $this->subscribe2_options['one_click_profile'] ) {
add_action( 'show_user_profile', array(&$this, 'one_click_profile_form') );
add_action( 'edit_user_profile', array(&$this, 'one_click_profile_form') );
add_action( 'personal_options_update', array(&$this, 'one_click_profile_form_save') );
add_action( 'edit_user_profile_update', array(&$this, 'one_click_profile_form_save') );
}
if ( isset($_POST['s2_admin']) && isset($_POST['csv']) ) {
$date = date('Y-m-d');
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=subscribe2_users_$date.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $this->prepare_export($_POST['exportcsv']);
exit(0);
}
} else {
add_action('wp', array(&$this, 'load_strings'));
if ( isset($_GET['s2']) ) {
if ( defined('DOING_S2_CONFIRM') && DOING_S2_CONFIRM ) { return; }
define( 'DOING_S2_CONFIRM', true );
add_filter('request', array(&$this, 'query_filter'));
add_filter('the_title', array(&$this, 'title_filter'));
add_filter('the_content', array(&$this, 'confirm'));
}
add_shortcode('subscribe2', array(&$this, 'shortcode'));
add_filter('the_content', array(&$this, 'filter'), 10);
if ( '1' == $this->subscribe2_options['show_meta'] ) {
add_action('wp_meta', array(&$this, 'add_minimeta'), 0);
}
if ( '1' == $this->subscribe2_options['ajax'] ) {
add_action('wp_enqueue_scripts', array(&$this, 'add_ajax'));
add_action('wp_footer', array(&$this, 'add_s2_ajax'));
}
}
}
function __construct() {
$this->word_wrap = apply_filters('s2_word_wrap', 80);
$this->excerpt_length = apply_filters('s2_excerpt_length', 55);
$this->site_switching = apply_filters('s2_allow_site_switching', false);
$this->clean_interval = apply_filters('s2_clean_interval', 28);
$this->lockout = apply_filters('s2_lockout', 0);
}
var $subscribe2_options = array();
var $all_confirmed = '';
var $all_unconfirmed = '';
var $all_registered_id = '';
var $all_registered_email = '';
var $all_authors = '';
var $excluded_cats = '';
var $post_title = '';
var $permalink = '';
var $post_date = '';
var $post_time = '';
var $myname = '';
var $myemail = '';
var $authorname = '';
var $post_cat_names = '';
var $post_tag_names = '';
var $post_count = '';
var $signup_dates = array();
var $filtered = 0;
var $preview_email = false;
var $s2_mu = false;
var $action = '';
var $email = '';
var $message = '';
var $word_wrap;
var $excerpt_length;
var $site_switching;
var $clean_interval;
var $please_log_in = '';
var $profile = '';
var $confirmation_sent = '';
var $already_subscribed = '';
var $not_subscribed ='';
var $not_an_email = '';
var $barred_domain = '';
var $error = '';
var $mail_sent = '';
var $mail_failed = '';
var $form = '';
var $no_such_email = '';
var $added = '';
var $deleted = '';
var $subscribe = '';
var $unsubscribe = '';
var $confirm_subject = '';
}
?>