installed plugin Subscribe2 version 10.35

This commit is contained in:
2021-07-25 23:28:47 +00:00
committed by Gitium
parent 13a3f7b718
commit b69f6155de
63 changed files with 15023 additions and 0 deletions

View File

@ -0,0 +1,183 @@
<?php
if ( ! class_exists( 'MO_Admin_Notice' ) ) {
class MO_Admin_Notice {
public function __construct() {
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
add_action( 'network_admin_notices', array( $this, 'admin_notice' ) );
add_action( 'admin_init', array( $this, 'dismiss_admin_notice' ) );
}
public function dismiss_admin_notice() {
if ( ! isset( $_GET['mo-adaction'] ) || 'mo_dismiss_adnotice' !== $_GET['mo-adaction'] ) {
return;
}
$url = admin_url();
update_option( 'mo_dismiss_adnotice', 'true' );
wp_safe_redirect( $url );
exit;
}
public function admin_notice() {
global $pagenow;
if ( 'index.php' === $pagenow || ( isset( $_GET['page'] ) && false !== strpos( $_GET['page'], 's2_' ) ) ) {
if ( get_option( 'mo_dismiss_adnotice', 'false' ) === 'true' ) {
return;
}
if ( $this->is_plugin_installed() && $this->is_plugin_active() ) {
return;
}
$dismiss_url = esc_url_raw(
add_query_arg(
array(
'mo-adaction' => 'mo_dismiss_adnotice',
),
admin_url()
)
);
$this->notice_css();
$install_url = wp_nonce_url(
admin_url( 'plugin-install.php?s=wemail&tab=search&type=term' ),
'install-plugin_mailoptin'
);
$activate_url = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=wemail%2Fwemail.php' ), 'activate-plugin_wemail/wemail.php' );
?>
<div class="mo-admin-notice notice notice-success">
<div class="mo-notice-first-half">
<p>
<?php
printf(
// Translators: Mail Optin admin notice
__( 'Free email newsletter plugin that will %1$sincrease your email list subscribers%2$s and keep them engaged with %1$sautomated and schedule newsletters%2$s.', 'subscribe2' ),
'<span class="mo-stylize"><strong>',
'</strong></span>'
);
?>
</p>
<p style="text-decoration: underline;font-size: 12px;">Recommended by Subscribe2 plugin</p>
</div>
<div class="mo-notice-other-half">
<?php if ( ! $this->is_plugin_installed() ) : ?>
<a class="button button-primary button-hero" id="mo-install-mailoptin-plugin" href="<?php echo $install_url; ?>">
<?php _e( 'Install weMail Now for Free!', 'subscribe2' ); ?>
</a>
<?php endif; ?>
<?php if ( $this->is_plugin_installed() && ! $this->is_plugin_active() ) : ?>
<a class="button button-primary button-hero" id="mo-activate-mailoptin-plugin" href="<?php echo $activate_url; ?>">
<?php _e( 'Activate weMail Now!', 'subscribe2' ); ?>
</a>
<?php endif; ?>
<div class="mo-notice-learn-more">
<a target="_blank" href="https://getwemail.io">Learn more</a>
</div>
</div>
<a href="<?php echo $dismiss_url; ?>">
<button type="button" class="notice-dismiss">
<span class="screen-reader-text"><?php _e( 'Dismiss this notice', 'subscribe2' ); ?>.</span>
</button>
</a>
</div>
<?php
}
}
public function current_admin_url() {
$parts = wp_parse_url( home_url() );
$uri = $parts['scheme'] . '://' . $parts['host'];
if ( array_key_exists( 'port', $parts ) ) {
$uri .= ':' . $parts['port'];
}
$uri .= add_query_arg( array() );
return $uri;
}
public function is_plugin_installed() {
$installed_plugins = get_plugins();
return isset( $installed_plugins['wemail/wemail.php'] );
}
public function is_plugin_active() {
return is_plugin_active( 'wemail/wemail.php' );
}
public function notice_css() {
?>
<style type="text/css">
.mo-admin-notice {
background: #fff;
color: #000;
border-left-color: #46b450;
position: relative;
}
.mo-admin-notice .notice-dismiss:before {
color: #72777c;
}
.mo-admin-notice .mo-stylize {
line-height: 2;
}
.mo-admin-notice .button-primary {
background: #006799;
text-shadow: none;
border: 0;
box-shadow: none;
}
.mo-notice-first-half {
width: 66%;
display: inline-block;
margin: 10px 0;
}
.mo-notice-other-half {
width: 33%;
display: inline-block;
padding: 20px 0;
position: absolute;
text-align: center;
}
.mo-notice-first-half p {
font-size: 14px;
}
.mo-notice-learn-more a {
margin: 10px;
}
.mo-notice-learn-more {
margin-top: 10px;
}
</style>
<?php
}
public static function instance() {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new self();
}
return $instance;
}
}
MO_Admin_Notice::instance();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,174 @@
<?php
class S2_Ajax {
/**
* Constructor
*/
public function __construct() {
// maybe use dev scripts
$this->script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
if ( is_admin() ) {
add_action( 'wp_ajax_nopriv_subscribe2_form', array( &$this, 's2_ajax_form_handler' ) );
add_action( 'wp_ajax_nopriv_subscribe2_submit', array( &$this, 's2_ajax_submit_handler' ) );
add_filter( 's2_ajax_form', array( &$this, 's2_ajax_form_class' ), 1 );
add_filter( 'safe_style_css', array( &$this, 's2_safe_css' ) );
global $s2_frontend;
require_once S2PATH . 'classes/class-s2-core.php';
require_once S2PATH . 'classes/class-s2-frontend.php';
$s2_frontend = new S2_Frontend();
$s2_frontend->subscribe2_options = get_option( 'subscribe2_options' );
} else {
// add actions for ajax form if enabled
add_action( 'wp_enqueue_scripts', array( &$this, 'add_ajax' ) );
}
}
/**
* Add jQuery code and CSS to front pages for ajax form
*/
public function add_ajax() {
// enqueue the jQuery script we need and let WordPress handle the dependencies
wp_enqueue_script( 'jquery-ui-dialog' );
$css = apply_filters( 's2_jqueryui_css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/ui-darkness/jquery-ui.css' );
if ( is_ssl() ) {
$css = str_replace( 'http:', 'https:', $css );
}
wp_register_style( 'jquery-ui-style', $css, array(), '1.11.4' );
wp_enqueue_style( 'jquery-ui-style' );
wp_register_script( 's2-ajax', S2URL . 'include/s2-ajax' . $this->script_debug . '.js', array(), '1.3', true );
$translation_array = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'title' => __( 'Subscribe to this blog', 'subscribe2' ),
'nonce' => wp_create_nonce( 's2_ajax_form_nonce' ),
);
wp_localize_script( 's2-ajax', 's2AjaxScriptStrings', $translation_array );
wp_enqueue_script( 's2-ajax' );
}
/**
* Ajax form handler
*/
public function s2_ajax_form_handler() {
require_once ABSPATH . '/wp-includes/shortcodes.php';
$response = str_replace( ':', '&', $_POST['data'] );
$response = str_replace( '-', '=', $response );
wp_parse_str( $response, $atts );
global $s2_frontend;
$content = $s2_frontend->shortcode( $atts );
$content = apply_filters( 's2_ajax_form', $content );
$allowed_tags = array(
'form' => array(
'action' => true,
'id' => true,
'method' => true,
'name' => true,
),
'span' => array(
'style' => true,
),
'label' => array(
'for' => true,
),
'input' => array(
'id' => true,
'name' => true,
'onblur' => true,
'onfocus' => true,
'size' => true,
'type' => true,
'value' => true,
),
'p' => true,
'br' => true,
);
echo wp_kses( $content, $allowed_tags );
exit();
}
/**
* Ajax submit handler
*/
public function s2_ajax_submit_handler() {
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 's2_ajax_form_nonce' ) ) {
echo '<p>' . esc_html__( 'There was an error validating your request. Please try again later.', 'subscribe2' ) . '</p>';
wp_die();
}
$data = $_POST['data'];
if ( ( isset( $data['firstname'] ) && '' !== $data['firstname'] ) || ( isset( $data['lastname'] ) && '' !== $data['lastname'] ) || ( isset( $data['uri'] ) && 'http://' !== $data['uri'] ) ) {
// looks like some invisible-to-user fields were changed; falsely report success
echo '<p>' . esc_html__( 'A confirmation message is on its way!', 'subscribe2' ) . '</p>';
wp_die();
}
global $s2_frontend, $wpdb;
$s2_frontend->email = $s2_frontend->sanitize_email( $data['email'] );
$s2_frontend->ip = $data['ip'];
if ( false === $s2_frontend->validate_email( $s2_frontend->email ) ) {
echo '<p>' . esc_html__( 'Sorry, but that does not look like an email address to me.', 'subscribe2' ) . '</p>';
} elseif ( $s2_frontend->is_barred( $s2_frontend->email ) ) {
echo '<p>' . esc_html__( 'Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2' ) . '</p>';
} else {
if ( is_int( $s2_frontend->lockout ) && $s2_frontend->lockout > 0 ) {
$date = gmdate( 'H:i:s.u', $s2_frontend->lockout );
$ips = $wpdb->get_col( $wpdb->prepare( "SELECT ip FROM $wpdb->subscribe2 WHERE date = CURDATE() AND time > SUBTIME(CURTIME(), %s)", $date ) );
if ( in_array( $s2_frontend->ip, $ips, true ) ) {
echo '<p>' . esc_html__( 'Slow down, you move too fast.', 'subscribe2' ) . '</p>';
}
}
$check = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE user_email = %s", $s2_frontend->email ) );
if ( null !== $check ) {
// Translators: Link to login page
printf( wp_kses_post( __( 'To manage your subscription options please <a href="%1$s">login.</a>', 'subscribe2' ) ), esc_url( get_option( 'siteurl' ) . '/wp-login.php' ) );
}
if ( 'subscribe' === $data['button'] ) {
if ( '1' !== $s2_frontend->is_public( $s2_frontend->email ) ) {
// the user is unknown or inactive
$s2_frontend->add( $s2_frontend->email );
$status = $s2_frontend->send_confirm( 'add' );
if ( $status ) {
echo '<p>' . esc_html__( 'A confirmation message is on its way!', 'subscribe2' ) . '</p>';
} else {
echo '<p>' . esc_html__( 'Sorry, there seems to be an error on the server. Please try again later.', 'subscribe2' ) . '</p>';
}
} else {
// they're already subscribed
echo '<p>' . esc_html__( 'That email address is already subscribed.', 'subscribe2' ) . '</p>';
}
} elseif ( 'unsubscribe' === $data['button'] ) {
if ( false === $s2_frontend->is_public( $s2_frontend->email ) ) {
echo '<p>' . esc_html__( 'That email address is not subscribed.', 'subscribe2' ) . '</p>';
} else {
$status = $s2_frontend->send_confirm( 'del' );
if ( $status ) {
echo '<p>' . esc_html__( 'A confirmation message is on its way!', 'subscribe2' ) . '</p>';
} else {
echo '<p>' . esc_html__( 'Sorry, there seems to be an error on the server. Please try again later.', 'subscribe2' ) . '</p>';
}
}
}
}
wp_die();
}
/**
* Filter to add ajax id to form
*/
public function s2_ajax_form_class( $content ) {
$content = str_replace( '<form', '<form id="s2ajaxform"', $content );
$content = str_replace( 'wp-login.php"', 'wp-login.php" style="text-decoration: underline;"', $content );
return $content;
}
/**
* Add display attribute to safe CSS
*/
public function s2_safe_css( $style_attributes ) {
$style_attributes[] = 'display';
return $style_attributes;
}
}

View File

