From fd859eef3d150f4625d4c8de8676c0587adb6d13 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Mon, 3 Feb 2014 09:04:23 +1100 Subject: [PATCH] Add Countdown Timer widget --- admin/templates/events.php | 5 +- admin/widgets/countdown-timer.php | 91 +++++++++++++ .../{calendar.php => events-calendar.php} | 8 +- .../widgets/{events.php => future-events.php} | 33 ++--- admin/widgets/{table.php => league-table.php} | 2 +- admin/widgets/recent-events.php | 128 ++++++++++++++++++ assets/css/admin.css | 9 +- functions.php | 30 ++-- sportspress.php | 18 +-- 9 files changed, 268 insertions(+), 56 deletions(-) create mode 100644 admin/widgets/countdown-timer.php rename admin/widgets/{calendar.php => events-calendar.php} (79%) rename admin/widgets/{events.php => future-events.php} (77%) rename admin/widgets/{table.php => league-table.php} (95%) create mode 100644 admin/widgets/recent-events.php diff --git a/admin/templates/events.php b/admin/templates/events.php index aeee8542..3b3e59bb 100644 --- a/admin/templates/events.php +++ b/admin/templates/events.php @@ -13,8 +13,9 @@ if ( !function_exists( 'sportspress_events' ) ) { $options['posts_per_page'] = $args['number']; endif; - if ( isset( $args['status'] ) && $args['status'] == 'any' || $args['status'] == 'scheduled' ): - $options['post_status'] = array( 'publish', 'future' ); + if ( isset( $args['status'] ) && $args['status'] == 'future' ): + $options['post_status'] = array( 'future' ); + $options['order'] = 'ASC'; endif; if ( isset( $args['league'] ) ): diff --git a/admin/widgets/countdown-timer.php b/admin/widgets/countdown-timer.php new file mode 100644 index 00000000..7e5c38f1 --- /dev/null +++ b/admin/widgets/countdown-timer.php @@ -0,0 +1,91 @@ + 'widget_countdown_timer widget_sp_countdown_timer', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_countdown_timer', __( 'Countdown Timer', 'sportspress' ), $widget_ops); + } + + function widget( $args, $instance ) { + extract($args); + $title = apply_filters('widget_title', empty($instance['title']) ? __( 'Countdown Timer', 'sportspress' ) : $instance['title'], $instance, $this->id_base); + echo $before_widget; + $id = empty($instance['id']) ? null : $instance['id']; + if ( $title ) + echo $before_title . $title . $after_title; + if ( $id ) + $post = get_post( $id ); + if ( isset( $post ) ): + echo '
'; + echo '

' . $post->post_title . '

'; + + $leagues = get_the_terms( $post->ID, 'sp_league' ); + if ( $leagues ): + foreach( $leagues as $league ): + $term = get_term( $league->term_id, 'sp_league' ); + echo '
' . $term->name . '
'; + endforeach; + endif; + + $venues = get_the_terms( $post->ID, 'sp_venue' ); + if ( $venues ): + foreach( $venues as $venue ): + $term = get_term( $venue->term_id, 'sp_venue' ); + echo '
' . $term->name . '
'; + endforeach; + endif; + + $now = new DateTime( date("Y-m-d H:i:s") ); + $date = new DateTime( $post->post_date ); + $interval = $date->diff( $now ); + + echo '

'; + + echo '
'; + endif; + 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_event', + 'name' => $this->get_field_name('id'), + 'id' => $this->get_field_id('id'), + 'selected' => $id, + 'show_option_none' => '(' . __( 'Next Event', 'premier' ) . ')', + 'values' => 'ID', + 'class' => 'widefat', + 'show_dates' => true, + 'post_status' => 'future', + ); + if ( ! sportspress_dropdown_pages( $args ) ): + sportspress_post_adder( 'sp_event' ); + endif; + ?> +

