S2_Form_widget

The Subscribe2 S2 Form widget class.

Defined (1)

The class is defined in the following location(s).

/include/widget.php  
  1. class S2_Form_widget extends WP_Widget { 
  2. /** 
  3. Declares the Subscribe2 widget class. 
  4. */ 
  5. function S2_Form_widget() { 
  6. $widget_ops = array('classname' => 's2_form_widget', 'description' => __('Sidebar Widget for Subscribe2', 'subscribe2') ); 
  7. $control_ops = array('width' => 250, 'height' => 300); 
  8. $this->WP_Widget('s2_form_widget', __('Subscribe2 Widget', 'subscribe2'), $widget_ops, $control_ops); 
  9.  
  10. /** 
  11. Displays the Widget 
  12. */ 
  13. function widget($args, $instance) { 
  14. extract($args); 
  15. $title = empty($instance['title']) ? __('Subscribe2', 'subscribe2') : $instance['title']; 
  16. $div = empty($instance['div']) ? 'search' : $instance['div']; 
  17. $widgetprecontent = empty($instance['widgetprecontent']) ? '' : $instance['widgetprecontent']; 
  18. $widgetpostcontent = empty($instance['widgetpostcontent']) ? '' : $instance['widgetpostcontent']; 
  19. $textbox_size = empty($instance['size']) ? 20 : $instance['size']; 
  20. $hidebutton = empty($instance['hidebutton']) ? 'none' : $instance['hidebutton']; 
  21. $postto = empty($instance['postto']) ? '' : $instance['postto']; 
  22. $js = empty($instance['js']) ? '' : $instance['js']; 
  23. $noantispam = empty($instance['noantispam']) ? '' : $instance['noantispam']; 
  24. $hide = ''; 
  25. if ( $hidebutton == 'subscribe' || $hidebutton == 'unsubscribe' ) { 
  26. $hide = " hide=\"" . $hidebutton . "\""; 
  27. } elseif ( $hidebutton == 'link' ) { 
  28. $hide = " link=\"" . __('(Un)Subscribe to Posts', 'subscribe2') . "\""; 
  29. $postid = ''; 
  30. if ( !empty($postto) ) { 
  31. $postid = " id=\"" . $postto . "\""; 
  32. $size = " size=\"" . $textbox_size . "\""; 
  33. $nojs = ''; 
  34. if ( $js ) { 
  35. $nojs = " nojs=\"true\""; 
  36. if ( $noantispam ) { 
  37. $noantispam = " noantispam=\"true\""; 
  38. $shortcode = "[subscribe2" . $hide . $postid . $size . $nojs . $noantispam . "]"; 
  39. echo $before_widget; 
  40. echo $before_title . $title . $after_title; 
  41. echo "<div class=\"" . $div . "\">"; 
  42. $content = do_shortcode( $shortcode ); 
  43. if ( !empty($widgetprecontent) ) { 
  44. echo $widgetprecontent; 
  45. echo $content; 
  46. if ( !empty($widgetpostcontent) ) { 
  47. echo $widgetpostcontent; 
  48. echo "</div>"; 
  49. echo $after_widget; 
  50.  
  51. /** 
  52. Saves the widgets settings. 
  53. */ 
  54. function update($new_instance, $old_instance) { 
  55. $instance = $old_instance; 
  56. $instance['title'] = strip_tags(stripslashes($new_instance['title'])); 
  57. $instance['div'] = strip_tags(stripslashes($new_instance['div'])); 
  58. $instance['widgetprecontent'] = stripslashes($new_instance['widgetprecontent']); 
  59. $instance['widgetpostcontent'] = stripslashes($new_instance['widgetpostcontent']); 
  60. $instance['size'] = intval(stripslashes($new_instance['size'])); 
  61. $instance['hidebutton'] = strip_tags(stripslashes($new_instance['hidebutton'])); 
  62. $instance['postto'] = stripslashes($new_instance['postto']); 
  63. $instance['js'] = stripslashes($new_instance['js']); 
  64. $instance['noantispam'] = stripslashes($new_instance['noantispam']); 
  65.  
  66. return $instance; 
  67.  
  68. /** 
  69. Creates the edit form for the widget. 
  70. */ 
  71. function form($instance) { 
  72. // set some defaults, getting any old options first 
  73. $options = get_option('widget_subscribe2widget'); 
  74. if ( $options === false ) { 
  75. $defaults = array('title' => 'Subscribe2', 'div' => 'search', 'widgetprecontent' => '', 'widgetpostcontent' => '', 'size' => 20, 'hidebutton' => 'none', 'postto' => '', 'js' => '', 'noantispam' => ''); 
  76. } else { 
  77. $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']); 
  78. delete_option('widget_subscribe2widget'); 
  79. // code to obtain old settings too 
  80. $instance = wp_parse_args( (array) $instance, $defaults); 
  81.  
  82. $title = htmlspecialchars($instance['title'], ENT_QUOTES); 
  83. $div = htmlspecialchars($instance['div'], ENT_QUOTES); 
  84. $widgetprecontent = htmlspecialchars($instance['widgetprecontent'], ENT_QUOTES); 
  85. $widgetpostcontent = htmlspecialchars($instance['widgetpostcontent'], ENT_QUOTES); 
  86. $size = htmlspecialchars($instance['size'], ENT_QUOTES); 
  87. $hidebutton = htmlspecialchars($instance['hidebutton'], ENT_QUOTES); 
  88. $postto = htmlspecialchars($instance['postto'], ENT_QUOTES); 
  89. $js = htmlspecialchars($instance['js'], ENT_QUOTES); 
  90. $noantispam = htmlspecialchars($instance['noantispam'], ENT_QUOTES); 
  91.  
  92. global $wpdb, $mysubscribe2; 
  93. $sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish'"; 
  94.  
  95. echo "<div>\r\n"; 
  96. echo "<p><label for=\"" . $this->get_field_id('title') . "\">" . __('Title', 'subscribe2') . ":\r\n"; 
  97. echo "<input class=\"widefat\" id=\"" . $this->get_field_id('title') . "\" name=\"" . $this->get_field_name('title') . "\" type=\"text\" value=\"" . $title . "\" /></label></p>\r\n"; 
  98. echo "<p><label for=\"" . $this->get_field_id('div') . "\">" . __('Div class name', 'subscribe2') . ":\r\n"; 
  99. echo "<input class=\"widefat\" id=\"" . $this->get_field_id('div') . "\" name=\"" . $this->get_field_name('div') . "\" type=\"text\" value=\"" . $div . "\" /></label></p>\r\n"; 
  100. echo "<p><label for=\"" . $this->get_field_id('widgetprecontent') . "\">" . __('Pre-Content', 'subscribe2') . ":\r\n"; 
  101. echo "<textarea class=\"widefat\" id=\"" . $this->get_field_id('widgetprecontent') . "\" name=\"" . $this->get_field_name('widgetprecontent') . "\" rows=\"2\" cols=\"25\">" . $widgetprecontent . "</textarea></label></p>\r\n"; 
  102. echo "<p><label for=\"" . $this->get_field_id('widgetpostcontent') . "\">" . __('Post-Content', 'subscribe2') . ":\r\n"; 
  103. echo "<textarea class=\"widefat\" id=\"" . $this->get_field_id('widgetpostcontent') . "\" name=\"" . $this->get_field_name('widgetpostcontent') . "\" rows=\"2\" cols=\"25\">" . $widgetpostcontent . "</textarea></label></p>\r\n"; 
  104. echo "<p><label for=\"" . $this->get_field_id('size') . "\">" . __('Text Box Size', 'subscribe2') . ":\r\n"; 
  105. echo "<input class=\"widefat\" id=\"" . $this->get_field_id('size') . "\" name=\"" . $this->get_field_name('size') . "\" type=\"text\" value=\"" . $size . "\" /></label></p>\r\n"; 
  106. echo "<p>" . __('Display options', 'subscribe2') . ":<br />\r\n"; 
  107. echo "<label for=\"" . $this->get_field_id('hidebutton') . "complete\"><input id=\"" . $this->get_field_id('hidebutton') . "complete\" name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"none\"". checked('none', $hidebutton, false) . "/> " . __('Show complete form', 'subscribe2') . "</label>\r\n"; 
  108. echo "<br /><label for=\"" . $this->get_field_id('hidebutton') . "subscribe\"><input id=\"" . $this->get_field_id('hidebutton') . "subscribe\" name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"subscribe\"". checked('subscribe', $hidebutton, false) . "/> " . __('Hide Subscribe button', 'subscribe2') . "</label>\r\n"; 
  109. echo "<br /><label for=\"" . $this->get_field_id('hidebutton') . "unsubscribe\"><input id=\"" . $this->get_field_id('hidebutton') . "unsubscribe\" name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"unsubscribe\"". checked('unsubscribe', $hidebutton, false) . "/> " . __('Hide Unsubscribe button', 'subscribe2') . "</label>\r\n"; 
  110. if ( '1' == $mysubscribe2->subscribe2_options['ajax'] ) { 
  111. echo "<br /><label for=\"" . $this->get_field_id('hidebutton') . "ajax\"><input id=\"" . $this->get_field_id('hidebutton') . "ajax\" name=\"" . $this->get_field_name('hidebutton') . "\" type=\"radio\" value=\"link\"". checked('link', $hidebutton, false) . "/> " . __('Show as link', 'subscribe2') . "</label>\r\n"; 
  112. echo "</p>\r\n"; 
  113. echo "<p><label for=\"" . $this->get_field_id('postto') . "\">" . __('Post form content to page', 'subscribe2') . ":\r\n"; 
  114. echo "<select class=\"widefat\" id=\"" . $this->get_field_id('postto') . "\" name=\"" . $this->get_field_name('postto') . "\">\r\n"; 
  115. echo "<option value=\"" . $mysubscribe2->subscribe2_options['s2page'] . "\">" . __('Use Subscribe2 Default', 'subscribe2') . "</option>\r\n"; 
  116. echo "<option value=\"home\""; 
  117. if ( $postto === 'home' ) { echo " selected=\"selected\""; } 
  118. echo ">" . __('Use Home Page', 'subscribe2') . "</option>\r\n"; 
  119. echo "<option value=\"self\""; 
  120. if ( $postto === 'self' ) { echo " selected=\"selected\""; } 
  121. echo ">" . __('Use Referring Page', 'subscribe2') . "</option>\r\n"; 
  122. $mysubscribe2->pages_dropdown($postto); 
  123. echo "</select></label></p>\r\n"; 
  124. echo "<p><label for=\"" . $this->get_field_id('js') . "\">" . __('Disable JavaScript', 'subscribe2') . ":\r\n"; 
  125. echo "<input id=\"" . $this->get_field_id('js') . "\" name =\"" . $this->get_field_name('js') . "\" value=\"true\" type=\"checkbox\"" . checked('true', $js, false) . "/>"; 
  126. echo "</label></p>\r\n"; 
  127. echo "<p><label for=\"" . $this->get_field_id('noantispam') . "\">" . __('Disable Anti-spam measures', 'subscribe2') . ":\r\n"; 
  128. echo "<input id=\"" . $this->get_field_id('noantispam') . "\" name =\"" . $this->get_field_name('noantispam') . "\" value=\"true\" type=\"checkbox\"" . checked('true', $noantispam, false) . "/>"; 
  129. echo "</label></p>\r\n"; 
  130. echo "</div>\r\n"; 
  131. } // End S2_Form_widget class