@ -0,0 +1,211 @@
<?php
class S2_Block_Editor {
/**
* Constructor
*/
public function __construct() {
// maybe use dev scripts
$this->script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
add_action( 'init', array( &$this, 'register_s2_meta' ) );
add_action( 'rest_api_init', array( $this, 'register_preview_endpoint' ) );
add_action( 'rest_api_init', array( $this, 'register_resend_endpoint' ) );
add_action( 'rest_api_init', array( $this, 'register_settings_endpoint' ) );
if ( is_admin() ) {
add_action( 'enqueue_block_editor_assets', array( &$this, 'gutenberg_block_editor_assets' ), 6 );
add_action( 'enqueue_block_editor_assets', array( &$this, 'gutenberg_i18n' ), 6 );
}
}
/**
* Register _s2mail meta data for Block Editor
*/
public function register_s2_meta() {
register_meta(
'post',
'_s2mail',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => function() {
return current_user_can( 'edit_posts' );
},
)
);
}
/**
* Register REST endpoints for preview email
*/
public function register_preview_endpoint() {
register_rest_route(
's2/v1',
'/preview/(?P<id>[0-9]+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'preview' ),
'args' => array(
'id' => array(
'validate_callback' => function( $param ) {
return is_numeric( $param );
},
),
),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
)
);
}
/**
* Register REST endpoints for resending emails
*/
public function register_resend_endpoint() {
register_rest_route(
's2/v1',
'/resend/(?P<id>[0-9]+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'resend' ),
'args' => array(
'id' => array(
'validate_callback' => function( $param ) {
return is_numeric( $param );
},
),
),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
)
);
}
/**
* Register REST endpoints for surfacing settings
*/
public function register_settings_endpoint() {
register_rest_route(
's2/v1',
'/settings/(?P<setting>[a-z0-9_]+)',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'setting' ),
'args' => array(
'id' => array(
'validate_callback' => function( $param ) {
return preg_match( '/^[a-z0-9_]+$/', $param ) > 0;
},
),
),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
)
);
}
/**
* Function to trigger Preview email on REST API request
*/
public function preview( $data ) {
global $mysubscribe2;
$post = get_post( intval( $data['id'] ) );
$current_user = wp_get_current_user();
if ( 0 === $current_user->ID ) {
return false;
}
if ( 'never' !== $this->subscribe2_options['email_freq'] ) {
$mysubscribe2->subscribe2_cron( $current_user->user_email );
} else {
$mysubscribe2->publish( $post, $current_user->user_email );
}
return true;
}
/**
* Function to trigger resending of email on REST API request
*/
public function resend( $data ) {
global $mysubscribe2;
$post = get_post( intval( $data['id'] ) );
$current_user = wp_get_current_user();
if ( 0 === $current_user->ID ) {
return false;
}
$mysubscribe2->publish( $post );
return true;
}
/**
* Function to return value for passed setting
*/
public function setting( $data ) {
global $mysubscribe2;
if ( array_key_exists( $data['setting'], $mysubscribe2->subscribe2_options ) ) {
return $mysubscribe2->subscribe2_options[ $data['setting'] ];
}
return false;
}
/**
* Enqueue Block Editor assets
*/
public function gutenberg_block_editor_assets() {
wp_enqueue_script(
'subscribe2-shortcode',
S2URL . 'gutenberg/shortcode' . $this->script_debug . '.js',
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
'1.1',
true
);
register_block_type(
'subscribe2-html/shortcode',
array(
'editor_script' => 'subscribe2-shortcode',
)
);
wp_enqueue_script(
'subscribe2-sidebar',
S2URL . 'gutenberg/sidebar' . $this->script_debug . '.js',
array( 'wp-plugins', 'wp-element', 'wp-i18n', 'wp-edit-post', 'wp-components', 'wp-data', 'wp-compose', 'wp-api-fetch' ),
'1.1',
true
);
}
/**
* Handle translation of Block Editor assets
*/
public function gutenberg_i18n() {
$translations = get_translations_for_domain( 'subscribe2' );
$locale_data = array(
'' => array(
'domain' => 'subscribe2',
'lang' => get_user_locale(),
'plural_forms' => 'nplurals=2; plural=n != 1;',
),
);
foreach ( $translations->entries as $msgid => $entry ) {
$locale_data[ $msgid ] = $entry->translations;
}
wp_add_inline_script(
'wp-i18n',
'wp.i18n.setLocaleData( ' . wp_json_encode( $locale_data ) . ', "subscribe2" );'
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
<?php
class S2_Counter_Widget extends WP_Widget {
/**
* Declares the S2_Counter_widget class.
*/
public function __construct() {
$widget_options = array(
'classname' => 's2_counter',
'description' => esc_html__( 'Subscriber Counter widget for Subscribe2', 'subscribe2' ),
'customize_selective_refresh' => true,
);
$control_options = array(
'width' => 250,
'height' => 500,
);
parent::__construct( 's2_counter', esc_html__( 'Subscribe2 Counter', 'subscribe2' ), $widget_options, $control_options );
}
/**
* Displays the Widget
*/
public function widget( $args, $instance ) {
$title = empty( $instance['title'] ) ? 'Subscriber Count' : $instance['title'];
$s2w_bg = empty( $instance['s2w_bg'] ) ? '#e3dacf' : $instance['s2w_bg'];
$s2w_fg = empty( $instance['s2w_fg'] ) ? '#345797' : $instance['s2w_fg'];
$s2w_width = empty( $instance['s2w_width'] ) ? '82' : $instance['s2w_width'];
$s2w_height = empty( $instance['s2w_height'] ) ? '16' : $instance['s2w_height'];
$s2w_font = empty( $instance['s2w_font'] ) ? '11' : $instance['s2w_font'];
echo wp_kses_post( $args['before_widget'] );
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_html( $title ) . wp_kses_post( $args['after_title'] );
}
global $mysubscribe2;
$registered = $mysubscribe2->get_registered();
$confirmed = $mysubscribe2->get_public();
$count = ( count( $registered ) + count( $confirmed ) );
echo wp_kses_post( '<ul><div style="text-align:center; background-color:' . $s2w_bg . '; color:' . $s2w_fg . '; width:' . $s2w_width . 'px; height:' . $s2w_height . 'px; font:' . $s2w_font . 'pt Verdana, Arial, Helvetica, sans-serif; vertical-align:middle; padding:3px; border:1px solid #444;">' );
echo esc_html( $count );
echo '</div></ul>';
echo wp_kses_post( $args['after_widget'] );
}
/**
* Saves the widgets settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
$instance['s2w_bg'] = wp_strip_all_tags( stripslashes( $new_instance['s2w_bg'] ) );
$instance['s2w_fg'] = wp_strip_all_tags( stripslashes( $new_instance['s2w_fg'] ) );
$instance['s2w_width'] = wp_strip_all_tags( stripslashes( $new_instance['s2w_width'] ) );
$instance['s2w_height'] = wp_strip_all_tags( stripslashes( $new_instance['s2w_height'] ) );
$instance['s2w_font'] = wp_strip_all_tags( stripslashes( $new_instance['s2w_font'] ) );
return $instance;
}
/**
* Creates the edit form for the widget.
*/
public function form( $instance ) {
// set some defaults
$options = get_option( 'widget_s2counter' );
if ( false === $options ) {
$defaults = array(
'title' => 'Subscriber Count',
's2w_bg' => '#e3dacf',
's2w_fg' => '#345797',
's2w_width' => '82',
's2w_height' => '16',
's2w_font' => '11',
);
} else {
$defaults = array(
'title' => $options['title'],
's2w_bg' => $options['s2w_bg'],
's2w_fg' => $options['s2w_fg'],
's2w_width' => $options['s2w_width'],
's2w_height' => $options['s2w_height'],
's2w_font' => $options['s2w_font'],
);
delete_option( 'widget_s2counter' );
}
$instance = wp_parse_args( (array) $instance, $defaults );
// Be sure you format your options to be valid HTML attributes.
$s2w_title = htmlspecialchars( $instance['title'], ENT_QUOTES );
$s2w_bg = htmlspecialchars( $instance['s2w_bg'], ENT_QUOTES );
$s2w_fg = htmlspecialchars( $instance['s2w_fg'], ENT_QUOTES );
$s2w_width = htmlspecialchars( $instance['s2w_width'], ENT_QUOTES );
$s2w_height = htmlspecialchars( $instance['s2w_height'], ENT_QUOTES );
$s2w_font = htmlspecialchars( $instance['s2w_font'], ENT_QUOTES );
echo '<div>' . "\r\n";
echo '<fieldset><legend><label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Widget Title', 'subscribe2' ) . '</label></legend>' . "\r\n";
echo '<input type="text" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" value="' . esc_attr( $s2w_title ) . '" />' . "\r\n";
echo '</fieldset>' . "\r\n";
echo '<fieldset>' . "\r\n";
echo '<legend>' . esc_html__( 'Color Scheme', 'subscribe2' ) . '</legend>' . "\r\n";
echo '<label>' . "\r\n";
echo '<input type="text" name="' . esc_attr( $this->get_field_name( 's2w_bg' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_bg' ) ) . '" maxlength="6" value="' . esc_attr( $s2w_bg ) . '" class="colorpickerField" style="width:60px;" /> ' . esc_html__( 'Body', 'subscribe2' ) . '</label><br>' . "\r\n";
echo '<label>' . "\r\n";
echo '<input type="text" name="' . esc_attr( $this->get_field_name( 's2w_fg' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_fg' ) ) . '" maxlength="6" value="' . esc_attr( $s2w_fg ) . '" class="colorpickerField" style="width:60px;" /> ' . esc_html__( 'Text', 'subscribe2' ) . '</label><br>' . "\r\n";
echo '<div class="s2_colorpicker" id ="' . esc_attr( $this->get_field_id( 's2_colorpicker' ) ) . '"></div>';
echo '</fieldset>';
echo '<fieldset>' . "\r\n";
echo '<legend>' . esc_html__( 'Width, Height and Font Size', 'subscribe2' ) . '</legend>' . "\r\n";
echo '<table style="border:0; padding:0; margin:0 0 12px 0; border-collapse:collapse;" align="center">' . "\r\n";
echo '<tr><td><label for="' . esc_attr( $this->get_field_id( 's2w_width' ) ) . '">' . esc_html__( 'Width', 'subscribe2' ) . '</label></td>' . "\r\n";
echo '<td><input type="text" name="' . esc_attr( $this->get_field_name( 's2w_width' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_width' ) ) . '" value="' . esc_attr( $s2w_width ) . '" /></td></tr>' . "\r\n";
echo '<tr><td><label for="' . esc_attr( $this->get_field_id( 's2w_height' ) ) . '">' . esc_html__( 'Height', 'subscribe2' ) . '</label></td>' . "\r\n";
echo '<td><input type="text" name="' . esc_attr( $this->get_field_name( 's2w_height' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_height' ) ) . '" value="' . esc_attr( $s2w_height ) . '" /></td></tr>' . "\r\n";
echo '<tr><td><label for="' . esc_attr( $this->get_field_id( 's2w_font' ) ) . '">' . esc_html__( 'Font', 'subscribe2' ) . '</label></td>' . "\r\n";
echo '<td><input type="text" name="' . esc_attr( $this->get_field_name( 's2w_font' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_font' ) ) . '" value="' . esc_attr( $s2w_font ) . '" /></td></tr>' . "\r\n";
echo '</table></fieldset></div>' . "\r\n";
}
}// end S2_Counter_widget class

View File

@ -0,0 +1,187 @@
<?php
class S2_Form_Widget extends WP_Widget {
/**
* Declares the Subscribe2 widget class.
*/
public function __construct() {
$widget_ops = array(
'classname' => 's2_form_widget',
'description' => esc_html__( 'Sidebar Widget for Subscribe2', 'subscribe2' ),
'customize_selective_refresh' => true,
);
$control_ops = array(
'width' => 250,
'height' => 300,
);
parent::__construct( 's2_form_widget', esc_html__( 'Subscribe2 Widget', 'subscribe2' ), $widget_ops, $control_ops );
}
/**
* Displays the Widget
*/
public function widget( $args, $instance ) {
$title = empty( $instance['title'] ) ? __( 'Subscribe2', 'subscribe2' ) : $instance['title'];
$div = empty( $instance['div'] ) ? 'search' : $instance['div'];
$widgetprecontent = empty( $instance['widgetprecontent'] ) ? '' : $instance['widgetprecontent'];
$widgetpostcontent = empty( $instance['widgetpostcontent'] ) ? '' : $instance['widgetpostcontent'];
$textbox_size = empty( $instance['size'] ) ? 20 : $instance['size'];
$hidebutton = empty( $instance['hidebutton'] ) ? 'none' : $instance['hidebutton'];
$postto = empty( $instance['postto'] ) ? '' : $instance['postto'];
$js = empty( $instance['js'] ) ? '' : $instance['js'];
$noantispam = empty( $instance['noantispam'] ) ? '' : $instance['noantispam'];
$nowrap = empty( $instance['nowrap'] ) ? '' : $instance['nowrap'];
$hide = '';
if ( 'subscribe' === $hidebutton || 'unsubscribe' === $hidebutton ) {
$hide = ' hide="' . $hidebutton . '"';
} elseif ( 'link' === $hidebutton ) {
$hide = ' link="' . __( '(Un)Subscribe to Posts', 'subscribe2' ) . '"';
}
$postid = '';
if ( ! empty( $postto ) ) {
$postid = ' id="' . $postto . '"';
}
$size = ' size="' . $textbox_size . '"';
$nojs = '';
if ( $js ) {
$nojs = ' nojs="true"';
}
if ( $noantispam ) {
$noantispam = ' noantispam="true"';
}
if ( $nowrap ) {
$nowrap = ' wrap="false"';
}
$shortcode = '[subscribe2' . $hide . $postid . $size . $nojs . $noantispam . $nowrap . ' widget="true"]';
echo wp_kses_post( $args['before_widget'] );
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_attr( $title ) . wp_kses_post( $args['after_title'] );
}
echo '<div class="' . esc_attr( $div ) . '">';
if ( ! empty( $widgetprecontent ) ) {
echo wp_kses_post( $widgetprecontent );
}
echo do_shortcode( $shortcode );
if ( ! empty( $widgetpostcontent ) ) {
echo wp_kses_post( $widgetpostcontent );
}
echo '</div>';
echo wp_kses_post( $args['after_widget'] );
}
/**
* Saves the widgets settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
$instance['div'] = wp_strip_all_tags( stripslashes( $new_instance['div'] ) );
$instance['widgetprecontent'] = stripslashes( $new_instance['widgetprecontent'] );
$instance['widgetpostcontent'] = stripslashes( $new_instance['widgetpostcontent'] );
$instance['size'] = intval( stripslashes( $new_instance['size'] ) );
$instance['hidebutton'] = wp_strip_all_tags( stripslashes( $new_instance['hidebutton'] ) );
$instance['postto'] = stripslashes( $new_instance['postto'] );
$instance['js'] = stripslashes( $new_instance['js'] );
$instance['noantispam'] = stripslashes( $new_instance['noantispam'] );
$instance['nowrap'] = stripslashes( $new_instance['nowrap'] );
return $instance;
}
/**
* Creates the edit form for the widget.
*/
public function form( $instance ) {
// set some defaults, getting any old options first
$options = get_option( 'widget_subscribe2widget' );
if ( false === $options ) {
$defaults = array(
'title' => 'Subscribe2',
'div' => 'search',
'widgetprecontent' => '',
'widgetpostcontent' => '',
'size' => 20,
'hidebutton' => 'none',
'postto' => '',
'js' => '',
'noantispam' => '',
'nowrap' => '',
);
} else {
$defaults = array(
'title' => $options['title'],
'div' => $options['div'],
'widgetprecontent' => $options['widgetprecontent'],
'widgetpostcontent' => $options['widgetpostcontent'],
'size' => $options['size'],
'hidebutton' => $options['hidebutton'],
'postto' => $options['postto'],
'js' => $options['js'],
'noantispam' => $options['noantispam'],
'nowrap' => $options['nowrap'],
);
delete_option( 'widget_subscribe2widget' );
}
// code to obtain old settings too
$instance = wp_parse_args( (array) $instance, $defaults );
$title = htmlspecialchars( $instance['title'], ENT_QUOTES );
$div = htmlspecialchars( $instance['div'], ENT_QUOTES );
$widgetprecontent = htmlspecialchars( $instance['widgetprecontent'], ENT_QUOTES );
$widgetpostcontent = htmlspecialchars( $instance['widgetpostcontent'], ENT_QUOTES );
$size = htmlspecialchars( $instance['size'], ENT_QUOTES );
$hidebutton = htmlspecialchars( $instance['hidebutton'], ENT_QUOTES );
$postto = htmlspecialchars( $instance['postto'], ENT_QUOTES );
$js = htmlspecialchars( $instance['js'], ENT_QUOTES );
$noantispam = htmlspecialchars( $instance['noantispam'], ENT_QUOTES );
$nowrap = htmlspecialchars( $instance['nowrap'], ENT_QUOTES );
global $wpdb, $mysubscribe2;
$sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish'";
echo '<div>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Title', 'subscribe2' ) . ':' . "\r\n";
echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $title ) . '" /></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'div' ) ) . '">' . esc_html__( 'Div class name', 'subscribe2' ) . ':' . "\r\n";
echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'div' ) ) . '" name="' . esc_attr( $this->get_field_name( 'div' ) ) . '" type="text" value="' . esc_attr( $div ) . '" /></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'widgetprecontent' ) ) . '">' . esc_html__( 'Pre-Content', 'subscribe2' ) . ':' . "\r\n";
echo '<textarea class="widefat" id="' . esc_attr( $this->get_field_id( 'widgetprecontent' ) ) . '" name="' . esc_attr( $this->get_field_name( 'widgetprecontent' ) ) . '" rows="2" cols="25">' . esc_attr( $widgetprecontent ) . '</textarea></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'widgetpostcontent' ) ) . '">' . esc_html__( 'Post-Content', 'subscribe2' ) . ':' . "\r\n";
echo '<textarea class="widefat" id="' . esc_attr( $this->get_field_id( 'widgetpostcontent' ) ) . '" name="' . esc_attr( $this->get_field_name( 'widgetpostcontent' ) ) . '" rows="2" cols="25">' . esc_attr( $widgetpostcontent ) . '</textarea></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'size' ) ) . '">' . esc_html__( 'Text Box Size', 'subscribe2' ) . ':' . "\r\n";
echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'size' ) ) . '" name="' . esc_attr( $this->get_field_name( 'size' ) ) . '" type="text" value="' . esc_attr( $size ) . '" /></label></p>' . "\r\n";
echo '<p>' . esc_html__( 'Display options', 'subscribe2' ) . ':<br>' . "\r\n";
echo '<label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'complete"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'complete" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="none"' . checked( 'none', $hidebutton, false ) . '/> ' . esc_html__( 'Show complete form', 'subscribe2' ) . '</label>' . "\r\n";
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'subscribe"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'subscribe" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="subscribe"' . checked( 'subscribe', $hidebutton, false ) . '/> ' . esc_html__( 'Hide Subscribe button', 'subscribe2' ) . '</label>' . "\r\n";
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'unsubscribe"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'unsubscribe" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="unsubscribe"' . checked( 'unsubscribe', $hidebutton, false ) . '/> ' . esc_html__( 'Hide Unsubscribe button', 'subscribe2' ) . '</label>' . "\r\n";
if ( '1' === $mysubscribe2->subscribe2_options['ajax'] ) {
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'ajax"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'ajax" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="link"' . checked( 'link', $hidebutton, false ) . '/> ' . esc_html__( 'Show as link', 'subscribe2' ) . '</label>' . "\r\n";
}
echo '</p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'postto' ) ) . '">' . esc_html__( 'Post form content to page', 'subscribe2' ) . ':' . "\r\n";
echo '<select class="widefat" id="' . esc_attr( $this->get_field_id( 'postto' ) ) . '" name="' . esc_attr( $this->get_field_name( 'postto' ) ) . '">' . "\r\n";
echo '<option value="' . esc_attr( $mysubscribe2->subscribe2_options['s2page'] ) . '">' . esc_html__( 'Use Subscribe2 Default', 'subscribe2' ) . '</option>' . "\r\n";
echo '<option value="home"';
if ( 'home' === $postto ) {
echo ' selected="selected"';
}
echo '>' . esc_html__( 'Use Home Page', 'subscribe2' ) . '</option>' . "\r\n";
echo '<option value="self"';
if ( 'self' === $postto ) {
echo ' selected="selected"';
}
echo '>' . esc_html__( 'Use Referring Page', 'subscribe2' ) . '</option>' . "\r\n";
$mysubscribe2->pages_dropdown( $postto );
echo '</select></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'js' ) ) . '">' . esc_html__( 'Disable JavaScript', 'subscribe2' ) . ':' . "\r\n";
echo '<input id="' . esc_attr( $this->get_field_id( 'js' ) ) . '" name ="' . esc_attr( $this->get_field_name( 'js' ) ) . '" value="true" type="checkbox"' . checked( 'true', $js, false ) . '/>';
echo '</label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'noantispam' ) ) . '">' . esc_html__( 'Disable Anti-spam measures', 'subscribe2' ) . ':' . "\r\n";
echo '<input id="' . esc_attr( $this->get_field_id( 'noantispam' ) ) . '" name ="' . esc_attr( $this->get_field_name( 'noantispam' ) ) . '" value="true" type="checkbox"' . checked( 'true', $noantispam, false ) . '/>';
echo '</label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'nowrap' ) ) . '">' . esc_html__( 'Disable wrapping of form buttons', 'subscribe2' ) . ':' . "\r\n";
echo '<input id="' . esc_attr( $this->get_field_id( 'nowrap' ) ) . '" name ="' . esc_attr( $this->get_field_name( 'nowrap' ) ) . '" value="true" type="checkbox"' . checked( 'true', $nowrap, false ) . '/>';
echo '</label></p>' . "\r\n";
echo '</div>' . "\r\n";
}
} // End S2_Form_widget class

View File

@ -0,0 +1,428 @@
<?php
class S2_Forms {
/**
* Functions to Display content of Your Subscriptions page and process any input
*/
public function init() {
add_action( 's2_subscription_submit', array( &$this, 's2_your_subscription_submit' ) );
add_action( 's2_subscription_form', array( &$this, 's2_your_subscription_form' ), 10, 2 );
}
/**
* Return appropriate user ID if user can edit other users subscriptions
*/
public function get_userid() {
if ( isset( $_GET['id'] ) ) {
if ( ! current_user_can( apply_filters( 's2_capability', 'manage_options', 'manage' ) ) ) {
die( '<p>' . esc_html__( 'Permission error! Your request cannot be completed.', 'subscribe2' ) . '</p>' );
}
if ( is_multisite() ) {
if ( ! is_user_member_of_blog( $_GET['id'], get_current_blog_id() ) ) {
die( '<p>' . esc_html__( 'Permission error! Your request cannot be completed.', 'subscribe2' ) . '</p>' );
} else {
$userid = (int) $_GET['id'];
}
} else {
$userid = (int) $_GET['id'];
}
} else {
global $user_ID;
return $user_ID;
}
return $userid;
}
/**
* Display the form to allow Regsitered users to amend their subscription
*/
public function s2_your_subscription_form( $userid ) {
if ( ! is_int( $userid ) ) {
return false;
}
global $mysubscribe2;
echo '<input type="hidden" name="s2_admin" value="user" />';
if ( 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
echo esc_html__( 'Receive email as', 'subscribe2' ) . ': &nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="html"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'html', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Full', 'subscribe2' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="html_excerpt"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'html_excerpt', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Excerpt', 'subscribe2' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="post"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'post', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Full', 'subscribe2' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="excerpt"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'excerpt', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Excerpt', 'subscribe2' ) . '</label><br><br>' . "\r\n";
if ( 'yes' === $mysubscribe2->subscribe2_options['show_autosub'] ) {
echo esc_html__( 'Automatically subscribe me to newly created categories', 'subscribe2' ) . ': &nbsp;&nbsp;';
echo '<label><input type="radio" name="new_category" value="yes"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), true ), 'yes', false ) . ' />';
echo ' ' . esc_html__( 'Yes', 'subscribe2' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="new_category" value="no"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), true ), 'no', false ) . ' />';
echo ' ' . esc_html__( 'No', 'subscribe2' ) . '</label>';
echo '</p>';
}
if ( 'yes' === $mysubscribe2->subscribe2_options['one_click_profile'] ) {
// One-click subscribe and unsubscribe buttons
echo '<h2>' . esc_html__( 'One Click Subscription / Unsubscription', 'subscribe2' ) . "</h2>\r\n";
echo '<p class="submit"><input type="submit" class="button-primary" name="subscribe" value="' . esc_html__( 'Subscribe to All', 'subscribe2' ) . '" />&nbsp;&nbsp;';
echo '<input type="submit" class="button-primary" name="unsubscribe" value="' . esc_html__( 'Unsubscribe from All', 'subscribe2' ) . '" /></p>';
}
// subscribed categories
if ( $mysubscribe2->s2_mu ) {
global $blog_id;
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
// if we are subscribed to the current blog display an "unsubscribe" link
if ( ! empty( $subscribed ) ) {
$unsubscribe_link = esc_url( add_query_arg( 's2mu_unsubscribe', $blog_id ) );
echo '<p><a href="' . esc_url( $unsubscribe_link ) . '" class="button">' . esc_html__( 'Unsubscribe me from this blog', 'subscribe2' ) . '</a></p>';
} else {
// else we show a "subscribe" link
$subscribe_link = esc_url( add_query_arg( 's2mu_subscribe', $blog_id ) );
echo '<p><a href="' . esc_url( $subscribe_link ) . '" class="button">' . esc_html__( 'Subscribe to all categories', 'subscribe2' ) . '</a></p>';
}
echo '<h2>' . esc_html__( 'Subscribed Categories on', 'subscribe2' ) . ' ' . esc_html( get_option( 'blogname' ) ) . ' </h2>' . "\r\n";
} else {
echo '<h2>' . esc_html__( 'Subscribed Categories', 'subscribe2' ) . '</h2>' . "\r\n";
}
('' === $mysubscribe2->subscribe2_options['compulsory']) ? $compulsory = array() : $compulsory = explode( ',', $mysubscribe2->subscribe2_options['compulsory'] );
$this->display_category_form( explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ), $mysubscribe2->subscribe2_options['reg_override'], $compulsory );
} else {
// we're doing daily digests, so just show
// subscribe / unnsubscribe
echo esc_html__( 'Receive periodic summaries of new posts?', 'subscribe2' ) . ': &nbsp;&nbsp;';
echo '<label>';
echo '<input type="radio" name="category" value="digest"';
if ( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'Yes', 'subscribe2' ) . '</label> <label><input type="radio" name="category" value="-1" ';
if ( ! get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'No', 'subscribe2' );
echo '</label></p>';
}
if ( count( $this->get_authors() ) > 1 && 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
echo '<div class="s2_admin" id="s2_authors">' . "\r\n";
echo '<h2>' . esc_html__( 'Do not send notifications for post made by these authors', 'subscribe2' ) . '</h2>' . "\r\n";
$this->display_author_form( explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), true ) ) );
echo '</div>' . "\r\n";
}
// list of subscribed blogs on WordPress mu
if ( $mysubscribe2->s2_mu && ! isset( $_GET['email'] ) ) {
global $blog_id, $s2class_multisite;
$s2blog_id = $blog_id;
$current_user = wp_get_current_user();
$blogs = $s2class_multisite->get_mu_blog_list();
$blogs_subscribed = array();
$blogs_notsubscribed = array();
foreach ( $blogs as $blog ) {
// switch to blog
switch_to_blog( $blog['blog_id'] );
// check that the Subscribe2 plugin is active on the current blog
$current_plugins = get_option( 'active_plugins' );
if ( ! is_array( $current_plugins ) ) {
$current_plugins = (array) $current_plugins;
}
if ( ! in_array( S2DIR . 'subscribe2.php', $current_plugins, true ) ) {
continue;
}
// check if we're subscribed to the blog
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$blogname = get_option( 'blogname' );
if ( strlen( $blogname ) > 30 ) {
$blog['blogname'] = wp_html_excerpt( $blogname, 30 ) . '..';
} else {
$blog['blogname'] = $blogname;
}
$blog['description'] = get_option( 'blogdescription' );
$blog['blogurl'] = get_option( 'home' );
$blog['subscribe_page'] = get_option( 'home' ) . '/wp-admin/admin.php?page=s2';
$key = strtolower( $blog['blogname'] . '-' . $blog['blog_id'] );
if ( ! empty( $subscribed ) ) {
$blogs_subscribed[ $key ] = $blog;
} else {
$blogs_notsubscribed[ $key ] = $blog;
}
restore_current_blog();
}
echo '<div class="s2_admin" id="s2_mu_sites">' . "\r\n";
if ( ! empty( $blogs_subscribed ) ) {
ksort( $blogs_subscribed );
echo '<h2>' . esc_html__( 'Subscribed Blogs', 'subscribe2' ) . '</h2>' . "\r\n";
echo '<ul class="s2_blogs">' . "\r\n";
foreach ( $blogs_subscribed as $blog ) {
echo '<li><span class="name"><a href="' . esc_url( $blog['blogurl'] ) . '" title="' . esc_attr( $blog['description'] ) . '">' . esc_html( $blog['blogname'] ) . '</a></span>' . "\r\n";
if ( $s2blog_id === $blog['blog_id'] ) {
echo '<span class="buttons">' . esc_html__( 'Viewing Settings Now', 'subscribe2' ) . '</span>' . "\r\n";
} else {
echo '<span class="buttons">';
if ( is_user_member_of_blog( $current_user->id, $blog['blog_id'] ) ) {
echo '<a href="' . esc_url( $blog['subscribe_page'] ) . '">' . esc_html__( 'View Settings', 'subscribe2' ) . '</a>' . "\r\n";
}
echo '<a href="' . esc_url( add_query_arg( 's2mu_unsubscribe', $blog['blog_id'] ) ) . '">' . esc_html__( 'Unsubscribe', 'subscribe2' ) . '</a></span>' . "\r\n";
}
echo '<div class="additional_info">' . esc_html( $blog['description'] ) . '</div>' . "\r\n";
echo '</li>';
}
echo '</ul>' . "\r\n";
}
if ( ! empty( $blogs_notsubscribed ) ) {
ksort( $blogs_notsubscribed );
echo '<h2>' . esc_html__( 'Subscribe to new blogs', 'subscribe2' ) . "</h2>\r\n";
echo '<ul class="s2_blogs">';
foreach ( $blogs_notsubscribed as $blog ) {
echo '<li><span class="name"><a href="' . esc_url( $blog['blogurl'] ) . '" title="' . esc_attr( $blog['description'] ) . '">' . esc_html( $blog['blogname'] ) . '</a></span>' . "\r\n";
if ( $s2blog_id === $blog['blog_id'] ) {
echo '<span class="buttons">' . esc_html__( 'Viewing Settings Now', 'subscribe2' ) . '</span>' . "\r\n";
} else {
echo '<span class="buttons">';
if ( is_user_member_of_blog( $current_user->id, $blog['blog_id'] ) ) {
echo '<a href="' . esc_url( $blog['subscribe_page'] ) . '">' . esc_html__( 'View Settings', 'subscribe2' ) . '</a>' . "\r\n";
}
echo '<a href="' . esc_url( add_query_arg( 's2mu_subscribe', $blog['blog_id'] ) ) . '">' . esc_html__( 'Subscribe', 'subscribe2' ) . '</a></span>' . "\r\n";
}
echo '<div class="additional_info">' . esc_html( $blog['description'] ) . '</div>' . "\r\n";
echo '</li>';
}
echo '</ul>' . "\r\n";
}
echo '</div>' . "\r\n";
}
}
/**
* Process input from the form that allows Regsitered users to amend their subscription
*/
public function s2_your_subscription_submit() {
global $mysubscribe2, $user_ID;
$userid = $this->get_userid();
if ( isset( $_POST['submit'] ) ) {
if ( isset( $_POST['s2_format'] ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), $_POST['s2_format'] );
} else {
// value has not been set so use default
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), 'excerpt' );
}
if ( isset( $_POST['new_category'] ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), $_POST['new_category'] );
} else {
// value has not been passed so use Settings defaults
if ( 'yes' === $mysubscribe2->subscribe2_options['show_autosub'] && 'yes' === $mysubscribe2->subscribe2_options['autosub_def'] ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), 'yes' );
} else {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), 'no' );
}
}
$cats = ( isset( $_POST['category'] ) ) ? $_POST['category'] : '';
if ( empty( $cats ) || '-1' === $cats ) {
$oldcats = explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) );
if ( $oldcats ) {
foreach ( $oldcats as $cat ) {
delete_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), '' );
} elseif ( 'digest' === $cats ) {
$all_cats = $mysubscribe2->all_cats( false, 'ID' );
foreach ( $all_cats as $cat ) {
( '' === $catids ) ? $catids = "$cat->term_id" : $catids .= ",$cat->term_id";
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat->term_id, $cat->term_id );
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $catids );
} else {
if ( ! is_array( $cats ) ) {
$cats = (array) $_POST['category'];
}
sort( $cats );
$old_cats = explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) );
$remove = array_diff( $old_cats, $cats );
$new = array_diff( $cats, $old_cats );
if ( ! empty( $remove ) ) {
// remove subscription to these cat IDs
foreach ( $remove as $id ) {
delete_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $id );
}
}
if ( ! empty( $new ) ) {
// add subscription to these cat IDs
foreach ( $new as $id ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $id, $id );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), implode( ',', $cats ) );
}
$authors = ( isset( $_POST['author'] ) ) ? $_POST['author'] : '';
if ( is_array( $authors ) ) {
$authors = implode( ',', $authors );
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), $authors );
} elseif ( empty( $authors ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), '' );
}
} elseif ( isset( $_POST['subscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'subscribe' );
} elseif ( isset( $_POST['unsubscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'unsubscribe' );
}
echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Subscription preferences updated.', 'subscribe2' ) . '</strong></p></div>' . "\r\n";
}
/**
* Display a table of categories with checkboxes
* Optionally pre-select those categories specified
*/
public function display_category_form( $selected = array(), $override = 1, $compulsory = array(), $name = 'category' ) {
global $wpdb, $mysubscribe2;
if ( 0 === $override ) {
$all_cats = $mysubscribe2->all_cats( true );
} else {
$all_cats = $mysubscribe2->all_cats( false );
}
$half = ( count( $all_cats ) / 2 );
$i = 0;
$j = 0;
echo '<table style="width: 100%; border-collapse: separate; border-spacing: 2px; *border-collapse: expression(\'separate\', cellSpacing = \'2px\');" class="editform">' . "\r\n";
echo '<tr><td style="text-align: left;" colspan="2">' . "\r\n";
echo '<label><input type="checkbox" name="checkall" value="checkall_' . esc_attr( $name ) . '" /> ' . esc_html__( 'Select / Unselect All', 'subscribe2' ) . '</label>' . "\r\n";
echo '</td></tr>' . "\r\n";
echo '<tr style="vertical-align: top;"><td style="width: 50%; text-align: left;">' . "\r\n";
foreach ( $all_cats as $cat ) {
if ( $i >= $half && 0 === $j ) {
echo '</td><td style="width: 50%; text-align: left;">' . "\r\n";
$j++;
}
$cat_name = '';
$parents = array_reverse( get_ancestors( $cat->term_id, $cat->taxonomy ) );
if ( $parents ) {
foreach ( $parents as $parent ) {
$parent = get_term( $parent, $cat->taxonomy );
$cat_name .= $parent->name . ' &raquo; ';
}
}
$cat_name .= $cat->name;
if ( 0 === $j ) {
echo '<label><input class="checkall_' . esc_attr( $name ) . '" type="checkbox" name="' . esc_attr( $name ) . '[]" value="' . esc_attr( $cat->term_id ) . '"';
if ( in_array( (string) $cat->term_id, $selected, true ) || in_array( (string) $cat->term_id, $compulsory, true ) ) {
echo ' checked="checked"';
}
if ( in_array( (string) $cat->term_id, $compulsory, true ) && 'category' === $name ) {
echo ' DISABLED';
}
echo ' /> <abbr title="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat_name ) . '</abbr></label><br>' . "\r\n";
} else {
echo '<label><input class="checkall_' . esc_attr( $name ) . '" type="checkbox" name="' . esc_attr( $name ) . '[]" value="' . esc_attr( $cat->term_id ) . '"';
if ( in_array( (string) $cat->term_id, $selected, true ) || in_array( (string) $cat->term_id, $compulsory, true ) ) {
echo ' checked="checked"';
}
if ( in_array( (string) $cat->term_id, $compulsory, true ) && 'category' === $name ) {
echo ' DISABLED';
}
echo ' /> <abbr title="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat_name ) . '</abbr></label><br>' . "\r\n";
}
$i++;
}
if ( ! empty( $compulsory ) ) {
foreach ( $compulsory as $cat ) {
echo '<input type="hidden" name="' . esc_attr( $name ) . '[]" value="' . esc_attr( $cat ) . '">' . "\r\n";
}
}
echo '</td></tr>' . "\r\n";
echo '</table>' . "\r\n";
}
/**
* Display a table of authors with checkboxes
* Optionally pre-select those authors specified
*/
public function display_author_form( $selected = array() ) {
$all_authors = $this->get_authors();
$half = ( count( $all_authors ) / 2 );
$i = 0;
$j = 0;
echo '<table style="width: 100%; border-collapse: separate; border-spacing: 2px; *border-collapse: expression(\'separate\', cellSpacing = \'2px\');" class="editform">' . "\r\n";
echo '<tr><td style="text-align: left;" colspan="2">' . "\r\n";
echo '<label><input type="checkbox" name="checkall" value="checkall_author" /> ' . esc_html__( 'Select / Unselect All', 'subscribe2' ) . '</label>' . "\r\n";
echo '</td></tr>' . "\r\n";
echo '<tr style="vertical-align: top;"><td style="width: 50%; test-align: left;">' . "\r\n";
foreach ( $all_authors as $author ) {
if ( $i >= $half && 0 === $j ) {
echo '</td><td style="width: 50%; text-align: left;">' . "\r\n";
$j++;
}
if ( 0 === $j ) {
echo '<label><input class="checkall_author" type="checkbox" name="author[]" value="' . esc_attr( $author->ID ) . '"';
if ( in_array( $author->ID, $selected, true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html( $author->display_name ) . '</label><br>' . "\r\n";
} else {
echo '<label><input class="checkall_author" type="checkbox" name="author[]" value="' . esc_attr( $author->ID ) . '"';
if ( in_array( $author->ID, $selected, true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html( $author->display_name ) . '</label><br>' . "\r\n";
$i++;
}
}
echo '</td></tr>' . "\r\n";
echo '</table>' . "\r\n";
}
/**
* Collect an array of all author level users and above
*/
public function get_authors() {
if ( '' === $this->all_authors ) {
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'administrator',
);
$administrators = get_users( $role );
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'editor',
);
$editors = get_users( $role );
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'author',
);
$authors = get_users( $role );
$this->all_authors = array_merge( $administrators, $editors, $authors );
}
return apply_filters( 's2_authors', $this->all_authors );
}
/**
* Define some variables
*/
private $all_authors = '';
}

View File

@ -0,0 +1,571 @@
<?php
class S2_Frontend extends S2_Core {
/**
* Load all our strings
*/
public function load_strings() {
// Translators: Link to login page
$this->please_log_in = '<p class="s2_message">' . sprintf( __( 'To manage your subscription options please <a href="%1$s">login</a>.', 'subscribe2' ), get_option( 'siteurl' ) . '/wp-login.php' ) . '</p>';
$profile = apply_filters( 's2_profile_link', get_option( 'siteurl' ) . '/wp-admin/admin.php?page=s2' );
// Translators: Link to Profile page
$this->profile = '<p class="s2_message">' . sprintf( __( 'You may manage your subscription options from your <a href="%1$s">profile</a>.', 'subscribe2' ), $profile ) . '</p>';
if ( true === $this->s2_mu ) {
global $blog_id;
$user_ID = get_current_user_id();
if ( ! is_user_member_of_blog( $user_ID, $blog_id ) ) {
// if we are on multisite and the user is not a member of this blog change the link
$mu_profile = apply_filters( 's2_mu_profile_link', get_option( 'siteurl' ) . '/wp-admin/?s2mu_subscribe=' . $blog_id );
// Translators: Link to Profile page
$this->profile = '<p class="s2_message">' . sprintf( __( '<a href="%1$s">Subscribe</a> to email notifications when this blog posts new content.', 'subscribe2' ), $mu_profile ) . '</p>';
}
}
$this->confirmation_sent = '<p class="s2_message">' . __( 'A confirmation message is on its way!', 'subscribe2' ) . '</p>';
$this->already_subscribed = '<p class="s2_error">' . __( 'That email address is already subscribed.', 'subscribe2' ) . '</p>';
$this->not_subscribed = '<p class="s2_error">' . __( 'That email address is not subscribed.', 'subscribe2' ) . '</p>';
$this->not_an_email = '<p class="s2_error">' . __( 'Sorry, but that does not look like an email address to me.', 'subscribe2' ) . '</p>';
$this->barred_domain = '<p class="s2_error">' . __( 'Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2' ) . '</p>';
$this->error = '<p class="s2_error">' . __( 'Sorry, there seems to be an error on the server. Please try again later.', 'subscribe2' ) . '</p>';
// confirmation messages
$this->no_such_email = '<p class="s2_error">' . __( 'No such email address is registered.', 'subscribe2' ) . '</p>';
$this->added = '<p class="s2_message">' . __( 'You have successfully subscribed!', 'subscribe2' ) . '</p>';
$this->deleted = '<p class="s2_message">' . __( 'You have successfully unsubscribed.', 'subscribe2' ) . '</p>';
$this->subscribe = __( 'subscribe', 'subscribe2' ); //ACTION replacement in subscribing confirmation email
$this->unsubscribe = __( 'unsubscribe', 'subscribe2' ); //ACTION replacement in unsubscribing in confirmation email
if ( isset( $_GET['s2_unsub'] ) && ! empty( $_GET['s2_unsub'] ) ) {
$this->unsubscribe( $_GET['s2_unsub'] );
}
}
/**
* Process unsubscribe
*
* @param $email
*/
public function unsubscribe( $email ) {
global $wpdb;
$email = base64_decode( $email );
if (! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
$count = $wpdb->delete( $wpdb->subscribe2,
[
'email' => $email
]
);
if ( ! $count ) {
wp_safe_redirect( home_url() );
}
}
/* ===== template and filter functions ===== */
/**
* Display our form; also handles (un)subscribe requests
*/
public function shortcode( $atts ) {
$args = shortcode_atts(
array(
'hide' => '',
'id' => '',
'nojs' => 'false',
'noantispam' => 'false',
'link' => '',
'size' => 20,
'wrap' => 'true',
'widget' => 'false',
),
$atts
);
// if link is true return a link to the page with the ajax class
if ( '1' === $this->subscribe2_options['ajax'] && '' !== $args['link'] && ! is_user_logged_in() ) {
$id = '';
foreach ( $args as $arg_name => $arg_value ) {
if ( ! empty( $arg_value ) && 'link' !== $arg_name && 'id' !== $arg_name ) {
if ( 'nojs' === $arg_name ) {
$arg_value = 'true';
}
( '' === $id ) ? $id .= $arg_name . '-' . $arg_value : $id .= ':' . $arg_name . '-' . $arg_value;
}
}
$this->s2form = '<a href="#" class="s2popup" id="' . esc_attr( $id ) . '">' . esc_html( $args['link'] ) . '</a>' . "\r\n";
return $this->s2form;
}
// Apply filters to button text
$unsubscribe_button_value = apply_filters( 's2_unsubscribe_button', __( 'Unsubscribe', 'subscribe2' ) );
$subscribe_button_value = apply_filters( 's2_subscribe_button', __( 'Subscribe', 'subscribe2' ) );
// if a button is hidden, show only other
$hide = strtolower( $args['hide'] );
if ( 'subscribe' === $hide ) {
$this->input_form_action = '<input type="submit" name="unsubscribe" value="' . esc_attr( $unsubscribe_button_value ) . '" />';
} elseif ( 'unsubscribe' === $hide ) {
$this->input_form_action = '<input type="submit" name="subscribe" value="' . esc_attr( $subscribe_button_value ) . '" />';
} else {
// both form input actions
$this->input_form_action = '<input type="submit" name="subscribe" value="' . esc_attr( $subscribe_button_value ) . '" />&nbsp;<input type="submit" name="unsubscribe" value="' . esc_attr( $unsubscribe_button_value ) . '" />';
}
// if ID is provided, get permalink
$action = '';
if ( is_numeric( $args['id'] ) ) {
$action = ' action="' . get_permalink( $args['id'] ) . '"';
} elseif ( 'home' === $args['id'] ) {
$action = ' action="' . get_site_url() . '"';
} elseif ( 'self' === $args['id'] ) {
// Correct for Static front page redirect behaviour
if ( 'page' === get_option( 'show_on_front' ) && is_front_page() ) {
$post = get_post( get_option( 'page_on_front' ) );
$action = ' action="' . get_option( 'home' ) . '/' . $post->post_name . '/"';
} else {
$action = '';
}
} elseif ( $this->subscribe2_options['s2page'] > 0 ) {
$action = ' action="' . get_permalink( $this->subscribe2_options['s2page'] ) . '"';
}
// allow remote setting of email in form
if ( isset( $_REQUEST['email'] ) ) {
$email = $this->sanitize_email( $_REQUEST['email'] );
}
if ( isset( $_REQUEST['email'] ) && false !== $this->validate_email( $email ) ) {
$value = $email;
} elseif ( 'true' === strtolower( $args['nojs'] ) ) {
$value = '';
} else {
$value = __( 'Enter email address...', 'subscribe2' );
}
// if wrap is true add paragraph html tags
$wrap_text = '';
if ( 'true' === strtolower( $args['wrap'] ) ) {
$wrap_text = '</p><p>';
}
// deploy some anti-spam measures
$antispam_text = '';
if ( 'true' !== strtolower( $args['noantispam'] ) ) {
$antispam_text = '<span style="display:none !important">';
$antispam_text .= '<label for="firstname">Leave This Blank:</label><input type="text" id="firstname" name="firstname" />';
$antispam_text .= '<label for="lastname">Leave This Blank Too:</label><input type="text" id="lastname" name="lastname" />';
$antispam_text .= '<label for="uri">Do Not Change This:</label><input type="text" id="uri" name="uri" value="http://" />';
$antispam_text .= '</span>';
}
// get remote IP address
$remote_ip = $this->get_remote_ip();
// form name
if ( 'true' === $args['widget'] ) {
$form_name = 's2formwidget';
} else {
$form_name = 's2form';
}
// build default form
if ( 'true' === strtolower( $args['nojs'] ) ) {
$this->form = '<form name="' . $form_name . '" method="post"' . $action . '><input type="hidden" name="ip" value="' . esc_attr( $_SERVER['REMOTE_ADDR'] ) . '" />' . $antispam_text . '<p><label for="s2email">' . __( 'Your email:', 'subscribe2' ) . '</label><br><input type="email" name="email" id="s2email" value="' . $value . '" size="' . $args['size'] . '" />' . $wrap_text . $this->input_form_action . '</p></form>';
} else {
$this->form = '<form name="' . $form_name . '" method="post"' . $action . '><input type="hidden" name="ip" value="' . esc_attr( $_SERVER['REMOTE_ADDR'] ) . '" />' . $antispam_text . '<p><label for="s2email">' . __( 'Your email:', 'subscribe2' ) . '</label><br><input type="email" name="email" id="s2email" value="' . $value . '" size="' . $args['size'] . '" onfocus="if (this.value === \'' . $value . '\') {this.value = \'\';}" onblur="if (this.value === \'\') {this.value = \'' . $value . '\';}" />' . $wrap_text . $this->input_form_action . '</p></form>' . "\r\n";
}
$this->s2form = apply_filters( 's2_form', $this->form, $args );
global $user_ID;
if ( 0 !== $user_ID ) {
return $this->profile;
}
if ( isset( $_POST['subscribe'] ) || isset( $_POST['unsubscribe'] ) ) {
// anti spam sign up measure
if ( ( isset( $_POST['firstname'] ) && '' !== $_POST['firstname'] ) || ( isset( $_POST['lastname'] ) && '' !== $_POST['lastname'] ) || ( isset( $_POST['uri'] ) && 'http://' !== $_POST['uri'] ) ) {
// looks like some invisible-to-user fields were changed; falsely report success
return $this->confirmation_sent;
}
$validation = apply_filters( 's2_form_submission', true );
if ( true !== $validation ) {
return apply_filters( 's2_form_failed_validation', $this->s2form );
}
global $wpdb;
$this->email = $this->sanitize_email( $_POST['email'] );
if ( false === $this->validate_email( $this->email ) ) {
$this->s2form = $this->s2form . $this->not_an_email;
} elseif ( $this->is_barred( $this->email ) ) {
$this->s2form = $this->s2form . $this->barred_domain;
} else {
$this->ip = $_POST['ip'];
if ( is_int( $this->lockout ) && $this->lockout > 0 ) {
$date = gmdate( 'H:i:s.u', $this->lockout );
$ips = $wpdb->get_col( $wpdb->prepare( "SELECT ip FROM $wpdb->subscribe2 WHERE date = CURDATE() AND time > SUBTIME(CURTIME(), %s)", $date ) );
if ( in_array( $this->ip, $ips, true ) ) {
return __( 'Slow down, you move too fast.', 'subscribe2' );
}
}
// does the supplied email belong to a registered user?
$check = $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM $wpdb->users WHERE user_email = %s", $this->email ) );
if ( null !== $check ) {
// this is a registered email
$this->s2form = $this->please_log_in;
} else {
// this is not a registered email
// what should we do?
if ( isset( $_POST['subscribe'] ) ) {
// someone is trying to subscribe
// lets see if they've tried to subscribe previously
if ( '1' !== $this->is_public( $this->email ) ) {
// the user is unknown or inactive
$this->add( $this->email );
$status = $this->send_confirm( 'add' );
// set a variable to denote that we've already run, and shouldn't run again
$this->filtered = 1;
if ( $status ) {
$this->s2form = $this->confirmation_sent;
} else {
$this->s2form = $this->error;
}
} else {
// they're already subscribed
$this->s2form = $this->already_subscribed;
}
$this->action = 'subscribe';
} elseif ( isset( $_POST['unsubscribe'] ) ) {
// is this email a subscriber?
if ( false === $this->is_public( $this->email ) ) {
$this->s2form = $this->s2form . $this->not_subscribed;
} else {
$status = $this->send_confirm( 'del' );
// set a variable to denote that we've already run, and shouldn't run again
$this->filtered = 1;
if ( $status ) {
$this->s2form = $this->confirmation_sent;
} else {
$this->s2form = $this->error;
}
}
$this->action = 'unsubscribe';
}
}
}
}
return $this->s2form;
}
/**
* Display form when deprecated <!--subscribe2--> is used
*/
public function filter( $content = '' ) {
if ( '' === $content || ! strstr( $content, '<!--subscribe2-->' ) ) {
return $content;
}
return preg_replace( '/(<p>)?(\n)*<!--subscribe2-->(\n)*(<\/p>)?/', do_shortcode( '[subscribe2]' ), $content );
}
/**
* Overrides the default query when handling a (un)subscription confirmation
* This is basically a trick: if the s2 variable is in the query string, just grab the first
* static page and override it's contents later with title_filter()
*/
public function query_filter() {
// don't interfere if we've already done our thing
if ( 1 === $this->filtered ) {
return;
}
global $wpdb;
// brute force Simple Facebook Connect to bypass compatiblity issues
$priority = has_filter( 'wp_head', 'sfc_base_meta' );
if ( false !== $priority ) {
remove_action( 'wp_head', 'sfc_base_meta', $priority );
}
if ( 0 !== $this->subscribe2_options['s2page'] ) {
return array(
'page_id' => $this->subscribe2_options['s2page'],
);
} else {
$id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' LIMIT 1" );
if ( $id ) {
return array(
'page_id' => $id,
);
} else {
return array(
'showposts' => 1,
);
}
}
}
/**
* Overrides the page title
*/
public function title_filter( $title ) {
if ( in_the_loop() ) {
$code = $_GET['s2'];
$action = intval( substr( $code, 0, 1 ) );
if ( 1 === $action ) {
return __( 'Subscription Confirmation', 'subscribe2' );
} else {
return __( 'Unsubscription Confirmation', 'subscribe2' );
}
} else {
return $title;
}
}
/**
* Confirm request from the link emailed to the user and email the admin
*/
public function confirm( $content = '' ) {
global $wpdb;
if ( 1 === $this->filtered && '' !== $this->message ) {
return $this->message;
} elseif ( 1 === $this->filtered ) {
return $content;
}
$code = $_GET['s2'];
$action = substr( $code, 0, 1 );
$hash = substr( $code, 1, 32 );
$id = intval( substr( $code, 33 ) );
if ( $id ) {
$this->email = $this->sanitize_email( $this->get_email( $id ) );
if ( ! $this->email || wp_hash( $this->email ) !== $hash ) {
return $this->no_such_email;
}
} else {
return $this->no_such_email;
}
// get current status of email so messages are only sent once per emailed link
$current = $this->is_public( $this->email );
if ( '1' === $action ) {
// make this subscription active
$this->message = apply_filters( 's2_subscribe_confirmed', $this->added );
if ( '1' !== $this->is_public( $this->email ) ) {
$this->ip = esc_html( $this->get_remote_ip() );
$this->toggle( $this->email );
if ( 'subs' === $this->subscribe2_options['admin_email'] || 'both' === $this->subscribe2_options['admin_email'] ) {
$this->admin_email( 'subscribe' );
}
}
$this->filtered = 1;
} elseif ( '0' === $action ) {
// remove this public subscriber
$this->message = apply_filters( 's2_unsubscribe_confirmed', $this->deleted );
if ( '0' !== $this->is_public( $this->email ) ) {
$this->delete( $this->email );
if ( 'unsubs' === $this->subscribe2_options['admin_email'] || 'both' === $this->subscribe2_options['admin_email'] ) {
$this->admin_email( 'unsubscribe' );
}
}
$this->filtered = 1;
}
if ( '' !== $this->message ) {
return $this->message;
}
}
/**
* Prepare and send emails to admins on new subscriptions and unsubsriptions
*/
public function admin_email( $action ) {
if ( ! in_array( $action, array( 'subscribe', 'unsubscribe' ), true ) ) {
return false;
}
( '' === get_option( 'blogname' ) ) ? $subject = '' : $subject = '[' . stripslashes( html_entity_decode( get_option( 'blogname' ), ENT_QUOTES ) ) . '] ';
if ( 'subscribe' === $action ) {
$subject .= __( 'New Subscription', 'subscribe2' );
$message = $this->email . ' ' . __( 'subscribed to email notifications!', 'subscribe2' );
} elseif ( 'unsubscribe' === $action ) {
$subject .= __( 'New Unsubscription', 'subscribe2' );
$message = $this->email . ' ' . __( 'unsubscribed from email notifications!', 'subscribe2' );
}
$subject = html_entity_decode( $subject, ENT_QUOTES );
$role = array(
'fields' => array(
'user_email',
),
'role' => 'administrator',
);
$wp_user_query = get_users( $role );
foreach ( $wp_user_query as $user ) {
$recipients[] = $user->user_email;
}
$recipients = apply_filters( 's2_admin_email', $recipients, $action );
$headers = $this->headers();
// send individual emails so we don't reveal admin emails to each other
foreach ( $recipients as $recipient ) {
$status = wp_mail( $recipient, $subject, $message, $headers );
}
}
/**
* Add hook for Minimeta Widget plugin
*/
public function add_minimeta() {
if ( 0 !== $this->subscribe2_options['s2page'] ) {
echo '<li><a href="' . esc_url( get_permalink( $this->subscribe2_options['s2page'] ) ) . '">' . esc_html__( '[Un]Subscribe to Posts', 'subscribe2' ) . '</a></li>' . "\r\n";
}
}
/**
* Check email is not from a barred domain
*/
public function is_barred( $email = '' ) {
if ( '' === $email ) {
return false;
}
list( $user, $domain ) = explode( '@', $email, 2 );
$domain = '@' . $domain;
foreach ( preg_split( '/[\s,]+/', $this->subscribe2_options['barred'] ) as $barred_domain ) {
if ( false !== strpos( $barred_domain, '!' ) ) {
$url = explode( '.', str_replace( '!', '', $barred_domain ) );
$count = count( $url );
// make sure our exploded domain has at least 2 components e.g. yahoo.*
if ( $count < 2 ) {
continue;
}
for ( $i = 0; $i < $count; $i++ ) {
if ( '*' === $url[ $i ] ) {
unset( $url[ $i ] );
}
}
$new_barred_domain = '@' . strtolower( trim( implode( '.', $url ) ) );
if ( false !== strpos( $barred_domain, '*' ) ) {
$new_barred_subdomain = '.' . strtolower( trim( implode( '.', $url ) ) );
if ( false !== stripos( $domain, $new_barred_domain ) || false !== stripos( $domain, $new_barred_subdomain ) ) {
return false;
}
} else {
if ( false !== stripos( $domain, $new_barred_domain ) ) {
return false;
}
}
}
if ( false === strpos( $barred_domain, '!' ) && false !== strpos( $barred_domain, '*' ) ) {
// wildcard and explictly allowed checking
$url = explode( '.', str_replace( '!', '', $barred_domain ) );
$count = count( $url );
// make sure our exploded domain has at least 2 components e.g. yahoo.*
if ( $count < 2 ) {
continue;
}
for ( $i = 0; $i < $count; $i++ ) {
if ( '*' === $url[ $i ] ) {
unset( $url[ $i ] );
}
}
$new_barred_domain = '@' . strtolower( trim( implode( '.', $url ) ) );
$new_barred_subdomain = '.' . strtolower( trim( implode( '.', $url ) ) );
if ( false !== stripos( $domain, $new_barred_domain ) || false !== stripos( $domain, $new_barred_subdomain ) ) {
return true;
}
} else {
// direct domain string comparison
$barred_domain = '@' . $barred_domain;
if ( strtolower( $domain ) === strtolower( trim( $barred_domain ) ) ) {
return true;
}
}
}
return false;
}
/**
* Collect and return the IP address of the remote client machine
*/
public function get_remote_ip() {
$remote_ip = false;
// In order of preference, with the best ones for this purpose first
$address_headers = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
);
foreach ( $address_headers as $header ) {
if ( array_key_exists( $header, $_SERVER ) ) {
// HTTP_X_FORWARDED_FOR can contain a chain of comma-separated
// addresses. The first one is the original client. It can't be
// trusted for authenticity, but we don't need to for this purpose.
$address_chain = explode( ',', $_SERVER[ $header ] );
$remote_ip = trim( $address_chain[0] );
break;
}
}
return $remote_ip;
}
/**
* Enqueue javascript ip updater code
*/
public function js_ip_script() {
wp_register_script( 's2_ip_updater', S2URL . 'include/s2-ip-updater' . $this->script_debug . '.js', array(), '1.1', true );
wp_enqueue_script( 's2_ip_updater' );
}
/**
* Add ip updater library to footer
*/
public function js_ip_library_script() {
$args = array(
'format' => 'jsonp',
'callback' => 'getip',
);
wp_enqueue_script( 's2_ip_library', add_query_arg( $args, 'https://api.ipify.org' ), array(), S2VERSION, true );
}
/**
* Reformat WordPress escaped link to IPify library
*/
public function tag_replace_ampersand( $tag ) {
if ( strstr( $tag, 'ipify' ) !== false ) {
$tag = str_replace( '&#038;', '&', $tag );
}
return $tag;
}
/* ===== define some variables ===== */
public $profile = '';
}

View File

@ -0,0 +1,443 @@
<?php
/**
* List Table class used in WordPress 4.3.x and above
*/
class S2_List_Table extends WP_List_Table {
private $date_format = '';
private $time_format = '';
public function __construct() {
global $status, $page;
parent::__construct(
array(
'singular' => 'subscriber',
'plural' => 'subscribers',
'ajax' => false,
)
);
$this->date_format = get_option( 'date_format' );
$this->time_format = get_option( 'time_format' );
}
public function column_default( $item, $column_name ) {
global $current_tab;
switch ( $column_name ) {
case 'email':
case 'date':
return $item[ $column_name ];
}
}
public function column_email( $item ) {
global $current_tab;
if ( 'registered' === $current_tab ) {
$actions = array(
'edit' => sprintf( '<a href="?page=%s&amp;id=%d">%s</a>', 's2', rawurlencode( $item['id'] ), __( 'Edit', 'subscribe2' ) ),
);
return sprintf( '%1$s %2$s', $item['email'], $this->row_actions( $actions ) );
} else {
global $mysubscribe2;
if ( '0' === $mysubscribe2->is_public( $item['email'] ) ) {
return sprintf( '<span style="color:#FF0000"><abbr title="%2$s">%1$s</abbr></span>', $item['email'], $item['ip'] );
} else {
return sprintf( '<abbr title="%2$s">%1$s</abbr>', $item['email'], $item['ip'] );
}
}
}
public function column_date( $item ) {
global $current_tab;
if ( 'registered' === $current_tab ) {
$timestamp = strtotime( $item['date'] );
return sprintf( '<abbr title="%2$s">%1$s</abbr>', date_i18n( $this->date_format, $timestamp ), date_i18n( $this->time_format, $timestamp ) );
} else {
$timestamp = strtotime( $item['date'] . ' ' . $item['time'] );
return sprintf( '<abbr title="%2$s">%1$s</abbr>', date_i18n( $this->date_format, $timestamp ), date_i18n( $this->time_format, $timestamp ) );
}
}
public function column_cb( $item ) {
return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $item['email'] );
}
public function get_columns() {
global $current_tab;
$columns = array(
'cb' => '<input type="checkbox" />',
'email' => _x( 'Email', 'column name', 'subscribe2' ),
'date' => _x( 'Date', 'column name', 'subscribe2' ),
);
return $columns;
}
public function get_sortable_columns() {
global $current_tab;
$sortable_columns = array(
'email' => array( 'email', true ),
'date' => array( 'date', false ),
);
return $sortable_columns;
}
public function print_column_headers( $with_id = true ) {
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$current_url = remove_query_arg( 'paged', $current_url );
if ( isset( $_REQUEST['what'] ) ) {
$current_url = add_query_arg(
array(
'what' => $_REQUEST['what'],
),
$current_url
);
}
if ( isset( $_GET['orderby'] ) ) {
$current_orderby = $_GET['orderby'];
} else {
$current_orderby = '';
}
if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
$current_order = 'desc';
} else {
$current_order = 'asc';
}
if ( ! empty( $columns['cb'] ) ) {
static $cb_counter = 1;
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All', 'subscribe2' ) . '</label>'
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
$cb_counter++;
}
foreach ( $columns as $column_key => $column_display_name ) {
$class = array( 'manage-column', "column-$column_key" );
if ( in_array( $column_key, $hidden, true ) ) {
$class[] = 'hidden';
}
if ( 'cb' === $column_key ) {
$class[] = 'check-column';
}
if ( $column_key === $primary ) {
$class[] = 'column-primary';
}
if ( isset( $sortable[ $column_key ] ) ) {
list( $orderby, $desc_first ) = $sortable[ $column_key ];
if ( $current_orderby === $orderby ) {
$order = 'asc' === $current_order ? 'desc' : 'asc';
$class[] = 'sorted';
$class[] = $current_order;
} else {
$order = $desc_first ? 'desc' : 'asc';
$class[] = 'sortable';
$class[] = $desc_first ? 'asc' : 'desc';
}
$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
}
$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
$id = $with_id ? "id='$column_key'" : '';
if ( ! empty( $class ) ) {
$class = "class='" . join( ' ', $class ) . "'";
}
echo "<$tag $scope $id $class>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput
}
}
public function get_bulk_actions() {
global $current_tab;
if ( 'registered' === $current_tab ) {
if ( is_multisite() ) {
return array();
} else {
return array(
'delete' => __( 'Delete', 'subscribe2' ),
);
}
} else {
$actions = array(
'delete' => __( 'Delete', 'subscribe2' ),
'toggle' => __( 'Toggle', 'subscribe2' ),
);
return $actions;
}
}
public function process_bulk_action() {
if ( in_array( $this->current_action(), array( 'delete', 'toggle' ), true ) ) {
if ( ! isset( $_REQUEST['subscriber'] ) ) {
echo '<div id="message" class="error"><p><strong>' . esc_html__( 'No users were selected.', 'subscribe2' ) . '</strong></p></div>';
return;
}
}
if ( 'delete' === $this->current_action() ) {
global $mysubscribe2, $current_user, $subscribers;
$message = array();
foreach ( $_REQUEST['subscriber'] as $address ) {
$address = trim( stripslashes( $address ) );
if ( false !== $mysubscribe2->is_public( $address ) ) {
$mysubscribe2->delete( $address );
$key = array_search( $address, $subscribers, true );
unset( $subscribers[ $key ] );
$message['public_deleted'] = __( 'Address(es) deleted!', 'subscribe2' );
} else {
$user = get_user_by( 'email', $address );
if ( ! current_user_can( 'delete_user', $user->ID ) || $user->ID === $current_user->ID ) {
$message['reg_delete_error'] = __( 'Delete failed! You cannot delete some or all of these users.', 'subscribe2' );
continue;
} else {
$message['reg_deleted'] = __( 'Registered user(s) deleted! Any posts made by these users were assigned to you.', 'subscribe2' );
foreach ( $subscribers as $key => $data ) {
if ( in_array( $address, $data, true ) ) {
unset( $subscribers[ $key ] );
}
}
wp_delete_user( $user->ID, $current_user->ID );
}
}
}
$final_message = implode( '<br><br>', array_filter( $message ) );
echo '<div id="message" class="updated fade"><p><strong>' . esc_html( $final_message ) . '</strong></p></div>';
}
if ( 'toggle' === $this->current_action() ) {
global $mysubscribe2, $current_user, $subscribers;
$mysubscribe2->ip = $current_user->user_login;
foreach ( $_REQUEST['subscriber'] as $address ) {
$address = trim( stripslashes( $address ) );
$mysubscribe2->toggle( $address );
if ( 'confirmed' === $_POST['what'] || 'unconfirmed' === $_POST['what'] ) {
$key = array_search( $address, $subscribers, true );
unset( $subscribers[ $key ] );
}
}
echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Status changed!', 'subscribe2' ) . '</strong></p></div>';
}
}
public function pagination( $which ) {
if ( empty( $this->_pagination_args ) ) {
return;
}
$total_items = intval( $this->_pagination_args['total_items'] );
$total_pages = intval( $this->_pagination_args['total_pages'] );
$infinite_scroll = false;
if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
}
if ( 'top' === $which && $total_pages > 1 ) {
$this->screen->render_screen_reader_content( 'heading_pagination' );
}
// Translators: Pagination
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items, 'subscribe2' ), number_format_i18n( $total_items ) ) . '</span>';
if ( isset( $_POST['what'] ) ) {
$current = 1;
} else {
$current = intval( $this->get_pagenum() );
}
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
if ( isset( $_REQUEST['what'] ) ) {
$current_url = add_query_arg(
array(
'what' => $_REQUEST['what'],
),
$current_url
);
}
if ( isset( $_POST['s'] ) ) {
$current_url = add_query_arg(
array(
's' => $_POST['s'],
),
$current_url
);
}
$page_links = array();
$total_pages_before = '<span class="paging-input">';
$total_pages_after = '</span>';
$disable_first = false;
$disable_last = false;
$disable_prev = false;
$disable_next = false;
if ( 1 === $current ) {
$disable_first = true;
$disable_prev = true;
}
if ( 2 === $current ) {
$disable_first = true;
}
if ( $current === $total_pages ) {
$disable_last = true;
$disable_next = true;
}
if ( $current === $total_pages - 1 ) {
$disable_last = true;
}
if ( $disable_first ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( remove_query_arg( 'paged', $current_url ) ),
__( 'First page', 'subscribe2' ),
'&laquo;'
);
}
if ( $disable_prev ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
__( 'Previous page', 'subscribe2' ),
'&lsaquo;'
);
}
if ( 'bottom' === $which ) {
$html_current_page = $current;
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page', 'subscribe2' ) . '</span><span id="table-paging" class="paging-input">';
} else {
$html_current_page = sprintf(
"%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page', 'subscribe2' ) . '</label>',
$current,
strlen( $total_pages )
);
}
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
// Translators: Pagination
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging', 'subscribe2' ), $html_current_page, $html_total_pages ) . $total_pages_after;
if ( $disable_next ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
__( 'Next page', 'subscribe2' ),
'&rsaquo;'
);
}
if ( $disable_last ) {
$page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
} else {
$page_links[] = sprintf(
"<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
__( 'Last page', 'subscribe2' ),
'&raquo;'
);
}
$pagination_links_class = 'pagination-links';
if ( ! empty( $infinite_scroll ) ) {
$pagination_links_class = ' hide-if-js';
}
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
if ( $total_pages ) {
$page_class = $total_pages < 2 ? ' one-page' : '';
} else {
$page_class = ' no-pages';
}
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
echo $this->_pagination; // phpcs:ignore WordPress.Security.EscapeOutput
}
public function prepare_items() {
global $mysubscribe2, $subscribers, $current_tab;
$user = get_current_user_id();
$screen = get_current_screen();
$screen_option = $screen->get_option( 'per_page', 'option' );
$per_page = get_user_meta( $user, $screen_option, true );
if ( empty( $per_page ) || $per_page < 1 ) {
$per_page = $screen->get_option( 'per_page', 'default' );
}
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$this->process_bulk_action();
$data = array();
if ( 'public' === $current_tab ) {
foreach ( (array) $subscribers as $email ) {
$data[] = array(
'email' => $email,
'date' => $mysubscribe2->signup_date( $email ),
'time' => $mysubscribe2->signup_time( $email ),
'ip' => $mysubscribe2->signup_ip( $email ),
);
}
} else {
foreach ( (array) $subscribers as $subscriber ) {
$data[] = array(
'email' => $subscriber['user_email'],
'id' => $subscriber['ID'],
'date' => get_userdata( $subscriber['ID'] )->user_registered,
);
}
}
function usort_reorder( $a, $b ) {
$orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : 'email';
$order = ( ! empty( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : 'asc';
$result = strcasecmp( $a[ $orderby ], $b[ $orderby ] );
return ( 'asc' === $order ) ? $result : -$result;
}
usort( $data, 'usort_reorder' );
if ( isset( $_POST['what'] ) ) {
$current_page = 1;
} else {
$current_page = $this->get_pagenum();
}
$total_items = count( $data );
$data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
$this->items = $data;
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
)
);
}
}

