function sfc_base_meta() { global $post; $options = get_option('sfc_options'); // exclude bbPress post types if (function_exists('bbp_is_custom_post_type') && bbp_is_custom_post_type()) { return; } $excerpt = ''; if (is_singular()) { global $wp_the_query; if ($id = $wp_the_query->get_queried_object_id()) { $post = get_post($id); } // get the content from the main post on the page $content = sfc_base_make_excerpt($post); $images = sfc_base_find_images($post); $video = sfc_base_find_video($post); $title = get_the_title(); $permalink = get_permalink(); echo "<meta property='og:type' content='article' />\n"; echo "<meta property='og:title' content='" . esc_attr($title) . "' />\n"; echo "<meta property='og:url' content='" . esc_url($permalink) . "' />\n"; echo "<meta property='og:description' content='" . esc_attr($content) . "' />\n"; if (!empty($images)) { foreach ($images as $image) { echo "<meta property='og:image' content='{$image}' />\n"; } } if (!empty($video)) { foreach ($video as $type => $value) { echo "<meta property='og:video{$type}' href='{$value}' />\n"; } } } else { if (is_home()) { echo "<meta property='og:type' content='blog' />\n"; echo "<meta property='og:title' content='" . get_bloginfo("name") . "' />\n"; echo "<meta property='og:url' content='" . esc_url(get_bloginfo("url")) . "' />\n"; } } // stuff on all pages echo "<meta property='og:site_name' content='" . get_bloginfo("name") . "' />\n"; echo "<meta property='fb:app_id' content='" . esc_attr($options["appid"]) . "' />\n"; }
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; } // build the post to send to FB // look for the images/video to add with image_src $images = sfc_media_find_images($post); $video = sfc_media_find_video($post); if (!empty($video['og:image'])) { array_unshift($images, $video['og:image'][0]); } // build the attachment $permalink = apply_filters('sfc_publish_permalink', wp_get_shortlink($post->ID), $post->ID); $title = get_the_title($post->ID); $title = strip_tags($title); $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); $title = htmlspecialchars_decode($title); $attachment['name'] = $title; $attachment['message'] = $title; $attachment['link'] = $permalink; $attachment['scrape'] = 'true'; $attachment['description'] = sfc_base_make_excerpt($post); $attachment['caption'] = ' '; if (!empty($images)) { $attachment['picture'] = $images[0]; } if (!empty($video)) { $attachment['source'] = $video['og:video']; } // Actions $actions[0]['name'] = 'Share'; $actions[0]['link'] = 'http://www.facebook.com/share.php?u=' . urlencode($permalink); $attachment['actions'] = json_encode($actions); $attachment = apply_filters('sfc_publish_automatic', $attachment, $post); // publish to page if (!empty($options['fanpage']) && $options['autopublish_app'] && !get_post_meta($id, '_fb_post_id_app', true)) { $url = "https://graph.facebook.com/{$options['fanpage']}/" . SFC_PUBLISH_ENDPOINT; $attachment['access_token'] = $options['page_access_token']; $data = wp_remote_post($url, array('body' => $attachment)); if (!is_wp_error($data)) { $resp = json_decode($data['body'], true); if ($resp['id']) { update_post_meta($id, '_fb_post_id_app', $resp['id']); } } } // publish to profile if ($options['autopublish_profile'] && !get_post_meta($id, '_fb_post_id_profile', true)) { $url = "https://graph.facebook.com/{$options['user']}/" . SFC_PUBLISH_ENDPOINT; // check the cookie for an access token. If not found, try to use the stored one. $cookie = sfc_cookie_parse(); if ($cookie['access_token']) { $attachment['access_token'] = $cookie['access_token']; } else { $attachment['access_token'] = $options['access_token']; } $data = wp_remote_post($url, array('body' => $attachment)); if (!is_wp_error($data)) { $resp = json_decode($data['body'], true); if ($resp['id']) { update_post_meta($id, '_fb_post_id_profile', $resp['id']); } } } }
function sfc_comm_add_meta($comment_id) { $uid = $_POST['sfc_user_id']; $token = $_POST['sfc_user_token']; // 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); $actions[0]['name'] = 'Read Post'; $actions[0]['link'] = $permalink; $attachment['actions'] = json_encode($actions); $url = "https://graph.facebook.com/{$uid}/feed&access_token={$token}"; $attachment['access_token'] = $token; $data = wp_remote_post($url, array('sslverify' => 0, 'body' => $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']); } } } if (!empty($uid) && !empty($token)) { // validate token $url = "https://graph.facebook.com/{$uid}/?fields=name,email&access_token={$token}"; $data = wp_remote_get($url, array('sslverify' => 0)); if (!is_wp_error($data)) { $json = json_decode($data['body'], true); if (!empty($json['name'])) { update_comment_meta($comment_id, 'fbuid', $uid); } } } }
function sfc_base_meta() { $post = ''; $fbmeta = array(); $options = get_option('sfc_options'); // exclude bbPress post types if (function_exists('bbp_is_custom_post_type') && bbp_is_custom_post_type()) { return; } $excerpt = ''; if (is_singular()) { global $wp_the_query; if ($id = $wp_the_query->get_queried_object_id()) { $post = get_post($id); } // get the content from the main post on the page $content = sfc_base_make_excerpt($post); $title = get_the_title($post->ID); $title = strip_tags($title); $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); $title = htmlspecialchars_decode($title); $permalink = get_permalink(); $fbmeta['og:type'] = 'article'; $fbmeta['og:title'] = esc_attr($title); $fbmeta['og:url'] = esc_url($permalink); $fbmeta['og:description'] = esc_attr($content); } else { // non singular pages need images and descriptions too if (!empty($options['default_image'])) { $fbmeta['og:image'][] = $options['default_image']; } if (!empty($options['default_description'])) { $fbmeta['og:description'] = esc_attr($options['default_description']); } } if (is_home()) { $fbmeta['og:type'] = 'blog'; $fbmeta['og:title'] = get_bloginfo("name"); $fbmeta['og:url'] = esc_url(get_bloginfo("url")); } // stuff on all pages $fbmeta['og:site_name'] = get_bloginfo("name"); if (!empty($options["appid"])) { $fbmeta['fb:app_id'] = esc_attr($options["appid"]); } $fbmeta['og:locale'] = sfc_get_locale(); $fbmeta = apply_filters('sfc_base_meta', $fbmeta, $post); foreach ($fbmeta as $prop => $content) { if (is_array($content)) { foreach ($content as $item) { echo "<meta property='{$prop}' content='{$item}' />\n"; if ($prop == 'og:image') { echo "<link rel='image_src' href='{$item}' />\n"; } } } else { echo "<meta property='{$prop}' content='{$content}' />\n"; if ($prop == 'og:image') { echo "<link rel='image_src' href='{$content}' />\n"; } } } }