S2_Counter_widget

The Subscribe2 S2 Counter widget class.

Defined (1)

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

/include/counterwidget.php  
  1. class S2_Counter_widget extends WP_Widget { 
  2. /** 
  3. Declares the S2_Counter_widget class. 
  4. */ 
  5. function S2_Counter_widget() { 
  6. $widget_options = array('classname' => 's2_counter', 'description' => __('Subscriber Counter widget for Subscribe2', 'subscribe2') ); 
  7. $control_options = array('width' => 250, 'height' => 500); 
  8. $this->WP_Widget('s2_counter', __('Subscribe2 Counter', 'subscribe2'), $widget_options, $control_options); 
  9.  
  10. /** 
  11. Displays the Widget 
  12. */ 
  13. function widget($args, $instance) { 
  14. extract($args); 
  15.  
  16. $title = empty($instance['title']) ? 'Subscriber Count' : $instance['title']; 
  17. $s2w_bg = empty($instance['s2w_bg']) ? '#e3dacf' : $instance['s2w_bg']; 
  18. $s2w_fg = empty($instance['s2w_fg']) ? '#345797' : $instance['s2w_fg']; 
  19. $s2w_width = empty($instance['s2w_width']) ? '82' : $instance['s2w_width']; 
  20. $s2w_height = empty($instance['s2w_height']) ? '16' : $instance['s2w_height']; 
  21. $s2w_font = empty($instance['s2w_font']) ? '11' : $instance['s2w_font']; 
  22.  
  23. echo $before_widget; 
  24. echo $before_title . $title . $after_title; 
  25. global $mysubscribe2; 
  26. $registered = $mysubscribe2->get_registered(); 
  27. $confirmed = $mysubscribe2->get_public(); 
  28. $count = (count($registered) + count($confirmed)); 
  29. echo "<ul><div style=\"text-align:center; background-color:" . $s2w_bg . "; color:" . $s2w_fg . "; width:" . $s2w_width . "px; height:" . $s2w_height . "px; font:" . $s2w_font . "pt Verdana, Arial, Helvetica, sans-serif; vertical-align:middle; padding:3px; border:1px solid #444;\">"; 
  30. echo $count; 
  31. echo "</div></ul>"; 
  32. echo $after_widget; 
  33.  
  34. /** 
  35. Saves the widgets settings. 
  36. */ 
  37. function update($new_instance, $old_instance) { 
  38. $instance = $old_instance; 
  39. $instance['title'] = strip_tags(stripslashes($new_instance['title'])); 
  40. $instance['s2w_bg'] = strip_tags(stripslashes($new_instance['s2w_bg'])); 
  41. $instance['s2w_fg'] = strip_tags(stripslashes($new_instance['s2w_fg'])); 
  42. $instance['s2w_width'] = strip_tags(stripslashes($new_instance['s2w_width'])); 
  43. $instance['s2w_height'] = strip_tags(stripslashes($new_instance['s2w_height'])); 
  44. $instance['s2w_font'] = strip_tags(stripslashes($new_instance['s2w_font'])); 
  45.  
  46. return $instance; 
  47.  
  48. /** 
  49. Creates the edit form for the widget. 
  50. */ 
  51. function form($instance) { 
  52. // set some defaults 
  53. $options = get_option('widget_s2counter'); 
  54. if ( $options === false ) { 
  55. $defaults = array('title'=>'Subscriber Count', 's2w_bg'=>'#e3dacf', 's2w_fg'=>'#345797', 's2w_width'=>'82', 's2w_height'=>'16', 's2w_font'=>'11'); 
  56. } else { 
  57. $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']); 
  58. delete_option('widget_s2counter'); 
  59. $instance = wp_parse_args( (array) $instance, $defaults); 
  60. // Be sure you format your options to be valid HTML attributes. 
  61. $s2w_title = htmlspecialchars($instance['title'], ENT_QUOTES); 
  62. $s2w_bg = htmlspecialchars($instance['s2w_bg'], ENT_QUOTES); 
  63. $s2w_fg = htmlspecialchars($instance['s2w_fg'], ENT_QUOTES); 
  64. $s2w_width = htmlspecialchars($instance['s2w_width'], ENT_QUOTES); 
  65. $s2w_height = htmlspecialchars($instance['s2w_height'], ENT_QUOTES); 
  66. $s2w_font = htmlspecialchars($instance['s2w_font'], ENT_QUOTES); 
  67. echo "<div>\r\n"; 
  68. echo "<fieldset><legend><label for=\"" . $this->get_field_id('title') . "\">" . __('Widget Title', 'subscribe2') . "</label></legend>\r\n"; 
  69. echo "<input type=\"text\" name=\"" . $this->get_field_name('title') . "\" id=\"" . $this->get_field_id('title') . "\" value=\"" . $s2w_title . "\" />\r\n"; 
  70. echo "</fieldset>\r\n"; 
  71.  
  72. echo "<fieldset>\r\n"; 
  73. echo "<legend>" . __('Color Scheme', 'subscribe2') . "</legend>\r\n"; 
  74. echo "<label>\r\n"; 
  75. echo "<input type=\"text\" name=\"" . $this->get_field_name('s2w_bg') . "\" id=\"" . $this->get_field_id('s2w_bg') . "\" maxlength=\"6\" value=\"" . $s2w_bg . "\" class=\"colorpickerField\" style=\"width:60px;\" /> " . __('Body', 'subscribe2') . "</label><br />\r\n"; 
  76. echo "<label>\r\n"; 
  77. echo "<input type=\"text\" name=\"" . $this->get_field_name('s2w_fg') . "\" id=\"" . $this->get_field_id('s2w_fg') . "\" maxlength=\"6\" value=\"" . $s2w_fg . "\" class=\"colorpickerField\" style=\"width:60px;\" /> " . __('Text', 'subscribe2') . "</label><br />\r\n"; 
  78. echo "<div class=\"s2_colorpicker\" id =\"" . $this->get_field_id('s2_colorpicker') . "\"></div>"; 
  79. echo "</fieldset>"; 
  80.  
  81. echo "<fieldset>\r\n"; 
  82. echo "<legend>" . __('Width, Height and Font Size', 'subscribe2') . "</legend>\r\n"; 
  83. echo "<table style=\"border:0; padding:0; margin:0 0 12px 0; border-collapse:collapse;\" align=\"center\">\r\n"; 
  84. echo "<tr><td><label for=\"" . $this->get_field_id('s2w_width') . "\">" . __('Width', 'subscribe2') . "</label></td>\r\n"; 
  85. echo "<td><input type=\"text\" name=\"" . $this->get_field_name('s2w_width') . "\" id=\"" . $this->get_field_id('s2w_width') . "\" value=\"" . $s2w_width . "\" /></td></tr>\r\n"; 
  86. echo "<tr><td><label for=\"" . $this->get_field_id('s2w_height') . "\">" . __('Height', 'subscribe2') . "</label></td>\r\n"; 
  87. echo "<td><input type=\"text\" name=\"" . $this->get_field_name('s2w_height') . "\" id=\"" . $this->get_field_id('s2w_height') . "\" value=\"" . $s2w_height . "\" /></td></tr>\r\n"; 
  88. echo "<tr><td><label for=\"" . $this->get_field_id('s2w_font') . "\">" . __('Font', 'subscribe2') . "</label></td>\r\n"; 
  89. echo "<td><input type=\"text\" name=\"" . $this->get_field_name('s2w_font') . "\" id=\"" . $this->get_field_id('s2w_font') . "\" value=\"" . $s2w_font . "\" /></td></tr>\r\n"; 
  90. echo "</table></fieldset></div>\r\n"; 
  91. }// end S2_Counter_widget class