Add Events widget

This commit is contained in:
Brian Miyaji
2014-02-03 05:51:09 +11:00
parent eca5c08d16
commit 39d7bbac7f
18 changed files with 323 additions and 30 deletions

View File

@@ -1,5 +1,9 @@
<?php
function sportspress_admin_enqueue_scripts() {
// Add ThemeBoy icon font, used in the admin stylesheet.
wp_enqueue_style( 'themeboy', SPORTSPRESS_PLUGIN_URL . 'assets/css/themeboy.css', array(), null );
// Load our admin stylesheet.
wp_enqueue_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), time() );
wp_enqueue_script( 'jquery' );

View File

@@ -60,7 +60,7 @@ function sportspress_event_details_meta( $post ) {
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $league_id,
'value' => 'term_id',
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
sportspress_dropdown_taxonomies( $args );
@@ -73,7 +73,7 @@ function sportspress_event_details_meta( $post ) {
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $season_id,
'value' => 'term_id',
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
sportspress_dropdown_taxonomies( $args );
@@ -86,7 +86,7 @@ function sportspress_event_details_meta( $post ) {
'taxonomy' => 'sp_venue',
'name' => 'sp_venue',
'selected' => $venue_id,
'value' => 'term_id',
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
sportspress_dropdown_taxonomies( $args );

View File

@@ -60,7 +60,7 @@ function sportspress_list_player_meta( $post ) {
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $league_id,
'value' => 'term_id'
'values' => 'term_id'
);
sportspress_dropdown_taxonomies( $args );
?>
@@ -72,7 +72,7 @@ function sportspress_list_player_meta( $post ) {
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $season_id,
'value' => 'term_id'
'values' => 'term_id'
);
sportspress_dropdown_taxonomies( $args );
?>

View File

@@ -38,6 +38,7 @@ function sportspress_table_meta_init( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
remove_meta_box( 'sp_seasondiv', 'sp_table', 'side' );
remove_meta_box( 'sp_leaguediv', 'sp_table', 'side' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_table_team_meta', 'sp_table', 'side', 'high' );
if ( $teams && $teams != array(0) ):
@@ -57,7 +58,7 @@ function sportspress_table_team_meta( $post, $test ) {
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $league_id,
'value' => 'term_id'
'values' => 'term_id'
);
sportspress_dropdown_taxonomies( $args );
?>
@@ -69,7 +70,7 @@ function sportspress_table_team_meta( $post, $test ) {
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $season_id,
'value' => 'term_id'
'values' => 'term_id'
);
sportspress_dropdown_taxonomies( $args );
?>

View File

@@ -80,7 +80,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-right" href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
}
@@ -88,7 +88,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-left" href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
}
@@ -157,7 +157,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= '<td>';
if ( array_key_exists($day, $daywithpost) ) // any posts today?
$calendar_output .= '<a href="' . ( sizeof( $daywithpost[ $day ] ) > 1 ? add_query_arg( array( 'post_type' => 'sp_event' ), get_day_link( $thisyear, $thismonth, $day ) ) : get_permalink( $daywithpost[ $day ][0] ) ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
$calendar_output .= '<a data-tooltip data-options="disable_for_touch:true" class="has-tip" href="' . ( sizeof( $daywithpost[ $day ] ) > 1 ? add_query_arg( array( 'post_type' => 'sp_event' ), get_day_link( $thisyear, $thismonth, $day ) ) . '" title="' . sprintf( '%s Events', ( sizeof( $daywithpost[ $day ] ) ) ) : get_permalink( $daywithpost[ $day ][0] ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) ) . "\">$day</a>";
else
$calendar_output .= $day;
$calendar_output .= '</td>';

View File

@@ -0,0 +1,65 @@
<?php
if ( !function_exists( 'sportspress_events' ) ) {
function sportspress_events( $args = array() ) {
$options = array(
'post_type' => 'sp_event',
'posts_per_page' => 1,
'post_status' => 'publish',
'tax_query' => array(),
);
if ( isset( $args['number'] ) ):
$options['posts_per_page'] = $args['number'];
endif;
if ( isset( $args['status'] ) && $args['status'] == 'any' || $args['status'] == 'scheduled' ):
$options['post_status'] = array( 'publish', 'future' );
endif;
if ( isset( $args['league'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league
);
endif;
if ( isset( $args['season'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season
);
endif;
if ( isset( $args['venue'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue
);
endif;
$query = new WP_Query( $options );
if ( $query->have_posts() ):
$output = '<ul class="sp-events-list">';
while ( $query->have_posts() ):
$query->the_post();
$output .=
'<li>' .
'<span class="post-date">' . get_the_date() . '</span>' .
'<a href="' . get_permalink() . '">' . get_the_title() . '</a>' .
'</li>';
endwhile;
$output .= '</ul>';
wp_reset_postdata();
endif;
return apply_filters( 'sportspress_events', $output );
}
}

View File

@@ -17,19 +17,23 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$seasons = get_the_terms( $id, 'sp_season' );
$terms = array();
if ( sizeof( $leagues ) ):
if ( $leagues ):
$league = reset( $leagues );
$terms[] = $league->name;
endif;
if ( sizeof( $seasons ) ):
if ( $seasons ):
$season = reset( $seasons );
$terms[] = $season->name;
endif;
$title = sizeof( $terms ) ? implode( ' &mdash; ', $terms ) : get_the_title( $id );
$output = '<h4 class="sp-table-caption">' . $title . '</h4>' .
'<div class="sp-table-wrapper">' .
if ( ! is_singular( 'sp_table' ) )
$output = '<h4 class="sp-table-caption"><a href="' . get_permalink( $id ) . '">' . $title . '</a></h4>';
else
$output = '<h4 class="sp-table-caption">' . $title . '</h4>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-league-table sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id );

145
admin/widgets/events.php Normal file
View File

@@ -0,0 +1,145 @@
<?php
class SportsPress_Widget_Events extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_recent_entries widget_sp_events', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_events', __( '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'];
$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,
'league' => $league,
'season' => $season,
'venue' => $venue,
'team' => $team,
'number' => $number,
);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo '<div id="sp_events_wrap">';
echo sportspress_events( $args );
echo '</div>';
echo $after_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']);
$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' => '', 'status' => '', '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']);
$team = intval($instance['team']);
$number = intval($instance['number']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('status'); ?>"><?php _e( 'Status:', 'sportspress' ); ?></label>
<?php
$options = array(
'any' => __( 'Any', 'sportspress' ),
'played' => __( 'Played', 'sportspress' ),
'scheduled' => __( 'Scheduled', 'sportspress' ),
);
?>
<select id="<?php echo $this->get_field_id('status'); ?>" name="<?php echo $this->get_field_name('status'); ?>" class="widefat">
<?php foreach( $options as $key => $name ): ?>
<option value="<?php echo $key; ?>" <?php selected ( $key, $status ); ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<p><label for="<?php echo $this->get_field_id('league'); ?>"><?php _e( 'League:', 'sportspress' ); ?></label>
<?php
$args = array(
'taxonomy' => '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 );
?>
</p>
<p><label for="<?php echo $this->get_field_id('season'); ?>"><?php _e( 'Season:', 'sportspress' ); ?></label>
<?php
$args = array(
'taxonomy' => '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 );
?>
</p>
<p><label for="<?php echo $this->get_field_id('venue'); ?>"><?php _e( 'Venue:', 'sportspress' ); ?></label>
<?php
$args = array(
'taxonomy' => '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 );
?>
</p>
<p><label for="<?php echo $this->get_field_id('team'); ?>"><?php _e( 'Team:', 'sportspress' ); ?></label>
<?php
$args = array(
'post_type' => '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;
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php printf( __( 'Number of %s to show:', 'sportspress' ), __( 'events', 'sportspress' ) ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3"></p>
<?php
}
}
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Events" );' ) );

View File

@@ -3,7 +3,7 @@ class SportsPress_Widget_League_Table extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops);
parent::__construct('sp_table', __( 'League Table', 'sportspress' ), $widget_ops);
}
function widget( $args, $instance ) {
@@ -35,17 +35,19 @@ class SportsPress_Widget_League_Table extends WP_Widget {
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e( 'League Table:', 'sportspress' ); ?></label>
<?php
$args = array(
'post_type' => 'sp_table',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'show_option_none' => __( '-- Select --', 'sportspress' ),
'selected' => $id,
'values' => 'ID',
'class' => 'widefat',
);
sportspress_dropdown_pages( $args );
if ( ! sportspress_dropdown_pages( $args ) ):
sportspress_post_adder( 'sp_table' );
endif;
?>
</p>
<?php