Index: include/counterwidget.php =================================================================== --- include/counterwidget.php (revision 1228025) +++ include/counterwidget.php (working copy) @@ -3,34 +3,34 @@ /** Declares the S2_Counter_widget class. */ - function S2_Counter_widget() { - $widget_options = array('classname' => 's2_counter', 'description' => __('Subscriber Counter widget for Subscribe2', 'subscribe2') ); - $control_options = array('width' => 250, 'height' => 500); - $this->WP_Widget('s2_counter', __('Subscribe2 Counter', 'subscribe2'), $widget_options, $control_options); + function __construct() { + $widget_options = array( 'classname' => 's2_counter', 'description' => esc_html__( 'Subscriber Counter widget for Subscribe2', 'subscribe2' ) ); + $control_options = array( 'width' => 250, 'height' => 500 ); + parent::__construct( 's2_counter', esc_html__( 'Subscribe2 Counter', 'subscribe2' ), $widget_options, $control_options ); } /** Displays the Widget */ - 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']; + 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 $args['before_widget']; - if ( !empty($title) ) { + if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } global $mysubscribe2; $registered = $mysubscribe2->get_registered(); $confirmed = $mysubscribe2->get_public(); - $count = (count($registered) + count($confirmed)); - echo "'; echo $args['after_widget']; } @@ -37,14 +37,14 @@ /** Saves the widgets settings. */ - function update($new_instance, $old_instance) { + function update( $new_instance, $old_instance ) { $instance = $old_instance; - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['s2w_bg'] = strip_tags(stripslashes($new_instance['s2w_bg'])); - $instance['s2w_fg'] = strip_tags(stripslashes($new_instance['s2w_fg'])); - $instance['s2w_width'] = strip_tags(stripslashes($new_instance['s2w_width'])); - $instance['s2w_height'] = strip_tags(stripslashes($new_instance['s2w_height'])); - $instance['s2w_font'] = strip_tags(stripslashes($new_instance['s2w_font'])); + $instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) ); + $instance['s2w_bg'] = strip_tags( stripslashes( $new_instance['s2w_bg'] ) ); + $instance['s2w_fg'] = strip_tags( stripslashes( $new_instance['s2w_fg'] ) ); + $instance['s2w_width'] = strip_tags( stripslashes( $new_instance['s2w_width'] ) ); + $instance['s2w_height'] = strip_tags( stripslashes( $new_instance['s2w_height'] ) ); + $instance['s2w_font'] = strip_tags( stripslashes( $new_instance['s2w_font'] ) ); return $instance; } @@ -52,47 +52,47 @@ /** Creates the edit form for the widget. */ - function form($instance) { + function form( $instance ) { // set some defaults - $options = get_option('widget_s2counter'); - if ( $options === false ) { - $defaults = array('title'=>'Subscriber Count', 's2w_bg'=>'#e3dacf', 's2w_fg'=>'#345797', 's2w_width'=>'82', 's2w_height'=>'16', 's2w_font'=>'11'); + $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'); + $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); + $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 "
\r\n"; - echo "
\r\n"; - echo "get_field_name('title') . "\" id=\"" . $this->get_field_id('title') . "\" value=\"" . $s2w_title . "\" />\r\n"; - echo "
\r\n"; + $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 '
' . "\r\n"; + echo '
' . "\r\n"; + echo '' . "\r\n"; + echo '
' . "\r\n"; - echo "
\r\n"; - echo "" . __('Color Scheme', 'subscribe2') . "\r\n"; - echo "
\r\n"; - echo "
\r\n"; - echo "
get_field_id('s2_colorpicker') . "\">
"; - echo "
"; + echo '
' . "\r\n"; + echo '' . esc_html__( 'Color Scheme', 'subscribe2' ) . '' . "\r\n"; + echo '
' . "\r\n"; + echo '
' . "\r\n"; + echo '
'; + echo '
'; - echo "
\r\n"; - echo "" . __('Width, Height and Font Size', 'subscribe2') . "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "\r\n"; - echo "
get_field_name('s2w_width') . "\" id=\"" . $this->get_field_id('s2w_width') . "\" value=\"" . $s2w_width . "\" />
get_field_name('s2w_height') . "\" id=\"" . $this->get_field_id('s2w_height') . "\" value=\"" . $s2w_height . "\" />
get_field_name('s2w_font') . "\" id=\"" . $this->get_field_id('s2w_font') . "\" value=\"" . $s2w_font . "\" />
\r\n"; + echo '
' . "\r\n"; + echo '' . esc_html__( 'Width, Height and Font Size', 'subscribe2' ) . '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '' . "\r\n"; + echo '
' . "\r\n"; } }// end S2_Counter_widget class ?> \ No newline at end of file Index: include/widget.php =================================================================== --- include/widget.php (revision 1228025) +++ include/widget.php (working copy) @@ -3,62 +3,62 @@ /** Declares the Subscribe2 widget class. */ - function S2_Form_widget() { - $widget_ops = array('classname' => 's2_form_widget', 'description' => __('Sidebar Widget for Subscribe2', 'subscribe2') ); - $control_ops = array('width' => 250, 'height' => 300); - $this->WP_Widget('s2_form_widget', __('Subscribe2 Widget', 'subscribe2'), $widget_ops, $control_ops); + function __construct() { + $widget_ops = array( 'classname' => 's2_form_widget', 'description' => esc_html__( 'Sidebar Widget for Subscribe2', 'subscribe2' ) ); + $control_ops = array( 'width' => 250, 'height' => 300 ); + parent::__construct( 's2_form_widget', esc_html__( 'Subscribe2 Widget', 'subscribe2' ), $widget_ops, $control_ops ); } /** Displays the Widget */ - 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']; + 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 ( $hidebutton == 'subscribe' || $hidebutton == 'unsubscribe' ) { - $hide = " hide=\"" . $hidebutton . "\""; - } elseif ( $hidebutton == 'link' ) { - $hide = " link=\"" . __('(Un)Subscribe to Posts', 'subscribe2') . "\""; + 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 . "\""; + if ( ! empty( $postto ) ) { + $postid = ' id="' . $postto . '"'; } - $size = " size=\"" . $textbox_size . "\""; + $size = ' size="' . $textbox_size . '"'; $nojs = ''; if ( $js ) { - $nojs = " nojs=\"true\""; + $nojs = ' nojs="true"'; } if ( $noantispam ) { - $noantispam = " noantispam=\"true\""; + $noantispam = ' noantispam="true"'; } if ( $nowrap ) { - $nowrap = " wrap=\"false\""; + $nowrap = ' wrap="false"'; } - $shortcode = "[subscribe2" . $hide . $postid . $size . $nojs . $noantispam . $nowrap . "]"; + $shortcode = '[subscribe2' . $hide . $postid . $size . $nojs . $noantispam . $nowrap . ']'; echo $args['before_widget']; - if ( !empty($title) ) { - echo $args['before_title'] . $title . $args['after_title']; + if ( ! empty( $title ) ) { + echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; } - echo "
"; + echo '
'; $content = do_shortcode( $shortcode ); - if ( !empty($widgetprecontent) ) { - echo $widgetprecontent; + if ( ! empty( $widgetprecontent ) ) { + echo wp_kses( $widgetprecontent, 'post' ); } echo $content; - if ( !empty($widgetpostcontent) ) { - echo $widgetpostcontent; + if ( ! empty( $widgetpostcontent ) ) { + echo wp_kses( $widgetpostcontent, 'post' ); } - echo "
"; + echo '
'; echo $args['after_widget']; } @@ -65,18 +65,18 @@ /** Saves the widgets settings. */ - function update($new_instance, $old_instance) { + function update( $new_instance, $old_instance ) { $instance = $old_instance; - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['div'] = strip_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'] = strip_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']); + $instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) ); + $instance['div'] = strip_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'] = strip_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; } @@ -84,72 +84,72 @@ /** Creates the edit form for the widget. */ - function form($instance) { + function form( $instance ) { // set some defaults, getting any old options first - $options = get_option('widget_subscribe2widget'); - if ( $options === false ) { - $defaults = array('title' => 'Subscribe2', 'div' => 'search', 'widgetprecontent' => '', 'widgetpostcontent' => '', 'size' => 20, 'hidebutton' => 'none', 'postto' => '', 'js' => '', 'noantispam' => '', 'nowrap' => ''); + $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'); + $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); + $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); + $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 "
\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

" . __('Display options', 'subscribe2') . ":
\r\n"; - echo "\r\n"; - echo "
\r\n"; - echo "
\r\n"; - if ( '1' == $mysubscribe2->subscribe2_options['ajax'] ) { - echo "
\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . __( 'Display options', 'subscribe2' ) . ':
' . "\r\n"; + echo '' . "\r\n"; + echo '
' . "\r\n"; + echo '
' . "\r\n"; + if ( '1' === $mysubscribe2->subscribe2_options['ajax'] ) { + echo '
' . "\r\n"; } - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "

\r\n"; - echo "
\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '

' . "\r\n"; + echo '
' . "\r\n"; } } // End S2_Form_widget class ?> \ No newline at end of file