/** * Iterate through possible view types for subscribe button * Change subscribe to follow if found * * @since 1.1.9 */ public static function update_views() { if (!class_exists('Facebook_Follow_Button_Settings')) { require_once dirname(__FILE__) . '/settings-follow-button.php'; } // archives + post types $all_possible_display_types = Facebook_Social_Plugin_Settings::get_show_on_choices('all'); // archives + post types supporting authorship $follow_display_types = Facebook_Follow_Button_Settings::get_show_on_choices(); // iterate through all display types, looking for our feature in each foreach ($all_possible_display_types as $display_type) { $option_name = "facebook_{$display_type}_features"; $display_preferences = get_option($option_name); if (!is_array($display_preferences)) { continue; } if (isset($display_preferences['subscribe'])) { unset($display_preferences['subscribe']); // remove any post types not supporting authorship if (in_array($display_type, $follow_display_types, true)) { $display_preferences['follow'] = true; } // save new values update_option($option_name, $display_preferences); } unset($option_name); unset($display_preferences); } }
/** * Sanitize social plugin button common settings before they are saved to the database * * @since 1.1 * * @uses Facebook_Social_Plugin_Settings::sanitize_options() * @param array $options social plugin button options * @return array clean option set */ public static function sanitize_options($options) { $clean_options = parent::sanitize_options($options); if (isset($options['position']) && in_array($options['position'], self::$position_choices, true)) { $clean_options['position'] = $options['position']; } else { $clean_options['position'] = 'both'; } return $clean_options; }
/** * Load post meta boxes for a given post type * * @since 1.1 * @param string $post_type the current page's post type */ public static function after_posts_load($post_type) { if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(dirname(dirname(__FILE__))) . '/settings-social-plugin.php'; } // only show mentions box if mentions displayed alongside posts $enabled_post_types = Facebook_Social_Plugin_Settings::get_display_conditionals_by_feature('mentions'); if (!is_array($enabled_post_types) || empty($enabled_post_types) || !isset($enabled_post_types[$post_type])) { return; } add_action('admin_enqueue_scripts', array('Facebook_Mentions_Box', 'enqueue_scripts')); if (!class_exists('Facebook_Mentions_Box_Friends')) { require_once dirname(__FILE__) . '/mentions-box-friends.php'; } Facebook_Mentions_Box_Friends::add_meta_box($post_type); if (!class_exists('Facebook_Mentions_Box_Pages')) { require_once dirname(__FILE__) . '/mentions-box-pages.php'; } Facebook_Mentions_Box_Pages::add_meta_box($post_type); }
/** * Choose a light or dark color scheme * * @since 1.1 * @param string $existing_value saved colorscheme value */ public function display_colorscheme($existing_value = 'light') { if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(dirname(dirname(__FILE__))) . '/admin/settings-social-plugin.php'; } $color_schemes = Facebook_Social_Plugin_Settings::color_scheme_choices($this->get_field_name('colorscheme'), $existing_value); if ($color_schemes) { echo '<fieldset id="' . $this->get_field_id('colorscheme') . '">' . esc_html(__('Color scheme', 'facebook')) . ': ' . $color_schemes . '</fieldset>'; } }
/** * Sanitize Comments Box settings before they are saved to the database * * @since 1.1 * @param array $options Comments Box options * @return array clean option sets. note: we remove Comments Box social plugin default options, storing only custom settings (e.g. dark color scheme stored, light is default and therefore not stored) */ public static function sanitize_options($options) { if (!is_array($options) || empty($options)) { return array(); } if (!class_exists('Facebook_Comments_Box')) { require_once dirname(dirname(__FILE__)) . '/social-plugins/class-facebook-comments-box.php'; } // Handle display preferences first $clean_options = parent::sanitize_options($options); if (isset($clean_options['show_on'])) { self::update_display_conditionals('comments', $clean_options['show_on'], self::post_types_supporting_comments()); if (empty($clean_options['show_on'])) { delete_option('facebook_comments_enabled'); } else { update_option('facebook_comments_enabled', '1'); } unset($clean_options['show_on']); } else { delete_option('facebook_comments_enabled'); } unset($options['show_on']); $comments_box = Facebook_Comments_Box::fromArray($options); if ($comments_box) { return array_merge($clean_options, self::html_data_to_options($comments_box->toHTMLDataArray())); } return $clean_options; }
/** * Which features are enabled for the site on each major view type? * * @since 1.1.6 * * @return void */ public static function enabled_features_by_view_type() { if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(__FILE__) . '/settings-social-plugin.php'; } $views = Facebook_Social_Plugin_Settings::get_show_on_choices('all'); if (!is_array($views) || empty($views)) { return; } echo '<section id="debug-social-plugins"><header><h3>' . esc_html(__('Social Plugins', 'facebook')) . '</h3></header>'; echo '<table><caption>' . esc_html(_x('Features enabled by view type', 'software features available based on different classifications website view', 'facebook')) . '</caption>'; $features = array('like' => array('name' => __('Like Button', 'facebook'), 'url' => 'https://developers.facebook.com/docs/reference/plugins/like/'), 'send' => array('name' => __('Send Button', 'facebook'), 'url' => 'https://developers.facebook.com/docs/reference/plugins/send/'), 'follow' => array('name' => __('Follow Button', 'facebook'), 'url' => 'https://developers.facebook.com/docs/reference/plugins/follow/'), 'recommendations_bar' => array('name' => __('Recommendations Bar', 'facebook'), 'url' => 'https://developers.facebook.com/docs/reference/plugins/recommendationsbar/'), 'comments' => array('name' => __('Comments Box', 'facebook'), 'url' => 'https://developers.facebook.com/docs/reference/plugins/comments/')); echo '<thead><tr><th>' . esc_html(__('View', 'facebook')) . '</th>'; foreach ($features as $slug => $properties) { echo '<th>'; if (isset($properties['url'])) { echo '<a href="' . esc_url($properties['url'], array('http', 'https')) . '">' . esc_html($properties['name']) . '</a>'; } else { echo esc_html($properties['name']); } echo '</th>'; } echo '</tr></thead><tbody>'; foreach ($views as $view) { echo '<tr><th>' . $view . '</th>'; $view_features = get_option('facebook_' . $view . '_features'); if (!is_array($view_features)) { $view_features = array(); } foreach ($features as $feature => $properties) { echo '<td>'; if (isset($view_features[$feature])) { echo self::EXISTS; } else { echo ' '; } echo '</td>'; } echo '</tr>'; } echo '</tbody></table>'; echo '</section>'; }
/** * Identify active features for debugging purposes or sent via a Facebook beacon * * @since 1.1 * * @global Facebook_Loader $facebook_loader Access Facebook application information * @param string $app_id Facebook application identifier * @return array { * debug information * * @type string parameter to include in debugger (typically as a URI query parameter) * @type string|array information about the current site installation * } */ public static function debug_output($app_id = '') { global $facebook_loader; $debug = array(); // Facebook application identifier if (!$app_id && isset($facebook_loader) && isset($facebook_loader->credentials['app_id'])) { $app_id = $facebook_loader->credentials['app_id']; } if ($app_id) { $debug['appid'] = $app_id; } // plugin version if (isset($facebook_loader)) { $debug['version'] = Facebook_Loader::VERSION; } // site domain $hostname = parse_url(site_url(), PHP_URL_HOST); if ($hostname) { $debug['domain'] = $hostname; } unset($hostname); // where are we running? if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(__FILE__) . '/settings-social-plugin.php'; } $enabled_features = array(); $views = Facebook_Social_Plugin_Settings::get_show_on_choices('all'); foreach ($views as $view) { $features = get_option('facebook_' . $view . '_features'); if (is_array($features) && !empty($features)) { $enabled_features[$view] = array_keys($features); } else { $enabled_features[$view] = false; } // show a potential target where nothing appears unset($features); } unset($views); if (!empty($enabled_features)) { $debug['features'] = $enabled_features; } unset($enabled_features); // active widgets $widgets = self::get_active_widgets(); if (!empty($widgets)) { $debug['widgets'] = $widgets; } return $debug; }
/** * Sanitize Recommendations Bar settings before they are saved to the database. * * @since 1.1 * * @param array $options recommendation bar options * @return array clean option sets. note: we remove Recommendation Button social plugin default options, storing only custom settings (e.g. recommend action preference value stored, like is not stored) */ public static function sanitize_options($options) { if (!is_array($options) || empty($options)) { return array(); } if (isset($options['trigger']) && $options['trigger'] === 'pct') { $pct = 0; if (isset($options['trigger_pct'])) { $pct = absint($options['trigger_pct']); unset($options['trigger_pct']); } if ($pct > 0) { $options['trigger'] = $pct . '%'; } else { $options['trigger'] = 'onvisible'; } } foreach (array('read_time', 'num_recommendations', 'max_age') as $option) { if (isset($options[$option])) { $options[$option] = absint($options[$option]); } } self::require_recommendations_bar_builder(); // Handle like button display preferences first $clean_options = parent::sanitize_options($options); if (isset($clean_options['show_on'])) { self::update_display_conditionals('recommendations_bar', $clean_options['show_on'], self::get_show_on_choices()); unset($clean_options['show_on']); } unset($options['show_on']); $bar = Facebook_Recommendations_Bar::fromArray($options); if ($bar) { return array_merge($clean_options, self::html_data_to_options($bar->toHTMLDataArray())); } return $clean_options; }
/** * Where should the button appear? * * @since 1.1 * @param array $extra_attributes custom form attributes */ public function display_mentions_show_on() { if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(__FILE__) . '/settings-social-plugin.php'; } echo '<fieldset id="facebook-mentions-show-on">' . Facebook_Social_Plugin_Settings::show_on_choices(self::MENTIONS_OPTION_NAME . '[show_on]', Facebook_Social_Plugin_Settings::get_display_conditionals_by_feature('mentions', 'all'), 'all') . '</fieldset>'; echo '<p>' . esc_html(Facebook_Social_Plugin_Settings::show_on_description(__('Social Mentions', 'facebook'))) . '</p>'; }
/** * Identify active features for debugging purposes or sent via a Facebook beacon * * @since 1.1 * @param string $app_id application identifier * @return array debug information */ public static function debug_output($app_id = '') { global $facebook_loader; if (!$app_id && isset($facebook_loader) && isset($facebook_loader->credentials['app_id'])) { $app_id = $facebook_loader->credentials['app_id']; } $debug = array(); if ($app_id) { $debug['appid'] = $app_id; } if (isset($facebook_loader)) { $debug['version'] = Facebook_Loader::VERSION; } $hostname = parse_url(site_url(), PHP_URL_HOST); if ($hostname) { $debug['domain'] = $hostname; } unset($hostname); // where are we running? if (!class_exists('Facebook_Social_Plugin_Settings')) { require_once dirname(__FILE__) . '/settings-social-plugin.php'; } $enabled_features = array(); $all_targets = Facebook_Social_Plugin_Settings::get_show_on_choices('all'); $option_name = 'facebook_%s_features'; foreach ($all_targets as $target) { $features = get_option(sprintf($option_name, $target)); if (is_array($features) && !empty($features)) { $enabled_features[$target] = $features; } else { $enabled_features[$target] = false; } // show a potential target where nothing appears unset($features); } unset($option_name); unset($all_targets); if (!empty($enabled_features)) { $debug['features'] = $enabled_features; } unset($enabled_features); $sidebar_widgets = wp_get_sidebars_widgets(); unset($sidebar_widgets['wp_inactive_widgets']); // no need to track inactives $sidebar_widgets = array_unique(array_merge(array_values($sidebar_widgets))); // track widgets, not sidebar names if (is_array($sidebar_widgets) && isset($sidebar_widgets[0])) { $sidebar_widgets = $sidebar_widgets[0]; $widgets = array(); // iterate through each sidebar configuration // note any facebook widgets we find along the way foreach ($sidebar_widgets as $widget_id) { if (strlen($widget_id) > 9 && substr_compare($widget_id, 'facebook-', 0, 9) === 0) { $feature = substr($widget_id, 9, strrpos($widget_id, '-') - 9); if (!isset($widgets[$feature])) { $widgets[$feature] = true; } unset($feature); } } if (!empty($widgets)) { $debug['widgets'] = array_keys($widgets); } unset($widgets); } return $debug; }