+ 'widget_calendar widget_sp_calendar', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); - parent::__construct('sp_calendar', __( 'Events Calendar', 'sportspress' ), $widget_ops); + $widget_ops = array('classname' => 'widget_calendar widget_sp_events_calendar', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_events_calendar', __( 'Events Calendar', 'sportspress' ), $widget_ops); } function widget( $args, $instance ) { @@ -34,4 +34,4 @@ class SportsPress_Widget_Calendar extends WP_Widget { 'widget_recent_entries widget_sp_events', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); - parent::__construct('sp_events', __( 'Events', 'sportspress' ), $widget_ops); + $widget_ops = array('classname' => 'widget_recent_entries widget_sp_future_events', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_future_events', __( 'Future Events', 'sportspress' ), $widget_ops); } function widget( $args, $instance ) { extract($args); - $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); - $status = empty($instance['status']) ? null : $instance['status']; + $title = apply_filters('widget_title', empty($instance['title']) ? __( 'Future Events' ) : $instance['title'], $instance, $this->id_base); $league = empty($instance['league']) ? null : $instance['league']; $season = empty($instance['season']) ? null : $instance['season']; $venue = empty($instance['venue']) ? null : $instance['venue']; $team = empty($instance['team']) ? null : $instance['team']; $number = empty($instance['number']) ? get_option( 'posts_per_page' ) : $instance['number']; $args = array( - 'status' => $status, + 'status' => 'future', 'league' => $league, 'season' => $season, 'venue' => $venue, @@ -26,7 +25,7 @@ class SportsPress_Widget_Events extends WP_Widget { echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; - echo '
'; + echo '
'; echo sportspress_events( $args ); echo '
'; echo $after_widget; @@ -35,7 +34,6 @@ class SportsPress_Widget_Events extends WP_Widget { function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); - $instance['status'] = strip_tags($new_instance['status']); $instance['league'] = intval($new_instance['league']); $instance['season'] = intval($new_instance['season']); $instance['venue'] = intval($new_instance['venue']); @@ -46,9 +44,8 @@ class SportsPress_Widget_Events extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'status' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) ); $title = strip_tags($instance['title']); - $status = strip_tags($instance['status']); $league = intval($instance['league']); $season = intval($instance['season']); $venue = intval($instance['venue']); @@ -58,20 +55,6 @@ class SportsPress_Widget_Events extends WP_Widget {

-

- __( 'Any', 'sportspress' ), - 'played' => __( 'Played', 'sportspress' ), - 'scheduled' => __( 'Scheduled', 'sportspress' ), - ); - ?> - -

'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); - parent::__construct('sp_table', __( 'League Table', 'sportspress' ), $widget_ops); + parent::__construct('sp_league_table', __( 'League Table', 'sportspress' ), $widget_ops); } function widget( $args, $instance ) { diff --git a/admin/widgets/recent-events.php b/admin/widgets/recent-events.php new file mode 100644 index 00000000..c70b9297 --- /dev/null +++ b/admin/widgets/recent-events.php @@ -0,0 +1,128 @@ + 'widget_recent_entries widget_sp_recent_events', 'description' => __( 'SportsPress widget.', 'sportspress' ) ); + parent::__construct('sp_recent_events', __( 'Recent Events', 'sportspress' ), $widget_ops); + } + + function widget( $args, $instance ) { + extract($args); + $title = apply_filters('widget_title', empty($instance['title']) ? __( 'Recent Events' ) : $instance['title'], $instance, $this->id_base); + $league = empty($instance['league']) ? null : $instance['league']; + $season = empty($instance['season']) ? null : $instance['season']; + $venue = empty($instance['venue']) ? null : $instance['venue']; + $team = empty($instance['team']) ? null : $instance['team']; + $number = empty($instance['number']) ? get_option( 'posts_per_page' ) : $instance['number']; + $args = array( + 'status' => 'publish', + 'league' => $league, + 'season' => $season, + 'venue' => $venue, + 'team' => $team, + 'number' => $number, + ); + echo $before_widget; + if ( $title ) + echo $before_title . $title . $after_title; + echo '

'; + echo sportspress_events( $args ); + echo '
'; + echo $after_widget; + } + + function update( $new_instance, $old_instance ) { + $instance = $old_instance; + $instance['title'] = strip_tags($new_instance['title']); + $instance['league'] = intval($new_instance['league']); + $instance['season'] = intval($new_instance['season']); + $instance['venue'] = intval($new_instance['venue']); + $instance['team'] = intval($new_instance['team']); + $instance['number'] = intval($new_instance['number']); + + return $instance; + } + + function form( $instance ) { + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) ); + $title = strip_tags($instance['title']); + $league = intval($instance['league']); + $season = intval($instance['season']); + $venue = intval($instance['venue']); + $team = intval($instance['team']); + $number = intval($instance['number']); +?> +

+

+ +

+ 'sp_league', + 'name' => $this->get_field_name('league'), + 'id' => $this->get_field_id('league'), + 'selected' => $league, + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), + 'hide_empty' => 0, + 'values' => 'term_id', + 'class' => 'widefat', + ); + wp_dropdown_categories( $args ); + ?> +

