'.__('Connect with Facebook', 'sfc').'

'; } // this exists so that other plugins (simple twitter connect) 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 '
'; } add_action('alt_comment_login','alt_login_method_div_close',20,0); add_action('comment_form_before_fields', 'alt_login_method_div_close',20,0); // WP 3.0 support function alt_login_method_div_close() { echo '
'; } } // WP 3.0 support if (!function_exists('comment_user_details_begin')) { add_action('comment_form_before_fields', 'comment_user_details_begin',1,0); function comment_user_details_begin() { echo '
'; } add_action('comment_form_after_fields', 'comment_user_details_end',20,0); function comment_user_details_end() { 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 ""; } 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) { $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_base_make_excerpt($post); $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']); } } } // 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 $cookie = sfc_cookie_parse(); if (empty($cookie)) return; $uid = $cookie['uid']; $token = $cookie['access_token']; if (empty($uid) || empty($token)) return; // need both of these to get the data from FB $url = "https://graph.facebook.com/{$uid}/?fields=name,email,website&access_token={$token}"; $data = wp_remote_get($url); if (!is_wp_error($data)) { $json = json_decode($data['body'],true); if ($json) { $_POST['author'] = $json['name']; $_POST['url'] = $json['website']; $_POST['email'] = $json['email']; } } } // hook to the footer to add our scripting add_action('wp_footer','sfc_comm_footer_script',30); // 30 to ensure we happen after sfc base 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'); ?>