/**
  * Remove the WordPress comments menu bar item, replacing with a Facebook comments link
  * Check if Facebook comments enabled and if the current user might be able to view a comments edit screen on Facebook
  *
  * @since 1.1
  * @see WP_Admin_Bar->add_menus()
  */
 public static function admin_bar_menu()
 {
     global $facebook_loader;
     if (is_network_admin() && is_user_admin()) {
         return;
     }
     // use moderate_comments capability as a local proxy for accounts that might be granted moderate comments permissions for the Facebook application if the application administrator fully setup the app
     // technically the WordPress menu item is added for users with 'edit_posts' due to the permissions of the destination page but we'll check for the specific comments permission instead
     // TODO: check if Facebook data stored for current user, check if Facebook user is moderator
     if (!current_user_can('moderate_comments')) {
         return;
     }
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     $current_user = wp_get_current_user();
     $facebook_user_data = Facebook_User::get_user_meta($current_user->ID, 'fb_data', true);
     if (!(is_array($facebook_user_data) && isset($facebook_user_data['fb_uid']))) {
         return;
     }
     // swap only. don't add a menu item if none existed
     if (remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60)) {
         add_action('admin_bar_menu', array('Facebook_Comments', 'admin_bar_add_comments_menu'), 60);
     }
 }
 /**
  * Load extra assets early in the page build process to tap into proper hooks
  *
  * @since 1.1
  */
 public function onload()
 {
     global $facebook, $facebook_loader;
     // prompt to log in or update account info
     if (!class_exists('Facebook_Admin_Login')) {
         require_once dirname(__FILE__) . '/login.php';
     }
     Facebook_Admin_Login::connect_facebook_account(array('manage_pages', 'publish_actions', 'publish_stream'));
     // prep user-specific functionality and comparisons
     $this->current_user = wp_get_current_user();
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     // does the current user have associated Facebook account data stored in WordPress?
     $facebook_user_data = Facebook_User::get_user_meta($this->current_user->ID, 'fb_data', true);
     if (is_array($facebook_user_data) && isset($facebook_user_data['fb_uid'])) {
         $this->user_associated_with_facebook_account = true;
         if (isset($facebook) || isset($facebook_loader) && $facebook_loader->load_php_sdk()) {
             $this->user_permissions = $facebook->get_current_user_permissions($this->current_user);
         }
         if (!is_array($this->user_permissions)) {
             $this->user_permissions = array();
         }
     } else {
         $this->user_associated_with_facebook_account = false;
         $this->user_permissions = array();
     }
     $this->settings_api_init();
 }
