Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

version 1.1. new settings pages. custom post types. async JS. validat…

…ed social plugins + settings. more hooks
  • Loading branch information...
commit 2b1b3852c9e90ece6675dd69746d89953ef0afda 1 parent 079ead5
@niallkennedy niallkennedy authored
Showing with 8,286 additions and 4,417 deletions.
  1. +118 −0 admin/login.php
  2. +233 −0 admin/migrate-options-10.php
  3. +470 −0 admin/settings-app.php
  4. +329 −0 admin/settings-comments.php
  5. +571 −0 admin/settings-like-button.php
  6. +416 −0 admin/settings-recommendations-bar.php
  7. +310 −0 admin/settings-send-button.php
  8. +69 −0 admin/settings-social-plugin-button.php
  9. +255 −0 admin/settings-social-plugin.php
  10. +495 −0 admin/settings-social-publisher.php
  11. +488 −0 admin/settings-subscribe-button.php
  12. +348 −0 admin/settings.php
  13. +194 −0 admin/social-publisher/mentions/mentions-box-friends.php
  14. +195 −0 admin/social-publisher/mentions/mentions-box-pages.php
  15. +90 −0 admin/social-publisher/mentions/mentions-box.php
  16. +220 −0 admin/social-publisher/mentions/mentions-search.php
  17. +101 −0 admin/social-publisher/publish-box-page.php
  18. +100 −0 admin/social-publisher/publish-box-profile.php
  19. +838 −0 admin/social-publisher/social-publisher.php
  20. +18 −0 channel.php
  21. +0 −149 conflicting-plugins.php
  22. +161 −0 facebook-user.php
  23. +342 −22 facebook.php
  24. +0 −488 fb-admin-menu.php
  25. +0 −247 fb-core.php
  26. +0 −79 fb-login.php
  27. +0 −169 fb-open-graph.php
  28. +0 −424 fb-social-publisher-mentioning.php
  29. +0 −693 fb-social-publisher.php
  30. +0 −334 fb-wp-helpers.php
  31. BIN  images/nux_app_settings.png
  32. BIN  images/nux_create_app.png
  33. BIN  images/settings_comments.png
  34. BIN  images/settings_like_button.png
  35. BIN  images/settings_recommendations_bar.png
  36. BIN  images/settings_send_button.png
  37. BIN  images/settings_social_publisher.png
  38. BIN  images/settings_subscribe_button.png
  39. +33 −33 includes/facebook-php-sdk/class-facebook-wp.php
  40. 0  {lang → }/index.php
  41. +2 −0  languages/index.php
  42. +246 −0 open-graph-protocol.php
  43. +69 −39 readme.txt
  44. +0 −128 scripts/fb-admin.dev.js
  45. +0 −1  scripts/fb-admin.js
  46. +0 −1  scripts/loopj-jquery-tokeninput/jquery.tokeninput.js
  47. +26 −26 social-plugins/class-facebook-activity-feed.php
  48. +20 −20 social-plugins/class-facebook-comments-box.php
  49. +32 −32 social-plugins/class-facebook-comments.php
  50. +32 −32 social-plugins/class-facebook-like-button.php
  51. +36 −36 social-plugins/class-facebook-recommendations-bar.php
  52. +41 −41 social-plugins/class-facebook-recommendations-box.php
  53. +12 −12 social-plugins/class-facebook-send-button.php
  54. +31 −22 social-plugins/class-facebook-social-plugin.php
  55. +25 −25 social-plugins/class-facebook-subscribe-button.php
  56. +0 −99 social-plugins/fb-activity-feed.php
  57. +0 −67 social-plugins/fb-comments.php
  58. +0 −199 social-plugins/fb-like.php
  59. +0 −104 social-plugins/fb-recommendations-bar.php
  60. +0 −93 social-plugins/fb-recommendations.php
  61. +0 −146 social-plugins/fb-send.php
  62. +0 −299 social-plugins/fb-social-plugins.php
  63. +0 −176 social-plugins/fb-subscribe.php
  64. +248 −0 social-plugins/social-plugins.php
  65. +200 −17 social-plugins/widgets/activity-feed.php
  66. +125 −15 social-plugins/widgets/like-button.php
  67. +179 −17 social-plugins/widgets/recommendations-box.php
  68. +79 −14 social-plugins/widgets/send-button.php
  69. +102 −16 social-plugins/widgets/subscribe-button.php
  70. +67 −0 social-publisher/mentions.php
  71. +31 −0 static/css/admin/icons.css
  72. +1 −0  static/css/admin/icons.min.css
  73. +51 −0 style/tipsy.css → static/css/admin/mentions.css
  74. +1 −1  style/tipsy.min.css → static/css/admin/mentions.min.css
  75. 0  {style → static/css}/hide-wp-comments.css
  76. 0  {style → static/css}/hide-wp-comments.min.css
  77. +1 −2  {style → static/css}/style.css
  78. 0  {style → static/css}/style.min.css
  79. BIN  static/img/create-app.png
  80. BIN  static/img/icon-2x.png
  81. BIN  static/img/icon-bw-2x.png
  82. 0  {images → static/img}/icon-bw.png
  83. 0  {images → static/img}/icon.png
  84. 0  {images → static/img}/logo.png
  85. 0  {scripts → static/js/admin}/jquery.tipsy.dev.js
  86. 0  {scripts → static/js/admin}/jquery.tipsy.js
  87. +73 −0 static/js/admin/login.dev.js
  88. +1 −0  static/js/admin/login.js
  89. +17 −9 {scripts → static/js/admin}/loopj-jquery-tokeninput/jquery.tokeninput.dev.js
  90. +1 −0  static/js/admin/loopj-jquery-tokeninput/jquery.tokeninput.js
  91. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input-facebook.css
  92. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input-facebook.min.css
  93. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input-mac.css
  94. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input-mac.min.css
  95. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input.css
  96. 0  {scripts → static/js/admin}/loopj-jquery-tokeninput/styles/token-input.min.css
  97. +97 −0 static/js/admin/mentions.dev.js
  98. +1 −0  static/js/admin/mentions.js
  99. +15 −0 static/js/admin/settings-app.dev.js
  100. +1 −0  static/js/admin/settings-app.js
  101. +0 −85 style/style-admin.css
  102. +0 −1  style/style-admin.min.css
  103. +29 −4 uninstall.php
