function sfc_comm_add_meta($comment_id)
{
    $cookie = sfc_cookie_parse();
    if (empty($cookie)) {
        return;
    }
    $uid = $cookie['uid'];
    $token = $cookie['access_token'];
    if (!empty($uid)) {
        update_comment_meta($comment_id, 'fbuid', $cookie['uid']);
    }
    // did the user select to share the post on FB?
    if (!empty($_POST['sfc_comm_share']) && !empty($uid) && !empty($token)) {
        $comment = get_comment($comment_id);
        $postid = $comment->comment_post_ID;
        $permalink = get_comment_link($comment_id);
        $attachment['name'] = get_the_title($postid);
        $attachment['link'] = $permalink;
        $attachment['description'] = sfc_comm_make_excerpt($post->post_content);
        $attachment['caption'] = '{*actor*} left a comment on ' . get_the_title($postid);
        $attachment['message'] = get_comment_text($comment_id);
        $attachment['comments_xid'] = urlencode($permalink);
        //$action_links[0]['text'] = 'Read Post';
        //$action_links[0]['href'] = get_permalink();
        $url = "https://graph.facebook.com/{$uid}/feed";
        $attachment['access_token'] = $token;
        $data = wp_remote_post($url, array('body' => http_build_query($attachment)));
        if (!is_wp_error($data)) {
            $resp = json_decode($data['body'], true);
            if ($resp['id']) {
                update_comment_meta($comment_id, '_fb_post_id', $resp['id']);
            }
        }
    }
}
function sfc_comm_footer_script()
{
    global $sfc_comm_comments_form;
    if ($sfc_comm_comments_form != true) {
        return;
    }
    // nothing to do, not showing comments
    if (is_user_logged_in()) {
        return;
    }
    // don't bother with this stuff for logged in users
    $options = get_option('sfc_options');
    ?>
<style type="text/css">
#fb-user { border: 1px dotted #C0C0C0; padding: 5px; display: block; height: 96px; }
#fb-user .fb_profile_pic_rendered { margin-right: 5px; }
#fb-user a.FB_Link img { float: left; }
</style>

<script type="text/javascript">
var fb_connect_user = false;

function sfc_update_user_details() {
	fb_connect_user = true;

	// Show their FB details TODO this should be configurable, or at least prettier...
	if (!jQuery('#fb-user').length) {
		jQuery('#comment-user-details').hide().after("<span id='fb-user'>" +
		"<fb:profile-pic uid='loggedinuser' facebook-logo='true' size='normal' height='96'></fb:profile-pic>" +
		"<span id='fb-msg'><strong><fb:intl><?php 
    echo addslashes(__('Hi', 'sfc'));
    ?>
</fb:intl> <fb:name uid='loggedinuser' useyou='false'></fb:name>!</strong><br /><fb:intl><?php 
    echo addslashes(__('You are connected with your Facebook account.', 'sfc'));
    ?>
</fb:intl>" +
		"<a href='#' onclick='FB.Connect.logoutAndRedirect(\"<?php 
    the_permalink();
    ?>
\"); return false;'> <?php 
    echo addslashes(__('Logout', 'sfc'));
    ?>
</a>" +
		"</span></span>");
		jQuery('#sfc_comm_send').html('<input style="width: auto;" type="checkbox" id="sfc_comm_share" /><label for="sfc_comm_send"><fb:intl><?php 
    echo addslashes(__('Share Comment on Facebook', 'sfc'));
    ?>
</fb:intl></label>');
	}

	// Refresh the DOM
	FB.XFBML.Host.parseDomTree();
}

jQuery("#commentform").bind('submit',sfc_handle_submit_share);
function sfc_handle_submit_share() {
	if (jQuery('#sfc_comm_share:checked').val() == 'on') {
		sfc_setCookie('sfc_share', 'yes');
	}
	return true;
}

<?php 
    if (get_option('require_name_email') && !SFC_DISABLE_EMAIL_PERMISSION) {
        ?>
// first, check if we already have email permission
var sfc_comm_email_perm = false;
FB.ensureInit ( function () { 
	FB.Facebook.apiClient.users_hasAppPermission('email',function(res,ex){
		if (res == 0) {
			// no permission, ask for it on submit
			jQuery("#commentform").bind('submit',sfc_get_email_perms);
		} else {
			// we have permission, no special handler needed
			sfc_comm_email_perm = true;
		}
	});
});

// ask for email permission
function sfc_get_email_perms() {
	if (sfc_comm_email_perm) return true;
	if (fb_connect_user) {
		FB.Facebook.apiClient.users_hasAppPermission('email',function(res,ex){
			if (res == 0) {
				FB.Connect.showPermissionDialog("email", function(perms) {
					if (perms.match("email")) {
						sfc_commentform_submit();
					} else {
						var dialog = FB.UI.FBMLPopupDialog('<?php 
        echo addslashes(__('Email required', 'sfc'));
        ?>
', '');
						var fbml='\
<div id="fb_dialog_content" class="fb_dialog_content">\
	<div class="fb_confirmation_stripes"></div>\
	<div class="fb_confirmation_content"><p><?php 
        echo addslashes(__('This site requires permission to get your email address for you to leave a comment. You can not leave a comment without granting that permission.', 'sfc'));
        ?>
</p></div>\
</div>';
						dialog.setFBMLContent(fbml);
						dialog.setContentWidth(540); 
						dialog.setContentHeight(65);
						dialog.set_placement(FB.UI.PopupPlacement.topCenter);
						dialog.show();
						setTimeout ( function() { dialog.close(); }, 5000 );					
					}
				});
			} else {
				sfc_commentform_submit();
			}
		});
		return false;
	} else {
		return true;
	}	
}

// submit the form
function sfc_commentform_submit() {
	jQuery("#commentform").unbind('submit',sfc_get_email_perms);
	jQuery("#commentform :submit").click();
}
<?php 
    }
    ?>

function sfc_setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function sfc_getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

FB.ensureInit ( function () { 
	FB.Connect.ifUserConnected(sfc_update_user_details);
	if (sfc_getCookie('sfc_share') == 'yes') {
		sfc_setCookie('sfc_share', null);
		<?php 
    global $post;
    // build the attachment
    $permalink = get_permalink($post->ID);
    $attachment['name'] = get_the_title();
    $attachment['href'] = get_permalink();
    $attachment['description'] = sfc_comm_make_excerpt($post->post_content);
    $attachment['caption'] = '{*actor*} left a comment on ' . get_the_title();
    $attachment['comments_xid'] = urlencode(get_permalink());
    $action_links[0]['text'] = 'Read Post';
    $action_links[0]['href'] = get_permalink();
    ?>
		
		FB.Connect.streamPublish(null, 
			<?php 
    echo json_encode($attachment);
    ?>
,
			<?php 
    echo json_encode($action_links);
    ?>
			);
	}
}); 
</script>
<?php 
}