Esempio n. 3
0
 /**
  * Check if the current user has associated his or her Facebook profile with his or her WordPress account
  * If the current user can edit posts and has not authorized Facebook then show a prompt encouraging action.
  *
  * @since 1.1
  */
 public static function connect_facebook_account($verify_permissions = null)
 {
     global $facebook;
     $profile_prompt = false;
     // check for permission to publish Open Graph action (publish article)
     // check for the superset permission: publish_stream
     if (!is_array($verify_permissions)) {
         $profile_prompt = true;
         $verify_permissions = array('publish_actions', 'publish_stream');
     }
     $current_user = wp_get_current_user();
     // no need to alert if he cannot create a post
     if (!user_can($current_user, 'edit_posts')) {
         return;
     }
     if (!class_exists('Facebook_User')) {
         require_once dirname(__FILE__) . '/facebook-user.php';
     }
     $facebook_user_data_exists = false;
     $facebook_user_data = Facebook_User::get_user_meta($current_user->ID, 'fb_data', true);
     if (is_array($facebook_user_data) && isset($facebook_user_data['fb_uid'])) {
         if (empty($verify_permissions)) {
             return;
         }
         $facebook_user_data_exists = true;
     }
     // Facebook information not found
     $facebook_user = Facebook_User::get_current_user(array('id', 'username'));
     if ($facebook_user) {
         $permissions = $facebook->get_current_user_permissions($facebook_user);
         $all_permissions_exist = true;
         foreach ($verify_permissions as $permission_to_verify) {
             if (!isset($permissions[$permission_to_verify])) {
                 $all_permissions_exist = false;
                 break;
             }
         }
         if ($all_permissions_exist) {
             if (!$facebook_user_data_exists || $facebook_user_data['fb_uid'] != $facebook_user['id']) {
                 $facebook_user_data = array('fb_uid' => $facebook_user['id'], 'activation_time' => time());
                 if (!empty($facebook_user['username'])) {
                     $facebook_user_data['username'] = $facebook_user['username'];
                 }
                 Facebook_User::update_user_meta($current_user->ID, 'fb_data', $facebook_user_data);
             }
             return;
         }
     }
     // priority before js sdk registration needed to add JS inside FbAsyncInit
     add_action('admin_enqueue_scripts', array('Facebook_Admin_Login', 'add_async_load_javascript_filter'), -1, 0);
     // add all others at P11 after scripts registered
     add_action('admin_enqueue_scripts', array('Facebook_Admin_Login', 'enqueue_scripts'), 11);
     if ($profile_prompt) {
         add_action('admin_notices', array('Facebook_Admin_Login', 'admin_notice'), 1, 0);
     }
     // up top
 }
 /**
  * Can the current user publish to Facebook?
  *
  * @since 1.1
  * @param int $wordpress_user_id WordPress user identifier
  * @return bool true if Facebook data stored for user and permissions exist
  */
 public static function user_can_publish_to_facebook($wordpress_user_id = null)
 {
     global $facebook_loader;
     if (!class_exists('Facebook_User')) {
         require_once $facebook_loader->plugin_directory . 'facebook-user.php';
     }
     if (!(is_int($wordpress_user_id) && $wordpress_user_id)) {
         $current_user = wp_get_current_user();
         if (isset($current_user->ID)) {
             $wordpress_user_id = (int) $current_user->ID;
         }
         unset($current_user);
     }
     if (is_int($wordpress_user_id) && $wordpress_user_id && Facebook_User::get_facebook_profile_id($wordpress_user_id) && !Facebook_User::get_user_meta($wordpress_user_id, 'facebook_timeline_disabled', true)) {
         return true;
     }
     return false;
 }
 /**
  * Add a Facebook form field to the contact info section
  *
  * @since 1.2
  * @param array $user_contactmethods associative array of id label pairs.
  * @param WP_User $user WordPress user
  */
 public static function user_contactmethods($user_contactmethods, $user)
 {
     if (is_array($user_contactmethods) && $user && method_exists($user, 'exists') && user_can($user, 'edit_posts')) {
         $user_contactmethods['facebook'] = 'Facebook';
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         $facebook_user_data = Facebook_User::get_user_meta(get_current_user_id(), 'fb_data', true);
         if (isset($facebook_user_data['username'])) {
             $user->facebook = esc_url_raw('https://www.facebook.com/' . $facebook_user_data['username'], array('http', 'https'));
         } else {
             if (isset($facebook_user_data['fb_uid'])) {
                 $user->facebook = esc_url_raw('https://www.facebook.com/profile.php?' . http_build_query(array('id' => $facebook_user_data['fb_uid']), '', '&'), array('http', 'https'));
             }
         }
         unset($facebook_user_data);
     }
     return $user_contactmethods;
 }
Esempio n. 6
0
/**
 * Add Subscribe Button(s) to post content
 * Adds a subscribe button above the post, below the post, or both above and below the post depending on stored preferences.
 *
 * @since 1.1
 * @param string $content existing content
 * @return string passed content with Subscribe Button markup prepended, appended, or both.
 */
