From eca5c08d16a25d221eb7ba1bd5788d20d331dd79 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 2 Feb 2014 05:23:43 +1100 Subject: [PATCH] Add League Table widget and display future events --- admin/hooks/the-posts.php | 17 +++++++++ admin/hooks/widgets-init.php | 15 -------- admin/templates/events-calendar.php | 10 +++--- admin/widgets/calendar.php | 9 ++--- admin/widgets/table.php | 54 +++++++++++++++++++++++++++++ functions.php | 4 +-- sportspress.php | 3 +- 7 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 admin/hooks/the-posts.php delete mode 100644 admin/hooks/widgets-init.php create mode 100644 admin/widgets/table.php diff --git a/admin/hooks/the-posts.php b/admin/hooks/the-posts.php new file mode 100644 index 00000000..46d21110 --- /dev/null +++ b/admin/hooks/the-posts.php @@ -0,0 +1,17 @@ +post_count == 0 && isset( $wp_query->query_vars['sp_event'] ) ) { + $posts = $wpdb->get_results( $wp_query->request ); + } + return $posts; +} +//add_filter( 'the_posts', 'sportspress_the_posts' ); + +function sportspress_posts_where( $where, $that ) { + global $wpdb; + if( 'sp_event' == $that->query_vars['post_type'] && is_archive() ) + $where = str_replace( "{$wpdb->posts}.post_status = 'publish'", "{$wpdb->posts}.post_status = 'publish' OR $wpdb->posts.post_status = 'future'", $where ); + return $where; +} +add_filter( 'posts_where', 'sportspress_posts_where', 2, 10 ); diff --git a/admin/hooks/widgets-init.php b/admin/hooks/widgets-init.php deleted file mode 100644 index d864d2e2..00000000 --- a/admin/hooks/widgets-init.php +++ /dev/null @@ -1,15 +0,0 @@ -'; if ( $previous ) { - $calendar_output .= "\n\t\t".'« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . ''; + $calendar_output .= "\n\t\t".'« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . ''; } else { $calendar_output .= "\n\t\t".' '; } @@ -88,7 +88,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { $calendar_output .= "\n\t\t".' '; if ( $next ) { - $calendar_output .= "\n\t\t".'' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »'; + $calendar_output .= "\n\t\t".'' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »'; } else { $calendar_output .= "\n\t\t".' '; } diff --git a/admin/widgets/calendar.php b/admin/widgets/calendar.php index 035358ac..c126a220 100644 --- a/admin/widgets/calendar.php +++ b/admin/widgets/calendar.php @@ -2,8 +2,8 @@ class SportsPress_Widget_Calendar extends WP_Widget { function __construct() { - $widget_ops = array('classname' => 'widget_calendar sp_widget_calendar', 'description' => __( 'A calendar of your site’s Events.') ); - parent::__construct('sp_calendar', __('Events Calendar'), $widget_ops); + $widget_ops = array('classname' => 'widget_calendar widget_sp_calendar', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_calendar', __( 'Events Calendar', 'sportspress' ), $widget_ops); } function widget( $args, $instance ) { @@ -12,7 +12,7 @@ class SportsPress_Widget_Calendar extends WP_Widget { echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; - echo '
'; + echo '
'; echo sportspress_events_calendar(); echo '
'; echo $after_widget; @@ -29,8 +29,9 @@ class SportsPress_Widget_Calendar extends WP_Widget { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = strip_tags($instance['title']); ?> -

+

'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops); + } + + function widget( $args, $instance ) { + extract($args); + $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); + $id = empty($instance['id']) ? null : $instance['id']; + echo $before_widget; + if ( $title ) + echo $before_title . $title . $after_title; + echo '
'; + echo sportspress_league_table( $id ); + echo '
'; + echo $after_widget; + } + + function update( $new_instance, $old_instance ) { + $instance = $old_instance; + $instance['title'] = strip_tags($new_instance['title']); + $instance['id'] = intval($new_instance['id']); + + return $instance; + } + + function form( $instance ) { + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) ); + $title = strip_tags($instance['title']); + $id = intval($instance['id']); +?> +

+

+ +

+ 'sp_table', + 'name' => $this->get_field_name('id'), + 'id' => $this->get_field_id('id'), + 'show_option_none' => __( '-- Select --', 'sportspress' ), + 'selected' => $id, + 'values' => 'ID', + ); + sportspress_dropdown_pages( $args ); + ?> +

+