View
118 admin/login.php
@@ -0,0 +1,118 @@
+<?php
+
+/**
+ * Encourage WordPress users to associate their account with a Facebook profile
+ *
+ * @since 1.1
+ */
+class Facebook_Admin_Login {
+ /**
+ * 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 ( ! in_array( $permission_to_verify, $permissions, true ) ) {
+ $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', 'Facebook_Admin_Login::add_async_load_javascript_filter', -1, 0 );
+ // add all others at P11 after scripts registered
+ add_action( 'admin_enqueue_scripts', 'Facebook_Admin_Login::enqueue_scripts', 11 );
+
+ if ( $profile_prompt )
+ add_action( 'admin_notices', 'Facebook_Admin_Login::admin_notice', 1, 0 ); // up top
+ }
+
+ /**
+ * Prompt current user to associate his or her WordPress account with a Facebook profile
+ *
+ * @since 1.1
+ */
+ public static function admin_notice() {
+ // prompt user to associate his or her WordPress account with a Facebook account
+ echo '<div class="updated"><p>';
+ echo sprintf( esc_html( __( '%s to publish new posts to your Facebook timeline.', 'facebook' ) ), '<span class="facebook-login" data-scope="person" style="font-weight:bold">' . esc_html( __( 'Associate your WordPress account with a Facebook profile', 'facebook' ) ) . '</span>' );
+ echo '</p></div>';
+ }
+
+ public static function add_async_load_javascript_filter() {
+ // async load our script after we async load Facebook JavaScript SDK
+ add_filter( 'facebook_jssdk_init_extras', 'Facebook_Admin_Login::async_load_javascript', 10, 2 );
+ }
+
+ /**
+ * Load support for Facebook JavaScript SDK and FB.login
+ *
+ * @since 1.1
+ */
+ public static function enqueue_scripts() {
+ wp_enqueue_script( 'jquery' ); // should already be enqueued in wp-admin
+ wp_enqueue_script( 'facebook-jssdk' );
+ }
+
+ /**
+ * add JavaScript code to the fbAsyncInit function run after Facebook JavaScript SDK has loaded.
+ *
+ * @since 1.1
+ * @return string JavaScript code to be appended to the fbAsyncInit function
+ */
+ public static function async_load_javascript( $js_block = '', $app_id = '' ) {
+ return $js_block . 'jQuery.ajax({url:' . json_encode( plugins_url( 'static/js/admin/login' . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '' ) . '.js', dirname(__FILE__) ) ) . ',cache:true,dataType:"script"}).success(function(){FB_WP.admin.login.attach_events();});';
+ }
+}
+?>
View
233 admin/migrate-options-10.php
@@ -0,0 +1,233 @@
+<?php
+/**
+ * Migrate settings from the fb_options structure of plugin version 1.0.* to the multiple options of plugin version 1.1+
+ *
+ * @since 1.1
+ */
+class Facebook_Migrate_Options_10 {
+ /**
+ * Convert old show_on choices to new show_on array
+ *
+ * @since 1.1
+ * @param array $options existing feature options
+ * @return array show_on post type array
+ */
+ public static function show_on( $options ) {
+ $show_on = array();
+
+ if ( ! isset( $options['enabled'] ) ) {
+ $options['show_on'] = array();
+ return $options;
+ }
+
+ if ( isset( $options['show_on'] ) ) {
+ if ( $options['show_on'] === 'all posts and pages' )
+ $show_on = array( 'post', 'page' );
+ else if ( $options['show_on'] === 'all posts' )
+ $show_on = array( 'post' );
+ else if ( $options['show_on'] === 'all pages' )
+ $show_on = array( 'page' );
+ }
+ if ( isset( $options['show_on_homepage'] ) ) {
+ $show_on[] = 'home';
+ unset( $options['show_on_homepage'] );
+ }
+
+ if ( empty( $show_on ) )
+ unset( $options['show_on'] );
+ else
+ $options['show_on'] = $show_on;
+
+ return $options;
+ }
+
+ /**
+ * migrate options from Facebook plugin 1.0 style to 1.1
+ *
+ * @since 1.1
+ */
+ public static function migrate() {
+ $old_options = get_option( 'fb_options' );
+ if ( ! is_array( $old_options ) || empty( $old_options ) )
+ return;
+
+ $app_settings = array();
+ foreach( array( 'app_id', 'app_secret', 'app_namespace' ) as $option_name ) {
+ if ( isset( $old_options[$option_name] ) )
+ $app_settings[$option_name] = trim( $old_options[$option_name] );
+ }
+ if ( ! empty( $app_settings ) ) {
+ if ( ! class_exists( 'Facebook_Application_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-app.php' );
+
+ $app_settings = Facebook_Application_Settings::sanitize_options( $app_settings );
+ if ( ! empty( $app_settings ) )
+ update_option( Facebook_Application_Settings::OPTION_NAME, $app_settings );
+ }
+ unset( $app_settings );
+
+ if ( isset( $old_options['comments'] ) )
+ self::migrate_comments( $old_options['comments'] );
+ if ( isset( $old_options['like'] ) )
+ self::migrate_like_button( $old_options['like'] );
+ if ( isset( $old_options['recommendations_bar'] ) )
+ self::migrate_recommendations_bar( $old_options['recommendations_bar'] );
+ if ( isset( $old_options['send'] ) )
+ self::migrate_send_button( $old_options['send'] );
+ if ( isset( $old_options['social_publisher'] ) )
+ self::migrate_social_publisher( $old_options['social_publisher'] );
+ if ( isset( $old_options['subscribe'] ) )
+ self::migrate_subscribe_button( $old_options['subscribe'] );
+ }
+
+ /**
+ * Migrate comments-specific settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_comments( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ $options = self::show_on( $options );
+
+ // pass comments settings through same sanitizer as individual settings page
+ if ( ! class_exists( 'Facebook_Comments_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-comments.php' );
+ $options = Facebook_Comments_Settings::sanitize_options( $options );
+ if ( ! empty( $options ) )
+ return update_option( Facebook_Comments_Settings::OPTION_NAME, $options );
+ }
+
+ /**
+ * Migrate like button settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_like_button( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ $options = self::show_on( $options );
+
+ // pass like button settings through same sanitizer as individual settings page
+ if ( ! class_exists( 'Facebook_Like_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-like-button.php' );
+
+ $options = Facebook_Like_Button_Settings::sanitize_options( $options );
+ if ( ! empty( $options ) )
+ return update_option( Facebook_Like_Button_Settings::OPTION_NAME, $options );
+ }
+
+ /**
+ * Migrate recommendations bar settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_recommendations_bar( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ if ( isset( $options['trigger'] ) ) {
+ $trigger_pct = absint( $options['trigger'] );
+ if ( $trigger_pct > 0 ) {
+ $options['trigger'] = 'pct';
+ $options['trigger_pct'] = $trigger_pct;
+ } else {
+ unset( $options['trigger'] );
+ }
+ unset( $trigger_pct );
+ }
+
+ // pass like button settings through same sanitizer as individual settings page
+ if ( ! class_exists( 'Facebook_Recommendations_Bar_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-recommendations-bar.php' );
+ $options = Facebook_Recommendations_Bar_Settings::sanitize_options( $options );
+ if ( ! empty( $options ) )
+ return update_option( Facebook_Recommendations_Bar_Settings::OPTION_NAME, $options );
+ }
+
+ /**
+ * Migrate send button settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_send_button( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ $options = self::show_on( $options );
+
+ if ( ! class_exists( 'Facebook_Send_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-send-button.php' );
+ $options = Facebook_Send_Button_Settings::sanitize_options( $options );
+ if ( ! empty( $options ) )
+ return update_option( Facebook_Send_Button_Settings::OPTION_NAME, $options );
+ }
+
+ /**
+ * Migrate social publisher settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_social_publisher( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ $mentions = array( 'show_on' => array( 'post', 'page' ), 'position' => 'both' );
+ if ( isset( $options['mentions_position'] ) )
+ $mentions['position'] = $options['mentions_position'];
+ if ( isset( $options['show_on_homepage'] ) )
+ $mentions['show_on'][] = 'home';
+
+ if ( ! class_exists( 'Facebook_Social_Publisher_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-social-publisher.php' );
+
+ $mentions = Facebook_Social_Publisher_Settings::sanitize_mentions_options( $mentions );
+ if ( ! empty( $mentions ) )
+ update_option( Facebook_Social_Publisher_Settings::MENTIONS_OPTION_NAME, $mentions );
+
+ // publish to fan page info
+ if ( isset( $options['publish_to_fan_page'] ) && $options['publish_to_fan_page'] !== 'disabled' ) {
+ preg_match_all( "/(.*?)@@!!(.*?)@@!!(.*?)$/su", $options['publish_to_fan_page'], $fan_page_info, PREG_SET_ORDER );
+ if ( isset( $fan_page_info ) && isset( $fan_page_info[0] ) && is_array( $fan_page_info[0] ) && ! empty( $fan_page_info[0][1] ) && ! empty( $fan_page_info[0][2] ) && ! empty( $fan_page_info[0][3] ) ) {
+ Facebook_Social_Publisher_Settings::update_publish_to_page( array(
+ 'access_token' => $fan_page_info[0][3],
+ 'id' => $fan_page_info[0][2],
+ 'name' => $fan_page_info[0][1]
+ ) );
+ }
+ }
+ }
+
+ /**
+ * Migrate subscribe button settings
+ *
+ * @since 1.1
+ * @param array $options existing settings
+ * @return result of update_option, if run
+ */
+ public static function migrate_subscribe_button( $options ) {
+ if ( ! is_array( $options ) || empty( $options ) )
+ return;
+
+ $options = self::show_on( $options );
+
+ if ( ! class_exists( 'Facebook_Subscribe_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-subscribe-button.php' );
+ $options = Facebook_Subscribe_Button_Settings::sanitize_options( $options );
+ if ( ! empty( $options ) )
+ return update_option( Facebook_Subscribe_Button_Settings::OPTION_NAME, $options );
+ }
+}
+?>
View
470 admin/settings-app.php
@@ -0,0 +1,470 @@
+<?php
+
+class Facebook_Application_Settings {
+ /**
+ * Settings page identifier
+ *
+ * @since 1.1
+ * @var string
+ */
+ const PAGE_SLUG = 'facebook-application-settings';
+
+ /**
+ * Define our option array value
+ *
+ * @since 1.1
+ * @var string
+ */
+ const OPTION_NAME = 'facebook_application';
+
+ /**
+ * Initialize with an options array
+ *
+ * @since 1.1
+ * @param array $options existing options
+ * @param string $hook_suffix (optional) page slug. used to build settings fields
+ */
+ public function __construct( $options = array() ) {
+ if ( is_array( $options ) && ! empty( $options ) )
+ $this->existing_options = $options;
+ else
+ $this->existing_options = array();
+ }
+
+ /**
+ * Add a menu item to WordPress admin
+ *
+ * @since 1.1
+ * @uses add_utility_page()
+ * @return string page hook
+ */
+ public static function menu_item() {
+ $app_settings = new Facebook_Application_Settings();
+
+ $hook_suffix = add_utility_page(
+ sprintf( __( '%s Plugin Settings', 'facebook' ), 'Facebook' ), // page <title>
+ 'Facebook', // menu title
+ 'manage_options', // capability needed
+ self::PAGE_SLUG, // what should I call you?
+ array( &$app_settings, 'settings_page' ), // pageload callback
+ plugins_url( 'static/img/icon-bw.png', dirname(__FILE__) ) // icon make pretty
+ );
+
+ // conditional load CSS, scripts
+ if ( $hook_suffix ) {
+ $app_settings->hook_suffix = $hook_suffix;
+ register_setting( $hook_suffix, self::OPTION_NAME, 'Facebook_Application_Settings::sanitize_options' );
+ add_action( 'load-' . $hook_suffix, array( &$app_settings, 'onload' ) );
+ }
+
+ return $hook_suffix;
+ }
+
+ /**
+ * Load stored options and scripts on settings page view
+ *
+ * @since 1.1
+ */
+ public function onload() {
+ $options = get_option( self::OPTION_NAME );
+ if ( ! is_array( $options ) )
+ $options = array();
+ $this->existing_options = $options;
+
+ $this->settings_api_init();
+
+ add_action( 'admin_enqueue_scripts', 'Facebook_Application_Settings::enqueue_scripts' );
+ }
+
+ /**
+ * Load the settings page
+ *
+ * @since 1.1
+ */
+ public function settings_page() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ // notify of conflicts on the main settings page
+ // tie to an action to allow easy removal on sites/networks that rather not run checks
+ add_action( 'facebook_notify_plugin_conflicts', 'Facebook_Settings::plugin_conflicts' );
+
+ add_action( 'facebook_settings_before_header_' . $this->hook_suffix, 'Facebook_Application_Settings::before_header' );
+ add_action( 'facebook_settings_after_header_' . $this->hook_suffix, 'Facebook_Application_Settings::after_header' );
+
+ Facebook_Settings::settings_page_template( $this->hook_suffix, __( 'Facebook for WordPress', 'facebook' ) );
+ }
+
+ /**
+ * Enhance settings page with JavaScript
+ *
+ * @since 1.1
+ * @uses wp_enqueue_script()
+ */
+ public function enqueue_scripts() {
+ wp_enqueue_script( 'facebook-jssdk' );
+ wp_enqueue_script( self::PAGE_SLUG, plugins_url( 'static/js/admin/settings-app' . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.dev' : '' ) . '.js', dirname(__FILE__) ), array( 'jquery' ), '1.1', true );
+ }
+
+ /**
+ * Add Facebook logo before the header
+ *
+ * @since 1.1
+ */
+ public static function before_header() {
+ echo '<div class="facebook-logo"></div>'; // display facebook Logo before text
+ }
+
+ /**
+ * Facebook Like Button after header
+ *
+ * @since 1.1
+ */
+ public static function after_header() {
+ if ( ! class_exists( 'Facebook_Like_Button' ) )
+ require_once( dirname( dirname(__FILE__) ) . '/social-plugins/class-facebook-like-button.php' );
+
+ // promote Facebook for WordPress page on Facebook Developers site
+ $like_button = new Facebook_Like_Button(false);
+ $like_button->setURL( 'http://developers.facebook.com/wordpress/' );
+ $like_button->setLayout( 'button_count' );
+ $like_button->includeSendButton();
+ $like_button->setFont( 'arial' );
+ $like_button->setReference( 'wp-admin' );
+ echo $like_button->asHTML();
+
+ do_action( 'facebook_notify_plugin_conflicts' );
+ }
+
+ /**
+ * Hook into the settings API
+ *
+ * @since 1.1
+ * @uses add_settings_section()
+ * @uses add_settings_field()
+ */
+ private function settings_api_init() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ // Facebook application settings
+ $section = 'facebook-app';
+ add_settings_section(
+ $section,
+ __( 'Application information', 'facebook' ),
+ array( &$this, 'section_header' ),
+ $this->hook_suffix
+ );
+
+ $app_abbr = '<abbr title="' . esc_attr( _x( 'application', 'computer application or program', 'facebook' ) ) . '">' . esc_html( _x( 'App', 'application', 'facebook' ) ) . '</abbr>';
+
+ add_settings_field(
+ 'facebook-app-id',
+ sprintf( __( '%s ID', 'facebook' ), $app_abbr ),
+ array( &$this, 'display_app_id' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-app-id' )
+ );
+ add_settings_field(
+ 'facebook-app-secret',
+ sprintf( __( '%s secret', 'facebook' ), $app_abbr ),
+ array( &$this, 'display_app_secret' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-app-secret' )
+ );
+ add_settings_field(
+ 'facebook-app-namespace',
+ sprintf( __( '%s namespace', 'facebook' ), $app_abbr ),
+ array( &$this, 'display_app_namespace' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-app-namespace' )
+ );
+
+ $this->inline_help_content();
+ }
+
+ /**
+ * Introduction to the application settings section
+ *
+ * @since 1.1
+ */
+ public function section_header() {
+ global $facebook;
+
+ if ( isset( $facebook ) && $facebook ) {
+ if ( isset( $this->existing_options['app_id'] ) && $this->existing_options['app_id'] ) {
+ echo '<p><a href="' . esc_url( 'https://developers.facebook.com/apps/' . $this->existing_options['app_id'] ) . '">' . esc_html( __( 'Edit your application settings on Facebook', 'facebook' ) ) . '</a></p>';
+ }
+ } else {
+ echo '<p><a href="https://developers.facebook.com/apps/">' . esc_html( sprintf( __( 'Create a new Facebook application or associate %s with an existing Facebook application.', 'facebook' ), get_bloginfo( 'name' ) ) ) . '</a></p>';
+ }
+ }
+
+ /**
+ * Display the application ID input field
+ *
+ * @since 1.1
+ */
+ public function display_app_id() {
+ $key = 'app_id';
+
+ if ( isset( $this->existing_options[$key] ) && $this->existing_options[$key] )
+ $existing_value = $this->existing_options[$key];
+ else
+ $existing_value = '';
+
+ $id = 'facebook-app-id';
+ settings_errors( $id );
+ echo '<input type="text" name="' . self::OPTION_NAME . '[' . $key . ']" id="' . $id . '"';
+ if ( $existing_value )
+ echo ' value="' . esc_attr( $existing_value ) . '"';
+ echo ' maxlength="32" size="40" autocomplete="off" pattern="[0-9]+" />';
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'An application identifier associates your site, its pages, and visitor actions with a registered %s application.', 'facebook' ), 'Facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Display the Facebook application secret input field
+ *
+ * @since 1.1
+ */
+ public function display_app_secret() {
+ $key = 'app_secret';
+
+ if ( isset( $this->existing_options[$key] ) && $this->existing_options[$key] )
+ $existing_value = $this->existing_options[$key];
+ else
+ $existing_value = '';
+
+ $id = 'facebook-app-secret';
+ settings_errors( $id );
+ echo '<input type="text" name="' . self::OPTION_NAME . '[' . $key . ']" id="' . $id . '"';
+ if ( $existing_value )
+ echo ' value="' . esc_attr( $existing_value ) . '"';
+ echo ' size="40" autocomplete="off" pattern="[0-9a-f]+" />';
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'An application secret is a secret shared between %s and your application, similar to a password.', 'facebook' ), 'Facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Display the Facebook application namespace input field
+ *
+ * @since 1.1
+ */
+ public function display_app_namespace() {
+ $key = 'app_namespace';
+
+ if ( isset( $this->existing_options[$key] ) && $this->existing_options[$key] )
+ $existing_value = $this->existing_options[$key];
+ else
+ $existing_value = '';
+
+ $id = 'facebook-app-namespace';
+ settings_errors( $id );
+ echo '<input type="text" name="' . self::OPTION_NAME . '[' . $key . ']" id="' . $id . '"';
+ if ( $existing_value )
+ echo ' value="' . esc_attr( $existing_value ) . '"';
+ echo ' size="40" autocomplete="off" pattern="[a-z\-\_]{3,25}" />';
+
+ echo '<p class="description">' . esc_html( __( 'An application namespace allows your website to define custom Open Graph objects and actions. It is an advanced and optional feature.', 'facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Clean user inputs before saving to database
+ *
+ * @since 1.1
+ * @param array $options form options values
+ */
+ public static function sanitize_options( $options ) {
+ // start fresh
+ $clean_options = array();
+
+ if ( isset( $options['app_id'] ) ) {
+ // leading spaces is a common copy-paste mistake
+ $app_id = trim( $options['app_id'] );
+ if ( $app_id ) {
+ // digit characters only
+ // better to reject a known bad value than remove its bad characters & save bad value
+ if ( function_exists( 'ctype_digit' ) ) { // ctype might not always be present
+ if ( ctype_digit( $app_id ) )
+ $clean_options['app_id'] = $app_id;
+ } else if ( preg_match( '/^[0-9]+$/', $app_id ) ) {
+ $clean_options['app_id'] = $app_id;
+ } else {
+ add_settings_error( 'facebook-app-id', 'facebook-app-id-error', __( 'App ID must contain only digits.', 'facebook' ) );
+ }
+ }
+ unset( $app_id );
+ }
+
+ if ( isset( $options['app_secret'] ) ) {
+ $app_secret = strtolower( trim( $options['app_secret'] ) );
+ if ( $app_secret ) {
+ if ( preg_match( '/^[0-9a-f]+$/', $app_secret ) ) // hex
+ $clean_options['app_secret'] = $app_secret;
+ else
+ add_settings_error( 'facebook-app-secret', 'facebook-app-secret-error', __( 'Invalid app secret.', 'facebook' ) );
+ }
+ unset( $app_secret );
+ }
+
+ if ( isset( $options['app_namespace'] ) ) {
+ $app_ns = strtolower( trim( $options['app_namespace'] ) );
+ if ( $app_ns ) {
+ if ( preg_match( '/^[a-z\-\_]{3,25}$/', $app_ns ) )
+ $clean_options['app_namespace'] = $app_ns;
+ else
+ add_settings_error( 'facebook-app-namespace', 'facebook-app-namespace-error', __( 'Invalid namespace.', 'facebook' ) );
+ }
+ unset( $app_ns );
+ }
+
+ return $clean_options;
+ }
+
+ /**
+ * Display helpful information about setting up a new application
+ *
+ * @since 1.1
+ * @return string HTML content
+ */
+ public static function help_tab_new_app() {
+ $content = '<p>' . sprintf ( esc_html( __( '%1$s to take advantage of advantage of advanced %2$s features such as post to timeline, recommendations bar, and more.', 'facebook' ) ), '<a href="https://developers.facebook.com/apps/">' . __( 'Register for a Facebook application', 'facebook' ) . '</a>', 'Facebook' ) . ' ' . esc_html( sprintf( __( 'You may need to register your %1$s account as a developer account if this is your first time managing a %1$s application.', 'facebook' ), 'Facebook' ) ) . '</p>';
+
+ $content .= '<p>' . sprintf( esc_html( __( 'Click the %s button near the top right corner of the page to trigger an application creation dialog.', 'facebook' ) ), '<span style="background-color:#EEE;border:1px solid #999;color:#333;font-family:\'lucinda grande\',tahoma,verdana,arial,sans-serif;font-size:11px;font-weight:bold;line-height:13px;margin:0;padding-top:1px;padding-right:0;padding-bottom:2px;padding-left:0;text-align:center;white-space:nowrap;">+ Create New App</span>' ) . '</p>';
+
+ $content .= '<div style="text-align:center"><img alt="' . esc_attr( sprintf( __( '%s new application creation dialog', 'facebook' ), 'Facebook' ) ) . '" src="' . plugins_url( 'static/img/create-app.png', dirname(__FILE__) ) . '" width="610" height="179" /></div>';
+
+ $content .= '<p>' . sprintf( esc_html( __( 'Uniquely identify your site on %1$s with an application name.', 'facebook' ) ), 'Facebook' );
+ $site_name = get_bloginfo( 'name' );
+ if ( $site_name ) {
+ $content .= ' ';
+ $site_name_length = strlen( $site_name );
+ $min_length = 3;
+ $max_length = 32;
+ if ( $site_name_length < $min_length ) {
+ $content .= esc_html( sprintf( __( 'You must choose an application name longer than "%s."', 'facebook' ), $site_name ) );
+ $content .= ' ' . esc_html( sprintf( __( 'An application name must be between %1$u and %2$u characters in length.', 'facebook' ), $min_length, $max_length ) );
+ } else if ( $site_name_length > 32 ) {
+ $content .= esc_html( sprintf( __( 'You must choose an application name shorter than "%s."','facebook' ), $site_name ) );
+ $content .= ' ' . esc_html( sprintf( __( 'An application name must be between %1$u and %2$u characters in length.', 'facebook' ), $min_length, $max_length ) );
+ } else {
+ $content .= esc_html( sprintf( __( 'You may choose to use "%1$s" as your %2$s application name.', 'facebook' ), $site_name, 'Facebook' ) );
+ }
+ }
+ $content .= '</p>';
+ return $content;
+ }
+
+ /**
+ * Display helpful information about retrieving application credentials from Facebook Developers site
+ *
+ * @since 1.1
+ * @return string HTML content
+ */
+ public static function help_tab_existing_app() {
+ $content = '<ol>';
+ $content .= '<li>';
+ $content .= sprintf(
+ esc_html( _x( 'Open the %s.', 'open the link to Facebook Developers dashboard site.', 'facebook' ) ),
+ '<a href="https://developers.facebook.com/apps?view=all_apps">' . esc_html( __( 'Facebook Developers Applications dashboard', 'facebook' ) ) . '</a>'
+ );
+ $content .= '</li>';
+ $content .= '<li>' . esc_html( __( 'Select your existing application from the list of applications', 'facebook' ) ) . '</li>';
+ $content .= '<li>' . esc_html( __( 'Copy your App ID, App Secret, and App Namespace from the Settings Summary section of your application.', 'facebook' ) ) . '</li>';
+ $content .= '</ol>';
+
+ return $content;
+ }
+
+ /**
+ * Help applications associate basic data with their Facebook application
+ *
+ * @since 1.1
+ * @return string HTML content
+ */
+ public static function help_tab_edit_app( $app_id = '' ) {
+ if ( $app_id ) {
+ $app_base_link = esc_url( 'https://developers.facebook.com/apps/' . $app_id . '/', array( 'https' ) );
+ $app_link = '<a href="' . $app_base_link . 'summary' . '">' . esc_html( __( 'Facebook application', 'facebook' ) ) . '</a>';
+ } else {
+ $app_base_link = '';
+ $app_link = '<a href="https://developers.facebook.com/apps/">' . esc_html( __( 'new Facebook application', 'facebook' ) ) . '</a>';
+ }
+
+ $site_url = site_url( '/' );
+
+ $content = '<p>' . sprintf( esc_html( __( 'Your %1$s should be associated with %2$s across desktop web, mobile web, iPhone, Android, or any other presence you have established.', 'facebook' ) ), $app_link, '<a href="' . esc_url( $site_url ) . '">' . esc_html( get_bloginfo( 'name' ) ) . '</a>' );
+ $content .= ' ' . esc_html( __( 'Facebook can send site visitors to the most appropriate URL based on their browsing context, market your site, and properly identify quality content with some extra information for your application.', 'facebook' ) );
+ $content .= '</p>';
+ unset( $app_link );
+
+ // Basic Settings screen
+ $content .= '<section id="facebook-application-details-help-basic"><header><h3>' . esc_html( __( 'Basic Settings', 'facebook' ) ) . '</h3></header>';
+ $content .= '<p>' . sprintf( esc_html( __( 'Associate your Facebook application with a domain, a desktop URL, and a mobile URL through your application\'s %s.', 'facebook' ) ), $app_base_link ? '<a href="' . $app_base_link . '">' . esc_html( __( 'basic settings', 'facebook' ) ) . '</a>' : esc_html( __( 'basic settings', 'facebook' ) ) ) . '</p>';
+ $content .= '<p>' . __( 'For example:', 'facebook' ) . '</p>';
+
+ $content .= '<table style="min-width:50%"><thead><tr><th>' . esc_html( _x( 'Field', 'data entry field', 'facebook' ) ) . '</th><th>' . esc_html( _x( 'Value', 'data entry value', 'facebook' ) ) . '</th></tr></thead><tbody>';
+
+ $user = wp_get_current_user();
+ if ( $user && isset( $user->user_email ) )
+ $content .= '<tr><th>' . esc_html( __( 'Contact Email', 'facebook' ) ) . '</th><td>' . esc_html( $user->user_email ) . '</td></tr>';
+
+ $content .= '<tr><th>' . esc_html( __( 'App Domains', 'facebook' ) ) . '</th><td>' . esc_html( parse_url( $site_url, PHP_URL_HOST ) ) . '</td></tr>';
+ $content .= '<tr><th>' . esc_html( __( 'Website with Facebook Login', 'facebook' ) ) . '</th><td>' . esc_html( $site_url ) . '</td></tr>';
+ $content .= '<tr><th>' . esc_html( __( 'Mobile website', 'facebook' ) ) . '</th><td>' . esc_html( $site_url ) . '</td></tr>';
+
+ $content .= '</tbody></table></section>';
+
+ // App Details
+ $content .= '<section id="facebook-application-details-help-details"><header><h3>' . esc_html( __( 'App Details', 'facebook' ) ) . '</h3></header>';
+ $content .= '<p>';
+ $content .= esc_html( __( 'Set your primary language, site description, and categorize your site.', 'facebook' ) ) . ' ';
+ $content .= esc_html( __( 'Add icons and images to establish trust when asking your publishers for publish permissions or marketing your site through Facebook.', 'facebook' ) );
+ $content .= '</p>';
+ $content .= '</section>';
+
+ return $content;
+ }
+
+ /**
+ * Display help content on the settings page
+ *
+ * @since 1.1
+ */
+ private function inline_help_content() {
+ $screen = get_current_screen();
+ if ( ! $screen ) // null if global not set
+ return;
+
+ $app_id = empty( $this->existing_options['app_id'] ) ? '' : $this->existing_options['app_id'];
+
+ if ( ! $app_id || empty( $this->existing_options['app_secret'] ) ) {
+ $app_id = '';
+ $screen->add_help_tab( array(
+ 'id' => 'facebook-new-app-help',
+ 'title' => sprintf( __( 'Create a %s application', 'facebook' ), 'Facebook' ),
+ 'content' => self::help_tab_new_app()
+ ) );
+ } else {
+ $screen->add_help_tab( array(
+ 'id' => 'facebook-existing-app-help',
+ 'title' => sprintf( __( 'Existing %s application', 'facebook' ), 'Facebook' ),
+ 'content' => self::help_tab_existing_app()
+ ) );
+ }
+
+ $screen->add_help_tab( array(
+ 'id' => 'facebook-application-details-help',
+ 'title' => __( 'Application details', 'facebook' ),
+ 'content' => self::help_tab_edit_app( $app_id )
+ ) );
+
+ $screen->set_help_sidebar( '<p><a href="https://developers.facebook.com/apps/">' . esc_html( sprintf( __( '%s Apps Tool', 'facebook' ), 'Facebook' ) ) . '</a></p>' );
+ }
+}
+
+?>
View
329 admin/settings-comments.php
@@ -0,0 +1,329 @@
+<?php
+
+if ( ! class_exists( 'Facebook_Social_Plugin_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-social-plugin.php' );
+
+class Facebook_Comments_Settings extends Facebook_Social_Plugin_Settings {
+
+ /**
+ * Setting page identifier
+ *
+ * @since 1.1
+ * @var string
+ */
+ const PAGE_SLUG = 'facebook-comments';
+
+ /**
+ * Define our option array value
+ *
+ * @since 1.1
+ * @var string
+ */
+ const OPTION_NAME = 'facebook_comments';
+
+ /**
+ * Initialize with an options array
+ *
+ * @since 1.1
+ * @param array $options existing options
+ */
+ public function __construct( $options = array() ) {
+ if ( is_array( $options ) && ! empty( $options ) )
+ $this->existing_options = $options;
+ else
+ $this->existing_options = array();
+
+ $this->supporting_post_types = self::post_types_supporting_comments();
+ }
+
+ /**
+ * Reference the social plugin by name
+ *
+ * @since 1.1
+ * @return string social plugin name
+ */
+ public static function social_plugin_name() {
+ return __( 'Comments Box', 'facebook' );
+ }
+
+ /**
+ * Navigate to the settings page through the Facebook top-level menu item
+ *
+ * @since 1.1
+ * @uses add_submenu_page()
+ * @param string $parent_slug Facebook top-level menu item slug
+ * @return string submenu hook suffix
+ */
+ public static function add_submenu_item( $parent_slug ) {
+ $comments_settings = new Facebook_Comments_Settings();
+
+ // no post types support comments. nothing to do here
+ if ( empty( $comments_settings->supporting_post_types ) )
+ return;
+
+ $hook_suffix = add_submenu_page(
+ $parent_slug,
+ self::social_plugin_name(),
+ self::social_plugin_name(),
+ 'manage_options',
+ self::PAGE_SLUG,
+ array( &$comments_settings, 'settings_page' )
+ );
+
+ if ( $hook_suffix ) {
+ $comments_settings->hook_suffix = $hook_suffix;
+ register_setting( $hook_suffix, self::OPTION_NAME, 'Facebook_Comments_Settings::sanitize_options' );
+ add_action( 'load-' . $hook_suffix, array( &$comments_settings, 'onload' ) );
+ }
+
+ return $hook_suffix;
+ }
+
+ /**
+ * Load stored options and scripts on settings page view
+ *
+ * @since 1.1
+ */
+ public function onload() {
+ $options = get_option( self::OPTION_NAME );
+ if ( ! is_array( $options ) )
+ $options = array();
+ $this->existing_options = $options;
+
+ $this->settings_api_init();
+ }
+
+ /**
+ * Load the page
+ *
+ * @since 1.1
+ */
+ public function settings_page() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ Facebook_Settings::settings_page_template( $this->hook_suffix, sprintf( __( '%s Settings', 'facebook' ), self::social_plugin_name() ) );
+ }
+
+ /**
+ * Hook into the settings API
+ *
+ * @since 1.1
+ * @uses add_settings_section()
+ * @uses add_settings_field()
+ */
+ private function settings_api_init() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ $section = 'facebook-comments-box';
+ add_settings_section(
+ $section,
+ '', // no title for main section
+ array( &$this, 'section_header' ),
+ $this->hook_suffix
+ );
+
+ add_settings_field(
+ 'facebook-comments-show-on',
+ __( 'Show on', 'facebook' ),
+ array( &$this, 'display_show_on' ),
+ $this->hook_suffix,
+ $section
+ );
+
+ // comments box options
+ add_settings_field(
+ 'facebook-comments-num-posts',
+ __( 'Number of comments', 'facebook' ),
+ array( &$this, 'display_num_posts' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-comments-num-posts' )
+ );
+ add_settings_field(
+ 'facebook-comments-width',
+ __( 'Width', 'facebook' ),
+ array( &$this, 'display_width' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-comments-width' )
+ );
+ add_settings_field(
+ 'facebook-comments-colorscheme',
+ __( 'Color scheme', 'facebook' ),
+ array( &$this, 'display_colorscheme' ),
+ $this->hook_suffix,
+ $section
+ );
+ }
+
+ /**
+ * Introduce publishers to the Comments Box social plugin
+ *
+ * @since 1.1
+ */
+ public function section_header() {
+ global $facebook_loader;
+
+ echo '<p>' . esc_html( sprintf( __( 'Enable social commenting backed by a %s account and optional providers AOL, Hotmail, or Yahoo!.', 'facebook' ), 'Facebook' ) ) . ' <a href="https://developers.facebook.com/docs/reference/plugins/comments/" title="' . esc_attr( sprintf( __( '%s social plugin documentation', 'facebook' ), 'Facebook ' . self::social_plugin_name() ) ) . '">' . esc_html( __( 'Read more...', 'facebook' ) ) . '</a></p>';
+ echo '<p>' . esc_html( sprintf( __( "Comments appear in the author's %s.", 'facebook' ), __( 'Facebook Timeline', 'facebook' ) ) ) . ' ' . esc_html( sprintf( __( 'All administrators of your %s application will be able to moderate comments.', 'facebook' ), 'Facebook' ) ) . '</p>';
+ echo '<p>' . sprintf( esc_html( __( 'You may customize your %1$s settings from the %2$s including moderated comments, blacklisted words, and comment sorting.', 'facebook' ) ), self::social_plugin_name(), '<a href="' . esc_url( 'https://developers.facebook.com/tools/comments' . ( isset( $facebook_loader->credentials['app_id'] ) ? '?' . http_build_query( array( 'id' => $facebook_loader->credentials['app_id'] ) ) : '' ), array( 'http', 'https' ) ) . '">' . esc_html( __( 'Facebook Comments Tool', 'facebook' ) ) . '</a>' ) . ' ' . esc_html( __( 'You may also specify individual comment moderators not associated with your application.', 'facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Return a list of all public post types supporting the comments feature
+ *
+ * @since 1.1
+ * @return array post type names supporting comments feature
+ */
+ public static function post_types_supporting_comments() {
+ // get a list of all public post types
+ $public_post_types = get_post_types( array( 'public' => true ) );
+
+ // reduce the list of public post types to just the post types supporting comments
+ $post_types_supporting_comments = array();
+ foreach( $public_post_types as $post_type ) {
+ if ( post_type_supports( $post_type, 'comments' ) )
+ $post_types_supporting_comments[] = $post_type;
+ }
+ return $post_types_supporting_comments;
+ }
+
+ /**
+ * On which single pages should the comments box appear?
+ *
+ * @since 1.1
+ */
+ public function display_show_on() {
+ $existing_value = self::get_display_conditionals_by_feature( 'comments', 'posts' );
+ if ( ! is_array( $existing_value ) )
+ $existing_value = $post_types_supporting_comments;
+
+ $fields = array();
+ foreach( $this->supporting_post_types as $type ) {
+ $field = '<label><input type="checkbox" name="' . self::OPTION_NAME . '[show_on][]" value="' . esc_attr( $type ) . '"';
+ $field .= checked( in_array( $type, $existing_value, true ), true, false );
+ $field .= ' /> ' . esc_html( $type ) . '</label>';
+
+ $fields[] = $field;
+ unset( $field );
+ }
+
+ echo '<fieldset id="facebook-comments-show-on">' . implode( ' ', $fields ) . '</fieldset>';
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'Display the %s on one or more post types.', 'facebook' ), self::social_plugin_name() ) ) . '</p>';
+ }
+
+ /**
+ * Maximum number of posts displayed before viewer expansion
+ *
+ * @since 1.1
+ */
+ public function display_num_posts() {
+ $key = 'num_posts';
+
+ $existing_value = 10;
+ if ( isset( $this->existing_options[$key] ) ) {
+ $val = absint( $this->existing_options[$key] );
+ if ( $val > 0 )
+ $existing_value = $val;
+ unset( $val );
+ }
+
+ echo '<input type="number" name="' . self::OPTION_NAME . '[' . $key . ']" id="facebook-comments-num-posts" size="3" min="1" step="1" value="' . $existing_value . '" /> ';
+ echo esc_html( __( 'top-level comments shown before viewer expansion.', 'facebook' ) );
+ }
+
+ /**
+ * Allow the publisher to customize the width of the Comments Box
+ *
+ * @since 1.1
+ */
+ public function display_width() {
+ global $content_width;
+
+ $key = 'width';
+
+ if ( isset( $this->existing_options[$key] ) )
+ $existing_value = absint( $this->existing_options[$key] );
+ else if ( isset( $content_width ) )
+ $existing_value = absint( $content_width );
+
+ if ( ! isset( $existing_value ) || $existing_value < 400 )
+ $existing_value = 470; // match social plugin config page default
+
+ echo '<input type="number" name="' . self::OPTION_NAME . '[' . $key . ']" id="facebook-comments-' . $key . '" size="5" min="400" step="1"';
+ if ( $existing_value >= 400 )
+ echo ' value="' . $existing_value . '"';
+ echo ' />';
+
+ if ( isset( $content_width ) )
+ echo ' ' . esc_html( sprintf( __( 'Content width: %u', 'facebook' ), absint( $content_width ) ) );
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'The width of the %s display area in whole pixels.', 'facebook' ), self::social_plugin_name() ) ) . '</p>';
+ }
+
+ /**
+ * Customize the color scheme
+ *
+ * @since 1.1
+ */
+ public function display_colorscheme() {
+ $key = 'colorscheme';
+
+ echo '<fieldset id="facebook-comments-' . $key . '">' . self::color_scheme_choices( self::OPTION_NAME . '[' . $key . ']', isset( $this->existing_options[$key] ) ? $this->existing_options[$key] : '' ) . '</fieldset>';
+ }
+
+ /**
+ * Translate HTML data response returned from Facebook social plugin builder into underscored keys and PHP values before saving
+ *
+ * @since 1.1
+ * @param array $options data-* options returned from Facebook social plugin builder
+ * @return array $options options to store in WordPress
+ */
+ public static function html_data_to_options( $options ) {
+ if ( ! is_array( $options ) )
+ return array();
+
+ if ( isset( $options['num-posts'] ) ) {
+ $options['num_posts'] = absint( $options['num-posts'] );
+ unset( $options['num-posts'] );
+ }
+ if ( isset( $options['width'] ) )
+ $options['width'] = absint( $options['width'] );
+
+ return $options;
+ }
+
+ /**
+ * 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() );
+ unset( $clean_options['show_on'] );
+ }
+ 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;
+ }
+}
+
+?>
View
571 admin/settings-like-button.php
@@ -0,0 +1,571 @@
+<?php
+
+if ( ! class_exists( 'Facebook_Social_Plugin_Button_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-social-plugin-button.php' );
+
+/**
+ * Site settings for the Facebook Like Button social plugin
+ *
+ * @since 1.1
+ */
+class Facebook_Like_Button_Settings extends Facebook_Social_Plugin_Button_Settings {
+
+ /**
+ * Setting page identifier
+ *
+ * @since 1.1
+ * @var string
+ */
+ const PAGE_SLUG = 'facebook-like-button';
+
+ /**
+ * Define our option array value
+ *
+ * @since 1.1
+ * @var string
+ */
+ const OPTION_NAME = 'facebook_like_button';
+
+ /**
+ * Initialize with an options array
+ *
+ * @since 1.1
+ * @param array $options existing options
+ */
+ public function __construct( $options = array() ) {
+ if ( is_array( $options ) && ! empty( $options ) )
+ $this->existing_options = $options;
+ else
+ $this->existing_options = array();
+ }
+
+ /**
+ * Evaluate the Facebook_Like_Button class file if it is not already loaded
+ *
+ * @since 1.1
+ */
+ public static function require_like_button_builder() {
+ if ( ! class_exists( 'Facebook_Like_Button' ) )
+ require_once( dirname( dirname(__FILE__) ) . '/social-plugins/class-facebook-like-button.php' );
+ }
+
+ /**
+ * Reference the social plugin by name
+ *
+ * @since 1.1
+ * @return string social plugin name
+ */
+ public static function social_plugin_name() {
+ return __( 'Like Button', 'facebook' );
+ }
+
+ /**
+ * Navigate to the settings page through the Facebook top-level menu item
+ *
+ * @since 1.1
+ * @uses add_submenu_page()
+ * @param string $parent_slug Facebook top-level menu item slug
+ * @return string submenu hook suffix
+ */
+ public static function add_submenu_item( $parent_slug ) {
+ $like_button_settings = new Facebook_Like_Button_Settings();
+
+ $hook_suffix = add_submenu_page(
+ $parent_slug,
+ self::social_plugin_name(),
+ self::social_plugin_name(),
+ 'manage_options',
+ self::PAGE_SLUG,
+ array( &$like_button_settings, 'settings_page' )
+ );
+
+ if ( $hook_suffix ) {
+ $like_button_settings->hook_suffix = $hook_suffix;
+ register_setting( $hook_suffix, self::OPTION_NAME, 'Facebook_Like_Button_Settings::sanitize_options' );
+ add_action( 'load-' . $hook_suffix, array( &$like_button_settings, 'onload' ) );
+ }
+
+ return $hook_suffix;
+ }
+
+ /**
+ * Load stored options and scripts on settings page view
+ *
+ * @since 1.1
+ */
+ public function onload() {
+ $options = get_option( self::OPTION_NAME );
+ if ( ! is_array( $options ) )
+ $options = array();
+ $this->existing_options = $options;
+
+ $this->settings_api_init();
+ }
+
+ /**
+ * Load the page
+ *
+ * @since 1.1
+ */
+ public function settings_page() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ Facebook_Settings::settings_page_template( $this->hook_suffix, sprintf( __( '%s Settings', 'facebook' ), self::social_plugin_name() ) );
+ }
+
+ /**
+ * Hook into the settings API
+ *
+ * @since 1.1
+ * @uses add_settings_section()
+ * @uses add_settings_field()
+ * @param string $page parent page slug
+ */
+ private function settings_api_init() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ $section = 'facebook-like-button';
+ add_settings_section(
+ $section,
+ '', // no title for main section
+ array( &$this, 'section_header' ),
+ $this->hook_suffix
+ );
+
+ /* when, where */
+ add_settings_field(
+ 'facebook-like-show-on',
+ __( 'Show on', 'facebook' ),
+ array( &$this, 'display_show_on' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-like-position',
+ __( 'Position', 'facebook' ),
+ array( &$this, 'display_position' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-like-position' )
+ );
+
+ /* like button options */
+ add_settings_field(
+ 'facebook-like-send',
+ __( 'Send Button', 'facebook' ),
+ array( &$this, 'display_send' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-like-send' )
+ );
+ add_settings_field(
+ 'facebook-like-layout',
+ __( 'Layout', 'facebook' ),
+ array( &$this, 'display_layout' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-like-show-faces',
+ __( 'Show faces', 'facebook' ),
+ array( &$this, 'display_show_faces' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-like-show-faces' )
+ );
+ add_settings_field(
+ 'facebook-like-width',
+ __( 'Width', 'facebook' ),
+ array( &$this, 'display_width' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-like-width' )
+ );
+ add_settings_field(
+ 'facebook-like-action',
+ __( 'Action', 'facebook' ),
+ array( &$this, 'display_action' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-like-font',
+ __( 'Font', 'facebook' ),
+ array( &$this, 'display_font' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-like-font' )
+ );
+ add_settings_field(
+ 'facebook-like-colorscheme',
+ __( 'Color scheme', 'facebook' ),
+ array( &$this, 'display_colorscheme' ),
+ $this->hook_suffix,
+ $section
+ );
+ }
+
+ /**
+ * Introduce publishers to the Like Button social plugin
+ *
+ * @since 1.1
+ */
+ public function section_header() {
+ echo '<p>' . esc_html( __( 'Help your visitors share your pages on their Facebook profile with one click.', 'facebook' ) ) . ' <a href="https://developers.facebook.com/docs/reference/plugins/like/" title="' . esc_attr( sprintf( __( '%s social plugin documentation', 'facebook' ), 'Facebook ' . self::social_plugin_name() ) ) . '">' . esc_html( __( 'Read more...', 'facebook' ) ) . '</a></p>';
+ }
+
+ /**
+ * Where should the button appear?
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_show_on( $extra_attributes = array() ) {
+ $key = 'show_on';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-show-on',
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<fieldset id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '>' . self::show_on_choices( $name, self::get_display_conditionals_by_feature( 'like', 'all' ), 'all' ) . '</fieldset>';
+
+ echo '<p class="description">' . esc_html( self::show_on_description( self::social_plugin_name() ) ) . '</p>';
+ }
+
+ /**
+ * Where would you like it?
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_position( $extra_attributes = array() ) {
+ $key = 'position';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<select name="' . esc_attr( $name ) . '" id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '>' . self::position_choices( isset( $this->existing_options[$key] ) ? $this->existing_options[$key] : '' ) . '</select>';
+ }
+
+ /**
+ * Display the send button option checkbox
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_send( $extra_attributes = array() ) {
+ $key = 'send';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<label><input type="checkbox" name="' . esc_attr( $name ) . '" id="' . $id . '" value="1"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ checked( isset( $this->existing_options[$key] ) );
+ echo ' /> ';
+
+ echo esc_html( sprintf( __( 'Include a %1$s alongside the %2$s.', 'facebook' ), __( 'Send Button', 'facebook' ), self::social_plugin_name() ) ) . '</label>';
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'Allows a %1$s user to easily send your URL to a friend via email, %1$s message, or post to a %1$s group.', 'facebook' ), 'Facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Describe layout choices
+ *
+ * @since 1.1
+ * @return array layout descriptions keyed by layout choice
+ */
+ public static function layout_descriptions() {
+ $like_plural = _x( 'likes', 'plural of the noun: Facebook Likes', 'facebook' );
+ return array(
+ 'standard' => __( 'Display social text next to the button.', 'facebook' ),
+ 'button_count' => sprintf( __( 'Display total number of %s next to the button.', 'facebook' ), $like_plural ),
+ 'box_count' => sprintf( __( 'Display total number of %s above the button.', 'facebook' ), $like_plural )
+ );
+ }
+
+ /**
+ * Choose a Like Button layout option
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_layout( $extra_attributes = array() ) {
+ $key = 'layout';
+
+ self::require_like_button_builder();
+
+ if ( isset( $this->existing_options[$key] ) && in_array( $this->existing_options[$key], Facebook_Like_Button::$layout_choices ) )
+ $existing_value = $this->existing_options[$key];
+ else
+ $existing_value = 'standard';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+ $name = esc_attr( $name );
+
+ $descriptions = self::layout_descriptions();
+
+ $choices = array();
+
+ foreach( Facebook_Like_Button::$layout_choices as $layout ) {
+ $choice = '<label><input type="radio" name="' . $name . '" value="' . $layout . '"';
+ $choice .= checked( $layout, $existing_value, false );
+ $choice .= ' /> ';
+
+ $choice .= $layout;
+ if ( isset( $descriptions[$layout] ) )
+ $choice .= esc_html( '' . $descriptions[$layout] );
+ $choice .= '</label>';
+
+ $choices[] = $choice;
+ unset( $choice );
+ }
+
+ if ( ! empty( $choices ) ) {
+ echo '<fieldset id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '><div>';
+ echo implode( '</div><div>', $choices );
+ echo '</div></fieldset>';
+ }
+ }
+
+ /**
+ * Option to display faces of friends below the Like Button
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_show_faces( $extra_attributes = array() ) {
+ $key = 'show_faces';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-show-faces',
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<label><input type="checkbox" name="' . esc_attr( $name ) . '" id="' . $id . '" value="1"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ checked( isset( $this->existing_options[$key] ) );
+ echo ' /> ' . esc_html( __( "Show profile photos of the viewer's friends who have already liked the URL.", 'facebook' ) ) . '</label>';
+ }
+
+ /**
+ * Allow the publisher to customize the width of the Like Button
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_width( $extra_attributes = array() ) {
+ global $content_width;
+
+ $key = 'width';
+
+ if ( isset( $this->existing_options[$key] ) )
+ $existing_value = absint( $this->existing_options[$key] );
+ else if ( isset( $content_width ) )
+ $existing_value = absint( $content_width );
+
+ if ( ! isset( $existing_value ) || $existing_value < 55 )
+ $existing_value = 450; // match social plugin config page default
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<input type="number" name="' . esc_attr( $name ) . '" id="' . $id . '" size="5" min="55" step="1" value="' . $existing_value . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo ' />';
+ if ( isset( $content_width ) && $name === self::OPTION_NAME . '[' . $key . ']' )
+ echo ' ' . esc_html( sprintf( __( 'Content width: %u', 'facebook' ), absint( $content_width ) ) );
+
+ echo '<p class="description">' . esc_html( sprintf( __( 'The width of the %s display area in whole pixels.', 'facebook' ), self::social_plugin_name() ) ) . '</p>';
+ }
+
+ /**
+ * Choose action text.
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_action( $extra_attributes = array() ) {
+ $key = 'action';
+
+ self::require_like_button_builder();
+
+ if ( isset( $this->existing_options[$key] ) && in_array( $this->existing_options[$key], Facebook_Like_Button::$action_choices ) )
+ $existing_value = $this->existing_options[$key];
+ else
+ $existing_value = 'like';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+ $name = esc_attr( $name );
+
+ $fields = array();
+ foreach( Facebook_Like_Button::$action_choices as $action ) {
+ $fields[] = '<label><input type="radio" name="' . $name . '" value="' . $action . '"' . checked( $action, $existing_value, false ) . ' /> ' . esc_html( __( $action, 'facebook' ) ) . '</label>';
+ }
+
+ echo '<fieldset id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '>' . implode( ' ', $fields ) . '</fieldset>';
+
+ echo '<p class="description">' . esc_html( __( 'Action verb displayed in button.', 'facebook' ) ) . '</p>';
+ }
+
+ /**
+ * Choose a custom font
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_font( $extra_attributes = array() ) {
+ $key = 'font';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<select name="' . esc_attr( $name ) . '" id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '>' . self::font_choices( isset( $this->existing_options[$key] ) ? $this->existing_options[$key] : '' ) . '</select>';
+ }
+
+ /**
+ * Customize the color scheme
+ *
+ * @since 1.1
+ * @param array $extra_attributes custom form attributes
+ */
+ public function display_colorscheme( $extra_attributes = array() ) {
+ $key = 'colorscheme';
+
+ extract( self::parse_form_field_attributes(
+ $extra_attributes,
+ array(
+ 'id' => 'facebook-like-' . $key,
+ 'class' => '',
+ 'name' => self::OPTION_NAME . '[' . $key . ']'
+ )
+ ) );
+
+ echo '<fieldset id="' . $id . '"';
+ if ( isset( $class ) && $class )
+ echo ' class="' . $class . '"';
+ echo '>' . self::color_scheme_choices( $name, isset( $this->existing_options[$key] ) ? $this->existing_options[$key] : '' ) . '</fieldset>';
+ }
+
+ /**
+ * Translate HTML data response returned from Facebook social plugin builder into underscored keys and PHP values before saving
+ *
+ * @since 1.1
+ * @param array $options data-* options returned from Facebook social plugin builder
+ * @return array $options options to store in WordPress
+ */
+ public static function html_data_to_options( $options ) {
+ if ( ! is_array( $options ) )
+ return array();
+
+ if ( isset( $options['send'] ) && $options['send'] === 'true' )
+ $options['send'] = true;
+ if ( isset( $options['show-faces'] ) && $options['show-faces'] === 'true' ) {
+ $options['show_faces'] = true;
+ unset( $options['show-faces'] );
+ }
+ if ( isset( $options['width'] ) )
+ $options['width'] = absint( $options['width'] );
+
+ return $options;
+ }
+
+ /**
+ * Sanitize Like Button settings before they are saved to the database
+ *
+ * @since 1.1
+ * @param array $options Like Button options
+ * @return array clean option sets. note: we remove Like Button 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();
+
+ self::require_like_button_builder();
+
+ // Handle like button display preferences first
+ $clean_options = parent::sanitize_options( $options );
+ if ( isset( $clean_options['show_on'] ) ) {
+ self::update_display_conditionals( 'like', $clean_options['show_on'], self::get_show_on_choices( 'all' ) );
+ unset( $clean_options['show_on'] );
+ }
+ unset( $options['show_on'] );
+
+ $like_button = Facebook_Like_Button::fromArray( $options );
+ if ( $like_button ) {
+ $like_button->validate();
+ return array_merge( $clean_options, self::html_data_to_options( $like_button->toHTMLDataArray() ) );
+ }
+
+ return $clean_options;
+ }
+}
+
+?>
View
416 admin/settings-recommendations-bar.php
@@ -0,0 +1,416 @@
+<?php
+
+if ( ! class_exists( 'Facebook_Social_Plugin_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings-social-plugin.php' );
+
+class Facebook_Recommendations_Bar_Settings extends Facebook_Social_Plugin_Settings {
+
+ /**
+ * Setting page identifier
+ *
+ * @since 1.1
+ * @var string
+ */
+ const PAGE_SLUG = 'facebook-recommendations-bar';
+
+ /**
+ * Define our option array value
+ *
+ * @since 1.1
+ * @var string
+ */
+ const OPTION_NAME = 'facebook_recommendations_bar';
+
+ /**
+ * Initialize with an options array
+ *
+ * @since 1.1
+ * @param array $options existing options
+ */
+ public function __construct( $options = array() ) {
+ if ( is_array( $options ) && ! empty( $options ) )
+ $this->existing_options = $options;
+ else
+ $this->existing_options = array();
+ }
+
+ /**
+ * Reference the social plugin by name
+ *
+ * @since 1.1
+ * @return string social plugin name
+ */
+ public static function social_plugin_name() {
+ return __( 'Recommendations Bar', 'facebook' );
+ }
+
+ /**
+ * Evaluate the Facebook_Recommendations_Bar class file if it is not already loaded
+ *
+ * @since 1.1
+ */
+ public static function require_recommendations_bar_builder() {
+ if ( ! class_exists( 'Facebook_Recommendations_Bar' ) )
+ require_once( dirname( dirname(__FILE__) ) . '/social-plugins/class-facebook-recommendations-bar.php' );
+ }
+
+ /**
+ * Navigate to the settings page through the Facebook top-level menu item
+ *
+ * @since 1.1
+ * @uses add_submenu_page()
+ * @param string $parent_slug Facebook top-level menu item slug
+ * @return string submenu hook suffix
+ */
+ public static function add_submenu_item( $parent_slug ) {
+ $recommendations_bar_settings = new Facebook_Recommendations_Bar_Settings();
+
+ $hook_suffix = add_submenu_page(
+ $parent_slug,
+ self::social_plugin_name(),
+ self::social_plugin_name(),
+ 'manage_options',
+ self::PAGE_SLUG,
+ array( &$recommendations_bar_settings, 'settings_page' )
+ );
+
+ if ( $hook_suffix ) {
+ $recommendations_bar_settings->hook_suffix = $hook_suffix;
+ register_setting( $hook_suffix, self::OPTION_NAME, 'Facebook_Recommendations_Bar_Settings::sanitize_options' );
+ add_action( 'load-' . $hook_suffix, array( &$recommendations_bar_settings, 'onload' ) );
+ }
+
+ return $hook_suffix;
+ }
+
+ /**
+ * Load stored options and scripts on settings page view
+ *
+ * @since 1.1
+ */
+ public function onload() {
+ $options = get_option( self::OPTION_NAME );
+ if ( ! is_array( $options ) )
+ $options = array();
+ $this->existing_options = $options;
+
+ $this->settings_api_init();
+ }
+
+ /**
+ * Load the page
+ *
+ * @since 1.1
+ */
+ public function settings_page() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ Facebook_Settings::settings_page_template( $this->hook_suffix, sprintf( __( '%s Settings', 'facebook' ), self::social_plugin_name() ) );
+ }
+
+ /**
+ * Hook into the settings API
+ *
+ * @since 1.1
+ * @uses add_settings_section()
+ * @uses add_settings_field()
+ * @param string $options_group target grouping
+ */
+ private function settings_api_init() {
+ if ( ! isset( $this->hook_suffix ) )
+ return;
+
+ $section = 'facebook-recommendations-bar';
+ add_settings_section(
+ $section,
+ '', // no title for main section
+ array( &$this, 'section_header' ),
+ $this->hook_suffix
+ );
+
+ // when, where
+ add_settings_field(
+ 'facebook-recommendations-bar-show-on',
+ __( 'Show on', 'facebook' ),
+ array( &$this, 'display_show_on' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-recommendations-bar-side',
+ __( 'Side', 'facebook' ),
+ array( &$this, 'display_side' ),
+ $this->hook_suffix,
+ $section
+ );
+
+ // social plugin fields
+ add_settings_field(
+ 'facebook-recommendations-bar-action',
+ __( 'Action', 'facebook' ),
+ array( &$this, 'display_action' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-recommendations-bar-trigger',
+ __( 'Trigger', 'facebook' ),
+ array( &$this, 'display_trigger' ),
+ $this->hook_suffix,
+ $section
+ );
+ add_settings_field(
+ 'facebook-recommendations-bar-read-time',
+ __( 'Read time', 'facebook' ),
+ array( &$this, 'display_read_time' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-recommendations-bar-read-time' )
+ );
+ add_settings_field(
+ 'facebook-recommendations-bar-num-recommendations',
+ __( 'Number of recommendations', 'facebook' ),
+ array( &$this, 'display_num_recommendations' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-recommendations-bar-num-recommendations' )
+ );
+ add_settings_field(
+ 'facebook-recommendations-bar-max-age',
+ __( 'Maximum age', 'facebook' ),
+ array( &$this, 'display_max_age' ),
+ $this->hook_suffix,
+ $section,
+ array( 'label_for' => 'facebook-recommendations-bar-max-age' )
+ );
+ }
+
+ /**
+ * Introduce publishers to the Recommendations Bar social plugin
+ *
+ * @since 1.1
+ */
+ public function section_header() {
+ echo '<p>' . esc_html( __( 'Encourage additional pageviews with site recommendations based on social context.', 'facebook' ) ) . ' ' . esc_html( sprintf( __( 'Adds a %s overlay to the bottom of your page with an expanded list of recommendations triggered by time or position on the page.', 'facebook' ), __( 'Like Button', 'facebook' ) ) ) . '<br /><a href="https://developers.facebook.com/docs/reference/plugins/recommendationsbar/" title="' . esc_attr( sprintf( __( '%s social plugin documentation', 'facebook' ), 'Facebook ' . self::social_plugin_name() ) ) . '">' . esc_html( __( 'Read more...', 'facebook' ) ) . '</a></p>';
+ }
+
+ /**
+ * Where should the button appear?
+ *
+ * @since 1.1
+ */
+ public function display_show_on() {
+ echo '<fieldset id="facebook-recommendations-bar-show-on">' . self::show_on_choices( self::OPTION_NAME . '[show_on]', self::get_display_conditionals_by_feature( 'recommendations_bar', 'all' ), 'recommendations_bar' ) . '</fieldset>';
+
+ echo '<p class="description">' . esc_html( self::show_on_description( self::social_plugin_name() ) ) . '</p>';
+ }