Advertisement
Guest User

Untitled

a guest
Dec 11th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. <?php
  2.  
  3. if( !class_exists( 'CD_FBSP_Like_Widget' ) )
  4. {
  5. class CD_FBSP_Like_Widget extends WP_Widget
  6. {
  7. function CD_FBSP_Like_Widget()
  8. {
  9. $widget_ops = array(
  10. 'classname' => 'cd-fb-like-widget',
  11. 'description' => __('Displays a Facebook Like Box', 'cd-fbspw' ),
  12. );
  13.  
  14. $this-> WP_Widget( 'CD_FBSP_Like_Widget', __('Facebook Like Box', 'cd-fbspw' ), $widget_ops );
  15.  
  16. if( is_active_widget( false, false, $this->id_base ) && !is_admin() )
  17. {
  18. add_action( 'wp_print_scripts', array( &$this, 'scripts' ) );
  19. }
  20. }
  21.  
  22. function form( $instance )
  23. {
  24. $defaults = array(
  25. 'title' => 'Find Us on Facebook',
  26. 'url' => 'http://www.facebook.com/WordPress',
  27. 'width' => 300,
  28. 'color_scheme' => 'light',
  29. 'show_faces' => 'on',
  30. 'border_color' => '',
  31. 'show_stream' => 'on',
  32. 'show_header' => 'off',
  33. 'height' => 400,
  34. 'force_wall' => 'on'
  35. );
  36.  
  37. $instance = wp_parse_args( (array) $instance, $defaults );
  38. extract( $instance );
  39.  
  40. ?>
  41. <p>
  42. <label for="cd-fb-title"><?php _e( 'Title:', 'cd-fbspw' ); ?></label>
  43. <input id="cd-fb-title" class="widefat" name="<?php echo $this-> get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  44. </p>
  45. <p>
  46. <label for="cd-fb-url"><?php _e( 'Facebook URL to Like:', 'cd-fbspw' ); ?></label>
  47. <input id="cd-fb-url" class="widefat" name="<?php echo $this->get_field_name( 'url' ); ?>" type="text" value="<?php echo esc_attr( $url ); ?>" />
  48. </p>
  49. <p>
  50. <label for="cd-fb-width"><?php _e( 'Width:', 'cd-fbspw' ); ?></label>
  51. <input id="cd-fb-width" class="widefat" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo esc_attr( $width ); ?>" />
  52. </p>
  53. <p>
  54. <label for="cd-fba-height"><?php _e( 'Height:', 'cd-fbspw' ); ?></label>
  55. <input id="cd-fba-height" class="widefat" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo esc_attr( $height ); ?>" />
  56. </p>
  57. <p>
  58. <label for="cd-fb-border"><?php _e( 'Border Color:', 'cd-fbspw' ); ?></label>
  59. <input id="cd-fb-border" class="widefat" name="<?php echo $this->get_field_name( 'border_color' ); ?>" type="text" value="<?php echo esc_attr( $border_color ); ?>" />
  60. </p>
  61. <p>
  62. <label for="cd-fb-color"><?php _e( 'Color Scheme:', 'cd-fbspw' ); ?></label>
  63. <select id="cd-fb-color" name="<?php echo $this->get_field_name( 'color_scheme' ); ?>">
  64. <option value="light" <?php selected( $color_scheme, 'light' ); ?>><?php _e( 'Light', 'cd-fbspw' ); ?></option>
  65. <option value="dark" <?php selected( $color_scheme, 'dark' ); ?>><?php _e( 'Dark', 'cd-fbspw' ); ?></option>
  66. </select>
  67. </p>
  68. <p>
  69. <input id="cd-fb-faces" name="<?php echo $this->get_field_name( 'show_faces' ); ?>" type="checkbox" <?php checked( $show_faces, 'on' ); ?> />
  70. <label for="cd-fb-faces"><?php _e( 'Check to show faces', 'cd-fbspw' ); ?></label>
  71. </p>
  72. <p>
  73. <input id="cd-fb-stream" name="<?php echo $this->get_field_name( 'show_stream' ); ?>" type="checkbox" <?php checked( $show_stream, 'on' ); ?> />
  74. <label for="cd-fb-stream"><?php _e( 'Check to show the page activity stream', 'cd-fbspw' ); ?></label>
  75. </p>
  76. <p>
  77. <input id="cd-fb-header" name="<?php echo $this->get_field_name( 'show_header' ); ?>" type="checkbox" <?php checked( $show_header, 'on' ); ?> />
  78. <label for="cd-fb-header"><?php _e( 'Check to show the facebook header', 'cd-fbspw' ); ?></label>
  79. </p>
  80. <p>
  81. <input id="cd-fb-header" name="<?php echo $this->get_field_name( 'force_wall' ); ?>" type="checkbox" <?php checked( $force_wall, 'on' ); ?> />
  82. <label for="cd-fb-header"><?php _e( 'Check to force the facebook wall to display', 'cd-fbspw' ); ?></label>
  83. </p>
  84. <?php
  85. }
  86.  
  87. function update( $new_instance, $old_instance )
  88. {
  89. $instance = $old_instance;
  90. $instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
  91. $instance['url'] = isset( $new_instance['url'] ) ? esc_url( $new_instance['url'], array( 'http' ) ) : '';
  92. $instance['width'] = isset( $new_instance['width'] ) ? absint( $new_instance['width'] ) : 300;
  93. $instance['height'] = isset( $new_instance['height'] ) ? absint( $new_instance['height'] ) : 400;
  94. $instance['border_color'] = isset( $new_instance['border_color'] ) ? strip_tags( $new_instance['border_color'] ) : '';
  95. $instance['color_scheme'] = strip_tags( $new_instance['color_scheme'] );
  96. $instance['show_faces'] = isset( $new_instance['show_faces'] ) && $new_instance['show_faces'] ? 'on' : 'off';
  97. $instance['show_stream'] = isset( $new_instance['show_stream'] ) && $new_instance['show_stream'] ? 'on' : 'off';
  98. $instance['show_header'] = isset( $new_instance['show_header'] ) && $new_instance['show_header'] ? 'on' : 'off';
  99. $instance['force_wall'] = isset( $new_instance['force_wall'] ) && $new_instance['force_wall'] ? 'on' : 'off';
  100.  
  101. return $instance;
  102. }
  103.  
  104. function widget( $args, $instance )
  105. {
  106. extract( $args );
  107.  
  108. // Get our widget variables
  109. $title = apply_filters( 'widget_title', $instance['title'] );
  110. $width = empty( $instance['width'] ) ? ' width="300"' : ' width="' . $instance['width'] . '"';
  111. $height = empty( $instance['height'] ) ? ' height="400"' : ' height="' . $instance['height'] . '"';
  112. $url = empty( $instance['url'] ) ? ' href="http://www.facebook.com/WordPress"' : ' href="' . $instance['url'] . '"';
  113. $border = empty( $instance['border_color'] ) ? ' border_color=""' : ' border_color="' . $instance['border_color'] . '"';
  114. $color = $instance['color_scheme'] == 'light' ? '' : ' colorscheme="dark"';
  115. $faces = $instance['show_faces'] == 'on' ? ' show_faces="true"' : ' show_faces="false"';
  116. $stream = $instance['show_stream'] == 'on' ? ' stream="true"' : ' stream="false"';
  117. $header = $instance['show_header'] == 'on' ? ' header="true"' : ' header="false"';
  118. $force_wall = $instance['force_wall'] == 'on' ? ' force_wall="true"' : ' force_wall="false"';
  119.  
  120. // Render the widget
  121. echo $before_widget;
  122. if( !empty( $title ) )
  123. {
  124. echo $before_title . $title . $after_title;
  125. }
  126. echo '<fb:like-box' . $url . $width . $height . $border . $color . $faces . $stream . $header . $force_wall . '></fb:like-box>';
  127. echo $after_widget;
  128.  
  129. }
  130.  
  131. function scripts()
  132. {
  133. wp_enqueue_script( 'xfbml' );
  134. }
  135. } // end class
  136.  
  137. /**
  138. * Register the widget here to make sure we get the right class...
  139. */
  140. add_action( 'widgets_init', 'cd_fbsp_like_register' );
  141. function cd_fbsp_like_register()
  142. {
  143. register_widget( 'CD_FBSP_Like_Widget' );
  144. }
  145.  
  146. } // end class_exists
  147.  
  148. ?>
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement