Advertisement
switzerbaden

Facebook Comments > class-frontend.php

Nov 29th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.93 KB | None | 0 0
  1. <?php
  2.  
  3. //ADD XFBML
  4. add_filter('language_attributes', 'fbcomments_schema');
  5. function fbcomments_schema($attr) {
  6.     $options = get_option('fbcomments');
  7. if (!isset($options['fbns'])) {$options['fbns'] = "";}
  8. if (!isset($options['opengraph'])) {$options['opengraph'] = "";}
  9.     if ($options['opengraph'] == 'on') {$attr .= "\n xmlns:og=\"http://ogp.me/ns#\"";}
  10.     if ($options['fbns'] == 'on') {$attr .= "\n xmlns:fb=\"http://ogp.me/ns/fb#\"";}
  11.     return $attr;
  12. }
  13.  
  14. //ADD OPEN GRAPH META
  15. function fbgraphinfo() {
  16.     $options = get_option('fbcomments'); ?>
  17. <meta property="fb:app_id" content="<?php echo $options['appID']; ?>"/>
  18. <meta property="fb:admins" content="<?php echo $options['mods']; ?>"/>
  19. <?php
  20. }
  21. add_action('wp_head', 'fbgraphinfo');
  22.  
  23.  
  24. function fbmlsetup() {
  25. $options = get_option('fbcomments');
  26. if (!isset($options['fbml'])) {$options['fbml'] = "";}
  27. if ($options['fbml'] == 'on') {
  28. ?>
  29. <!-- Facebook Comments for WordPress: http://3doordigital.com/wordpress/plugins/facebook-comments/ -->
  30. <div id="fb-root"></div>
  31. <script>(function(d, s, id) {
  32.   var js, fjs = d.getElementsByTagName(s)[0];
  33.   if (d.getElementById(id)) return;
  34.   js = d.createElement(s); js.id = id;
  35.   js.src = "//connect.facebook.net/<?php echo $options['language']; ?>/all.js#xfbml=1&appId=<?php echo $options['appID']; ?>";
  36.   fjs.parentNode.insertBefore(js, fjs);
  37. }(document, 'script', 'facebook-jssdk'));</script>
  38. <?php }}
  39. add_action('wp_footer', 'fbmlsetup', 100);
  40.  
  41.  
  42.  
  43. //COMMENT BOX
  44. function fbcommentbox($content) {
  45.     $options = get_option('fbcomments');
  46. if (!isset($options['html5'])) {$options['html5'] = "";}
  47. if (!isset($options['linklove'])) {$options['linklove'] = "";}
  48. if (!isset($options['posts'])) {$options['posts'] = "";}
  49. if (!isset($options['pages'])) {$options['pages'] = "";}
  50. if (!isset($options['homepage'])) {$options['homepage'] = "";}
  51. if (!isset($options['count'])) {$options['count'] = "";}
  52.     if (
  53.        (is_single() && $options['posts'] == 'on') ||
  54.        (is_page() && $options['pages'] == 'on') ||
  55.        ((is_home() || is_front_page()) && $options['homepage'] == 'on')) {
  56.  
  57.         if ($options['count'] == 'on') {
  58.             if ($options['countstyle'] == '') {
  59.                 $commentcount = "<p>";
  60.             } else {
  61.                 $commentcount = "<p class=\"".$options['countstyle']."\">";
  62.             }
  63.             $commentcount .= "<fb:comments-count href=".get_permalink()."></fb:comments-count> ".$options['countmsg']."</p>";
  64.         }
  65.         if ($options['title'] != '') {
  66.             if ($options['titleclass'] == '') {
  67.                 $commenttitle = "<h3>";
  68.             } else {
  69.                 $commenttitle = "<h3 class=\"".$options['titleclass']."\">";
  70.             }
  71.             $commenttitle .= $options['title']."</h3>";
  72.         }
  73.         //$content .= "<!-- Facebook Comments for WordPress: http://pleer.co.uk/wordpress/plugins/facebook-comments/ -->".$commenttitle.$commentcount;
  74.         $content .= $commenttitle.$commentcount;
  75.  
  76.         if ($options['html5'] == 'on') {
  77.             $content .= "<div class=\"fb-comments\" data-href=\"".get_permalink()."\" data-num-posts=\"".$options['num']."\" data-width=\"".$options['width']."\" data-colorscheme=\"".$options['scheme']."\"></div>";
  78.  
  79.     } else {
  80.     $content .= "<fb:comments href=\"".get_permalink()."\" num_posts=\"".$options['num']."\" width=\"".$options['width']."\" colorscheme=\"".$options['scheme']."\"></fb:comments>";
  81.      }
  82.   }
  83. return $content;
  84. }
  85. add_filter ('the_content', 'fbcommentbox', 100);
  86.  
  87.  
  88. function fbcommentshortcode($fbatts) {
  89.     extract(shortcode_atts(array(
  90.         "fbcomments" => get_option('fbcomments'),
  91.         "url" => get_permalink(),
  92.     ), $fbatts));
  93.     if (!empty($fbatts)) {
  94.         foreach ($fbatts as $key => $option)
  95.             $fbcomments[$key] = $option;
  96.     }
  97.         if ($fbcomments[count] == 'on') {
  98.             if ($fbcomments[countstyle] == '') {
  99.                 $commentcount = "<p>";
  100.             } else {
  101.                 $commentcount = "<p class=\"".$fbcomments[countstyle]."\">";
  102.             }
  103.             $commentcount .= "<fb:comments-count href=".$url."></fb:comments-count> ".$fbcomments[countmsg]."</p>";
  104.         }
  105.         if ($fbcomments[title] != '') {
  106.             if ($fbcomments[titleclass] == '') {
  107.                 $commenttitle = "<h3>";
  108.             } else {
  109.                 $commenttitle = "<h3 class=\"".$fbcomments[titleclass]."\">";
  110.             }
  111.             $commenttitle .= $fbcomments[title]."</h3>";
  112.         }
  113.         $fbcommentbox = $commenttitle.$commentcount;
  114.  
  115.         if ($fbcomments[html5] == 'on') {
  116.             $fbcommentbox .=    "<div class=\"fb-comments\" data-href=\"".$url."\" data-num-posts=\"".$fbcomments[num]."\" data-width=\"".$fbcomments[width]."\" data-colorscheme=\"".$fbcomments[scheme]."\"></div>";
  117.  
  118.     } else {
  119.     $fbcommentbox .= "<fb:comments href=\"".$url."\" num_posts=\"".$fbcomments[num]."\" width=\"".$fbcomments[width]."\" colorscheme=\"".$fbcomments[scheme]."\"></fb:comments>";
  120.      }
  121.  
  122.     if (!empty($fbcomments[linklove])) {
  123.       $fbcommentbox .= '<p>Powered by <a href="http://3doordigital.com/wordpress/plugins/facebook-comments/">Facebook Comments</a></p>';
  124.     }
  125.   return $fbcommentbox;
  126. }
  127. add_filter('widget_text', 'do_shortcode');
  128. add_shortcode('fbcomments', 'fbcommentshortcode');
  129.  
  130.  
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement