updated plugin `Subscribe2` version 10.36

This commit is contained in:
KawaiiPunk 2021-09-30 14:54:06 +00:00 committed by Gitium
parent 375bf37aad
commit 3025a64583
13 changed files with 298 additions and 249 deletions

View File

@ -161,7 +161,13 @@ if ( 'blogname' === $this->subscribe2_options['sender'] ) {
$sender = $user->user_email;
}
list( $user, $sender_domain ) = explode( '@', $sender, 2 );
if ( ! stristr( esc_html( $_SERVER['SERVER_NAME'] ), $sender_domain ) && 'author' !== $this->subscribe2_options['sender'] && '0' === $this->subscribe2_options['dismiss_sender_warning'] ) {
$dismis_sender_worning = '';
if(isset($this->subscribe2_options['dismiss_sender_warning'])) {
$dismis_sender_worning = $this->subscribe2_options['dismiss_sender_warning'];
}
if ( ! stristr( esc_html( $_SERVER['SERVER_NAME'] ), $sender_domain ) && 'author' !== $this->subscribe2_options['sender'] && '0' === (isset($this->subscribe2_options['dismiss_sender_warning']) ? $this->subscribe2_options['dismiss_sender_warning'] : '0') ) {
// Translators: Warning message
echo wp_kses_post( '<div id="sender_message" class="error notice is-dismissible"><p class="s2_error"><strong>' . sprintf( __( 'You appear to be sending notifications from %1$s, which has a different domain name than your blog server %2$s. This may result in failed emails.', 'subscribe2' ), $sender, $_SERVER['SERVER_NAME'] ) . '</strong></p></div>' );
}

View File

@ -23,6 +23,10 @@ if ( ! class_exists( 'Subscribe2_List_Table' ) ) {
// was anything POSTed ?
if ( isset( $_POST['s2_admin'] ) ) {
$s2_request_category = '';
if (isset($_REQUEST['category']) && $_REQUEST['category']) {
$s2_request_category = $_REQUEST['category'];
}
if ( false === wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-' . $s2_list_table->_args['plural'] ) ) {
die( '<p>' . esc_html__( 'Security error! Your request cannot be completed.', 'subscribe2' ) . '</p>' );
}
@ -81,16 +85,16 @@ if ( isset( $_POST['s2_admin'] ) ) {
echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Reminder Email(s) Sent!', 'subscribe2' ) . '</strong></p></div>';
} elseif ( isset( $_POST['sub_categories'] ) && 'subscribe' === $_POST['manage'] ) {
if ( isset( $_REQUEST['subscriber'] ) ) {
$this->subscribe_registered_users( implode( ",\r\n", $_REQUEST['subscriber'] ), $_POST['category'] );
$this->subscribe_registered_users( implode( ",\r\n", $_REQUEST['subscriber'] ), $s2_request_category );
} else {
$this->subscribe_registered_users( $_POST['exportcsv'], $_POST['category'] );
$this->subscribe_registered_users( $_POST['exportcsv'], $s2_request_category );
}
echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Registered Users Subscribed!', 'subscribe2' ) . '</strong></p></div>';
} elseif ( isset( $_POST['sub_categories'] ) && 'unsubscribe' === $_POST['manage'] ) {
if ( isset( $_REQUEST['subscriber'] ) ) {
$this->unsubscribe_registered_users( implode( ",\r\n", $_REQUEST['subscriber'] ), $_POST['category'] );
$this->unsubscribe_registered_users( implode( ",\r\n", $_REQUEST['subscriber'] ), $s2_request_category );
} else {
$this->unsubscribe_registered_users( $_POST['exportcsv'], $_POST['category'] );
$this->unsubscribe_registered_users( $_POST['exportcsv'], $s2_request_category );
}
echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Registered Users Unsubscribed!', 'subscribe2' ) . '</strong></p></div>';
} elseif ( isset( $_POST['sub_format'] ) ) {

View File

@ -1,3 +1,12 @@
= 10.36 (30th September, 2021) =
* WordPress 5.8 compatibility
* Fix form preview on widgets
* Fix pop up form
* Fix send schedule email options
* Fix one click subscription
* Fix some PHP warnings
= 10.35 (15th March, 2021) =
* Fix {UNSUBLINK} shortcode

View File

@ -804,6 +804,9 @@ class S2_Admin extends S2_Core {
asort( $sort );
$schedule_sorted = array();
foreach ( $sort as $key => $value ) {
if (! preg_match('/never|weekly|monthly|twicedaily|hourly/', $key)) {
continue;
}
$schedule_sorted[ $key ] = $schedule[ $key ];
}
foreach ( $schedule_sorted as $key => $value ) {
@ -1144,7 +1147,7 @@ class S2_Admin extends S2_Core {
return false;
}
if ( isset( $_POST['sub2-one-click-subscribe'] ) && 1 === $_POST['sub2-one-click-subscribe'] ) {
if ( isset( $_POST['sub2-one-click-subscribe'] ) && 1 === (int)$_POST['sub2-one-click-subscribe'] ) {
// Subscribe
$this->one_click_handler( $user_id, 'subscribe' );
} else {

View File

@ -57,7 +57,7 @@ class S2_Ajax {
wp_parse_str( $response, $atts );
global $s2_frontend;
$content = $s2_frontend->shortcode( $atts );
$content = $s2_frontend->widget_shortcode( $atts );
$content = apply_filters( 's2_ajax_form', $content );
$allowed_tags = array(

View File

@ -1,5 +1,8 @@
<?php
require_once S2PATH . 'traits/ShortcodeTrait.php';
class S2_Core {
use Shortcode;
// variables and constructor are declared at the end
/**
* Load translations
@ -2041,7 +2044,6 @@ class S2_Core {
}
// add the frontend filters
add_shortcode( 'subscribe2', array( &$this, 'shortcode' ) );
add_filter( 'the_content', array( &$this, 'filter' ), 10 );
// add actions for other plugins
@ -2055,6 +2057,7 @@ class S2_Core {
add_action( 'wp_footer', array( &$this, 'js_ip_library_script' ), 20 );
}
}
add_shortcode( 'subscribe2', array( &$this, 'widget_shortcode' ) );
}
/* ===== define some variables ===== */

View File

@ -1,5 +1,9 @@
<?php
class S2_Form_Widget extends WP_Widget {
// Display the widgets instance in the REST API
public $show_instance_in_rest = true;
/**
* Declares the Subscribe2 widget class.
*/
@ -8,8 +12,12 @@ class S2_Form_Widget extends WP_Widget {
'classname' => 's2_form_widget',
'description' => esc_html__( 'Sidebar Widget for Subscribe2', 'subscribe2' ),
'customize_selective_refresh' => true,
'show_instance_in_rest' => true,
);
// add_filter( 'widget_text', 'shortcode_unautop' );
// add_filter( 'widget_text', 'do_shortcode' );
$control_ops = array(
'width' => 250,
'height' => 300,
@ -57,11 +65,13 @@ class S2_Form_Widget extends WP_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 );
}
@ -184,4 +194,5 @@ class S2_Form_Widget extends WP_Widget {
echo '</label></p>' . "\r\n";
echo '</div>' . "\r\n";
}
} // End S2_Form_widget class

View File

@ -73,198 +73,6 @@ class S2_Frontend extends S2_Core {
}
}
/* ===== 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
*/
@ -505,37 +313,6 @@ class S2_Frontend extends S2_Core {
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
*/
@ -568,4 +345,12 @@ class S2_Frontend extends S2_Core {
/* ===== define some variables ===== */
public $profile = '';
/**
* Create and display a dropdown list of pages
*/
public function pages_dropdown( $s2page, $name = 's2page' ) {
//
}
}

View File

@ -29,7 +29,8 @@ s2jQuery( document ).ready(
zIndex: 10000,
minWidth: 350,
minHeight: 300,
title: s2AjaxScriptStrings.title
title: s2AjaxScriptStrings.title,
closeText: ""
}
);
dialog.dialog( 'open' );

View File

@ -27,9 +27,7 @@ jQuery( document ).ready(
var checkedStatus = true;
jQuery( 'input[class="' + this.className + '"]' ).each(
function() {
if ( ( true === this.checked ) && ( true === checkedStatus ) ) {
checkedStatus = true;
} else {
if ( ( ! this.checked ) ) {
checkedStatus = false;
}
jQuery( 'input[value="' + this.className + '"]' )
@ -40,16 +38,14 @@ jQuery( document ).ready(
);
// function to check or uncheck 'checkall' box when page is loaded
jQuery( 'input[class^="checkall"]' ).each(
function() {
jQuery( 'input[name^="checkall"]' ).each(function(value, item) {
var checkedStatus = true;
if ( ( true === this.checked ) && ( true === checkedStatus ) ) {
checkedStatus = true;
} else {
checkedStatus = false;
}
jQuery( 'input[value="' + this.className + '"]' )
.prop( 'checked', checkedStatus );
jQuery('input[class='+item.value).each(function () {
if ( ( ! this.checked ) ) {
checkedStatus = false;
}
});
jQuery(this).prop( 'checked', checkedStatus );
}
);
}

View File

@ -3,8 +3,8 @@ Contributors: tareq1988, nizamuddinbabu, wemail
Donate link: https://getwemail.io
Tags: posts, subscription, email, subscribe, notify, notification, newsletter, post notification, email marketing, optin, form
Requires at least: 4.0
Tested up to: 5.7
Stable tag: 10.35
Tested up to: 5.8
Stable tag: 10.36
Requires PHP: 5.4
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@ -72,6 +72,15 @@ This token will automatically be replaced by dynamic subscription information an
== Changelog ==
= 10.36 (30th September, 2021) =
* WordPress 5.8 compatibility
* Fix form preview on widgets
* Fix pop up form
* Fix send schedule email options
* Fix one click subscription
* Fix some PHP warnings
= 10.35 (15th March, 2021) =
* Fix {UNSUBLINK} shortcode
@ -86,4 +95,4 @@ This token will automatically be replaced by dynamic subscription information an
* Bump tested upto version 4.4
* Minimum PHP version set to 5.4
See complete [changelog](https://github.com/weMail/Subscribe2/blob/develop/changeLog.txt).
See complete [changelog](https://github.com/weMail/Subscribe2/blob/develop/changelog.txt).

View File

@ -3,7 +3,7 @@
Plugin Name: Subscribe2
Plugin URI: https://getwemail.io
Description: Notifies an email list when new entries are posted.
Version: 10.35
Version: 10.36
Author: weMail
Author URI: https://getwemail.io
Licence: GPLv3
@ -54,7 +54,7 @@ if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
// our version number. Don't touch this or any line below
// unless you know exactly what you are doing
define( 'S2VERSION', '10.35' );
define( 'S2VERSION', '10.36' );
define( 'S2PLUGIN', __FILE__ );
define( 'S2PATH', trailingslashit( dirname( __FILE__ ) ) );
define( 'S2DIR', trailingslashit( dirname( plugin_basename( __FILE__ ) ) ) );
@ -65,6 +65,7 @@ if ( function_exists( 'set_time_limit' ) ) {
set_time_limit( 300 );
}
global $mysubscribe2;
require_once S2PATH . 'classes/class-s2-core.php';

View File

@ -0,0 +1,221 @@
<?php
trait Shortcode {
/* ===== template and filter functions ===== */
/**
* Display our form; also handles (un)subscribe requests
*/
public function widget_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 );
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;
}
/**
* 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;
}
}