-
-
-api_client->admin_getAppProperties(array('connect_url'));
- } catch (Exception $e) {
- // bad API key or secret or something
- $error=true;
- echo '
'.__('Facebook doesn\'t like your settings, it says:', 'sfc').' ' . $e->getMessage() . '.
';
- }
-
- if (is_array($a)) {
- $connecturl = $a['connect_url'];
- } else if (is_object($a)) { // seems to happen on some setups.. dunno why.
- $connecturl = $a->connect_url;
- }
-
- if (!SFC_IGNORE_ERRORS && !empty($connecturl)) {
- $siteurl = trailingslashit(get_option('siteurl'));
- if (@strpos($siteurl, $connecturl) === false) {
- $error = true;
- echo '
';
- sprintf(__('Your Facebook Application\'s "Connect URL" is configured incorrectly. It is currently set to %1$s when it should be set to "%2$s"', 'sfc'), $connecturl, $siteurl);
- echo '.
';
- }
-
- if ($error) {
-?>
-
edit your applications settings and correct the values therein. The site will not work properly until the errors are corrected.', 'sfc'), $options['appid']); ?>
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.
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'); ?>
-
-";
-}
-
-// validate our options
-function sfc_options_validate($input) {
- if (!defined('SFC_API_KEY')) {
- // api keys are 32 bytes long and made of hex values
- $input['api_key'] = trim($input['api_key']);
- if(! preg_match('/^[a-f0-9]{32}$/i', $input['api_key'])) {
- $input['api_key'] = '';
- }
- }
-
- if (!defined('SFC_APP_SECRET')) {
- // api keys are 32 bytes long and made of hex values
- $input['app_secret'] = trim($input['app_secret']);
- if(! preg_match('/^[a-f0-9]{32}$/i', $input['app_secret'])) {
- $input['app_secret'] = '';
- }
- }
-
- if (!defined('SFC_APP_ID')) {
- // app ids are big integers
- $input['appid'] = trim($input['appid']);
- if(! preg_match('/^[0-9]+$/i', $input['appid'])) {
- $input['appid'] = '';
- }
- }
-
- if (!defined('SFC_FANPAGE')) {
- // fanpage ids are big integers
- $input['fanpage'] = trim($input['fanpage']);
- if(! preg_match('/^[0-9]+$/i', $input['fanpage'])) {
- $input['fanpage'] = '';
- }
- }
-
- $input = apply_filters('sfc_validate_options',$input); // filter to let sub-plugins validate their options too
- return $input;
-}
-
-
-// this adds the app id to allow you to use Facebook Insights on your domain, linked to your application.
-add_action('wp_head','sfc_meta_head');
-function sfc_meta_head() {
- $options = get_option('sfc_options');
-
- if ($options['appid']) {
- ?>
-' />
-
-
-get_queried_object_id() ) {
- $link = get_permalink( $id );
- echo "\n";
- }
- } else if (is_home()) {
- $link = get_bloginfo('url');
- echo "\n";
- }
-}
-
-
-// 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;
-}
+
+
+'.__('Settings', 'sfc').'';
+ $links[] = ''.__('Donate', 'sfc').'';
+ }
+ return $links;
+}
+
+// action links
+add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'sfc_settings_link', 10, 1);
+function sfc_settings_link($links) {
+ $links[] = ''.__('Settings', 'sfc').'';
+ return $links;
+}
+
+// add the admin settings and such
+add_action('admin_init', 'sfc_admin_init',9); // 9 to force it first, subplugins should use default
+function sfc_admin_init(){
+ $options = get_option('sfc_options');
+ if (empty($options['api_key']) || empty($options['app_secret']) || empty($options['appid'])) {
+ add_action('admin_notices', create_function( '', "echo '
".sprintf(__('Simple Facebook Connect needs configuration information on its settings page.', 'sfc'), admin_url('options-general.php?page=sfc'))."
+
+
+api_client->admin_getAppProperties(array('connect_url'));
+ } catch (Exception $e) {
+ // bad API key or secret or something
+ $error=true;
+ echo '
'.__('Facebook doesn\'t like your settings, it says:', 'sfc').' ' . $e->getMessage() . '.
';
+ }
+
+ if (is_array($a)) {
+ $connecturl = $a['connect_url'];
+ } else if (is_object($a)) { // seems to happen on some setups.. dunno why.
+ $connecturl = $a->connect_url;
+ }
+
+ if (!SFC_IGNORE_ERRORS && !empty($connecturl)) {
+ $siteurl = trailingslashit(get_option('siteurl'));
+ if (@strpos($siteurl, $connecturl) === false) {
+ $error = true;
+ echo '
';
+ sprintf(__('Your Facebook Application\'s "Connect URL" is configured incorrectly. It is currently set to %1$s when it should be set to "%2$s"', 'sfc'), $connecturl, $siteurl);
+ echo '.
';
+ }
+
+ if ($error) {
+?>
+
edit your applications settings and correct the values therein. The site will not work properly until the errors are corrected.', 'sfc'), $options['appid']); ?>
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.
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'); ?>
+
+";
+}
+
+// validate our options
+function sfc_options_validate($input) {
+ if (!defined('SFC_API_KEY')) {
+ // api keys are 32 bytes long and made of hex values
+ $input['api_key'] = trim($input['api_key']);
+ if(! preg_match('/^[a-f0-9]{32}$/i', $input['api_key'])) {
+ $input['api_key'] = '';
+ }
+ }
+
+ if (!defined('SFC_APP_SECRET')) {
+ // api keys are 32 bytes long and made of hex values
+ $input['app_secret'] = trim($input['app_secret']);
+ if(! preg_match('/^[a-f0-9]{32}$/i', $input['app_secret'])) {
+ $input['app_secret'] = '';
+ }
+ }
+
+ if (!defined('SFC_APP_ID')) {
+ // app ids are big integers
+ $input['appid'] = trim($input['appid']);
+ if(! preg_match('/^[0-9]+$/i', $input['appid'])) {
+ $input['appid'] = '';
+ }
+ }
+
+ if (!defined('SFC_FANPAGE')) {
+ // fanpage ids are big integers
+ $input['fanpage'] = trim($input['fanpage']);
+ if(! preg_match('/^[0-9]+$/i', $input['fanpage'])) {
+ $input['fanpage'] = '';
+ }
+ }
+
+ $input = apply_filters('sfc_validate_options',$input); // filter to let sub-plugins validate their options too
+ return $input;
+}
+
+
+// this adds the app id to allow you to use Facebook Insights on your domain, linked to your application.
+add_action('wp_head','sfc_meta_head');
+function sfc_meta_head() {
+ $options = get_option('sfc_options');
+
+ if ($options['appid']) {
+ ?>
+' />
+
+
+get_queried_object_id() ) {
+ $link = get_permalink( $id );
+ echo "\n";
+ }
+ } else if (is_home()) {
+ $link = get_bloginfo('url');
+ echo "\n";
+ }
+}
+
+
+// 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;
+}
diff --git a/sfc-bookmark-widget.php b/sfc-bookmark-widget.php
index 9a0ebe1..98dfdf4 100644
--- a/sfc-bookmark-widget.php
+++ b/sfc-bookmark-widget.php
@@ -1,88 +1,88 @@
-=')) {
- return;
- }
- }
- deactivate_plugins(basename(__FILE__)); // Deactivate ourself
- wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
-}
-register_activation_hook(__FILE__, 'sfc_bookmark_widget_activation_check');
-
-function get_sfc_bookmark($args='') {
- return '';
-}
-
-function sfc_bookmark($args='') {
- echo get_sfc_bookmark();
-}
-
-function sfc_bookmark_shortcode($atts) {
- return get_sfc_bookmark();
-}
-add_shortcode('fb-bookmark', 'sfc_bookmark_shortcode');
-
-class SFC_Bookmark_Widget extends WP_Widget {
- function SFC_Bookmark_Widget() {
- $widget_ops = array('classname' => 'widget_sfc-bookmark', 'description' => __('Facebook Bookmark', 'sfc'));
- $this->WP_Widget('sfc-bookmark', __('Facebook Bookmark (SFC)', 'sfc'), $widget_ops);
- }
-
- function widget($args, $instance) {
- extract( $args );
- $title = apply_filters('widget_title', $instance['title']);
- ?>
-
-
-
-
- '') );
- $instance['title'] = strip_tags($new_instance['title']);
- return $instance;
- }
-
- function form($instance) {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
- $title = strip_tags($instance['title']);
- ?>
-
- =')) {
+ return;
+ }
+ }
+ deactivate_plugins(basename(__FILE__)); // Deactivate ourself
+ wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
+}
+register_activation_hook(__FILE__, 'sfc_bookmark_widget_activation_check');
+
+function get_sfc_bookmark($args='') {
+ return '';
+}
+
+function sfc_bookmark($args='') {
+ echo get_sfc_bookmark();
+}
+
+function sfc_bookmark_shortcode($atts) {
+ return get_sfc_bookmark();
+}
+add_shortcode('fb-bookmark', 'sfc_bookmark_shortcode');
+
+class SFC_Bookmark_Widget extends WP_Widget {
+ function SFC_Bookmark_Widget() {
+ $widget_ops = array('classname' => 'widget_sfc-bookmark', 'description' => __('Facebook Bookmark', 'sfc'));
+ $this->WP_Widget('sfc-bookmark', __('Facebook Bookmark (SFC)', 'sfc'), $widget_ops);
+ }
+
+ function widget($args, $instance) {
+ extract( $args );
+ $title = apply_filters('widget_title', $instance['title']);
+ ?>
+
+
+
+
+ '') );
+ $instance['title'] = strip_tags($new_instance['title']);
+ return $instance;
+ }
+
+ function form($instance) {
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
+ $title = strip_tags($instance['title']);
+ ?>
+
+ =')) {
- return;
- }
- }
- deactivate_plugins(basename(__FILE__)); // Deactivate ourself
- wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
-}
-register_activation_hook(__FILE__, 'sfc_chicklet_activation_check');
-
-function sfc_chicklet($id = 0) {
- $options = get_option('sfc_options');
-
- if ($id == 0) {
- if ($options['fanpage']) $id = $options['fanpage'];
- else $id = $options['appid'];
- }
-
- $sfc_chicklet_fancount = get_transient('sfc_chicklet_fancount');
-
- if (!isset($sfc_chicklet_fancount[$id])) {
- include_once 'facebook-platform/facebook.php';
- $fb=new Facebook($options['api_key'], $options['app_secret']);
- $result = $fb->api_client->fql_query("SELECT fan_count, page_url FROM page WHERE page_id={$id}");
- if ($result) {
- $sfc_chicklet_fancount[$id] = $result[0];
- set_transient('sfc_chicklet_fancount',$sfc_chicklet_fancount,SFC_FANCOUNT_CACHE);
- }
- }
-
- if ($sfc_chicklet_fancount) {
- $fancount = $sfc_chicklet_fancount[$id]['fan_count'];
- $pageurl = $sfc_chicklet_fancount[$id]['page_url'];
- }
-
- global $sfc_chicklet_no_style;
- if (!$sfc_chicklet_no_style) {
-?>
-
-
-
+
+ 'widget_sfc-chicklet', 'description' => __('Facebook Chicklet', 'sfc'));
+ $this->WP_Widget('sfc-chicklet', __('Facebook Chicklet', 'sfc'), $widget_ops);
+ }
+
+ function widget($args, $instance) {
+ extract( $args );
+ $title = apply_filters('widget_title', $instance['title']);
+ ?>
+
+
+
+
+
+
+
-
-
-3. Just below the last input (not the comment text area, just the name/email/url inputs, add this:
-
-
-That will add the necessary pieces to allow the script to work.
-
-Hopefully, a future version of WordPress will make this simpler.
-
-*/
-
-add_action('admin_init','sfc_comm_error_check');
-function sfc_comm_error_check() {
- if ( get_option( 'comment_registration' ) ) {
- add_action('admin_notices', create_function( '', "_e('
SFC-Comments doesn\'t work with sites that require registration to comment. Use SFC-Login and SFC-Register to allow users to register on your site.
','sfc');" ) );
- }
-}
-
-// if you don't want the plugin to ask for email permission, ever, then define this to true in your wp-config
-if ( !defined('SFC_DISABLE_EMAIL_PERMISSION') )
- define( 'SFC_DISABLE_EMAIL_PERMISSION', false );
-
-
-// checks for sfc on activation
-function sfc_comm_activation_check(){
- if (function_exists('sfc_version')) {
- if (version_compare(sfc_version(), '0.1', '>=')) {
- return;
- }
- }
- deactivate_plugins(basename(__FILE__)); // Deactivate ourself
- wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
-}
-register_activation_hook(__FILE__, 'sfc_comm_activation_check');
-
-// force load jQuery (we need it later anyway)
-add_action('wp_enqueue_scripts','sfc_comm_jquery');
-function sfc_comm_jquery() {
- wp_enqueue_script('jquery');
-}
-
-// set a variable to know when we are showing comments (no point in adding js to other pages)
-add_action('comment_form','sfc_comm_comments_enable');
-function sfc_comm_comments_enable() {
- global $sfc_comm_comments_form;
- $sfc_comm_comments_form = true;
-}
-
-// add placeholder for sending comment to Facebook checkbox
-add_action('comment_form','sfc_comm_send_place');
-function sfc_comm_send_place() {
-?>
-
-
-
-', ']]>', $text);
- $text = wp_strip_all_tags($text);
- $text = str_replace(array("\r\n","\r","\n"),' ',$text);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $excerpt_more = apply_filters('excerpt_more', '[...]');
- $words = explode(' ', $text, $excerpt_length + 1);
- if (count($words) > $excerpt_length) {
- array_pop($words);
- array_push($words, $excerpt_more);
- $text = implode(' ', $words);
- }
- return $text;
-}
-
-// this bit is to allow the user to add the relevant comments login button to the comments form easily
-// user need only stick a do_action('alt_comment_login'); wherever he wants the button to display
-add_action('alt_comment_login','sfc_comm_login_button');
-add_action('comment_form_before_fields', 'sfc_comm_login_button',10,0); // WP 3.0 support
-
-function sfc_comm_login_button() {
- echo '
'.__('Connect with Facebook', 'sfc').'
';
-}
-
-// this exists so that other plugins can hook into the same place to add their login buttons
-if (!function_exists('alt_login_method_div')) {
-
-add_action('alt_comment_login','alt_login_method_div',5,0);
-add_action('comment_form_before_fields', 'alt_login_method_div',5,0); // WP 3.0 support
-
-function alt_login_method_div() { echo '
'; }
-
-}
-
-// generate facebook avatar code for FB user comments
-add_filter('get_avatar','sfc_comm_avatar', 10, 5);
-function sfc_comm_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = false) {
- // check to be sure this is for a comment
- if ( !is_object($id_or_email) || !isset($id_or_email->comment_ID) || $id_or_email->user_id)
- return $avatar;
-
- // check for fbuid comment meta
- $fbuid = get_comment_meta($id_or_email->comment_ID, 'fbuid', true);
- if ($fbuid) {
- // return the avatar code
- return "";
- }
-
- // check for number@facebook.com email address (deprecated, auto-converts to new meta data)
- if (preg_match('|(\d+)\@facebook\.com|', $id_or_email->comment_author_email, $m)) {
- // save the fbuid as meta data
- update_comment_meta($id_or_email->comment_ID, 'fbuid', $m[1]);
-
- // return the avatar code
- return "";
- }
-
- return $avatar;
-}
-
-// store the FB user ID as comment meta data ('fbuid')
-add_action('comment_post','sfc_comm_add_meta', 10, 1);
-function sfc_comm_add_meta($comment_id) {
- $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();
- if ($fbuid) {
- update_comment_meta($comment_id, 'fbuid', $fbuid);
- }
-}
-
-// Add user fields for FB commenters
-add_filter('pre_comment_on_post','sfc_comm_fill_in_fields');
-function sfc_comm_fill_in_fields($comment_post_ID) {
- if (is_user_logged_in()) return; // do nothing to WP users
-
- $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();
-
- // this is a facebook user, override the sent values with FB info
- if ($fbuid) {
- $user_details = $fb->api_client->users_getInfo($fbuid, 'name, profile_url');
- if (is_array($user_details)) {
- $_POST['author'] = $user_details[0]['name'];
- $_POST['url'] = $user_details[0]['profile_url'];
- }
-
- $query = "SELECT email FROM user WHERE uid=\"{$fbuid}\"";
- $email = $fb->api_client->fql_query($query);
- if (is_array($email)) {
- $email = $email[0]['email'];
- $_POST['email'] = $email;
- }
- }
-}
+
+
+
+3. Just below the last input (not the comment text area, just the name/email/url inputs, add this:
+
+
+That will add the necessary pieces to allow the script to work.
+
+Hopefully, a future version of WordPress will make this simpler.
+
+*/
+
+add_action('admin_init','sfc_comm_error_check');
+function sfc_comm_error_check() {
+ if ( get_option( 'comment_registration' ) ) {
+ add_action('admin_notices', create_function( '', "_e('
SFC-Comments doesn\'t work with sites that require registration to comment. Use SFC-Login and SFC-Register to allow users to register on your site.
','sfc');" ) );
+ }
+}
+
+// if you don't want the plugin to ask for email permission, ever, then define this to true in your wp-config
+if ( !defined('SFC_DISABLE_EMAIL_PERMISSION') )
+ define( 'SFC_DISABLE_EMAIL_PERMISSION', false );
+
+
+// checks for sfc on activation
+function sfc_comm_activation_check(){
+ if (function_exists('sfc_version')) {
+ if (version_compare(sfc_version(), '0.1', '>=')) {
+ return;
+ }
+ }
+ deactivate_plugins(basename(__FILE__)); // Deactivate ourself
+ wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
+}
+register_activation_hook(__FILE__, 'sfc_comm_activation_check');
+
+// force load jQuery (we need it later anyway)
+add_action('wp_enqueue_scripts','sfc_comm_jquery');
+function sfc_comm_jquery() {
+ wp_enqueue_script('jquery');
+}
+
+// set a variable to know when we are showing comments (no point in adding js to other pages)
+add_action('comment_form','sfc_comm_comments_enable');
+function sfc_comm_comments_enable() {
+ global $sfc_comm_comments_form;
+ $sfc_comm_comments_form = true;
+}
+
+// add placeholder for sending comment to Facebook checkbox
+add_action('comment_form','sfc_comm_send_place');
+function sfc_comm_send_place() {
+?>
+
+
+
+', ']]>', $text);
+ $text = wp_strip_all_tags($text);
+ $text = str_replace(array("\r\n","\r","\n"),' ',$text);
+ $excerpt_length = apply_filters('excerpt_length', 55);
+ $excerpt_more = apply_filters('excerpt_more', '[...]');
+ $words = explode(' ', $text, $excerpt_length + 1);
+ if (count($words) > $excerpt_length) {
+ array_pop($words);
+ array_push($words, $excerpt_more);
+ $text = implode(' ', $words);
+ }
+ return $text;
+}
+
+// this bit is to allow the user to add the relevant comments login button to the comments form easily
+// user need only stick a do_action('alt_comment_login'); wherever he wants the button to display
+add_action('alt_comment_login','sfc_comm_login_button');
+add_action('comment_form_before_fields', 'sfc_comm_login_button',10,0); // WP 3.0 support
+
+function sfc_comm_login_button() {
+ echo '
'.__('Connect with Facebook', 'sfc').'
';
+}
+
+// this exists so that other plugins can hook into the same place to add their login buttons
+if (!function_exists('alt_login_method_div')) {
+
+add_action('alt_comment_login','alt_login_method_div',5,0);
+add_action('comment_form_before_fields', 'alt_login_method_div',5,0); // WP 3.0 support
+
+function alt_login_method_div() { echo '
-
-
-
-
-
- user_email);
-
- // load facebook platform
- include_once 'facebook-platform/facebook.php';
- $fb=new Facebook($options['api_key'], $options['app_secret']);
-
- // user ids can be bigger than 32 bits, but are all digits
- $fbuid = trim($_POST['fbuid']);
- if(!preg_match('/^[0-9]+$/i', $fbuid)) {
- $fbuid = 0;
- }
- if ($fbuid) {
- // verify that users WP email address is a match to the FB email address (for security reasons)
- $aa[0]['email_hash'] = $hash;
- $aa[0]['account_id'] = $user->ID;
-
- $ret = $fb->api_client->connect_registerUsers(json_encode($aa));
- if (empty($ret)) {
- // return value is empty, not good
- _e('Facebook did not know your email address.', 'sfc');
- exit();
- } else {
- // now we check to see if that user gives the email_hash back to us
- $user_details = $fb->api_client->users_getInfo($fbuid, array('email_hashes'));
- if (!empty($user_details[0]['email_hashes'])) {
-
- // go through the hashes returned by getInfo, make sure the one we want is in them
- $valid = false;
- foreach($user_details[0]['email_hashes'] as $check) {
- if ($check == $hash) $valid = true;
- }
-
- if (!$valid) {
- // no good
- _e('Facebook could not confirm your email address.', 'sfc');
- exit();
- }
- }
- }
- } else {
- if (!SFC_ALLOW_DISCONNECT) {
- // disconnect not allowed
- echo 1;
- exit();
- }
- // user disconnecting, so disconnect them in FB too
- $aa[0] = $hash;
- $ret = $fb->api_client->connect_unregisterUsers(json_encode($aa));
-
- // we could check here, but why bother? just assume it worked.
- }
-
- update_usermeta($user->ID, 'fbuid', $fbuid);
- echo 1;
- exit();
-}
-
-// computes facebook's email hash thingy. See http://wiki.developers.facebook.com/index.php/Connect.registerUsers
-function sfc_login_fb_hash_email($email) {
- $email = strtolower(trim($email));
- $c = crc32($email);
- $m = md5($email);
- $fbhash = sprintf('%u_%s',$c,$m);
- return $fbhash;
-}
-
-add_action('login_form','sfc_login_add_login_button');
-function sfc_login_add_login_button() {
- global $action;
- ?>
-
- ';
-}
-
-add_filter('authenticate','sfc_login_check',90);
-function sfc_login_check($user) {
- if ( is_a($user, 'WP_User') ) { return $user; } // check if user is already logged in, skip FB stuff
-
- $options = get_option('sfc_options');
-
- // load facebook platform
- include_once 'facebook-platform/facebook.php';
-
- $fb=new Facebook($options['api_key'], $options['app_secret']);
- $fbuid=$fb->get_loggedin_user();
-
- if($fbuid):
- try {
- $test = $fb->api_client->fql_query('SELECT uid, pic_square, first_name FROM user WHERE uid = ' . $fbuid);
- if ($test) {
- global $wpdb;
- $user_id = $wpdb->get_var( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'fbuid' AND meta_value = %s", $fbuid) );
-
- if ($user_id) {
- $user = new WP_User($user_id);
- } else {
- do_action('sfc_login_new_fb_user',$fb); // hook for creating new users if desired
- global $error;
- $error = ''.__('ERROR', 'sfc').': '.__('Facebook user not recognized.', 'sfc');
- }
- }
-
- } catch (Exception $ex) {
- $fb->clear_cookie_state();
- }
-
- endif;
-
- return $user;
-}
-
-add_action('wp_logout','sfc_login_logout');
-function sfc_login_logout() {
- $options = get_option('sfc_options');
-
- // load facebook platform
- include_once 'facebook-platform/facebook.php';
-
- $fb=new Facebook($options['api_key'], $options['app_secret']);
- $fbuid=$fb->get_loggedin_user();
- if ($fbuid) {
- $fb->logout(wp_login_url().'?loggedout=true');
- }
-}
-
-add_action('login_head','sfc_login_featureloader');
-function sfc_login_featureloader() {
- if ($_SERVER['HTTPS'] == 'on')
- echo "";
- else
- echo "";
-}
-
-add_action('login_form','sfc_add_base_js');
-
-/*
-// generate facebook avatar code for users who login with Facebook
-// NOTE: This overrides Gravatar if you use it.
-//
-add_filter('get_avatar','sfc_login_avatar', 10, 5);
-function sfc_login_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = false) {
- // check to be sure this is for a user id
- if ( !is_numeric($id_or_email) ) return $avatar;
- $fbuid = get_usermeta( $id_or_email, 'fbuid');
- if ($fbuid) {
- // return the avatar code
- return "";
- }
- return $avatar;
-}
-*/
+=')) {
+ return;
+ }
+ }
+ deactivate_plugins(basename(__FILE__)); // Deactivate ourself
+ wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
+}
+register_activation_hook(__FILE__, 'sfc_login_activation_check');
+
+// add the section on the user profile page
+add_action('profile_personal_options','sfc_login_profile_page');
+
+function sfc_login_profile_page($profile) {
+ $options = get_option('sfc_options');
+?>
+
+
+
+ID, 'fbuid');
+ if (empty($fbuid)) {
+ ?>
+
+
+
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+ user_email);
+
+ // load facebook platform
+ include_once 'facebook-platform/facebook.php';
+ $fb=new Facebook($options['api_key'], $options['app_secret']);
+
+ // user ids can be bigger than 32 bits, but are all digits
+ $fbuid = trim($_POST['fbuid']);
+ if(!preg_match('/^[0-9]+$/i', $fbuid)) {
+ $fbuid = 0;
+ }
+ if ($fbuid) {
+ // verify that users WP email address is a match to the FB email address (for security reasons)
+ $aa[0]['email_hash'] = $hash;
+ $aa[0]['account_id'] = $user->ID;
+
+ $ret = $fb->api_client->connect_registerUsers(json_encode($aa));
+ if (empty($ret)) {
+ // return value is empty, not good
+ _e('Facebook did not know your email address.', 'sfc');
+ exit();
+ } else {
+ // now we check to see if that user gives the email_hash back to us
+ $user_details = $fb->api_client->users_getInfo($fbuid, array('email_hashes'));
+ if (!empty($user_details[0]['email_hashes'])) {
+
+ // go through the hashes returned by getInfo, make sure the one we want is in them
+ $valid = false;
+ foreach($user_details[0]['email_hashes'] as $check) {
+ if ($check == $hash) $valid = true;
+ }
+
+ if (!$valid) {
+ // no good
+ _e('Facebook could not confirm your email address.', 'sfc');
+ exit();
+ }
+ }
+ }
+ } else {
+ if (!SFC_ALLOW_DISCONNECT) {
+ // disconnect not allowed
+ echo 1;
+ exit();
+ }
+ // user disconnecting, so disconnect them in FB too
+ $aa[0] = $hash;
+ $ret = $fb->api_client->connect_unregisterUsers(json_encode($aa));
+
+ // we could check here, but why bother? just assume it worked.
+ }
+
+ update_usermeta($user->ID, 'fbuid', $fbuid);
+ echo 1;
+ exit();
+}
+
+// computes facebook's email hash thingy. See http://wiki.developers.facebook.com/index.php/Connect.registerUsers
+function sfc_login_fb_hash_email($email) {
+ $email = strtolower(trim($email));
+ $c = crc32($email);
+ $m = md5($email);
+ $fbhash = sprintf('%u_%s',$c,$m);
+ return $fbhash;
+}
+
+add_action('login_form','sfc_login_add_login_button');
+function sfc_login_add_login_button() {
+ global $action;
+ ?>
+
+ ';
+}
+
+add_filter('authenticate','sfc_login_check',90);
+function sfc_login_check($user) {
+ if ( is_a($user, 'WP_User') ) { return $user; } // check if user is already logged in, skip FB stuff
+
+ $options = get_option('sfc_options');
+
+ // load facebook platform
+ include_once 'facebook-platform/facebook.php';
+
+ $fb=new Facebook($options['api_key'], $options['app_secret']);
+ $fbuid=$fb->get_loggedin_user();
+
+ if($fbuid):
+ try {
+ $test = $fb->api_client->fql_query('SELECT uid, pic_square, first_name FROM user WHERE uid = ' . $fbuid);
+ if ($test) {
+ global $wpdb;
+ $user_id = $wpdb->get_var( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'fbuid' AND meta_value = %s", $fbuid) );
+
+ if ($user_id) {
+ $user = new WP_User($user_id);
+ } else {
+ do_action('sfc_login_new_fb_user',$fb); // hook for creating new users if desired
+ global $error;
+ $error = ''.__('ERROR', 'sfc').': '.__('Facebook user not recognized.', 'sfc');
+ }
+ }
+
+ } catch (Exception $ex) {
+ $fb->clear_cookie_state();
+ }
+
+ endif;
+
+ return $user;
+}
+
+add_action('wp_logout','sfc_login_logout');
+function sfc_login_logout() {
+ $options = get_option('sfc_options');
+
+ // load facebook platform
+ include_once 'facebook-platform/facebook.php';
+
+ $fb=new Facebook($options['api_key'], $options['app_secret']);
+ $fbuid=$fb->get_loggedin_user();
+ if ($fbuid) {
+ $fb->logout(wp_login_url().'?loggedout=true');
+ }
+}
+
+add_action('login_head','sfc_login_featureloader');
+function sfc_login_featureloader() {
+ if ($_SERVER['HTTPS'] == 'on')
+ echo "";
+ else
+ echo "";
+}
+
+add_action('login_form','sfc_add_base_js');
+
+/*
+// generate facebook avatar code for users who login with Facebook
+// NOTE: This overrides Gravatar if you use it.
+//
+add_filter('get_avatar','sfc_login_avatar', 10, 5);
+function sfc_login_avatar($avatar, $id_or_email, $size = '96', $default = '', $alt = false) {
+ // check to be sure this is for a user id
+ if ( !is_numeric($id_or_email) ) return $avatar;
+ $fbuid = get_usermeta( $id_or_email, 'fbuid');
+ if ($fbuid) {
+ // return the avatar code
+ return "";
+ }
+ return $avatar;
+}
+*/
diff --git a/sfc-publish.php b/sfc-publish.php
index 4cec6ed..7b3a5ea 100644
--- a/sfc-publish.php
+++ b/sfc-publish.php
@@ -1,437 +1,437 @@
-=')) {
- return;
- }
- }
- deactivate_plugins(basename(__FILE__)); // Deactivate ourself
- wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
-}
-register_activation_hook(__FILE__, 'sfc_publish_activation_check');
-
-// add the meta boxes
-add_action('admin_menu', 'sfc_publish_meta_box_add');
-function sfc_publish_meta_box_add() {
- add_meta_box('sfc-publish-div', __('Facebook Publisher', 'sfc'), 'sfc_publish_meta_box', 'post', 'side');
- add_meta_box('sfc-publish-div', __('Facebook Publisher', 'sfc'), 'sfc_publish_meta_box', 'page', 'side');
-}
-
-// add the admin sections to the sfc page
-add_action('admin_init', 'sfc_publish_admin_init');
-function sfc_publish_admin_init() {
- add_settings_section('sfc_publish', __('Publish Settings', 'sfc'), 'sfc_publish_section_callback', 'sfc');
- add_settings_field('sfc_publish_flags', __('Automatic Publishing', 'sfc'), 'sfc_publish_auto_callback', 'sfc', 'sfc_publish');
- add_settings_field('sfc_publish_extended_permissions', __('Extended Permissions', 'sfc'), 'sfc_publish_extended_callback', 'sfc', 'sfc_publish');
- wp_enqueue_script('jquery');
-}
-
-function sfc_publish_section_callback() {
- echo "
".__('Settings for the SFC-Publish plugin. The manual Facebook Publishing buttons can be found on the Edit Post or Edit Page screen, after you publish a post. If you can\'t find them, try scrolling down or seeing if you have the box disabled in the Options dropdown.', 'sfc')."
'.__('After publishing the post, you can send it to Facebook from here.', 'sfc').'
';
- return;
- }
-
- // apply the content filters, in case some plugin is doing weird image stuff
- $content = apply_filters('the_content', $post->post_content);
-
- // look for the images to add with image_src
- $images = array();
-
- // get the post thumbnail, put it first in the image list
- if (current_theme_supports('post-thumbnails')) {
- if ( 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];
- }
- }
-
- // look for any images in the content
- if ( preg_match_all('//', $content, $matches) ) {
- foreach ($matches[1] as $match) {
- foreach ( wp_kses_hair($match, array('http')) as $attr)
- $img[$attr['name']] = $attr['value'];
- if ( isset($img['src']) ) {
- if (!isset($img['class']) ||
- (isset($img['class']) && false === straipos($img['class'], apply_filters('sfc_img_exclude',array('wp-smiley'))))
- ) { // ignore smilies
- $images[] = $img['src'];
- }
- }
- }
- }
-
- // build the attachment
- $permalink = apply_filters('sfc_publish_permalink',get_permalink($post->ID),$post->ID);
- $attachment['name'] = $post->post_title;
- $attachment['href'] = $permalink;
- $attachment['description'] = sfc_publish_make_excerpt($post->post_content);
- $attachment['comments_xid'] = urlencode($permalink);
-
- // image attachments (up to 5, as that's all FB allows)
- $count=0;
- foreach ($images as $image) {
- $attachment['media'][$count]['type'] = 'image';
- $attachment['media'][$count]['src'] = $image;
- $attachment['media'][$count]['href'] = $permalink;
- $count++; if ($count==5) break;
- }
-
- // Share link
- $action_links[0]['text'] = 'Share';
- $action_links[0]['href'] = 'http://www.facebook.com/share.php?u='.urlencode($permalink);
- ?>
-
-
- ID, $post);
- }
-}
-
-function sfc_publish_automatic($id, $post) {
-
- // check to make sure post is published
- if ($post->post_status !== 'publish') return;
-
- // check options to see if we need to send to FB at all
- $options = get_option('sfc_options');
- if (!$options['autopublish_app'] && !$options['autopublish_profile'])
- return;
-
- // load facebook platform
- include_once 'facebook-platform/facebook.php';
- $fb=new Facebook($options['api_key'], $options['app_secret']);
-
- // to do this autopublish, we might need to switch users
- if ($options['user'] && $options['session_key']) {
- $tempuser = $fb->user;
- $tempkey = $fb->api_client->session_key = $session_key;
- $fb->set_user($options['user'], $options['session_key']);
- } else {
- return; // safety net: if we don't have a user and session key, we can't publish properly.
- }
-
- // build the post to send to FB
-
- // apply the content filters, in case some plugin is doing weird image stuff
- $content = apply_filters('the_content', $post->post_content);
-
- // look for the images to add with image_src
- $images = array();
-
- // get the post thumbnail, put it first in the image list
- if (current_theme_supports('post-thumbnails')) {
- if ( 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];
- }
- }
-
- // look for any images in the content
- if ( preg_match_all('//', $content, $matches) ) {
- foreach ($matches[1] as $match) {
- foreach ( wp_kses_hair($match, array('http')) as $attr)
- $img[$attr['name']] = $attr['value'];
- if ( isset($img['src']) ) {
- if ( isset( $img['class'] ) && false === straipos( $img['class'], apply_filters('sfc_img_exclude',array('wp-smiley')) ) ) { // ignore smilies
- $images[] = $img['src'];
- }
- }
- }
- }
-
- // build the attachment
- $permalink = apply_filters('sfc_publish_permalink',get_permalink($post->ID), $post->ID);
- $attachment['name'] = $post->post_title;
- $attachment['href'] = $permalink;
- $attachment['description'] = sfc_publish_make_excerpt($post->post_content);
- $attachment['comments_xid'] = urlencode($permalink);
-
- // image attachments (up to 5, as that's all FB allows)
- $count=0;
- foreach ($images as $image) {
- $attachment['media'][$count]['type'] = 'image';
- $attachment['media'][$count]['src'] = $image;
- $attachment['media'][$count]['href'] = $permalink;
- $count++; if ($count==5) break;
- }
-
- // Share link
- $action_links[0]['text'] = 'Share';
- $action_links[0]['href'] = 'http://www.facebook.com/share.php?u='.urlencode($permalink);
-
- // publish to page
- if ($options['autopublish_app'] && !get_post_meta($id,'_fb_post_id_app',true)
- && $options['fanpage'] // TODO eliminate this when Facebook fixes the bug
- ) {
-
- if ($options['fanpage']) $who = $options['fanpage'];
- else $who = $options['appid'];
-
- // check to see if we can send to FB at all
- $result = $fb->api_client->users_hasAppPermission('publish_stream', $who);
- if (!$result) break;
-
- $fb_post_id = $fb->api_client->stream_publish(null, json_encode($attachment), json_encode($action_links), null, $who);
-
- if ($fb_post_id) {
- // update the post id so as to prevent automatically posting it twice
- update_post_meta($id,'_fb_post_id_app',$fb_post_id);
- }
- }
-
- // publish to profile
- if ($options['autopublish_profile'] && !get_post_meta($id,'_fb_post_id_profile',true)) {
-
- // check to see if we can send to FB at all
- $result = $fb->api_client->users_hasAppPermission('publish_stream');
- if (!$result) break;
-
- $fb_post_prof_id = $fb->api_client->stream_publish(null, json_encode($attachment), json_encode($action_links));
-
- if ($fb_post_prof_id) {
- // update the post id so as to prevent automatically posting it twice
- update_post_meta($id,'_fb_post_id_profile',$fb_post_prof_id);
- }
- }
-
- // switch users back, just in case
- if ($tempuser) {
- $fb->set_user($tempuser, $tempkey);
- }
-}
-
-add_filter('sfc_validate_options','sfc_publish_validate_options');
-function sfc_publish_validate_options($input) {
- $options = get_option('sfc_options');
-
- if ($input['autopublish_app'] != 1) $input['autopublish_app'] = 0;
- if ($input['autopublish_profile'] != 1) $input['autopublish_profile'] = 0;
-
- // find the infinite session key and save it if it's there
- if ($_COOKIE[$options['api_key'].'_expires'] == 0) {
- // save the user and session key
- $input['user'] = $_COOKIE[$options['api_key'].'_user'];
- $input['session_key'] = $_COOKIE[$options['api_key'].'_session_key'];
- }
-
- return $input;
-}
-
-// finds a item from an array in a string
-if (!function_exists('straipos')) :
-function straipos($haystack,$array,$offset=0)
-{
- $occ = array();
- for ($i = 0;$i=')) {
+ return;
+ }
+ }
+ deactivate_plugins(basename(__FILE__)); // Deactivate ourself
+ wp_die(__('The base SFC plugin must be activated before this plugin will run.', 'sfc'));
+}
+register_activation_hook(__FILE__, 'sfc_publish_activation_check');
+
+// add the meta boxes
+add_action('admin_menu', 'sfc_publish_meta_box_add');
+function sfc_publish_meta_box_add() {
+ add_meta_box('sfc-publish-div', __('Facebook Publisher', 'sfc'), 'sfc_publish_meta_box', 'post', 'side');
+ add_meta_box('sfc-publish-div', __('Facebook Publisher', 'sfc'), 'sfc_publish_meta_box', 'page', 'side');
+}
+
+// add the admin sections to the sfc page
+add_action('admin_init', 'sfc_publish_admin_init');
+function sfc_publish_admin_init() {
+ add_settings_section('sfc_publish', __('Publish Settings', 'sfc'), 'sfc_publish_section_callback', 'sfc');
+ add_settings_field('sfc_publish_flags', __('Automatic Publishing', 'sfc'), 'sfc_publish_auto_callback', 'sfc', 'sfc_publish');
+ add_settings_field('sfc_publish_extended_permissions', __('Extended Permissions', 'sfc'), 'sfc_publish_extended_callback', 'sfc', 'sfc_publish');
+ wp_enqueue_script('jquery');
+}
+
+function sfc_publish_section_callback() {
+ echo "
".__('Settings for the SFC-Publish plugin. The manual Facebook Publishing buttons can be found on the Edit Post or Edit Page screen, after you publish a post. If you can\'t find them, try scrolling down or seeing if you have the box disabled in the Options dropdown.', 'sfc')."