'sfc-login.php', 'plugin_like'=>'sfc-like.php', 'plugin_publish'=>'sfc-publish.php', 'plugin_widgets'=>'sfc-widgets.php', 'plugin_comments'=>'sfc-comments.php', 'plugin_getcomm'=>'sfc-getcomm.php', 'plugin_register'=>'sfc-register.php', 'plugin_share'=>'sfc-share.php', 'plugin_photos'=>'sfc-photos.php', ); // load all the subplugins add_action('plugins_loaded','sfc_plugin_loader'); function sfc_plugin_loader() { global $sfc_plugin_list; $options = get_option('sfc_options'); if (!empty($options)) foreach ($options as $key=>$value) { if ($value === 'enable' && array_key_exists($key, $sfc_plugin_list)) { include_once($sfc_plugin_list[$key]); } } } // fix up the html tag to have the FBML extensions add_filter('language_attributes','sfc_lang_atts'); function sfc_lang_atts($lang) { return ' xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" '.$lang; } // basic XFBML load into footer add_action('wp_footer','sfc_add_base_js',20); // 20, to put it at the end of the footer insertions. sub-plugins should use 30 for their code function sfc_add_base_js() { $options = get_option('sfc_options'); sfc_load_api($options['appid']); }; function sfc_load_api($appid) { // validate that they're using a valid locale string $sfc_valid_fb_locales = array( 'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_DE', 'eu_ES', 'en_PI', 'en_UD', 'ck_US', 'en_US', 'es_LA', 'es_CL', 'es_CO', 'es_ES', 'es_MX', 'es_VE', 'fb_FI', 'fi_FI', 'fr_FR', 'gl_ES', 'hu_HU', 'it_IT', 'ja_JP', 'ko_KR', 'nb_NO', 'nn_NO', 'nl_NL', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sv_SE', 'th_TH', 'tr_TR', 'ku_TR', 'zh_CN', 'zh_HK', 'zh_TW', 'fb_LT', 'af_ZA', 'sq_AL', 'hy_AM', 'az_AZ', 'be_BY', 'bn_IN', 'bs_BA', 'bg_BG', 'hr_HR', 'nl_BE', 'en_GB', 'eo_EO', 'et_EE', 'fo_FO', 'fr_CA', 'ka_GE', 'el_GR', 'gu_IN', 'hi_IN', 'is_IS', 'id_ID', 'ga_IE', 'jv_ID', 'kn_IN', 'kk_KZ', 'la_VA', 'lv_LV', 'li_NL', 'lt_LT', 'mk_MK', 'mg_MG', 'ms_MY', 'mt_MT', 'mr_IN', 'mn_MN', 'ne_NP', 'pa_IN', 'rm_CH', 'sa_IN', 'sr_RS', 'so_SO', 'sw_KE', 'tl_PH', 'ta_IN', 'tt_RU', 'te_IN', 'ml_IN', 'uk_UA', 'uz_UZ', 'vi_VN', 'xh_ZA', 'zu_ZA', 'km_KH', 'tg_TJ', 'ar_AR', 'he_IL', 'ur_PK', 'fa_IR', 'sy_SY', 'yi_DE', 'gn_PY', 'qu_PE', 'ay_BO', 'se_NO', 'ps_AF', 'tl_ST' ); $locale = get_locale(); if ( !in_array($locale, $sfc_valid_fb_locales) ) { $locale = 'en_US'; // default if they're using one FB doesn't like } ?>
".sprintf(__('Simple Facebook Connect needs configuration information on its settings page.', 'sfc'), admin_url('options-general.php?page=sfc'))."
';" ) ); } else { add_action('admin_print_footer_scripts','sfc_add_base_js',20); } wp_enqueue_script('jquery'); register_setting( 'sfc_options', 'sfc_options', 'sfc_options_validate' ); add_settings_section('sfc_main', __('Main Settings', 'sfc'), 'sfc_section_text', 'sfc'); if (!defined('SFC_APP_SECRET')) add_settings_field('sfc_app_secret', __('Facebook Application Secret', 'sfc'), 'sfc_setting_app_secret', 'sfc', 'sfc_main'); if (!defined('SFC_APP_ID')) add_settings_field('sfc_appid', __('Facebook Application ID', 'sfc'), 'sfc_setting_appid', 'sfc', 'sfc_main'); if (!defined('SFC_FANPAGE')) add_settings_field('sfc_fanpage', __('Facebook Fan Page', 'sfc'), 'sfc_setting_fanpage', 'sfc', 'sfc_main'); add_settings_section('sfc_plugins', __('SFC Plugins', 'sfc'), 'sfc_plugins_text', 'sfc'); add_settings_field('sfc_subplugins', __('Plugins', 'sfc'), 'sfc_subplugins', 'sfc', 'sfc_plugins'); add_settings_section('sfc_meta', __('Facebook Metadata', 'sfc'), 'sfc_meta_text', 'sfc'); add_settings_field('sfc_default_image', __('Default Image', 'sfc'), 'sfc_default_image', 'sfc', 'sfc_meta'); add_settings_field('sfc_default_description', __('Default Description', 'sfc'), 'sfc_default_description', 'sfc', 'sfc_meta'); } // add the admin options page add_action('admin_menu', 'sfc_admin_add_page'); function sfc_admin_add_page() { global $sfc_options_page; $sfc_options_page = add_options_page(__('Simple Facebook Connect', 'sfc'), __('Simple Facebook Connect', 'sfc'), 'manage_options', 'sfc', 'sfc_options_page'); } function sfc_plugin_help($contextual_help, $screen_id, $screen) { global $sfc_options_page; if ($screen_id == $sfc_options_page) { $home = home_url('/'); $contextual_help = __("To connect your site to Facebook, you will need a Facebook Application. If you have already created one, please insert your Application Secret and Application ID below.
Can't find your key?
Haven't created an application yet? Don't worry, it's easy!
Each separate plugin can be enabled or disabled using the checkboxes below. Only enable the plugins you want to use, and the rest will not run at all! Here's a quick description of each plugin:
Here is a link to your applications wall. There you can give it a name, upload a profile picture, things like that. Look for the "Edit Application" link to modify the application.
', 'sfc'), $options['appid']); } function sfc_setting_fanpage() { if (defined('SFC_FANPAGE')) return; $options = get_option('sfc_options'); ?>replace the application, as that is not optional. However, you can use a Fan Page for specific parts of the SFC plugin, such as the Fan Box, the Publisher, and the Chicklet.', 'sfc'); ?>
Fan Page that you want to use for your site, enter the ID of the page here. Most users should leave this blank.', 'sfc'); ?>
"; } function sfc_plugins_text() { ?> $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $options['app_secret']) != $args['sig']) { return null; } return $args; } // this is not a hack or a dangerous function.. the base64 decode is required because Facebook is sending back base64 encoded data in the signed_request bits. // See http://developers.facebook.com/docs/authentication/signed_request/ for more info function sfc_base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); } /* // this function checks if the current FB user is a fan of your page. // Returns true if they are, false otherwise. function sfc_is_fan($pageid='0') { $options = get_option('sfc_options'); if ($pageid == '0') { if ($options['fanpage']) $pageid = $options['fanpage']; else $pageid = $options['appid']; } include_once 'facebook-platform/facebook.php'; $fb=new Facebook($options['api_key'], $options['app_secret']); $fbuid=$fb->get_loggedin_user(); if (!$fbuid) return false; if ($fb->api_client->pages_isFan($pageid) ) { return true; } else { return false; } } // get the current facebook user number (0 if the user is not connected to this site) function sfc_get_user() { $options = get_option('sfc_options'); include_once 'facebook-platform/facebook.php'; $fb=new Facebook($options['api_key'], $options['app_secret']); $fbuid=$fb->get_loggedin_user(); return $fbuid; } */ function sfc_remote($obj, $connection='', $args=array(), $type = 'GET') { $type = strtoupper($type); if (empty($obj)) return null; if (empty($args['access_token'])) { $cookie = sfc_cookie_parse(); if (!empty($cookie['access_token'])) { $args['access_token'] = $cookie['access_token']; } } $url = 'https://graph.facebook.com/'. $obj; if (!empty($connection)) $url .= '/'.$connection; if ($type == 'GET') $url .= '?access_token='.$args['access_token']; if ($type == 'POST') { $data = wp_remote_post($url, $args); } else if ($type == 'GET') { $data = wp_remote_get($url, $args); } if ($data && !is_wp_error($data)) { $resp = json_decode($data['body'],true); return $resp; } return false; } // code to create a pretty excerpt given a post object function sfc_base_make_excerpt($post) { if (!empty($post->post_excerpt)) $text = $post->post_excerpt; else $text = $post->post_content; $text = strip_shortcodes( $text ); remove_filter( 'the_content', 'wptexturize' ); $text = apply_filters('the_content', $text); add_filter( 'the_content', 'wptexturize' ); $text = str_replace(']]>', ']]>', $text); $text = wp_strip_all_tags($text); $text = str_replace(array("\r\n","\r","\n"),' ',$text); $excerpt_more = apply_filters('excerpt_more', '[...]'); $excerpt_more = html_entity_decode($excerpt_more, ENT_QUOTES, 'UTF-8'); $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); $max = min(1000,apply_filters('sfc_excerpt_length',1000)); $max -= strlen ($excerpt_more) + 1; $max -= strlen ('') * 2 - 1; if ($max<1) return ''; // nothing to send if (strlen($text) >= $max) { $text = substr($text, 0, $max); $words = explode(' ', $text); array_pop ($words); array_push ($words, $excerpt_more); $text = implode(' ', $words); } return $text; } // code to find any and all images in a post's actual content, given a post object (returns array of urls) // this should give the best representative sample of images from the post to push to FB function sfc_base_find_images($post) { $images = array(); // first we apply the filters to the content, just in case they're using shortcodes or oembed to display images $content = apply_filters('the_content', $post->post_content); // next, we get the post thumbnail, put it first in the image list if ( current_theme_supports('post-thumbnails') && has_post_thumbnail($post->ID) ) { $thumbid = get_post_thumbnail_id($post->ID); $att = wp_get_attachment_image_src($thumbid, 'full'); if (!empty($att[0])) { $images[] = $att[0]; } } // now search for images in the content itself if ( preg_match_all('/