+ +

+ 'sp_season', + 'name' => $this->get_field_name('season'), + 'id' => $this->get_field_id('season'), + 'selected' => $season, + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ), + 'hide_empty' => 0, + 'values' => 'term_id', + 'class' => 'widefat', + ); + wp_dropdown_categories( $args ); + ?> +

+ +

+ 'sp_venue', + 'name' => $this->get_field_name('venue'), + 'id' => $this->get_field_id('venue'), + 'selected' => $venue, + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Venues', 'sportspress' ) ), + 'hide_empty' => 0, + 'values' => 'term_id', + 'class' => 'widefat', + ); + wp_dropdown_categories( $args ); + ?> +

+ +

+ 'sp_team', + 'name' => $this->get_field_name('team'), + 'id' => $this->get_field_id('team'), + 'selected' => $team, + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'values' => 'ID', + 'class' => 'widefat', + ); + if ( ! sportspress_dropdown_pages( $args ) ): + sportspress_post_adder( 'sp_table' ); + endif; + ?> +

+ +

+

+ false, 'show_option_none' => false, + 'show_dates' => false, 'option_all_value' => 0, 'option_none_value' => -1, 'name' => 'page_id', @@ -270,15 +271,16 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) { 'posts_per_page' => -1, 'child_of' => 0, 'sort_order' => 'ASC', - 'sort_column' => 'post_title', + 'sort_column' => 'post_title', 'hierarchical' => 1, - 'exclude' => null, - 'include' => null, - 'meta_key' => null, - 'meta_value' => null, - 'authors' => null, + 'exclude' => null, + 'include' => null, + 'meta_key' => null, + 'meta_value' => null, + 'authors' => null, 'exclude_tree' => null, 'post_type' => 'page', + 'post_status' => 'publish', 'values' => 'post_name', 'class' => null, ); @@ -292,19 +294,21 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) { $posts = get_posts( $args ); if ( $posts ): printf( '' ); return true; else: diff --git a/sportspress.php b/sportspress.php index 0eee5009..1447fc2d 100644 --- a/sportspress.php +++ b/sportspress.php @@ -24,12 +24,12 @@ define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ ); // Libraries -include dirname( __FILE__ ) . '/lib/eos/eos.class.php' ; +require_once dirname( __FILE__ ) . '/lib/eos/eos.class.php' ; // Globals -include_once dirname( __FILE__ ) . '/admin/globals/continents.php'; -include_once dirname( __FILE__ ) . '/admin/globals/countries.php'; -include_once dirname( __FILE__ ) . '/admin/globals/sports.php'; +require_once dirname( __FILE__ ) . '/admin/globals/continents.php'; +require_once dirname( __FILE__ ) . '/admin/globals/countries.php'; +require_once dirname( __FILE__ ) . '/admin/globals/sports.php'; // Functions require_once dirname( __FILE__ ) . '/functions.php'; @@ -50,7 +50,7 @@ require_once dirname( __FILE__ ) . '/admin/templates/player-statistics.php'; require_once dirname( __FILE__ ) . '/admin/templates/team-columns.php'; // Settings -include dirname( __FILE__ ) . '/admin/settings/settings.php' ; +require_once dirname( __FILE__ ) . '/admin/settings/settings.php' ; // Custom post types require_once dirname( __FILE__ ) . '/admin/post-types/separator.php'; @@ -73,9 +73,11 @@ require_once dirname( __FILE__ ) . '/admin/terms/venue.php'; require_once dirname( __FILE__ ) . '/admin/terms/position.php'; // Widgets -require_once dirname( __FILE__ ) . '/admin/widgets/events.php'; -require_once dirname( __FILE__ ) . '/admin/widgets/calendar.php'; -require_once dirname( __FILE__ ) . '/admin/widgets/table.php'; +require_once dirname( __FILE__ ) . '/admin/widgets/recent-events.php'; +require_once dirname( __FILE__ ) . '/admin/widgets/future-events.php'; +require_once dirname( __FILE__ ) . '/admin/widgets/countdown-timer.php'; +require_once dirname( __FILE__ ) . '/admin/widgets/events-calendar.php'; +require_once dirname( __FILE__ ) . '/admin/widgets/league-table.php'; // Typical request actions require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php';