function facebook_the_content_subscribe_button($content)
{
    global $post;
    // Send Button should not be the only content
    if (!$content) {
        return $content;
    }
    $options = get_option('facebook_subscribe_button');
    if (!is_array($options)) {
        $options = array();
    }
    if (!class_exists('Facebook_User')) {
        require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
    }
    $facebook_user = Facebook_User::get_user_meta(get_the_author_meta('ID'), 'fb_data', true);
    if (!($facebook_user && isset($facebook_user['fb_uid']))) {
        return $content;
    }
    if (isset($facebook_user['username'])) {
        $options['href'] = 'https://www.facebook.com/' . $facebook_user['username'];
    } else {
        $options['href'] = 'https://www.facebook.com/profile.php?' . http_build_query(array('id' => $facebook_user['fb_uid']));
    }
    if ($options['position'] === 'top') {
        $options['ref'] = 'above-post';
        return facebook_get_subscribe_button($options) . $content;
    } else {
        if ($options['position'] === 'bottom') {
            $options['ref'] = 'below-post';
            return $content . facebook_get_subscribe_button($options);
        } else {
            if ($options['position'] === 'both') {
                $options['ref'] = 'above-post';
                $above = facebook_get_subscribe_button($options);
                $options['ref'] = 'below-post';
                return $above . $content . facebook_get_subscribe_button($options);
            }
        }
    }
    // don't break the filter
    return $content;
}
 /**
  * Add Open Graph protocol markup to <head>
  * We use full IRIs for consistent mapping between mapped CURIE prefixes defined in a parent element and self-contained properties using a full IRI
  *
  * @since 1.0
  * @link http://www.w3.org/TR/rdfa-syntax/#s_curieprocessing RDFa Core 1.1 CURIE and IRI processing
  */
 public static function add_og_protocol()
 {
     global $post, $facebook_loader;
     $meta_tags = array(self::OGP_NS . 'site_name' => get_bloginfo('name'), self::OGP_NS . 'type' => 'website');
     if (isset($facebook_loader)) {
         if (isset($facebook_loader->locale)) {
             $meta_tags[self::OGP_NS . 'locale'] = $facebook_loader->locale;
         }
         if (isset($facebook_loader->credentials) && isset($facebook_loader->credentials['app_id']) && $facebook_loader->credentials['app_id']) {
             $meta_tags[self::FB_NS . 'app_id'] = $facebook_loader->credentials['app_id'];
         }
     }
     if (is_home() || is_front_page()) {
         $meta_tags[self::OGP_NS . 'title'] = get_bloginfo('name');
         $meta_tags[self::OGP_NS . 'description'] = get_bloginfo('description');
         $meta_tags[self::OGP_NS . 'url'] = home_url();
     } else {
         if (is_single() && empty($post->post_password)) {
             setup_postdata($post);
             $post_type = get_post_type();
             $meta_tags[self::OGP_NS . 'url'] = apply_filters('facebook_rel_canonical', get_permalink());
             if (post_type_supports($post_type, 'title')) {
                 $meta_tags[self::OGP_NS . 'title'] = get_the_title();
             }
             if (post_type_supports($post_type, 'excerpt')) {
                 $description = '';
                 // did the publisher specify a custom excerpt? use it
                 if (!empty($post->post_excerpt)) {
                     $description = apply_filters('get_the_excerpt', $post->post_excerpt);
                 } else {
                     $description = $post->post_content;
                 }
                 $description = self::clean_description($description);
                 if ($description) {
                     $meta_tags[self::OGP_NS . 'description'] = $description;
                 }
             }
             $meta_tags[self::OGP_NS . 'type'] = 'article';
             $meta_tags[self::ARTICLE_NS . 'published_time'] = date('c', strtotime($post->post_date_gmt));
             $meta_tags[self::ARTICLE_NS . 'modified_time'] = date('c', strtotime($post->post_modified_gmt));
             if (post_type_supports($post_type, 'author') && isset($post->post_author)) {
                 $meta_tags[self::ARTICLE_NS . 'author'] = get_author_posts_url($post->post_author);
                 // adding an fb:admin grants comment moderation permissions for Comment Box
                 if (get_option('facebook_comments_enabled') && user_can($post->post_author, 'moderate_comments')) {
                     if (!class_exists('Facebook_Comments')) {
                         require_once dirname(__FILE__) . '/social-plugins/class-facebook-comments.php';
                     }
                     if (Facebook_Comments::comments_enabled_for_post_type($post)) {
                         if (!class_exists('Facebook_User')) {
                             require_once dirname(__FILE__) . '/facebook-user.php';
                         }
                         $facebook_user_data = Facebook_User::get_user_meta($post->post_author, 'fb_data', true);
                         if (is_array($facebook_user_data) && isset($facebook_user_data['fb_uid'])) {
                             $meta_tags[self::FB_NS . 'admins'] = $facebook_user_data['fb_uid'];
                         }
                         unset($facebook_user_data);
                     }
                 }
             }
             // add the first category as a section. all other categories as tags
             $cat_ids = get_the_category();
             if (!empty($cat_ids)) {
                 $no_category = apply_filters('the_category', __('Uncategorized'));
                 $cat = get_category($cat_ids[0]);
                 if (!empty($cat) && isset($cat->name) && $cat->name !== $no_category) {
                     $meta_tags[self::ARTICLE_NS . 'section'] = $cat->name;
                 }
                 //output the rest of the categories as tags
                 unset($cat_ids[0]);
                 if (!empty($cat_ids)) {
                     $meta_tags[self::ARTICLE_NS . 'tag'] = array();
                     foreach ($cat_ids as $cat_id) {
                         $cat = get_category($cat_id);
                         if (isset($cat->name) && $cat->name !== $no_category) {
                             $meta_tags[self::ARTICLE_NS . 'tag'][] = $cat->name;
                         }
                         unset($cat);
                     }
                 }
             }
             // add tags. treat tags as lower priority than multiple categories
             $tags = get_the_tags();
             if ($tags) {
                 if (!array_key_exists(self::ARTICLE_NS . 'tag', $meta_tags)) {
                     $meta_tags[self::ARTICLE_NS . 'tag'] = array();
                 }
                 foreach ($tags as $tag) {
                     $meta_tags[self::ARTICLE_NS . 'tag'][] = $tag->name;
                 }
             }
             // does current post type and the current theme support post thumbnails?
             if (post_type_supports($post_type, 'thumbnail') && function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                 list($post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height) = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
                 if (!empty($post_thumbnail_url)) {
                     $image = array('url' => $post_thumbnail_url);
                     if (!empty($post_thumbnail_width)) {
                         $image['width'] = absint($post_thumbnail_width);
                     }
                     if (!empty($post_thumbnail_height)) {
                         $image['height'] = absint($post_thumbnail_height);
                     }
                     $meta_tags[self::OGP_NS . 'image'] = array($image);
                 }
             }
             $gallery_images = self::gallery_images($post);
             if (!empty($gallery_images)) {
                 foreach ($gallery_images as $gallery_image) {
                     // do not repeat the thumbnail
                     if (isset($post_thumbnail_url) && $post_thumbnail_url === $gallery_image['url']) {
                         continue;
                     }
                     $meta_tags[self::OGP_NS . 'image'][] = $gallery_image;
                 }
             }
             unset($gallery_images);
         } else {
             if (is_author()) {
                 $author = get_queried_object();
                 if (!($author && isset($author->ID))) {
                     break;
                 }
                 $author_id = $author->ID;
                 $meta_tags[self::OGP_NS . 'type'] = 'profile';
                 $meta_tags[self::OGP_NS . 'title'] = get_the_author_meta('display_name', $author_id);
                 $meta_tags[self::OGP_NS . 'url'] = get_author_posts_url(get_the_author_meta('ID', $author_id));
                 $meta_tags[self::PROFILE_NS . 'first_name'] = get_the_author_meta('first_name', $author_id);
                 $meta_tags[self::PROFILE_NS . 'last_name'] = get_the_author_meta('last_name', $author_id);
                 $description = self::clean_description(get_the_author_meta('description', $author_id));
                 if ($description) {
                     $meta_tags[self::OGP_NS . 'description'] = $description;
                 }
                 if (!class_exists('Facebook_User')) {
                     require_once dirname(__FILE__) . '/facebook-user.php';
                 }
                 $facebook_user_data = Facebook_User::get_user_meta($author_id, 'fb_data', true);
                 if (is_array($facebook_user_data) && isset($facebook_user_data['third_party_id'])) {
                     $meta_tags[self::FB_NS . 'profile_id'] = $facebook_user_data['third_party_id'];
                 }
                 unset($facebook_user_data);
                 // no need to show username if there is only one
                 if (is_multi_author()) {
                     $meta_tags[self::PROFILE_NS . 'username'] = get_the_author_meta('login', $author_id);
                 }
             } else {
                 if (is_page()) {
                     $meta_tags[self::OGP_NS . 'type'] = 'article';
                     $meta_tags[self::OGP_NS . 'title'] = get_the_title();
                     $meta_tags[self::OGP_NS . 'url'] = apply_filters('facebook_rel_canonical', get_permalink());
                 }
             }
         }
     }
     $meta_tags = apply_filters('fb_meta_tags', $meta_tags, $post);
     // default: true while Facebook crawler corrects its indexing of full IRI values
     if (apply_filters('facebook_ogp_prefixed', true)) {
         $meta_tags = self::prefixed_properties($meta_tags);
     }
     foreach ($meta_tags as $property => $content) {
         self::meta_elements($property, $content);
     }
 }