View File

@ -0,0 +1,174 @@
<?php
class S2_Multisite {
/* === WP Multisite specific functions === */
/**
* Handles subscriptions and unsubscriptions for different blogs on WPMU installs
*/
public function wpmu_subscribe() {
global $mysubscribe2;
// subscribe to new blog
if ( ! empty( $_GET['s2mu_subscribe'] ) ) {
$sub_id = intval( $_GET['s2mu_subscribe'] );
if ( $sub_id >= 0 ) {
switch_to_blog( $sub_id );
$user_ID = get_current_user_id();
// if user is not a user of the current blog
if ( ! is_user_member_of_blog( $user_ID, $sub_id ) ) {
// add user to current blog as subscriber
add_user_to_blog( $sub_id, $user_ID, 'subscriber' );
// add an action hook for external manipulation of blog and user data
do_action_ref_array( 'subscribe2_wpmu_subscribe', array( $user_ID, $sub_id ) );
}
// get categories, remove excluded ones if override is off
if ( 0 === $mysubscribe2->subscribe2_options['reg_override'] ) {
$all_cats = $mysubscribe2->all_cats( true, 'ID' );
} else {
$all_cats = $mysubscribe2->all_cats( false, 'ID' );
}
$cats_string = '';
foreach ( $all_cats as $cat ) {
( '' === $cats_string ) ? $cats_string = "$cat->term_id" : $cats_string .= ",$cat->term_id";
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat->term_id, $cat->term_id );
}
if ( empty( $cats_string ) ) {
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ) );
} else {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $cats_string );
}
}
} elseif ( ! empty( $_GET['s2mu_unsubscribe'] ) ) {
// unsubscribe from a blog
$unsub_id = intval( $_GET['s2mu_unsubscribe'] );
if ( $unsub_id >= 0 ) {
switch_to_blog( $unsub_id );
$user_ID = get_current_user_id();
// delete subscription to all categories on that blog
$cats = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$cats = explode( ',', $cats );
if ( ! is_array( $cats ) ) {
$cats = array( $cats );
}
foreach ( $cats as $id ) {
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $id );
}
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ) );
// add an action hook for external manipulation of blog and user data
do_action_ref_array( 'subscribe2_wpmu_unsubscribe', array( $user_ID, $unsub_id ) );
restore_current_blog();
}
}
if ( ! is_user_member_of_blog( $user_ID ) ) {
$user_blogs = get_active_blog_for_user( $user_ID );
if ( is_array( $user_blogs ) ) {
switch_to_blog( key( $user_blogs ) );
} else {
// no longer a member of a blog
wp_safe_redirect( get_option( 'siteurl' ) ); // redirect to front page
exit( 0 );
}
}
// redirect to profile page
$url = get_option( 'siteurl' ) . '/wp-admin/admin.php?page=s2';
wp_safe_redirect( $url );
exit( 0 );
}
/**
* Obtain a list of current WordPress multiuser blogs
* Note this may affect performance but there is no alternative
*/
public function get_mu_blog_list() {
global $wpdb;
$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
foreach ( $blogs as $details ) {
//reindex the array so the key is the same as the blog_id
$blog_list[ $details['blog_id'] ] = $details;
}
if ( ! is_array( $blog_list ) ) {
return array();
}
return apply_filters( 's2_mu_blog_list', $blog_list );
}
/**
* Register user details when new user is added to a multisite blog
*/
public function wpmu_add_user( $user_ID = 0 ) {
global $mysubscribe2;
if ( 0 === $user_ID ) {
return;
}
if ( 'yes' === $mysubscribe2->subscribe2_options['autosub'] ) {
$mysubscribe2->register( $user_ID, true );
} else {
$mysubscribe2->register( $user_ID, false );
}
}
/**
* Delete user details when a user is removed from a multisite blog
*/
public function wpmu_remove_user( $user_ID ) {
global $mysubscribe2;
if ( 0 === $user_ID ) {
return;
}
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ) );
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ) );
$cats = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
if ( ! empty( $cats ) ) {
$cats = explode( ',', $cats );
foreach ( $cats as $cat ) {
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat );
}
}
delete_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ) );
}
/**
* Rename WPMU widgets on upgrade without requiring user to re-enable
*/
public function namechange_subscribe2_widget() {
global $wpdb;
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
foreach ( $blogs as $blog ) {
switch_to_blog( $blog );
$sidebars = get_option( 'sidebars_widgets' );
if ( empty( $sidebars ) || ! is_array( $sidebars ) ) {
return;
}
$changed = false;
foreach ( $sidebars as $s => $sidebar ) {
if ( empty( $sidebar ) || ! is_array( $sidebar ) ) {
break;
}
foreach ( $sidebar as $w => $widget ) {
if ( 'subscribe2widget' === $widget ) {
$sidebars[ $s ][ $w ] = 'subscribe2';
$changed = true;
}
}
}
if ( $changed ) {
update_option( 'sidebar_widgets', $sidebars );
}
restore_current_blog();
}
}
}

