* @copyright Copyright (c) 2008 - 2012, Justin Tadlock * @link http://themehybrid.com/hybrid-core * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ /** * Bookmarks Widget Class * * @since 0.6.0 */ class Hybrid_Widget_Bookmarks extends WP_Widget { /** * Set up the widget's unique name, ID, class, description, and other options. * * @since 1.2.0 */ function __construct() { /* Set up the widget options. */ $widget_options = array( 'classname' => 'bookmarks', 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your bookmarks (links).', 'hybrid-core' ) ); /* Set up the widget control options. */ $control_options = array( 'width' => 800, 'height' => 350 ); /* Create the widget. */ $this->WP_Widget( 'hybrid-bookmarks', // $this->id_base __( 'Bookmarks', 'hybrid-core' ), // $this->name $widget_options, // $this->widget_options $control_options // $this->control_options ); } /** * Outputs the widget based on the arguments input through the widget controls. * * @since 0.6.0 */ function widget( $sidebar, $instance ) { extract( $sidebar ); /* Set up the $before_widget ID for multiple widgets created by the bookmarks widget. */ if ( !empty( $instance['categorize'] ) ) $before_widget = preg_replace( '/id="[^"]*"/','id="%id"', $before_widget ); /* Add a class to $before_widget if one is set. */ if ( !empty( $instance['class'] ) ) $before_widget = str_replace( 'class="', 'class="' . esc_attr( $instance['class'] ) . ' ', $before_widget ); /* Set the $args for wp_list_bookmarks() to the $instance array. */ $args = $instance; /* wp_list_bookmarks() hasn't been updated in WP to use wp_parse_id_list(), so we have to pass strings for includes/excludes. */ if ( !empty( $args['category'] ) && is_array( $args['category'] ) ) $args['category'] = join( ', ', $args['category'] ); if ( !empty( $args['exclude_category'] ) && is_array( $args['exclude_category'] ) ) $args['exclude_category'] = join( ', ', $args['exclude_category'] ); if ( !empty( $args['include'] ) && is_array( $args['include'] ) ) $args['include'] = join( ',', $args['include'] ); if ( !empty( $args['exclude'] ) && is_array( $args['exclude'] ) ) $args['exclude'] = join( ',', $args['exclude'] ); /* If no limit is given, set it to -1. */ $args['limit'] = empty( $args['limit'] ) ? -1 : $args['limit']; /* Some arguments must be set to the sidebar arguments to be output correctly. */ $args['title_li'] = apply_filters( 'widget_title', ( empty( $args['title_li'] ) ? __( 'Bookmarks', 'hybrid-core' ) : $args['title_li'] ), $instance, $this->id_base ); $args['title_before'] = $before_title; $args['title_after'] = $after_title; $args['category_before'] = $before_widget; $args['category_after'] = $after_widget; $args['category_name'] = ''; $args['echo'] = false; /* Output the bookmarks widget. */ $bookmarks = str_replace( array( "\r", "\n", "\t" ), '', wp_list_bookmarks( $args ) ); /* If no title is given and the bookmarks aren't categorized, add a wrapper