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, array( '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 * * @return void */ 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 * * @return void */ 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() * @return void */ 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', _x( 'Show on', 'Display the social plugin in specific areas of a website', 'facebook' ), array( &$this, 'display_show_on' ), $this->hook_suffix, $section ); // comments box options add_settings_field( 'facebook-comments-num-posts', _x( 'Number of comments', 'Number of comments to display in a list of comments', 'facebook' ), array( &$this, 'display_num_posts' ), $this->hook_suffix, $section, array( 'label_for' => 'facebook-comments-num-posts' ) ); add_settings_field( 'facebook-comments-order-by', __( 'Order by', 'facebook' ), array( &$this, 'display_order_by' ), $this->hook_suffix, $section ); 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 * * @return void */ public function section_header() { global $facebook_loader; echo '

' . esc_html( __( 'Enable social commenting backed by a Facebook account and optional providers AOL, Hotmail, or Yahoo!.', 'facebook' ) ) . ' ' . esc_html( __( 'Read more...', 'facebook' ) ) . '

'; echo '

' . esc_html( __( "Comments appear in the author's Facebook Timeline.", 'facebook' ) ) . ' ' . esc_html( __( 'All administrators of your Facebook application will be able to moderate comments.', 'facebook' ) ) . '

'; echo '

' . 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(), '' . esc_html( __( 'Facebook Comments Tool', 'facebook' ) ) . '' ) . ' ' . esc_html( __( 'You may also specify individual comment moderators not associated with your application.', 'facebook' ) ) . '

'; } /** * Return a list of all public post types supporting the comments feature. * * @since 1.1 * * @uses get_post_types() * @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 * * @return void */ public function display_show_on() { $existing_value = self::get_display_conditionals_by_feature( 'comments', 'posts' ); if ( ! is_array( $existing_value ) ) { $existing_value = array(); foreach ( $this->supporting_post_types as $post_type ) { $existing_value[$post_type] = true; } } $fields = array(); foreach( $this->supporting_post_types as $type ) { $field = '