Esempio n. 8
0
 /**
  * Does the current WordPress user have Facebook data stored?
  * Has the current viewer authorized the current application to post on his or her behalf?
  *
  * @since 1.1
  * @return bool true if Facebook information present for current user and publish permissions exist
  */
 public static function can_publish_to_facebook()
 {
     global $facebook;
     if (!isset($facebook)) {
         return false;
     }
     $current_user = wp_get_current_user();
     // does the current user have associated Facebook account data stored in WordPress?
     $facebook_user_data = self::get_user_meta($current_user->ID, 'fb_data', true);
     if (!(is_array($facebook_user_data) && isset($facebook_user_data['fb_uid']))) {
         return false;
     }
     if (Facebook_User::get_user_meta($current_user->ID, 'facebook_timeline_disabled', true)) {
         return false;
     }
     $permissions = $facebook->get_current_user_permissions($current_user);
     if (!(is_array($permissions) && !empty($permissions) && isset($permissions['publish_stream']) && isset($permissions['publish_actions']))) {
         return false;
     }
     return true;
 }
 /**
  * Get data persisted by the Facebook PHP SDK using WordPress-specific access methods
  *
  * @since 1.0
  */
 protected function getPersistentData($key, $default = false)
 {
     if (!in_array($key, self::$kSupportedKeys)) {
         self::errorLog('Unsupported key passed to getPersistentData.');
         return $default;
     }
     // load user functions
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(dirname(__FILE__))) . '/facebook-user.php';
     }
     return Facebook_User::get_user_meta(get_current_user_id(), $key, true);
 }
