diff --git a/wp-content/plugins/subscribe2/admin/settings.php b/wp-content/plugins/subscribe2/admin/settings.php index 857bf969..9fbfbec9 100644 --- a/wp-content/plugins/subscribe2/admin/settings.php +++ b/wp-content/plugins/subscribe2/admin/settings.php @@ -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( '

' . 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'] ) . '

' ); } diff --git a/wp-content/plugins/subscribe2/admin/subscribers.php b/wp-content/plugins/subscribe2/admin/subscribers.php index a70fb85a..d1acdbcb 100644 --- a/wp-content/plugins/subscribe2/admin/subscribers.php +++ b/wp-content/plugins/subscribe2/admin/subscribers.php @@ -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( '

' . esc_html__( 'Security error! Your request cannot be completed.', 'subscribe2' ) . '

' ); } @@ -81,16 +85,16 @@ if ( isset( $_POST['s2_admin'] ) ) { echo '

' . esc_html__( 'Reminder Email(s) Sent!', 'subscribe2' ) . '

'; } 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 '

' . esc_html__( 'Registered Users Subscribed!', 'subscribe2' ) . '

'; } 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 '

' . esc_html__( 'Registered Users Unsubscribed!', 'subscribe2' ) . '

'; } elseif ( isset( $_POST['sub_format'] ) ) { diff --git a/wp-content/plugins/subscribe2/changelog.txt b/wp-content/plugins/subscribe2/changelog.txt index c740af23..fe07624a 100644 --- a/wp-content/plugins/subscribe2/changelog.txt +++ b/wp-content/plugins/subscribe2/changelog.txt @@ -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 diff --git a/wp-content/plugins/subscribe2/classes/class-s2-admin.php b/wp-content/plugins/subscribe2/classes/class-s2-admin.php index 2fc75980..4da7fdcc 100644 --- a/wp-content/plugins/subscribe2/classes/class-s2-admin.php +++ b/wp-content/plugins/subscribe2/classes/class-s2-admin.php @@ -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 { diff --git a/wp-content/plugins/subscribe2/classes/class-s2-ajax.php b/wp-content/plugins/subscribe2/classes/class-s2-ajax.php index 19e48120..a14e38c4 100644 --- a/wp-content/plugins/subscribe2/classes/class-s2-ajax.php +++ b/wp-content/plugins/subscribe2/classes/class-s2-ajax.php @@ -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( diff --git a/wp-content/plugins/subscribe2/classes/class-s2-core.php b/wp-content/plugins/subscribe2/classes/class-s2-core.php index 3d2b7add..ddcba244 100644 --- a/wp-content/plugins/subscribe2/classes/class-s2-core.php +++ b/wp-content/plugins/subscribe2/classes/class-s2-core.php @@ -1,5 +1,8 @@ '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 '
'; 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 '

' . "\r\n"; echo '
' . "\r\n"; } + } // End S2_Form_widget class diff --git a/wp-content/plugins/subscribe2/classes/class-s2-frontend.php b/wp-content/plugins/subscribe2/classes/class-s2-frontend.php index a1b70543..8bfb74ac 100644 --- a/wp-content/plugins/subscribe2/classes/class-s2-frontend.php +++ b/wp-content/plugins/subscribe2/classes/class-s2-frontend.php @@ -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 = '' . esc_html( $args['link'] ) . '' . "\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 = ''; - } elseif ( 'unsubscribe' === $hide ) { - $this->input_form_action = ''; - } else { - // both form input actions - $this->input_form_action = ' '; - } - - // 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 = '

'; - } - - // deploy some anti-spam measures - $antispam_text = ''; - if ( 'true' !== strtolower( $args['noantispam'] ) ) { - $antispam_text = ''; - $antispam_text .= ''; - $antispam_text .= ''; - $antispam_text .= ''; - $antispam_text .= ''; - } - - // 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 = '

' . $antispam_text . '


' . $wrap_text . $this->input_form_action . '

'; - } else { - $this->form = '
' . $antispam_text . '


' . $wrap_text . $this->input_form_action . '

' . "\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 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' ) { + // + } } diff --git a/wp-content/plugins/subscribe2/include/s2-ajax.js b/wp-content/plugins/subscribe2/include/s2-ajax.js index 5b2b9574..70c663c6 100644 --- a/wp-content/plugins/subscribe2/include/s2-ajax.js +++ b/wp-content/plugins/subscribe2/include/s2-ajax.js @@ -29,7 +29,8 @@ s2jQuery( document ).ready( zIndex: 10000, minWidth: 350, minHeight: 300, - title: s2AjaxScriptStrings.title + title: s2AjaxScriptStrings.title, + closeText: "" } ); dialog.dialog( 'open' ); diff --git a/wp-content/plugins/subscribe2/include/s2-checkbox.js b/wp-content/plugins/subscribe2/include/s2-checkbox.js index 8a7fb7c8..29b75054 100644 --- a/wp-content/plugins/subscribe2/include/s2-checkbox.js +++ b/wp-content/plugins/subscribe2/include/s2-checkbox.js @@ -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 ); } ); } diff --git a/wp-content/plugins/subscribe2/readme.txt b/wp-content/plugins/subscribe2/readme.txt index 106a88c4..7a3e34b8 100644 --- a/wp-content/plugins/subscribe2/readme.txt +++ b/wp-content/plugins/subscribe2/readme.txt @@ -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). diff --git a/wp-content/plugins/subscribe2/subscribe2.php b/wp-content/plugins/subscribe2/subscribe2.php index e563fa65..d0848cf6 100644 --- a/wp-content/plugins/subscribe2/subscribe2.php +++ b/wp-content/plugins/subscribe2/subscribe2.php @@ -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'; diff --git a/wp-content/plugins/subscribe2/traits/ShortcodeTrait.php b/wp-content/plugins/subscribe2/traits/ShortcodeTrait.php new file mode 100644 index 00000000..8214013a --- /dev/null +++ b/wp-content/plugins/subscribe2/traits/ShortcodeTrait.php @@ -0,0 +1,221 @@ + '', + '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 = '' . esc_html( $args['link'] ) . '' . "\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 = ''; + } elseif ( 'unsubscribe' === $hide ) { + $this->input_form_action = ''; + } else { + // both form input actions + $this->input_form_action = ' '; + } + + // 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 = '

'; + } + + // deploy some anti-spam measures + $antispam_text = ''; + if ( 'true' !== strtolower( $args['noantispam'] ) ) { + $antispam_text = ''; + $antispam_text .= ''; + $antispam_text .= ''; + $antispam_text .= ''; + $antispam_text .= ''; + } + + // 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 = '

' . $antispam_text . '


' . $wrap_text . $this->input_form_action . '

'; + } else { + $this->form = '
' . $antispam_text . '


' . $wrap_text . $this->input_form_action . '

' . "\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; + } +} \ No newline at end of file