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( __( 'Facebook Plugin Settings', 'facebook' ), // page
' . esc_html( __( 'Your server does not support communication with Facebook servers over HTTPS.', 'facebook' ) ) . '
'; echo '' . esc_html( __( 'Facebook application functionality such as posting to your Facebook Timeline requires a HTTPS connection to Facebook servers.', 'facebook' ) ) . '
'; echo '' . esc_html( __( 'Edit your application settings on Facebook', 'facebook' ) ) . '
'; else echo ''; } /** * Introduction to Facebook restrictions configurations. * * @since 1.5 * * @return void */ public static function restriction_section_header() { echo '' . esc_html( _x( 'Limit Facebook functionality', 'Section header for options limiting Facebook on your site', 'facebook' ) ) . '
'; } /** * Display the application ID input field. * * @since 1.1 * * @return void */ 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 ''; echo '' . esc_html( __( 'An application identifier associates your site, its pages, and visitor actions with a registered Facebook application.', 'facebook' ) ) . '
'; } /** * Display the Facebook application secret input field. * * @since 1.1 * * @return void */ 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 ''; echo '' . esc_html( __( 'An application secret is a secret shared between Facebook and your application, similar to a password.', 'facebook' ) ) . '
'; } /** * Display a checkbox to designate the site as child-focused. * * @since 1.5 * * @global Facebook_Loader $facebook_loader determine child directed site status * @return void */ public static function display_kid_directed_site() { global $facebook_loader; echo ''; } /** * Clean user inputs before saving to database. * * @since 1.1 * * @param array $options form options values * @return array $options sanitized options */ public static function sanitize_options( $options ) { // start fresh $clean_options = array(); if ( isset( $options['kid_directed_site'] ) ) update_option( self::OPTION_NAME_KID_DIRECTED, '1' ); else delete_option( self::OPTION_NAME_KID_DIRECTED ); 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 if ( function_exists( 'add_settings_error' ) ) { add_settings_error( 'facebook-app-id', 'facebook-app-id-error', __( 'App ID must contain only digits.', 'facebook' ) ); } } else { // removing app id disables other features such as comments delete_option( 'facebook_comments_enabled' ); } 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 if ( function_exists( 'add_settings_error' ) ) add_settings_error( 'facebook-app-secret', 'facebook-app-secret-error', __( 'Invalid app secret.', 'facebook' ) ); } unset( $app_secret ); } // store an application access token and verify additional data if ( isset( $clean_options['app_id'] ) && isset( $clean_options['app_secret'] ) ) { if ( ! class_exists( 'Facebook_WP_Extend' ) ) require_once( dirname( dirname(__FILE__) ) . '/includes/facebook-php-sdk/class-facebook-wp.php' ); if ( wp_http_supports( array( 'ssl' => true ) ) ) { $access_token = Facebook_WP_Extend::get_app_access_token( $clean_options['app_id'], $clean_options['app_secret'] ); if ( $access_token ) { $app_secret_proof = hash_hmac( 'sha256', $access_token, $clean_options['app_secret'] ); $app_info = Facebook_WP_Extend::get_app_details_by_access_token( $access_token, array( 'id', 'namespace' ), $app_secret_proof ); if ( empty( $app_info ) ) { if ( function_exists( 'add_settings_error' ) ) add_settings_error( 'facebook-app-auth', 'facebook-app-auth-error', __( 'Application access token failed on authentication with Facebook.', 'facebook' ) ); unset( $clean_options['app_id'] ); unset( $clean_options['app_secret'] ); } else { if ( isset( $app_info['namespace'] ) ) $clean_options['app_namespace'] = $app_info['namespace']; $clean_options['access_token'] = $access_token; if ( $app_secret_proof ) $clean_options['appsecret_proof'] = $app_secret_proof; } unset( $app_info ); unset( $app_secret_proof ); } else { if ( function_exists( 'add_settings_error' ) ) add_settings_error( 'facebook-app-auth', 'facebook-app-auth-error', __( 'Application ID and secret failed on authentication with Facebook.', 'facebook' ) ); unset( $clean_options['app_id'] ); unset( $clean_options['app_secret'] ); } unset( $access_token ); } else { $app_info = Facebook_WP_Extend::get_app_details( $clean_options['app_id'], array( 'id','namespace' ) ); if ( empty( $app_info ) ) { if ( function_exists( 'add_settings_error' ) ) add_settings_error( 'facebook-app-info', 'facebook-app-info-error', __( 'Unable to request application data from Facebook.', 'facebook' ) ); unset( $clean_options['app_id'] ); unset( $clean_options['app_secret'] ); } else if ( isset( $app_info['namespace'] ) ) { $clean_options['app_namespace'] = $app_info['namespace']; } unset( $app_info ); } } else { unset( $clean_options['app_id'] ); unset( $clean_options['app_secret'] ); } 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 = '' . sprintf ( esc_html( __( '%s to take advantage of advantage of advanced Facebook features such as post to timeline, recommendations bar, and more.', 'facebook' ) ), '' . __( 'Register for a Facebook application', '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' ) ) . '
'; $content .= '' . sprintf( esc_html( __( 'Click the %s button near the top right corner of the page to trigger an application creation dialog.', 'facebook' ) ), '+ Create New App' ) . '
'; $content .= ' ) . ')
' . esc_html( __( 'Uniquely identify your site on Facebook with an application name.', '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 "%s" as your Facebook application name.', 'facebook' ), $site_name ) ); } } $content .= '
'; 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 = '' . 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, '' . esc_html( get_bloginfo( 'name' ) ) . '' ); $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 .= '
'; unset( $app_link ); // Basic Settings screen $content .= '' . 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 ? '' . esc_html( __( 'basic settings', 'facebook' ) ) . '' : esc_html( __( 'basic settings', 'facebook' ) ) ) . '
'; $content .= '' . __( 'For example:', 'facebook' ) . '
'; $content .= '| ' . esc_html( _x( 'Field', 'data entry field', 'facebook' ) ) . ' | ' . esc_html( _x( 'Value', 'data entry value', 'facebook' ) ) . ' |
|---|---|
| ' . esc_html( __( 'Contact Email', 'facebook' ) ) . ' | ' . esc_html( $user->user_email ) . ' |
| ' . esc_html( __( 'App Domains', 'facebook' ) ) . ' | ' . esc_html( parse_url( $site_url, PHP_URL_HOST ) ) . ' |
| ' . esc_html( __( 'Website with Facebook Login', 'facebook' ) ) . ' | ' . esc_html( $site_url ) . ' |
| ' . esc_html( __( 'Mobile website', 'facebook' ) ) . ' | ' . esc_html( $site_url ) . ' |
'; $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 authors for publish permissions or marketing your site through Facebook.', 'facebook' ) ); $content .= '
'; $content .= '' . esc_html( __( 'Comply with privacy laws of your audience including information collected about children.', 'facebook' ) ) . '
'; $content .= '' . esc_html( __( 'Example: a site primary directed at children in the United States under the age of 13 might set this option to comply with privacy policies in the United States.', 'facebook' ) ) . '
'; $content .= ''; return $content; } /** * Display help content on the settings page * * @since 1.1 * * @uses get_current_screen() * @return void */ 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' => __( 'Create a Facebook application', 'facebook' ), 'content' => self::help_tab_new_app() ) ); } else { $screen->add_help_tab( array( 'id' => 'facebook-existing-app-help', 'title' => __( 'Existing Facebook application', '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->add_help_tab( array( 'id' => 'facebook-kid-directed-help', 'title' => __( 'Child directed', 'facebook' ), 'content' => self::help_tab_kid_directed() ) ); $screen->set_help_sidebar( '' ); } } ?>