Esempio n. 10
0
 /**
  * Map WordPress post data to Open Graph article object properties.
  *
  * @since 1.5
  *
  * @param stdClass|WP_Post $post the post of interest
  * @return array {
  *     Associative array of OGP properties and values related to the post
  *
  *     @type string Full IRI Open Graph protocol property
  *     @type string|array Open Graph protocol property value
  * }
  */
 public static function get_article_properties($post)
 {
     global $facebook_loader;
     $ogp = array(self::ARTICLE_NS . 'published_time' => date('c', strtotime($post->post_date_gmt)), self::ARTICLE_NS . 'modified_time' => date('c', strtotime($post->post_modified_gmt)));
     if (post_type_supports(get_post_type($post), 'author') && isset($post->post_author)) {
         if (!class_exists('Facebook_User')) {
             require_once $facebook_loader->plugin_directory . 'facebook-user.php';
         }
         $facebook_user_data = Facebook_User::get_user_meta($post->post_author, 'fb_data', true);
         if (is_array($facebook_user_data) && isset($facebook_user_data['link'])) {
             $ogp[self::ARTICLE_NS . 'author'] = $facebook_user_data['link'];
         } else {
             $ogp[self::ARTICLE_NS . 'author'] = get_author_posts_url($post->post_author);
         }
         unset($facebook_user_data);
     }
     $facebook_page = get_option('facebook_publish_page');
     if (is_array($facebook_page) && isset($facebook_page['link'])) {
         $ogp[self::ARTICLE_NS . 'publisher'] = $facebook_page['link'];
     }
     unset($facebook_page);
     // add the first category as a section. all other categories as tags
     $cat_ids = get_the_category($post->ID);
     if (!empty($cat_ids)) {
         $no_category = apply_filters('the_category', __('Uncategorized'));
         $cat = get_category($cat_ids[0]);
         if (!empty($cat) && isset($cat->name) && $cat->name !== $no_category) {
             $ogp[self::ARTICLE_NS . 'section'] = $cat->name;
         }
         // output the rest of the categories as tags
         unset($cat_ids[0]);
         if (!empty($cat_ids)) {
             $ogp[self::ARTICLE_NS . 'tag'] = array();
             foreach ($cat_ids as $cat_id) {
                 $cat = get_category($cat_id);
                 if (isset($cat->name) && $cat->name !== $no_category) {
                     $ogp[self::ARTICLE_NS . 'tag'][] = $cat->name;
                 }
                 unset($cat);
             }
         }
     }
     // add tags. treat tags as lower priority than multiple categories
     $tags = get_the_tags($post->ID);
     if ($tags) {
         if (!isset($ogp[self::ARTICLE_NS . 'tag'])) {
             $ogp[self::ARTICLE_NS . 'tag'] = array();
         }
         foreach ($tags as $tag) {
             $ogp[self::ARTICLE_NS . 'tag'][] = $tag->name;
         }
     }
     return $ogp;
 }
 /**
  * Load extra assets early in the page build process to tap into proper hooks
  *
  * @since 1.1
  *
  * @return void
  */
 public function onload()
 {
     // prep user-specific functionality and comparisons
     $this->current_user = wp_get_current_user();
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     // does the current user have associated Facebook account data stored in WordPress?
     $facebook_user_data = Facebook_User::get_user_meta($this->current_user->ID, 'fb_data', true);
     if (is_array($facebook_user_data) && isset($facebook_user_data['fb_uid'])) {
         $this->user_associated_with_facebook_account = true;
         add_action('admin_enqueue_scripts', array('Facebook_Social_Publisher_Settings', 'enqueue_scripts'));
     } else {
         $this->user_associated_with_facebook_account = false;
     }
     $this->settings_api_init();
 }