View File

@ -0,0 +1,52 @@
<?php
class S2_Uninstall {
public function uninstall() {
global $wp_version, $wpmu_version;
// Is Subscribe2 free active
if ( is_plugin_active( 'subscribe2/subscribe2.php' ) ) {
return;
}
// Is this WordPressMU or not?
if ( isset( $wpmu_version ) || strpos( $wp_version, 'wordpress-mu' ) ) {
$s2_mu = true;
}
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$s2_mu = true;
}
if ( isset( $s2_mu ) && true === $s2_mu ) {
global $wpdb;
$blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
foreach ( $blogs as $blog ) {
switch_to_blog( $blog );
$this->clean_database();
restore_current_blog();
}
} else {
$this->clean_database();
}
}
private function clean_database() {
global $wpdb;
// delete entry from wp_options table
delete_option( 'subscribe2_options' );
// delete legacy entry from wp-options table
delete_option( 's2_future_posts' );
// remove and scheduled events
wp_clear_scheduled_hook( 's2_digest_cron' );
// delete usermeta data for registered users
// use LIKE and % wildcard as meta_key names are prepended on WPMU
// and s2_cat is appended with category ID integer
$wpdb->query( "DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_cat%'" );
$wpdb->query( "DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_subscribed'" );
$wpdb->query( "DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_format'" );
$wpdb->query( "DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_autosub'" );
// delete any postmeta data that supressed notifications
$wpdb->query( "DELETE from $wpdb->postmeta WHERE meta_key = 's2mail'" );
// drop the subscribe2 table
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}subscribe2" );
}
}

