Permalink
Browse files

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

…ed social plugins + settings. more hooks
  • Loading branch information...
1 parent 079ead5 commit 2b1b3852c9e90ece6675dd69746d89953ef0afda @niallkennedy niallkennedy committed Nov 10, 2012
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. BIN {images → static/img}/icon-bw.png
  83. BIN {images → static/img}/icon.png
  84. BIN {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
@@ -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();});';
+ }
+}
+?>
@@ -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 );
+ }
+}
+?>
Oops, something went wrong.

0 comments on commit 2b1b385

Please sign in to comment.