Esempio n. 12
0
/**
 * Add Follow Button(s) to post content
 *
 * Adds a follow button above the post, below the post, or both above and below the post depending on stored preferences.
 *
 * @since 1.1
 *
 * @param string $content existing content
 * @return string passed content with Follow Button markup prepended, appended, or both.
 */
function facebook_the_content_follow_button($content)
{
    // Follow Button should not be the only content
    if (!$content) {
        return $content;
    }
    $options = get_option('facebook_follow_button');
    if (!is_array($options)) {
        $options = array();
    }
    if (!class_exists('Facebook_User')) {
        require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
    }
    $facebook_user = Facebook_User::get_user_meta(get_the_author_meta('ID'), 'fb_data', true);
    if (!($facebook_user && isset($facebook_user['fb_uid']))) {
        return $content;
    }
    $options['href'] = Facebook_User::facebook_profile_link($facebook_user);
    if (!$options['href']) {
        return $content;
    }
    if ($options['position'] === 'top') {
        $options['ref'] = 'above-post';
        return facebook_get_follow_button($options) . $content;
    } else {
        if ($options['position'] === 'bottom') {
            $options['ref'] = 'below-post';
            return $content . facebook_get_follow_button($options);
        } else {
            if ($options['position'] === 'both') {
                $options['ref'] = 'above-post';
                $above = facebook_get_follow_button($options);
                $options['ref'] = 'below-post';
                return $above . $content . facebook_get_follow_button($options);
            }
        }
    }
    // don't break the filter
    return $content;
}
Esempio n. 13
0
 /**
  * Add a Facebook section to the WordPress user profile page.
  *
  * @since 1.5
  *
  * @global \Facebook_Loader $facebook_loader Access Facebook application credentials.
  * @param WP_User $wp_user WordPress user for the current profile page.
  * @return void
  */
 public static function facebook_section($wp_user)
 {
     global $facebook_loader;
     if (!($wp_user && isset($wp_user->ID) && method_exists($wp_user, 'exists') && $wp_user->exists() && user_can($wp_user, 'edit_posts'))) {
         return;
     }
     $section = '<h3>' . esc_html(__('Facebook Account', 'facebook')) . '</h3>';
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     $facebook_user_data = Facebook_User::get_user_meta($wp_user->ID, 'fb_data', true);
     $section .= '<table id="facebook-info" class="form-table"';
     // test if Facebook account associated with current WordPress user context
     if (is_array($facebook_user_data) && isset($facebook_user_data['fb_uid'])) {
         $section .= ' data-fbid="' . esc_attr($facebook_user_data['fb_uid']) . '"';
         if (isset($facebook_loader->credentials['app_id'])) {
             $section .= ' data-appid="' . esc_attr($facebook_loader->credentials['app_id']) . '">';
         }
         $section .= '<tr><th scope="row">' . esc_html(_x('Connected Profile', 'Connected Facebook Profile', 'facebook')) . '</th>';
         $section .= '<td><p><a href="' . esc_url(Facebook_User::facebook_profile_link($facebook_user_data), array('http', 'https')) . '">' . esc_html($facebook_user_data['fb_uid']) . '</a></p>';
         if (isset($facebook_user_data['activation_time'])) {
             $section .= '<div class="description"><p>' . sprintf(esc_html(__('Associated on %s', 'facebook')), '<time datetime="' . gmstrftime('%FT%T', $facebook_user_data['activation_time']) . '+00:00">' . date_i18n(get_option('date_format'), $facebook_user_data['activation_time']) . '</time>') . '</p></div>';
         }
         $section .= '<p class="submit"><input id="facebook-remove" name="facebook_remove" class="button button-primary" type="submit" value="' . esc_attr(_x('Remove Facebook account', 'Remove an association between a Facebook account and a WordPress user profile', 'facebook')) . '" />' . '</p>';
         $section .= '</td></tr>';
         if (!class_exists('Facebook_WP_Extend')) {
             require_once $facebook_loader->plugin_directory . 'includes/facebook-php-sdk/class-facebook-wp.php';
         }
         $permissions = Facebook_WP_Extend::get_permissions_by_facebook_user_id($facebook_user_data['fb_uid']);
         if (!empty($permissions)) {
             $permission_labels = array();
             if (isset($permissions['installed'])) {
                 $permission_labels[] = '<a href="https://www.facebook.com/about/privacy/your-info#public-info">' . esc_html(__('Public profile information', 'facebook')) . '</a>';
             }
             if (isset($permissions['publish_actions'])) {
                 $permission_labels[] = esc_html(__('Publish to Timeline', 'facebook'));
             }
             if (isset($permissions['manage_pages']) && isset($permissions['publish_stream'])) {
                 $permission_labels[] = '<a href="https://developers.facebook.com/docs/reference/login/page-permissions/">' . esc_html(__('Manage your pages on your behalf (including creating content)', 'facebook')) . '</a>';
             }
             $section .= '<tr><th scope="row">' . esc_html(__('Permissions', 'facebook')) . '</th><td>';
             if (empty($permissions)) {
                 $section .= __('None', 'facebook');
             } else {
                 $section .= '<ul><li>' . implode('</li><li>', $permission_labels) . '</li></ul>';
             }
             $section .= '<div id="facebook-login"></div></td></tr>';
         }
     } else {
         $section .= '><tr><th scope="row">' . esc_html(_x('Get started', 'Begin the process', 'facebook')) . '</th>';
         $section .= '<td id="facebook-login"></td></tr>';
     }
     $section .= '</table>';
     echo $section;
 }