View File

@ -0,0 +1,554 @@
<?php
class S2_Upgrade {
/* ===== Install and reset ===== */
/**
* Install our table
*/
public function install() {
global $wpdb, $mysubscribe2;
// load our translations and strings
$mysubscribe2->load_translations();
// include upgrade functions
if ( ! function_exists( 'maybe_create_table' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
$charset_collate = '';
if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE {$wpdb->collate}";
}
$date = gmdate( 'Y-m-d' );
$sql = "CREATE TABLE $wpdb->subscribe2 (
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) ) $charset_collate";
// create the table, as needed
maybe_create_table( $wpdb->subscribe2, $sql );
// safety check if options exist and if not create them
if ( ! is_array( $mysubscribe2->subscribe2_options ) ) {
$this->reset();
}
// create table entries for registered users
$users = $mysubscribe2->get_all_registered( 'ID' );
if ( ! empty( $users ) ) {
foreach ( $users as $user_ID ) {
$check_format = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true );
if ( empty( $check_format ) ) {
// no prior settings so create them
$mysubscribe2->register( $user_ID );
}
}
}
}
/**
* Reset our options
*/
public function reset() {
// load our translations and strings
global $mysubscribe2;
$mysubscribe2->load_translations();
delete_option( 'subscribe2_options' );
wp_clear_scheduled_hook( 's2_digest_cron' );
unset( $mysubscribe2->subscribe2_options );
require S2PATH . 'include/options.php';
$mysubscribe2->subscribe2_options['version'] = S2VERSION;
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
/**
* Core upgrade function for the database and settings
*/
public function upgrade() {
global $mysubscribe2;
// load our translations and strings
$mysubscribe2->load_translations();
// ensure that the options are in the database
require S2PATH . 'include/options.php';
// catch older versions that didn't use serialised options
if ( ! isset( $mysubscribe2->subscribe2_options['version'] ) ) {
$mysubscribe2->subscribe2_options['version'] = '2.0';
}
// let's take the time to ensure that database entries exist for all registered users
$this->upgrade_core();
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '2.3', '<' ) ) {
$this->upgrade2_3();
$mysubscribe2->subscribe2_options['version'] = '2.3';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '5.1', '<' ) ) {
$this->upgrade5_1();
$mysubscribe2->subscribe2_options['version'] = '5.1';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '5.6', '<' ) ) {
$this->upgrade5_6();
$mysubscribe2->subscribe2_options['version'] = '5.6';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '5.9', '<' ) ) {
$this->upgrade5_9();
$mysubscribe2->subscribe2_options['version'] = '5.9';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '6.4', '<' ) ) {
$this->upgrade6_4();
$mysubscribe2->subscribe2_options['version'] = '6.4';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '7.0', '<' ) ) {
$this->upgrade7_0();
$mysubscribe2->subscribe2_options['version'] = '7.0';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '8.5', '<' ) ) {
$this->upgrade8_5();
$mysubscribe2->subscribe2_options['version'] = '8.5';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '8.6', '<' ) ) {
$this->upgrade8_6();
$mysubscribe2->subscribe2_options['version'] = '8.6';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '8.8', '<' ) ) {
$this->upgrade8_8();
$mysubscribe2->subscribe2_options['version'] = '8.8';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '9.5', '<' ) ) {
$this->upgrade9_5();
$mysubscribe2->subscribe2_options['version'] = '9.5';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '10.14', '<' ) ) {
$this->upgrade10_14();
$mysubscribe2->subscribe2_options['version'] = '10.14';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
if ( version_compare( $mysubscribe2->subscribe2_options['version'], '10.23', '<' ) ) {
$this->upgrade10_23();
$mysubscribe2->subscribe2_options['version'] = '10.23';
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
$mysubscribe2->subscribe2_options['version'] = S2VERSION;
update_option( 'subscribe2_options', $mysubscribe2->subscribe2_options );
}
private function upgrade_core() {
// let's take the time to double check data for registered users
global $mysubscribe2;
if ( version_compare( $mysubscribe2->wp_release, '3.5', '<' ) ) {
global $wpdb;
$users = $wpdb->get_col( $wpdb->prepare( "SELECT ID from $wpdb->users WHERE ID NOT IN (SELECT user_id FROM $wpdb->usermeta WHERE meta_key=%s)", $mysubscribe2->get_usermeta_keyname( 's2_format' ) ) );
if ( ! empty( $users ) ) {
foreach ( $users as $user_ID ) {
$mysubscribe2->register( $user_ID );
}
}
} else {
$args = array(
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_format' ),
'compare' => 'NOT EXISTS',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
$mysubscribe2->register( $user->ID );
}
}
}
// let's make sure that the 's2_authors' key exists on every site for all Registered Users too
$this->upgrade7_0();
}
private function upgrade2_3() {
global $mysubscribe2, $wpdb;
// include upgrade functions
if ( ! function_exists( 'maybe_add_column' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
$date = gmdate( 'Y-m-d' );
maybe_add_column( $wpdb->subscribe2, 'date', "ALTER TABLE $wpdb->subscribe2 ADD date DATE DEFAULT '$date' NOT NULL AFTER active" );
// update the options table to serialized format
$old_options = $wpdb->get_col( "SELECT option_name from $wpdb->options where option_name LIKE 's2%' AND option_name <> 's2_future_posts'" );
if ( ! empty( $old_options ) ) {
foreach ( $old_options as $option ) {
$value = get_option( $option );
$option_array = substr( $option, 3 );
$mysubscribe2->subscribe2_options[ $option_array ] = $value;
delete_option( $option );
}
}
}
private function upgrade5_1() {
global $mysubscribe2, $wpdb;
// include upgrade functions
if ( ! function_exists( 'maybe_add_column' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
maybe_add_column( $wpdb->subscribe2, 'ip', "ALTER TABLE $wpdb->subscribe2 ADD ip char(64) DEFAULT 'admin' NOT NULL AFTER date" );
}
private function upgrade5_6() {
global $mysubscribe2;
// correct autoformat to upgrade from pre 5.6
if ( 'text' === $mysubscribe2->subscribe2_options['autoformat'] ) {
$mysubscribe2->subscribe2_options['autoformat'] = 'excerpt';
}
if ( 'full' === $mysubscribe2->subscribe2_options['autoformat'] ) {
$mysubscribe2->subscribe2_options['autoformat'] = 'post';
}
}
private function upgrade5_9() {
global $mysubscribe2, $wpdb;
// ensure existing public subscriber emails are all sanitized
$confirmed = $mysubscribe2->get_public();
$unconfirmed = $mysubscribe2->get_public( 0 );
$public_subscribers = array_merge( (array) $confirmed, (array) $unconfirmed );
foreach ( $public_subscribers as $email ) {
$new_email = $mysubscribe2->sanitize_email( $email );
if ( $email !== $new_email ) {
$wpdb->get_results( $wpdb->prepare( "UPDATE $wpdb->subscribe2 SET email=%s WHERE CAST(email as binary)=%s", $new_email, $email ) );
}
}
}
private function upgrade6_4() {
global $mysubscribe2;
// change old CAPITALISED keywords to those in {PARENTHESES}; since version 6.4
$keywords = array( 'BLOGNAME', 'BLOGLINK', 'TITLE', 'POST', 'POSTTIME', 'TABLE', 'TABLELINKS', 'PERMALINK', 'TINYLINK', 'DATE', 'TIME', 'MYNAME', 'EMAIL', 'AUTHORNAME', 'LINK', 'CATS', 'TAGS', 'COUNT', 'ACTION' );
$keyword = implode( '|', $keywords );
$regex = '/(?<!\{)\b(' . $keyword . ')\b(?!\{)/xm';
$replace = '{\1}';
$mysubscribe2->subscribe2_options['mailtext'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['mailtext'] );
$mysubscribe2->subscribe2_options['notification_subject'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['notification_subject'] );
$mysubscribe2->subscribe2_options['confirm_email'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['confirm_email'] );
$mysubscribe2->subscribe2_options['confirm_subject'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['confirm_subject'] );
$mysubscribe2->subscribe2_options['remind_email'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['remind_email'] );
$mysubscribe2->subscribe2_options['remind_subject'] = preg_replace( $regex, $replace, $mysubscribe2->subscribe2_options['remind_subject'] );
if ( version_compare( $mysubscribe2->wp_release, '3.5', '<' ) ) {
$users = $mysubscribe2->get_all_registered( 'ID' );
foreach ( $users as $user_ID ) {
$check_format = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true );
// if user is already registered update format remove 's2_excerpt' field and update 's2_format'
if ( 'html' === $check_format ) {
delete_user_meta( $user_ID, 's2_excerpt' );
} elseif ( 'text' === $check_format ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ), get_user_meta( $user_ID, 's2_excerpt' ) );
delete_user_meta( $user_ID, 's2_excerpt' );
}
$subscribed = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
if ( strstr( $subscribed, '-1' ) ) {
// make sure we remove '-1' from any settings
$old_cats = explode( ',', $subscribed );
$pos = array_search( '-1', $old_cats, true );
unset( $old_cats[ $pos ] );
$cats = implode( ',', $old_cats );
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $cats );
}
}
} else {
$args = array(
'relation' => 'AND',
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_format' ),
'value' => 'html',
),
),
'meta_query' => array(
array(
'key' => 's2_excerpt',
'compare' => 'EXISTS',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
delete_user_meta( $user->ID, 's2_excerpt' );
}
}
$args = array(
'relation' => 'AND',
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_format' ),
'value' => 'text',
),
),
'meta_query' => array(
array(
'key' => 's2_excerpt',
'compare' => 'EXISTS',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ), get_user_meta( $user->ID, 's2_excerpt' ) );
delete_user_meta( $user->ID, 's2_excerpt' );
}
}
$args = array(
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ),
'value' => '-1',
'compare' => 'LIKE',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
$subscribed = get_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$old_cats = explode( ',', $subscribed );
$pos = array_search( '-1', $old_cats, true );
unset( $old_cats[ $pos ] );
$cats = implode( ',', $old_cats );
update_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $cats );
}
}
}
// upgrade old wpmu user meta data to new
if ( true === $mysubscribe2->s2_mu ) {
global $s2class_multisite, $wpdb;
$s2class_multisite->namechange_subscribe2_widget();
// loop through all users
foreach ( $users as $user_ID ) {
// get categories which the user is subscribed to (old ones)
$categories = get_user_meta( $user_ID, 's2_subscribed', true );
$categories = explode( ',', $categories );
$format = get_user_meta( $user_ID, 's2_format', true );
$autosub = get_user_meta( $user_ID, 's2_autosub', true );
// load blogs of user (only if we need them)
$blogs = array();
if ( count( $categories ) > 0 && ! in_array( '-1', $categories, true ) ) {
$blogs = get_blogs_of_user( $user_ID, true );
}
foreach ( $blogs as $blog ) {
switch_to_blog( $blog->userblog_id );
$blog_categories = (array) $wpdb->get_col( "SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category'" );
$subscribed_categories = array_intersect( $categories, $blog_categories );
if ( ! empty( $subscribed_categories ) ) {
foreach ( $subscribed_categories as $subscribed_category ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $subscribed_category, $subscribed_category );
}
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), implode( ',', $subscribed_categories ) );
}
if ( ! empty( $format ) ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_format' ), $format );
}
if ( ! empty( $autosub ) ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), $autosub );
}
restore_current_blog();
}
// delete old user meta keys
delete_user_meta( $user_ID, 's2_subscribed' );
delete_user_meta( $user_ID, 's2_format' );
delete_user_meta( $user_ID, 's2_autosub' );
foreach ( $categories as $cat ) {
delete_user_meta( $user_ID, 's2_cat' . $cat );
}
}
}
}
private function upgrade7_0() {
global $mysubscribe2, $wpdb;
if ( version_compare( $mysubscribe2->wp_release, '3.5', '<' ) ) {
$users = $wpdb->get_col( $wpdb->prepare( "SELECT ID from $wpdb->users WHERE ID NOT IN (SELECT user_id from $wpdb->usermeta WHERE meta_key=%s", $mysubscribe2->get_usermeta_keyname( 's2_authors' ) ) );
foreach ( $users as $user_ID ) {
$check_authors = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), true );
if ( empty( $check_authors ) ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), '' );
}
}
} else {
$args = array(
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_authors' ),
'compare' => 'NOT EXISTS',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), '' );
}
}
}
}
private function upgrade8_5() {
global $mysubscribe2, $wpdb;
// include upgrade functions
if ( ! function_exists( 'maybe_add_column' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
maybe_add_column( $wpdb->subscribe2, 'time', "ALTER TABLE $wpdb->subscribe2 ADD time TIME DEFAULT '00:00:00' NOT NULL AFTER date" );
// update postmeta field to a protected name, from version 8.5
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_s2mail' WHERE meta_key = 's2mail'" );
}
private function upgrade8_6() {
global $mysubscribe2, $wpdb;
// include upgrade functions
if ( ! function_exists( 'maybe_add_column' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
maybe_add_column( $wpdb->subscribe2, 'conf_date', "ALTER TABLE $wpdb->subscribe2 ADD conf_date DATE AFTER ip" );
maybe_add_column( $wpdb->subscribe2, 'conf_time', "ALTER TABLE $wpdb->subscribe2 ADD conf_time TIME AFTER conf_date" );
maybe_add_column( $wpdb->subscribe2, 'conf_ip', "ALTER TABLE $wpdb->subscribe2 ADD conf_ip char(64) AFTER conf_time" );
// remove unnecessary table data
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 's2_cat'" );
$users = $wpdb->get_results(
$wpdb->prepare(
"SELECT ID FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ( $wpdb->users.ID = $wpdb->usermeta.user_id) WHERE ( $wpdb->usermeta.meta_key = %s AND $wpdb->usermeta.meta_value LIKE %s )",
$mysubscribe2->get_usermeta_keyname( 's2_subscribed' ),
$wpdb->esc_like( ',' ) . '%'
)
);
foreach ( $users as $user ) {
// make sure we remove leading ',' from this setting
$subscribed = get_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$old_cats = explode( ',', $subscribed );
unset( $old_cats[0] );
$cats = implode( ',', $old_cats );
update_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $cats );
}
}
private function upgrade8_8() {
// to ensure compulsory category collects all users we need there to be s2_subscribed meta-keys for all users
global $mysubscribe2, $wpdb;
if ( version_compare( $mysubscribe2->wp_release, '3.5', '<' ) ) {
$all_registered = $mysubscribe2->get_all_registered( 'ID' );
if ( ! empty( $all_registered ) ) {
foreach ( $all_registered as $user_ID ) {
$check_subscribed = get_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
if ( empty( $check_subscribed ) ) {
update_user_meta( $user_ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), '' );
}
}
}
} else {
$args = array(
'meta_query' => array(
array(
'key' => $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ),
'compare' => 'NOT EXISTS',
),
),
);
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), '' );
}
}
}
// check the time column again as the upgrade8_6() function contained a bug
// include upgrade-functions for maybe_add_column;
if ( ! function_exists( 'maybe_add_column' ) ) {
require_once ABSPATH . 'wp-admin/install-helper.php';
}
maybe_add_column( $wpdb->subscribe2, 'time', "ALTER TABLE $wpdb->subscribe2 ADD time TIME DEFAULT '00:00:00' NOT NULL AFTER date" );
}
private function upgrade9_5() {
global $mysubscribe2;
if ( 'never' !== $mysubscribe2->subscribe2_options['email_freq'] ) {
$mysubscribe2->subscribe2_options['last_s2cron'] = '';
unset( $mysubscribe2->subscribe2_options['previous_s2cron'] );
}
}
private function upgrade10_14() {
global $mysubscribe2;
if ( ! isset( $mysubscribe2->subscribe2_options['frontend_form'] ) ) {
$mysubscribe2->subscribe2_options['frontend_form'] = '0';
}
if ( ! isset( $mysubscribe2->subscribe2_options['dismiss_sender_warning'] ) ) {
$mysubscribe2->subscribe2_options['dismiss_sender_warning'] = '0';
}
}
private function upgrade10_15() {
global $mysubscribe2;
if ( ! isset( $mysubscribe2->subscribe2_options['js_ip_updater'] ) ) {
$mysubscribe2->subscribe2_options['js_ip_updater'] = '0';
}
}
private function upgrade10_23() {
global $mysubscribe2;
if ( isset( $mysubscribe2->subscribe2_options['entries'] ) ) {
unset( $mysubscribe2->subscribe2_options['entries'] );
}
}
}