* @copyright Copyright (c) 2009-2013, Edward Caissie * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 2, as published by the * Free Software Foundation. * * You may NOT assume that you can use any other version of the GPL. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details * * You should have received a copy of the GNU General Public License along with * this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor * Boston, MA 02110-1301 USA * * The license for this software can also likely be found here: * http://www.gnu.org/licenses/gpl-2.0.html * * @version 2.2 * @date December 1, 2012 * Remove load_plugin_textdomain as redundant * Add filters to allow modification of author and date post meta details * Add filters to allow modification of category list post meta details * Add use current tag for single posts option * Add posts offset option * * @version 2.3 * @date February 17, 2013 * Added code block termination comments and other comments / documentation * Moved all code into class structure * Replace `query_posts` with new `WP_Query` class object * * @version 2.3.1 * @date February 17, 2013 * Fixed where content and excerpt post thumbnail sizes are used * Fixed conditional check for post thumbnails usage * * @todo Finish "use current" option * @todo Add Link to title option */ class BNS_Featured_Tag_Widget extends WP_Widget { /** * Constructor */ function BNS_Featured_Tag_Widget() { /** Widget settings */ $widget_ops = array( 'classname' => 'bns-featured-tag', 'description' => __( 'Displays most recent posts from a specific featured tag or tags.', 'bns-ft' ) ); /** Widget control settings */ $control_ops = array( 'width' => 200, 'id_base' => 'bns-featured-tag' ); /** Create the widget */ $this->WP_Widget( 'bns-featured-tag', 'BNS Featured Tag', $widget_ops, $control_ops ); /** * Check installed WordPress version for compatibility * @internal Requires WordPress version 2.9 * @internal @uses current_theme_supports * @internal @uses the_post_thumbnail * @internal @uses has_post_thumbnail */ global $wp_version; $exit_message = 'BNS Featured Tag requires WordPress version 2.9 or newer. Please Update!'; if ( version_compare( $wp_version, "2.9", "<") ) { exit ( $exit_message ); } /** End if - version compare */ /** Add Scripts and Styles */ add_action( 'wp_enqueue_scripts', array( $this, 'BNSFT_Scripts_and_Styles' ) ); /** Add Options Scripts and Styles */ add_action( 'admin_enqueue_scripts', array( $this, 'BNSFT_Options_Scripts_and_Styles' ) ); /** Add Shortcode */ add_shortcode( 'bnsft', array( $this, 'bnsft_shortcode' ) ); /** Add load_bnsft_widget function to the widgets_init hook */ add_action( 'widgets_init', array( $this, 'load_bnsft_widget' ) ); } /** End function - constructor */ /** * BNS Featured Tag Custom Excerpt * * Strips the post content of tags and returns the entire post content if there * are less than $length words; otherwise the amount of words equal to $length * is returned. In both cases, the returned text is appended with a permalink to * the full post. * * @package BNS_Featured_Tag * @since 1.9 * * @param $text - post content * @param int $length - user defined amount of words * * @uses apply_filters * @uses get_permalink * @uses the_title_attribute * * @return string * * @version 2.2 * @date December 1, 2012 * Added filter to full post link element */ function bnsft_custom_excerpt( $text, $length = 55 ) { $text = strip_tags( $text ); $words = explode( ' ', $text, $length + 1 ); /** @var $link_symbol - default: infinity symbol */ $link_symbol = apply_filters( 'bnsft_link_symbol', '∞' ); /** Create link to full post for end of custom length excerpt output */ $bnsft_link = ' ' . $link_symbol . ''; if ( ( ! $length ) || ( count( $words ) < $length ) ) { $text .= $bnsft_link; return $text; } else { array_pop( $words ); array_push( $words, '...' ); $text = implode( ' ', $words ); } /** End if - not length */ $text .= $bnsft_link; return $text; } /** End function - custom excerpt */ /** * Enqueue Plugin Scripts and Styles * * @package BNS_Featured_Tag * @since 1.9 * * @uses get_plugin_data * @uses plugin_dir_path * @uses plugin_dir_url * @uses wp_enqueue_style * * @internal Used with action: wp_enqueue_styles * * @version 1.9.1 * @date December 14, 2011 * Fixed 404 error when 'bnsft-custom-style.css' is not available * * @version 2.2 * @date December 1, 2012 * Programmatically add version number to enqueue calls */ function BNSFT_Scripts_and_Styles() { /** Call the wp-admin plugin code */ require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); /** @var $bnsfc_data - holds the plugin header data */ $bnsft_data = get_plugin_data( __FILE__ ); /** Enqueue Scripts */ /** Enqueue Styles */ wp_enqueue_style( 'BNSFT-Style', plugin_dir_url( __FILE__ ) . 'bnsft-style.css', array(), $bnsft_data['Version'], 'screen' ); if ( is_readable( plugin_dir_path( __FILE__ ) . 'bnsft-custom-style.css' ) ) { wp_enqueue_style( 'BNSFT-Custom-Style', plugin_dir_url( __FILE__ ) . 'bnsft-custom-style.css', array(), $bnsft_data['Version'], 'screen' ); } /** End if - is readable */ } /** End function - scripts and styles */ /** * Enqueue Options Plugin Scripts and Styles * * Add plugin options scripts and stylesheet(s) to be used only on the Administration Panels * * @package BNS_Featured_Category * @since 2.0 * * @uses plugin_dir_path * @uses plugin_dir_url * @uses wp_enqueue_script * @uses wp_enqueue_style * * @internal 'jQuery' is enqueued as a dependency of the 'bnsft-options.js' enqueue * @internal Used with action: admin_enqueue_scripts */ function BNSFT_Options_Scripts_and_Styles() { /** Call the wp-admin plugin code */ require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); /** @var $bnsfc_data - holds the plugin header data */ $bnsft_data = get_plugin_data( __FILE__ ); /** Enqueue Options Scripts */ wp_enqueue_script( 'bnsft-options', plugin_dir_url( __FILE__ ) . 'bnsft-options.js', array( 'jquery' ), $bnsft_data['Version'] ); /** Enqueue Options Style Sheets */ wp_enqueue_style( 'BNSFT-Option-Style', plugin_dir_url( __FILE__ ) . 'bnsft-option-style.css', array(), $bnsft_data['Version'], 'screen' ); if ( is_readable( plugin_dir_path( __FILE__ ) . 'bnsft-options-custom-style.css' ) ) { wp_enqueue_style( 'BNSFT-Options-Custom-Style', plugin_dir_url( __FILE__ ) . 'bnsft-options-custom-style.css', array(), $bnsft_data['Version'], 'screen' ); } /** End if - is readable */ } /** End function - options scripts and styles */ /** * Widget * * @param array $args * @param array $instance * * @version 2.3.1 * @date February 17, 2013 * Fixed where content and excerpt post thumbnail sizes are used */ function widget( $args, $instance ) { extract( $args ); /** User-selected settings */ $title = apply_filters( 'widget_title', $instance['title'] ); $tag_choice = $instance['tag_choice']; $use_current = $instance['use_current']; $show_count = $instance['show_count']; $offset = $instance['offset']; $sort_order = $instance['sort_order']; $use_thumbnails = $instance['use_thumbnails']; $content_thumb = $instance['content_thumb']; $excerpt_thumb = $instance['excerpt_thumb']; $show_meta = $instance['show_meta']; $show_comments = $instance['show_comments']; $show_cats = $instance['show_cats']; $show_tags = $instance['show_tags']; $show_tag_desc = $instance['show_tag_desc']; $only_titles = $instance['only_titles']; $no_titles = $instance['no_titles']; $show_full = $instance['show_full']; $excerpt_length = $instance['excerpt_length']; $no_excerpt = $instance['no_excerpt']; /** Plugin requires counter variable to be part of its arguments?! */ $count = $instance['count']; /** @var $before_widget string - defined by theme */ echo $before_widget; /** Widget $title $before_widget and $after_widget defined by theme */ if ( $title ) { /** @var $before_title string - defined by theme */ /** @var $after_title string - defined by theme */ echo $before_title . $title . $after_title; } /** End if - title */ /** Display posts from widget settings */ /** Replace spaces with hyphens to create tag slugs from the name */ $tag_choice = str_replace( ' ', '-', $tag_choice ); /** Remove leading hyphens from tag slugs if multiple tag names are entered with leading spaces */ $tag_choice = str_replace( ',-', ', ', $tag_choice ); /** Check if $sort_order is set to rand (random) and use the `orderby` parameter; otherwise use the `order` parameter */ if ( 'rand' == $sort_order ) { $query_args = array( 'tag' => $tag_choice, 'posts_per_page' => $show_count, 'offset' => $offset, 'orderby' => $sort_order ); } else { $query_args = array( 'tag' => $tag_choice, 'posts_per_page' => $show_count, 'offset' => $offset, 'order' => $sort_order ); } /** End if - sort order */ /** @var $bnsft_query - New query object to hold specific posts */ $bnsft_query = new WP_Query( $query_args ); if ( $show_tag_desc ) { echo '
' . __( 'Pages: ', 'bns-ft') . '', 'after' => '
', 'next_or_number' => 'number' ) ); } elseif ( isset( $instance['excerpt_length']) && $instance['excerpt_length'] > 0 ) { if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() && ( $use_thumbnails ) ) { ?> 'alignleft' ) ); ?> bnsft_custom_excerpt( get_the_content(), $instance['excerpt_length'] ); } elseif ( ! $instance['no_excerpt'] ) { if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() && ( $use_thumbnails ) ) { ?> 'alignleft' ) ); ?> 'alignleft' ) ); ?>
id="get_field_id( 'show_tag_desc' ); ?>" name="get_field_name( 'show_tag_desc' ); ?>" />
id="get_field_id( 'use_current' ); ?>" name="get_field_name( 'use_current' ); ?>" />
|
|
|
|
|
id="get_field_id( 'only_titles' ); ?>" name="get_field_name( 'only_titles' ); ?>" />
'; ?>|
|
|