Esempio n. 14
0
 /**
  * Publish new posts to your Facebook timeline
  *
  * @since 1.1
  */
 public function display_publish_author()
 {
     if (isset($this->user_permissions) && isset($this->user_permissions['publish_stream']) && isset($this->user_permissions['publish_actions'])) {
         echo '<label><input type="checkbox" name="' . self::PUBLISH_OPTION_NAME . '[author_timeline]" value="1"';
         echo checked(Facebook_User::get_user_meta($this->current_user->ID, 'facebook_timeline_disabled', true), '');
         echo ' /> ';
         echo esc_html(__('Post an article to my Facebook timeline after it is published.', 'facebook'));
         echo '</label>';
     } else {
         echo '<p><span class="facebook-login" data-scope="person" style="font-weight:bold">' . esc_html(__('Allow new posts to your Facebook timeline', 'facebook')) . '</span></p>';
     }
 }
Esempio n. 15
0
 /**
  * Can the current user publish to Facebook?
  *
  * @since 1.1
  * @return bool true if Facebook data stored for user and permissions exist
  */
 public static function user_can_publish_to_facebook()
 {
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/facebook-user.php';
     }
     $current_user = wp_get_current_user();
     if (Facebook_User::can_publish_to_facebook() && !Facebook_User::get_user_meta($current_user->ID, 'facebook_timeline_disabled', true)) {
         return true;
     }
     return false;
 }