Exemple #1
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;
}
 /**
  * Detail site users and their association with Facebook
  *
  * @since 1.1.6
  *
  * @global wpdb $wpdb escape SQL
  * @return void
  */
 public static function users_section()
 {
     global $wpdb;
     $users = self::get_all_wordpress_facebook_users();
     // should only happen if errors
     if (empty($users['fb']) && empty($users['wp'])) {
         return;
     }
     echo '<section id="debug-users"><header><h3>' . esc_html(__('Authors')) . '</h3></header>';
     if (!empty($users['fb'])) {
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         echo '<table><caption>' . esc_html(_x('Connected to Facebook', 'Local user account has an associated Facebook account stored', 'facebook')) . '</caption><colgroup><col><col span="2" class="permissions"></colgroup><thead><tr><th>' . esc_html(__('Name')) . '</th><th title="' . esc_attr(__('Facebook account', 'facebook')) . '"></th><th>' . esc_html(__('Post to timeline', 'facebook')) . '</th><th>' . esc_html(__('Manage pages', 'facebook')) . '</th></tr></thead><tbody>';
         foreach ($users['fb'] as $user) {
             echo '<tr><th><a href="' . esc_url(get_author_posts_url($user->id)) . '">' . esc_html($user->display_name) . '</a></th>';
             echo '<td>';
             $profile_link = Facebook_User::facebook_profile_link($user->fb_data);
             if ($profile_link) {
                 echo '<a class="facebook-icon" href="' . esc_url($profile_link, array('http', 'https')) . '"></a>';
             }
             unset($profile_link);
             echo '</td>';
             echo '<td>';
             if (isset($user->fb_data['permissions']['publish_actions']) && $user->fb_data['permissions']['publish_actions']) {
                 echo self::EXISTS;
             } else {
                 echo self::DOES_NOT_EXIST;
             }
             echo '</td>';
             echo '<td>';
             if (isset($user->fb_data['permissions']['manage_pages']) && $user->fb_data['permissions']['manage_pages'] && isset($user->fb_data['permissions']['publish_stream']) && $user->fb_data['permissions']['publish_stream']) {
                 echo self::EXISTS;
             } else {
                 echo self::DOES_NOT_EXIST;
             }
             echo '</td></tr>';
         }
         echo '</tbody></table>';
     }
     if (!empty($users['wp'])) {
         // last 90 days
         $where = ' AND ' . $wpdb->prepare('post_date > %s', date('Y-m-d H:i:s', time() - 90 * 24 * 60 * 60));
         $public_post_types = get_post_types(array('public' => true));
         if (is_array($public_post_types) && !empty($public_post_types)) {
             $public_post_types = array_values($public_post_types);
             $where .= ' AND post_type';
             if (count($public_post_types) === 1) {
                 $where .= $wpdb->prepare(' = %s', $public_post_types[0]);
             } else {
                 $s = '';
                 foreach ($public_post_types as $post_type) {
                     $s .= "'" . $wpdb->escape($post_type) . "',";
                 }
                 $where .= ' IN (' . rtrim($s, ',') . ')';
                 unset($s);
             }
         }
         $public_states = get_post_stati(array('public' => true));
         if (is_array($public_states) && !empty($public_states)) {
             $public_states = array_values($public_states);
             $where .= ' AND post_status';
             if (count($public_states) === 1) {
                 $where .= $wpdb->prepare(' = %s', $public_states[0]);
             } else {
                 $s = '';
                 foreach ($public_states as $state) {
                     $s .= "'" . $wpdb->escape($state) . "',";
                 }
                 $where .= ' IN (' . rtrim($s, ',') . ')';
                 unset($s);
             }
         }
         unset($public_states);
         echo '<table><caption>' . esc_html(__('Not connected to Facebook', 'facebook')) . '</caption><thead><th>' . esc_html(__('Name')) . '</th><th><abbr title="' . esc_attr(sprintf(__('Number of published posts in the last %u days', 'facebook'), 90)) . '">' . esc_html(_x('# of recent posts', 'recent articles. used as a table column header', 'facebook')) . '</abbr></th></thead><tbody>';
         foreach ($users['wp'] as $user) {
             echo '<tr><th><a href="' . esc_url(get_author_posts_url($user->id)) . '">' . esc_html($user->display_name) . '</a></th>';
             echo '<td>' . $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = %d {$where}", $user->id)) . '</td>';
             echo '</tr>';
         }
         echo '</tbody></table>';
     }
     echo '</section>';
 }
 /**
  * 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;
 }