whyisjake

Jake Spurlock

Jul 10th, 2010
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.72 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Facebook Social Widgets
  4. Plugin URI: http://www.jakespurlock.com/fb-social-widgets
  5. Description: Easily integrate Facebook Social Commenting into your WordPress website.
  6. Author: Jake Spurlock
  7. Version: 0.5
  8. Author URI: http://jakespurlock.com
  9. */
  10.  
  11. // create custom plugin settings menu
  12. add_action('admin_menu', 'fb_create_menu');
  13.  
  14. function fb_create_menu() {
  15.  
  16.     add_options_page('Facebook Comments', 'Facebook Comments', 'administrator', __FILE__, 'buildinternet_settings_page');
  17.     add_action( 'admin_init', 'register_mysettings' );
  18. }
  19.  
  20.  
  21. function register_mysettings() {
  22.     //register our settings
  23.     register_setting( 'fb-settings-group', 'fb_app_id' );
  24.     register_setting( 'fb-settings-group', 'fb_width' );
  25.     register_setting( 'fb-settings-group', 'fb_number' );
  26.     register_setting( 'fb-settings-group', 'fb_widget' );
  27.     register_setting( 'fb-settings-group', 'fb_connections' );
  28.     register_setting( 'fb-settings-group', 'fb_location_yes' );
  29.     register_setting( 'fb-settings-group', 'fb_location_no');
  30.     register_setting( 'fb-settings-group', 'fb_location');
  31. }
  32.  
  33. function buildinternet_settings_page() { ?>
  34.  
  35. <div class="wrap">
  36. <h2>Facebook Social Widget Options</h2>
  37.  
  38. <div id="custom_form">
  39.  
  40. <form method="post" action="options.php">
  41.    
  42.     <?php settings_fields('fb-settings-group'); ?>
  43.    
  44.     <table  summary="Facebook Options">
  45.        
  46.         <tbody>
  47.            
  48.             <tr>
  49.                 <td style="width:25%;padding-right:10px;">Unique Application ID</td>
  50.                 <td><input type="text" name="fb_app_id" value="<?php echo get_option('fb_app_id'); ?>"></td>
  51.                
  52.             </tr>
  53.            
  54.             <tr>
  55.                 <td style="padding-right:10px;">Nuber of Comments to Show Per Page</td>
  56.                 <td><input type="text" name="fb_number" value="<?php echo get_option('fb_number'); ?>"></td>
  57.             </tr>
  58.                
  59.             <tr>
  60.                 <td style="padding-right:10px;">Width of Comment Div</td>
  61.                 <td><input type="text" name="fb_width" value="<?php echo get_option('fb_width'); ?>"></td>
  62.             </tr>
  63.            
  64.             <tr>
  65.                 <td style="padding-right:10px;">Number of Connections to show in Like Widget</td>
  66.                 <td><input type="text" name="fb_connections" value="<?php echo get_option('fb_connections'); ?>"></td>
  67.             </tr>
  68.            
  69.             <tr>
  70.                 <td style="padding-right:10px;">Width of Sidebar Widget</td>
  71.                 <td><input type="text" name="fb_widget" value="<?php echo get_option('fb_widget'); ?>"></td>
  72.             </tr>
  73.            
  74.             <tr>
  75.                 <td style="padding-right:10px;">Display a like button below the post?</td>
  76.                 <td><select name="fb_location" id="fb_location">
  77.                         <option name="fb_location_yes" value="<?php echo get_option('fb_location_yes'); ?>">Yes</option>
  78.                         <option name="fb_location_no" value="<?php echo get_option('fb_location_no'); ?>">No</option>
  79.                     </select>
  80.                 </td>
  81.             </tr>
  82.            
  83.         </tbody>
  84.     </table>
  85.    
  86.     <p class="submit">
  87.     <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  88.     </p>
  89.    
  90.     </div>
  91.  
  92. </form>
  93. </div>
  94. <?php }
  95.  
  96. add_filter('comments_template', 'fb_comments');
  97.  
  98. function fb_comments() {
  99.     echo '<fb:comments xid="'.get_option('fb_app_id').'" numposts="'.get_option('fb_number').'" width="'.get_option('fb_width').'"></fb:comments>';
  100. }
  101.  
  102. add_action('wp_footer', 'fb_js');
  103. function fb_js(){
  104.     ?>
  105.  
  106. <div id="fb-root"></div>
  107. <script>
  108.   window.fbAsyncInit = function() {
  109.     FB.init({appId: '<?php echo get_option('fb_app_id'); ?>', status: true, cookie: true,
  110.              xfbml: true});
  111.   };
  112.   (function() {
  113.     var e = document.createElement('script'); e.async = true;
  114.     e.src = document.location.protocol +
  115.       '//connect.facebook.net/en_US/all.js';
  116.     document.getElementById('fb-root').appendChild(e);
  117.   }());
  118. </script>
  119.  
  120. <?php }
  121.  
  122. add_action('wp_head', 'og_head');
  123.  
  124. function og_head(){ ?>
  125.  
  126.     <meta property="og:title" content="<?php the_title(); ?>" />
  127.     <meta property="og:type" content="blog" />
  128.     <meta property="og:url" content="<?php the_permalink(); ?>" />
  129.     <?php if ($src){ ?>
  130.     <meta property="og:image" content="<?php echo $src; ?>" />
  131.     <?php } ?>
  132.     <?php $special_text = get_the_content(); ?>
  133.     <meta property="og:description" content="<?php echo strip_tags($special_text); ?>" />
  134.     <meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
  135.     <meta property="fb:app_id" content="<?php echo get_option('fb_app_id'); ?>" />
  136.     <?php }
  137.  
  138.  
  139. add_action("widgets_init", array('Recommendations_Widget', 'register'));
  140. class Recommendations_Widget {
  141.   function control(){
  142.     echo '<fb:friendpile>';
  143.   }
  144.   function widget($args){
  145.     echo $args['before_widget'];
  146.     echo '<fb:recommendations width="'.get_option('fb_widget').'"></fb:recommendations>';
  147.     echo $args['after_widget'];
  148.   }
  149.   function register(){
  150.     register_sidebar_widget('Facebook Recommendations Widget', array('Recommendations_Widget', 'widget'));
  151.     register_widget_control('Facebook Recommendations Widget', array('Recommendations_Widget', 'control'));
  152.   }
  153. }
  154.  
  155. add_action("widgets_init", array('Activity_Feed', 'register'));
  156. class Activity_Feed {
  157.   function control(){
  158.     echo '<fb:friendpile>';
  159.   }
  160.   function widget($args){
  161.     echo $args['before_widget'];
  162.     echo '<fb:activity width="'.get_option('fb_widget').'"></fb:recommendations>';
  163.     echo $args['after_widget'];
  164.   }
  165.   function register(){
  166.     register_sidebar_widget('Facebook Activity Feed', array('Activity_Feed', 'widget'));
  167.     register_widget_control('Facebook Activity Feed', array('Activity_Feed', 'control'));
  168.   }
  169. }
  170.  
  171. add_action("widgets_init", array('Like_Box', 'register'));
  172. class Like_Box {
  173.   function control(){
  174.     echo '<fb:friendpile>';
  175.   }
  176.   function widget($args){
  177.     echo $args['before_widget'];
  178.     echo '<fb:like-box profile_id="'.get_option('fb_app_id').'" width="'.get_option('fb_widget').'" connections="10"></fb:like-box>';
  179.     echo $args['after_widget'];
  180.   }
  181.   function register(){
  182.     register_sidebar_widget('Facebook Like Box', array('Like_Box', 'widget'));
  183.     register_widget_control('Facebook Like Box', array('Like_Box', 'control'));
  184.   }
  185. }
  186.  
  187. add_action("widgets_init", array('Like_Button', 'register'));
  188. class Like_Button {
  189.   function control(){
  190.     echo '<fb:friendpile>';
  191.   }
  192.   function widget($args){
  193.     echo $args['before_widget'];
  194.     echo '<fb:like href="'.the_permalink().'" width="'.get_option('fb_widget').'"></fb:like-box>';
  195.     echo $args['after_widget'];
  196.   }
  197.   function register(){
  198.     register_sidebar_widget('Facebook Like Button', array('Like_Button', 'widget'));
  199.     register_widget_control('Facebook Like Button', array('Like_Button', 'control'));
  200.   }
  201. }
  202.  
  203. function facebook_like($content)
  204. {
  205.     $like_me = '<fb:like href="'.get_permalink().'"></fb:like-box>';
  206.     return $content.$like_me;
  207. }
  208.  add_filter('the_content', 'facebook_like');
Add Comment
Please, Sign In to add comment