diff --git a/.eslintrc.js b/.eslintrc.js index 499963c..17ae337 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,84 +1,88 @@ -module.exports = { - "env": { - "browser": true, - "jquery": true - }, - - "extends": "eslint:recommended", - - "rules": { - "block-scoped-var": "error", - "comma-dangle": "error", - "comma-spacing": [ - "error", - { - "before": false, - "after": true - } - ], - "comma-style": [ - "error", "last" - ], - "curly": "error", - "eol-last": [ - "error", - "always" - ], - "eqeqeq": "error", - "indent": [ - "error", - "tab", - { - "SwitchCase": 1 - } - ], - "key-spacing": "error", - "linebreak-style": [ - "error", - "unix" - ], - "no-console": "error", - "no-else-return": "error", - "no-eval": "error", - "no-extra-parens": "error", - "no-implied-eval": "error", - "one-var-declaration-per-line": [ - "error", - "initializations" - ], - "semi": [ - "error", - "always" - ], - "semi-spacing": "error", - "space-in-parens": [ - "error", - "always", - { - "exceptions": [ - "empty", - ] - } - ], - "space-unary-ops": [ - "error", - { - "words": true, - "nonwords": true, - "overrides": { - "++": false, - "-": false - } - } - ], - "vars-on-top": "error", - "yoda": [ - "error", - "always" - ] - }, - - "parserOptions": { - "ecmaVersion": 6 - } -}; +module.exports = [ + { + "languageOptions": { + "ecmaVersion": 6 + }, + "rules": { + "block-scoped-var": "error", + "comma-dangle": "error", + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "comma-style": [ + "error", "last" + ], + "curly": "error", + "eol-last": [ + "error", + "always" + ], + "eqeqeq": "error", + "func-style": [ + "error", + "declaration", + { + "allowArrowFunctions": false + } + ], + "indent": [ + "error", + "tab", + { + "SwitchCase": 1 + } + ], + "key-spacing": "error", + "linebreak-style": [ + "error", + "unix" + ], + "no-confusing-arrow": "error", + "no-console": "error", + "no-else-return": "error", + "no-eval": "error", + "no-extra-parens": "error", + "no-implied-eval": "error", + "no-mixed-spaces-and-tabs": "error", + "no-trailing-spaces": "error", + "one-var-declaration-per-line": [ + "error", + "initializations" + ], + "semi": [ + "error", + "always" + ], + "semi-spacing": "error", + "space-in-parens": [ + "error", + "always", + { + "exceptions": [ + "empty", + ] + } + ], + "space-unary-ops": [ + "error", + { + "words": true, + "nonwords": true, + "overrides": { + "++": false, + "-": false + } + } + ], + "vars-on-top": "error", + "yoda": [ + "error", + "always" + ] + } + } +]; diff --git a/Gruntfile.js b/Gruntfile.js index 1148847..7055d03 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,6 +7,9 @@ module.exports = function( grunt ) { grunt.initConfig( { eslint: { + options: { + overrideConfigFile: '.eslintrc.js' + }, grunt: { src: [ 'Gruntfile.js' @@ -14,7 +17,6 @@ module.exports = function( grunt ) { }, core: { options: { - cwd: SOURCE_DIR, fix: grunt.option( 'fix' ) }, src: [ @@ -100,7 +102,7 @@ module.exports = function( grunt ) { ], options: { bin: '/usr/local/bin/phpcs', - standard: '~/Desktop/subscribe2/ruleset.xml', + standard: '~/Plugins/ruleset.xml', warningSeverity: 0 } }, @@ -114,7 +116,7 @@ module.exports = function( grunt ) { ], options: { bin: '/usr/local/bin/phpcs', - standard: '~/Desktop/subscribe2/ruleset.xml', + standard: '~/Plugins/ruleset.xml', warningSeverity: 1 } } @@ -157,17 +159,6 @@ module.exports = function( grunt ) { } } }, - csscomb: { - src: { - options: { - cwd: SOURCE_DIR - }, - files: { - './include/s2-user-admin.css': [ './include/s2-user-admin.css' ], - './tinymce/css/content.css': [ './tinymce/css/content.css' ] - } - } - }, replace: { version: { options: { @@ -342,7 +333,6 @@ module.exports = function( grunt ) { [ 'clean:minified', 'addtextdomain:s2cp', - 'csscomb', 'terser', 'cssmin', 'imagemin', @@ -362,13 +352,13 @@ module.exports = function( grunt ) { 'Preparing new release...', function ( release ) { var releases = [ 'major', 'minor', 'patch' ]; - if ( arguments.length === 0 ) { - grunt.log.writeln( "Please specify release type, for example `grunt release:minor`" ); + if ( 0 === arguments.length ) { + grunt.log.writeln( 'Please specify release type, for example `grunt release:minor`' ); } else { if ( releases.includes( release ) ) { grunt.task.run( 'release-' + release ); } else { - grunt.log.writeln( "Please specify a valid release type" ); + grunt.log.writeln( 'Please specify a valid release type' ); } } } diff --git a/admin/settings.php b/admin/settings.php index a4ac94f..0af696f 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -108,13 +108,11 @@ wp_schedule_event( $timestamp, $email_freq, 's2_digest_cron' ); } } - } else { - if ( isset( s2cp()->subscribe2_options[ $key ] ) ) { - if ( 'sender' === $key && s2cp()->subscribe2_options[ $key ] !== $_POST[ $key ] ) { - s2cp()->subscribe2_options['dismiss_sender_warning'] = '0'; - } - s2cp()->subscribe2_options[ $key ] = $_POST[ $key ]; + } elseif ( isset( s2cp()->subscribe2_options[ $key ] ) ) { + if ( 'sender' === $key && s2cp()->subscribe2_options[ $key ] !== $_POST[ $key ] ) { + s2cp()->subscribe2_options['dismiss_sender_warning'] = '0'; } + s2cp()->subscribe2_options[ $key ] = $_POST[ $key ]; } } diff --git a/admin/subscribers.php b/admin/subscribers.php index d7059a2..36e8e17 100644 --- a/admin/subscribers.php +++ b/admin/subscribers.php @@ -42,26 +42,26 @@ if ( false === s2cp()->validate_email( $clean_email ) ) { ( '' === $email_error ) ? $email_error = "$email" : $email_error .= ", $email"; continue; - } else { - if ( isset( $_POST['subscribe'] ) ) { - if ( false !== s2cp()->is_public( $clean_email ) ) { - ( '' === $pub_sub_error ) ? $pub_sub_error = "$clean_email" : $pub_sub_error .= ", $clean_email"; - continue; - } - if ( s2cp()->is_registered( $clean_email ) ) { - ( '' === $reg_sub_error ) ? $reg_sub_error = "$clean_email" : $reg_sub_error .= ", $clean_email"; - continue; - } - s2cp()->add( $clean_email, true ); - $message = __( 'Address(es) subscribed!', 'subscribe2-for-cp' ); - } elseif ( isset( $_POST['unsubscribe'] ) ) { - if ( false === s2cp()->is_public( $clean_email ) || s2cp()->is_registered( $clean_email ) ) { - ( '' === $unsub_error ) ? $unsub_error = "$clean_email" : $unsub_error .= ", $clean_email"; - continue; - } - s2cp()->delete( $clean_email ); - $message = __( 'Address(es) unsubscribed!', 'subscribe2-for-cp' ); + } + + if ( isset( $_POST['subscribe'] ) ) { + if ( false !== s2cp()->is_public( $clean_email ) ) { + ( '' === $pub_sub_error ) ? $pub_sub_error = "$clean_email" : $pub_sub_error .= ", $clean_email"; + continue; + } + if ( s2cp()->is_registered( $clean_email ) ) { + ( '' === $reg_sub_error ) ? $reg_sub_error = "$clean_email" : $reg_sub_error .= ", $clean_email"; + continue; + } + s2cp()->add( $clean_email, true ); + $message = __( 'Address(es) subscribed!', 'subscribe2-for-cp' ); + } elseif ( isset( $_POST['unsubscribe'] ) ) { + if ( false === s2cp()->is_public( $clean_email ) || s2cp()->is_registered( $clean_email ) ) { + ( '' === $unsub_error ) ? $unsub_error = "$clean_email" : $unsub_error .= ", $clean_email"; + continue; } + s2cp()->delete( $clean_email ); + $message = __( 'Address(es) unsubscribed!', 'subscribe2-for-cp' ); } } if ( '' !== $reg_sub_error ) { @@ -168,14 +168,12 @@ $what = 'all_users'; $subscribers = $all_users; } +} elseif ( 'public' === $current_tab ) { + $what = 'public'; + $subscribers = array_merge( (array) $confirmed, (array) $unconfirmed ); } else { - if ( 'public' === $current_tab ) { - $what = 'public'; - $subscribers = array_merge( (array) $confirmed, (array) $unconfirmed ); - } else { - $what = 'all_users'; - $subscribers = $all_users; - } + $what = 'all_users'; + $subscribers = $all_users; } if ( ! empty( $_POST['s'] ) ) { diff --git a/classes/class-s2-admin.php b/classes/class-s2-admin.php index 23b6f75..9f257f4 100644 --- a/classes/class-s2-admin.php +++ b/classes/class-s2-admin.php @@ -1,5 +1,10 @@ subscribe2_options['counterwidget'] ) { - add_action( 'admin_enqueue_scripts', array( &$this, 'widget_s2counter_css_and_js' ) ); - } - - // add admin actions for comment subscribers - if ( 'no' !== $this->subscribe2_options['comment_subs'] ) { - add_filter( 'jetpack_get_available_modules', array( &$this, 's2_hide_jetpack_comments' ) ); - add_action( 'wp_set_comment_status', array( &$this, 'comment_status' ) ); - } - - // add write button - if ( '1' === s2cp()->subscribe2_options['show_button'] ) { - add_action( 'admin_init', array( &$this, 'button_init' ) ); - } - - // add one-click handlers - if ( 'yes' === $this->subscribe2_options['one_click_profile'] ) { - add_action( 'show_user_profile', array( &$this, 'one_click_profile_form' ) ); - add_action( 'edit_user_profile', array( &$this, 'one_click_profile_form' ) ); - add_action( 'personal_options_update', array( &$this, 'one_click_profile_form_save' ) ); - add_action( 'edit_user_profile_update', array( &$this, 'one_click_profile_form_save' ) ); - } - // digest email preview and resend actions - add_action( 's2_digest_preview', array( &$this, 'digest_preview' ) ); - add_action( 's2_digest_resend', array( &$this, 'digest_resend' ) ); + // add counterwidget css and js + if ( '1' === $this->subscribe2_options['counterwidget'] ) { + add_action( 'admin_enqueue_scripts', array( &$this, 'widget_s2counter_css_and_js' ) ); + } - // add handler to dismiss sender error notice - add_action( 'wp_ajax_s2_dismiss_notice', array( &$this, 's2_dismiss_notice_handler' ) ); + // add admin actions for comment subscribers + if ( 'no' !== $this->subscribe2_options['comment_subs'] ) { + add_filter( 'jetpack_get_available_modules', array( &$this, 's2_hide_jetpack_comments' ) ); + add_action( 'wp_set_comment_status', array( &$this, 'comment_status' ) ); + } - // subscriber page options handler - add_filter( 'set-screen-option', array( &$this, 'subscribers_set_screen_option' ), 10, 3 ); + // add write button + if ( '1' === s2cp()->subscribe2_options['show_button'] ) { + add_action( 'admin_init', array( &$this, 'button_init' ) ); + } - // register uninstall functions - register_uninstall_hook( S2PLUGIN, array( 'S2_Admin', 's2_uninstall' ) ); + // add one-click handlers + if ( 'yes' === $this->subscribe2_options['one_click_profile'] ) { + add_action( 'show_user_profile', array( &$this, 'one_click_profile_form' ) ); + add_action( 'edit_user_profile', array( &$this, 'one_click_profile_form' ) ); + add_action( 'personal_options_update', array( &$this, 'one_click_profile_form_save' ) ); + add_action( 'edit_user_profile_update', array( &$this, 'one_click_profile_form_save' ) ); + } - // capture CSV export - if ( isset( $_POST['s2_admin'] ) && isset( $_POST['csv'] ) && false !== wp_verify_nonce( $_POST['_s2_export_csv'], 's2_export_csv' ) ) { - $date = gmdate( 'Y-m-d' ); - header( 'Content-Description: File Transfer' ); - header( 'Content-type: application/octet-stream' ); - header( "Content-Disposition: attachment; filename=subscribe2_users_$date.csv" ); - header( 'Pragma: no-cache' ); - header( 'Expires: 0' ); - echo esc_html( $this->prepare_export( $_POST['exportcsv'] ) ); - exit( 0 ); + // digest email preview and resend actions + add_action( 's2_digest_preview', array( &$this, 'digest_preview' ) ); + add_action( 's2_digest_resend', array( &$this, 'digest_resend' ) ); + + // subscriber page options handler + add_filter( 'set-screen-option', array( &$this, 'subscribers_set_screen_option' ), 10, 3 ); + + // register uninstall functions + register_uninstall_hook( S2PLUGIN, array( 'S2_Admin', 's2_uninstall' ) ); + + // capture CSV export + if ( isset( $_POST['s2_admin'] ) && isset( $_POST['csv'] ) && false !== wp_verify_nonce( $_POST['_s2_export_csv'], 's2_export_csv' ) ) { + $date = gmdate( 'Y-m-d' ); + header( 'Content-Description: File Transfer' ); + header( 'Content-type: application/octet-stream' ); + header( "Content-Disposition: attachment; filename=subscribe2_users_$date.csv" ); + header( 'Pragma: no-cache' ); + header( 'Expires: 0' ); + echo esc_html( $this->prepare_export( $_POST['exportcsv'] ) ); + exit( 0 ); + } } } @@ -77,28 +84,28 @@ public function admin_hooks() { * Hook the menu */ public function admin_menu() { - add_menu_page( __( 'Subscribe2', 'subscribe2-for-cp' ), __( 'Subscribe2', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'read', 'user' ), 's2', null, S2URL . 'include/email-edit.png' ); + add_menu_page( __( 'Subscribe2', 'subscribe2-for-cp' ), __( 'Subscribe2', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'read', 'user' ), 's2', null, S2URL . 'include/email-edit.png' ); // phpcs:ignore WordPress.WP.Capabilities - $s2user = add_submenu_page( 's2', __( 'Your Subscriptions', 'subscribe2-for-cp' ), __( 'Your Subscriptions', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'read', 'user' ), 's2', array( &$this, 'user_menu' ) ); + $s2user = add_submenu_page( 's2', __( 'Your Subscriptions', 'subscribe2-for-cp' ), __( 'Your Subscriptions', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'read', 'user' ), 's2', array( &$this, 'user_menu' ) ); // phpcs:ignore WordPress.WP.Capabilities add_action( "admin_print_scripts-$s2user", array( &$this, 'checkbox_form_js' ) ); add_action( "admin_print_styles-$s2user", array( &$this, 'user_admin_css' ) ); add_action( 'load-' . $s2user, array( &$this, 'user_help' ) ); - $s2subscribers = add_submenu_page( 's2', __( 'Subscribers', 'subscribe2-for-cp' ), __( 'Subscribers', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'manage_options', 'manage' ), 's2_tools', array( &$this, 'subscribers_menu' ) ); + $s2subscribers = add_submenu_page( 's2', __( 'Subscribers', 'subscribe2-for-cp' ), __( 'Subscribers', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'manage_options', 'manage' ), 's2_tools', array( &$this, 'subscribers_menu' ) ); // phpcs:ignore WordPress.WP.Capabilities add_action( "admin_print_scripts-$s2subscribers", array( &$this, 'checkbox_form_js' ) ); add_action( "admin_print_scripts-$s2subscribers", array( &$this, 'subscribers_form_js' ) ); add_action( "admin_print_scripts-$s2subscribers", array( &$this, 'subscribers_css' ) ); add_action( 'load-' . $s2subscribers, array( &$this, 'subscribers_help' ) ); add_action( 'load-' . $s2subscribers, array( &$this, 'subscribers_options' ) ); - $s2settings = add_submenu_page( 's2', __( 'Settings', 'subscribe2-for-cp' ), __( 'Settings', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'manage_options', 'settings' ), 's2_settings', array( &$this, 'settings_menu' ) ); + $s2settings = add_submenu_page( 's2', __( 'Settings', 'subscribe2-for-cp' ), __( 'Settings', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'manage_options', 'settings' ), 's2_settings', array( &$this, 'settings_menu' ) ); // phpcs:ignore WordPress.WP.Capabilities add_action( "admin_print_scripts-$s2settings", array( &$this, 'checkbox_form_js' ) ); add_action( "admin_print_scripts-$s2settings", array( &$this, 'option_form_js' ) ); add_action( "admin_print_scripts-$s2settings", array( &$this, 'dismiss_js' ) ); add_filter( 'plugin_row_meta', array( &$this, 'plugin_links' ), 10, 2 ); add_action( 'load-' . $s2settings, array( &$this, 'settings_help' ) ); - $s2mail = add_submenu_page( 's2', __( 'Send Email', 'subscribe2-for-cp' ), __( 'Send Email', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'publish_posts', 'send' ), 's2_posts', array( &$this, 'write_menu' ) ); + $s2mail = add_submenu_page( 's2', __( 'Send Email', 'subscribe2-for-cp' ), __( 'Send Email', 'subscribe2-for-cp' ), (string) apply_filters( 's2_capability', 'publish_posts', 'send' ), 's2_posts', array( &$this, 'write_menu' ) ); // phpcs:ignore WordPress.WP.Capabilities add_action( 'load-' . $s2mail, array( &$this, 'mail_help' ) ); } @@ -310,7 +317,7 @@ public function subscribers_form_js() { } public function subscribers_css() { - echo ''; } @@ -478,10 +485,8 @@ public function s2_meta_handler( $post_id ) { if ( ! current_user_can( 'edit_page', $post_id ) ) { return $post_id; } - } else { - if ( ! current_user_can( 'edit_post', $post_id ) ) { - return $post_id; - } + } elseif ( ! current_user_can( 'edit_post', $post_id ) ) { + return $post_id; } if ( isset( $_POST['s2_meta_field'] ) && 'no' === $_POST['s2_meta_field'] ) { @@ -661,12 +666,10 @@ public function prepare_export( $subscribers ) { $exportcsv .= __( 'Registered User', 'subscribe2-for-cp' ); $exportcsv .= ',' . $user_info->display_name; $exportcsv .= ',,' . $subscribed_cats . "\r\n"; - } else { - if ( '1' === $this->is_public( $subscriber ) ) { - $exportcsv .= $subscriber . ',' . __( 'Confirmed Public Subscriber', 'subscribe2-for-cp' ) . ',,' . $this->signup_date( $subscriber ) . ',' . $this->signup_ip( $subscriber ) . "\r\n"; - } elseif ( '0' === $this->is_public( $subscriber ) ) { - $exportcsv .= $subscriber . ',' . __( 'Unconfirmed Public Subscriber', 'subscribe2-for-cp' ) . ',,' . $this->signup_date( $subscriber ) . ',' . $this->signup_ip( $subscriber ) . "\r\n"; - } + } elseif ( '1' === $this->is_public( $subscriber ) ) { + $exportcsv .= $subscriber . ',' . __( 'Confirmed Public Subscriber', 'subscribe2-for-cp' ) . ',,' . $this->signup_date( $subscriber ) . ',' . $this->signup_ip( $subscriber ) . "\r\n"; + } elseif ( '0' === $this->is_public( $subscriber ) ) { + $exportcsv .= $subscriber . ',' . __( 'Unconfirmed Public Subscriber', 'subscribe2-for-cp' ) . ',,' . $this->signup_date( $subscriber ) . ',' . $this->signup_ip( $subscriber ) . "\r\n"; } } @@ -694,7 +697,7 @@ public function display_format_form( $formats, $selected = array() ) { foreach ( $formats[0] as $format ) { if ( $i >= $half && 0 === $j ) { echo '' . "\r\n"; - $j++; + ++$j; } if ( 0 === $j ) { @@ -710,7 +713,7 @@ public function display_format_form( $formats, $selected = array() ) { } echo '> ' . esc_html( ucwords( $format ) ) . '
' . "\r\n"; } - $i++; + ++$i; } echo '' . "\r\n"; echo '' . "\r\n"; @@ -757,7 +760,7 @@ public function display_subscriber_dropdown( $selected = 'registered', $submit = } else { $count['registered'] = $count['all_users']; } - } else { + } elseif ( ! $this->s2_mu ) { if ( '' === $this->subscribe2_options['compulsory'] ) { $count['registered'] = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_key) FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value <> ''", $this->get_usermeta_keyname( 's2_subscribed' ) ) ); } else { diff --git a/classes/class-s2-ajax.php b/classes/class-s2-ajax.php index 6eca5c0..04dab4b 100755 --- a/classes/class-s2-ajax.php +++ b/classes/class-s2-ajax.php @@ -1,5 +1,7 @@ post_title ), $string ); - $string = str_replace( '{TITLETEXT}', stripslashes( $this->post_title_text ), $string ); - $string = str_replace( '{PERMAURL}', $this->get_tracking_link( $this->permalink ), $string ); - $link = '' . $this->get_tracking_link( $this->permalink ) . ''; - $string = str_replace( '{PERMALINK}', $link, $string ); - if ( strstr( $string, '{TINYLINK}' ) ) { + $text = str_replace( '{BLOGNAME}', html_entity_decode( get_option( 'blogname' ), ENT_QUOTES ), $text ); + $text = str_replace( '{BLOGLINK}', get_option( 'home' ), $text ); + $text = str_replace( '{TITLE}', stripslashes( $this->post_title ), $text ); + $text = str_replace( '{TITLETEXT}', stripslashes( $this->post_title_text ), $text ); + $text = str_replace( '{PERMAURL}', $this->get_tracking_link( $this->permalink ), $text ); + $link = '' . $this->get_tracking_link( $this->permalink ) . ''; + $text = str_replace( '{PERMALINK}', $link, $text ); + if ( strstr( $text, '{TINYLINK}' ) ) { $response = wp_safe_remote_get( 'http://tinyurl.com/api-create.php?url=' . rawurlencode( $this->get_tracking_link( $this->permalink ) ) ); if ( ! is_wp_error( $response ) ) { $tinylink = wp_remote_retrieve_body( $response ); } if ( false !== $tinylink ) { - $tlink = '' . $tinylink . ''; - $string = str_replace( '{TINYLINK}', $tlink, $string ); + $tlink = '' . $tinylink . ''; + $text = str_replace( '{TINYLINK}', $tlink, $text ); } else { - $string = str_replace( '{TINYLINK}', $link, $string ); + $text = str_replace( '{TINYLINK}', $link, $text ); } } - $string = str_replace( '{DATE}', $this->post_date, $string ); - $string = str_replace( '{TIME}', $this->post_time, $string ); - $string = str_replace( '{MYNAME}', stripslashes( $this->myname ), $string ); - $string = str_replace( '{EMAIL}', $this->myemail, $string ); - $string = str_replace( '{AUTHORNAME}', stripslashes( $this->authorname ), $string ); - $string = str_replace( '{CATS}', $this->post_cat_names, $string ); - $string = str_replace( '{TAGS}', $this->post_tag_names, $string ); - $string = str_replace( '{COUNT}', $this->post_count, $string ); + $text = str_replace( '{DATE}', $this->post_date, $text ); + $text = str_replace( '{TIME}', $this->post_time, $text ); + $text = str_replace( '{MYNAME}', stripslashes( $this->myname ), $text ); + $text = str_replace( '{EMAIL}', $this->myemail, $text ); + $text = str_replace( '{AUTHORNAME}', stripslashes( $this->authorname ), $text ); + $text = str_replace( '{CATS}', $this->post_cat_names, $text ); + $text = str_replace( '{TAGS}', $this->post_tag_names, $text ); + $text = str_replace( '{COUNT}', $this->post_count, $text ); if ( ! empty( $digest_post_ids ) ) { - return (string) apply_filters( 's2_custom_keywords', $string, $digest_post_ids ); + return (string) apply_filters( 's2_custom_keywords', $text, $digest_post_ids ); } else { - return (string) apply_filters( 's2_custom_keywords', $string ); + return (string) apply_filters( 's2_custom_keywords', $text ); } } @@ -134,7 +134,7 @@ public function mail( $recipients = array(), $subject = '', $message = '', $type $batch[] = $bcc; $bcc = ''; } - $count++; + ++$count; } // add any partially completed batches to our batch array if ( '' !== $bcc ) { @@ -237,7 +237,7 @@ public function plain_email() { */ public function get_tracking_link( $link ) { if ( empty( $link ) ) { - return; + return ''; } if ( ! empty( $this->subscribe2_options['tracking'] ) ) { ( strpos( $link, '?' ) > 0 ) ? $delimiter .= '&' : $delimiter = '?'; @@ -249,7 +249,7 @@ public function get_tracking_link( $link ) { } if ( strpos( $tracking, '{TITLE}' ) ) { $id = url_to_postid( $link ); - $title = rawurlencode( htmlentities( get_the_title( $id ), 1 ), ENT_QUOTES ); + $title = rawurlencode( htmlentities( get_the_title( $id ), ENT_QUOTES ) ); $tracking = str_replace( '{TITLE}', $title, $tracking ); } return $link . $delimiter . $tracking; @@ -362,10 +362,10 @@ public function publish( $post, $preview = '' ) { $post_cats_string = implode( ',', get_terms( - 'category', array( - 'fields' => 'ids', - 'get' => 'all', + 'taxonomy' => 'category', + 'fields' => 'ids', + 'get' => 'all', ) ) ); @@ -442,7 +442,7 @@ public function publish( $post, $preview = '' ) { ); // Get email subject - $subject = html_entity_decode( stripslashes( wp_kses( $this->substitute( $this->subscribe2_options['notification_subject'] ), '' ) ) ); + $subject = html_entity_decode( stripslashes( wp_kses( $this->substitute( $this->subscribe2_options['notification_subject'] ), '' ) ), ENT_QUOTES ); // Get the message template $mailtext = (string) apply_filters( 's2_email_template', $this->subscribe2_options['mailtext'] ); $mailtext = stripslashes( $this->substitute( $mailtext ) ); @@ -738,7 +738,7 @@ public function add( $email = '', $confirm = false ) { } else { $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->subscribe2 SET date=CURDATE(), time=CURTIME() WHERE CAST(email as binary)=%s", $email ) ); } - } else { + } elseif ( false === $this->is_public( $email ) ) { if ( $confirm ) { global $current_user; $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->subscribe2 (email, active, date, time, ip) VALUES (%s, %d, CURDATE(), CURTIME(), %s)", $email, 1, $current_user->user_login ) ); @@ -857,19 +857,19 @@ public function get_user_id( $email = '' ) { /** * Return an array of all subscribers emails or IDs */ - public function get_all_registered( $return = 'email' ) { + public function get_all_registered( $field = 'email' ) { global $wpdb; static $all_registered_id = ''; static $all_registered_email_id = ''; static $all_registered_email = ''; if ( $this->s2_mu ) { - if ( 'ID' === $return ) { + if ( 'ID' === $field ) { if ( '' === $all_registered_id ) { $all_registered_id = $wpdb->get_col( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key='{$wpdb->prefix}capabilities'" ); } return $all_registered_id; - } elseif ( 'emailid' === $return ) { + } elseif ( 'emailid' === $field ) { if ( '' === $all_registered_email_id ) { $all_registered_email_id = $wpdb->get_results( "SELECT a.user_email, a.ID FROM $wpdb->users AS a INNER JOIN $wpdb->usermeta AS b on a.ID = b.user_id WHERE b.meta_key ='{$wpdb->prefix}capabilities'", ARRAY_A ); } @@ -880,8 +880,8 @@ public function get_all_registered( $return = 'email' ) { } return $all_registered_email; } - } else { - if ( 'ID' === $return ) { + } elseif ( ! $this->s2_mu ) { + if ( 'ID' === $field ) { if ( '' === $all_registered_id ) { $all_registered_id = $wpdb->get_col( "SELECT ID FROM $wpdb->users" ); } @@ -971,7 +971,7 @@ public function get_registered( $args = '' ) { ) ); } - } else { + } elseif ( ! $this->s2_mu ) { if ( '' === $this->subscribe2_options['compulsory'] ) { $result = $wpdb->get_col( $wpdb->prepare( @@ -1203,7 +1203,7 @@ public function all_cats( $exclude = false, $orderby = 'slug' ) { if ( in_array( (string) $cat->term_id, $excluded, true ) ) { unset( $all_cats[ $id ] ); } - $id++; + ++$id; } } @@ -1591,7 +1591,7 @@ public function subscribe2_cron( $preview = '', $resend = '' ) { // if this post is excluded // don't include it in the digest if ( $check ) { - $this->post_count --; + --$this->post_count; continue; } } @@ -1817,7 +1817,7 @@ public function __construct() { // maybe use dev scripts $this->script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; - $this->word_wrap = apply_filters( 's2_word_wrap', 78 ); + $this->word_wrap = (int) apply_filters( 's2_word_wrap', 78 ); // RFC5322 states line length MUST be no more than 998 characters // and SHOULD be no more than 78 characters // Use 78 as default and cap user values above 998 @@ -1828,6 +1828,7 @@ public function __construct() { $this->site_switching = (bool) apply_filters( 's2_allow_site_switching', false ); $this->clean_interval = (int) apply_filters( 's2_clean_interval', 28 ); $this->lockout = (int) apply_filters( 's2_lockout', 0 ); + // lockout is for a maximum of 24 hours so cap the value if ( $this->lockout > 86399 ) { $this->lockout > 86399; @@ -1837,6 +1838,13 @@ public function __construct() { $tmp = explode( '-', $wp_version, 2 ); $this->wp_release = $tmp[0]; + // define and register table name + $s2_table = $wpdb->prefix . 'subscribe2'; + if ( ! isset( $wpdb->subscribe2 ) ) { + $wpdb->subscribe2 = $s2_table; + $wpdb->tables[] = 'subscribe2'; + } + // Is this Multisite or not? if ( isset( $wpmu_version ) || strpos( $wp_version, 'wordpress-mu' ) ) { $this->s2_mu = true; @@ -1865,13 +1873,6 @@ public function s2hooks() { // load our translations add_action( 'init', array( &$this, 'load_translations' ) ); - // define and register table name - $s2_table = $wpdb->prefix . 'subscribe2'; - if ( ! isset( $wpdb->subscribe2 ) ) { - $wpdb->subscribe2 = $s2_table; - $wpdb->tables[] = 'subscribe2'; - } - // do we need to install anything? if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->subscribe2 ) ) !== $wpdb->subscribe2 ) { require_once S2PATH . 'classes/class-s2-upgrade.php'; @@ -1880,7 +1881,7 @@ public function s2hooks() { } //do we need to upgrade anything? - if ( false === $this->subscribe2_options || is_array( $this->subscribe2_options ) && S2VERSION !== $this->subscribe2_options['version'] ) { + if ( false === $this->subscribe2_options || ( is_array( $this->subscribe2_options ) && S2VERSION !== $this->subscribe2_options['version'] ) ) { if ( ! is_a( $s2_upgrade, 'S2_Upgrade' ) ) { require_once S2PATH . 'classes/class-s2-upgrade.php'; $s2_upgrade = new S2_Upgrade(); @@ -1904,7 +1905,7 @@ public function s2hooks() { add_action( 's2_digest_cron', array( &$this, 'subscribe2_cron' ) ); add_action( 'transition_post_status', array( &$this, 'digest_post_transitions' ), 10, 3 ); } else { - $statuses = apply_filters( 's2_post_statuses', array( 'new', 'draft', 'auto-draft', 'pending' ) ); + $statuses = (array) apply_filters( 's2_post_statuses', array( 'new', 'draft', 'auto-draft', 'pending' ) ); if ( 'yes' === $this->subscribe2_options['private'] ) { foreach ( $statuses as $status ) { add_action( "{$status}_to_private", array( &$this, 'publish' ) ); @@ -1951,19 +1952,28 @@ public function s2hooks() { public $subscribe2_options = array(); // state variables used to affect processing - public $s2_mu = false; - public $filtered = 0; - public $post_count; + public $s2_mu = false; + public $filtered = 0; + public $post_count = 1; // state variable used in substitute() function - public $post_title; - public $post_title_text; - public $permalink; - public $post_date; - public $post_time; - public $myname; - public $myemail; - public $authorname; - public $post_cat_names; - public $post_tag_names; + public $post_title = ''; + public $post_title_text = ''; + public $permalink = ''; + public $post_date = ''; + public $post_time = ''; + public $myname = ''; + public $myemail = ''; + public $authorname = ''; + public $post_cat_names = ''; + public $post_tag_names = ''; + public $email; + + public $script_debug; + public $wp_release; + public $word_wrap; + public $excerpt_length; + public $site_switching; + public $clean_interval; + public $lockout; } diff --git a/classes/class-s2-counter-widget.php b/classes/class-s2-counter-widget.php index b7d2e8e..c78b852 100755 --- a/classes/class-s2-counter-widget.php +++ b/classes/class-s2-counter-widget.php @@ -8,6 +8,7 @@ public function __construct() { 'classname' => 's2_counter', 'description' => esc_html__( 'Subscriber Counter widget for Subscribe2', 'subscribe2-for-cp' ), 'customize_selective_refresh' => true, + 'show_instance_in_rest' => true, ); $control_options = array( @@ -21,12 +22,12 @@ public function __construct() { * Displays the Widget */ public function widget( $args, $instance ) { - $title = empty( $instance['title'] ) ? 'Subscriber Count' : $instance['title']; + $title = empty( $instance['title'] ) ? esc_html__( 'Subscriber Count', 'subscribe2-for-cp' ) : $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']; + $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 ) ) { @@ -45,13 +46,21 @@ public function widget( $args, $instance ) { * 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'] ) ); + $instance = $old_instance; + $instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) ); + + $background_color = wp_strip_all_tags( stripslashes( $new_instance['s2w_bg'] ) ); + if ( null !== $this->sanitize_color( $background_color ) ) { + $instance['s2w_bg'] = $background_color; + } + $foreground_color = wp_strip_all_tags( stripslashes( $new_instance['s2w_fg'] ) ); + if ( null !== $this->sanitize_color( $foreground_color ) ) { + $instance['s2w_fg'] = $foreground_color; + } + + $instance['s2w_width'] = (int) wp_strip_all_tags( stripslashes( $new_instance['s2w_width'] ) ); + $instance['s2w_height'] = (int) wp_strip_all_tags( stripslashes( $new_instance['s2w_height'] ) ); + $instance['s2w_font'] = (int) wp_strip_all_tags( stripslashes( $new_instance['s2w_font'] ) ); return $instance; } @@ -67,9 +76,9 @@ public function form( $instance ) { 'title' => 'Subscriber Count', 's2w_bg' => '#e3dacf', 's2w_fg' => '#345797', - 's2w_width' => '82', - 's2w_height' => '16', - 's2w_font' => '11', + 's2w_width' => 82, + 's2w_height' => 16, + 's2w_font' => 11, ); } else { $defaults = array( @@ -115,4 +124,17 @@ public function form( $instance ) { echo '' . "\r\n"; echo '' . "\r\n"; } + + /** + * Sanitize hex color input + */ + private function sanitize_color( $color ) { + if ( '' === $color || null === $color ) { + return null; + } + + if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) { + return $color; + } + } } diff --git a/classes/class-s2-form-widget.php b/classes/class-s2-form-widget.php index 2b00689..d02728f 100755 --- a/classes/class-s2-form-widget.php +++ b/classes/class-s2-form-widget.php @@ -8,6 +8,7 @@ public function __construct() { 'classname' => 's2_form_widget', 'description' => esc_html__( 'Sidebar Widget for Subscribe2', 'subscribe2-for-cp' ), 'customize_selective_refresh' => true, + 'show_instance_in_rest' => true, ); $control_ops = array( diff --git a/classes/class-s2-forms.php b/classes/class-s2-forms.php index 5fef8ae..8ada773 100755 --- a/classes/class-s2-forms.php +++ b/classes/class-s2-forms.php @@ -17,7 +17,7 @@ public function get_userid() { } if ( isset( $_GET['id'] ) ) { - if ( ! current_user_can( (string) apply_filters( 's2_capability', 'manage_options', 'manage' ) ) ) { + if ( ! current_user_can( (string) apply_filters( 's2_capability', 'manage_options', 'manage' ) ) ) { // phpcs:ignore WordPress.WP.Capabilities die( '

' . esc_html__( 'Permission error! Your request cannot be completed.', 'subscribe2-for-cp' ) . '

' ); } if ( is_multisite() ) { @@ -226,13 +226,10 @@ public function s2_your_subscription_submit() { } if ( isset( $_POST['new_category'] ) ) { update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), $_POST['new_category'] ); + } elseif ( 'yes' === s2cp()->subscribe2_options['show_autosub'] && 'yes' === s2cp()->subscribe2_options['autosub_def'] ) { + update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), 'yes' ); } else { - // value has not been passed so use Settings defaults - if ( 'yes' === s2cp()->subscribe2_options['show_autosub'] && 'yes' === s2cp()->subscribe2_options['autosub_def'] ) { - update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), 'yes' ); - } else { - update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), 'no' ); - } + update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), 'no' ); } $cats = ( isset( $_POST['category'] ) ) ? $_POST['category'] : ''; @@ -334,7 +331,7 @@ public function display_category_form( $selected = array(), $override = 1, $comp echo ' DISABLED'; } echo '> ' . esc_html( $cat_name ) . '' . "\r\n"; - $col++; + ++$col; } else { echo '