diff --git a/admin/hooks/manage-posts-columns.php b/admin/hooks/manage-posts-columns.php index 2e2570f1..1299775c 100644 --- a/admin/hooks/manage-posts-columns.php +++ b/admin/hooks/manage-posts-columns.php @@ -97,17 +97,11 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) { case 'sp_sponsor': echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—'; break; - case 'sp_kickoff': - if ( $post->post_status == 'future' ): - _e( 'Scheduled', 'sportspress' ); - elseif( $post->post_status == 'publish' ): - _e( 'Played', 'sportspress' ); - elseif( $post->post_status == 'draft' ): - _e( 'Draft', 'sportspress' ); - else: - _e( 'Pending Review', 'sportspress' ); - endif; - echo '
' . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ); + case 'sp_datetime': + echo sportspress_get_post_datetime( $post ); + break; + case 'sp_events': + echo sizeof( sportspress_get_calendar_data( $post_id ) ); break; case 'sp_address': echo get_post_meta( $post_id, 'sp_address', true ) ? get_post_meta( $post_id, 'sp_address', true ) : '—'; diff --git a/admin/hooks/register-activation-hook.php b/admin/hooks/register-activation-hook.php index b7fb5c7b..1c085ded 100644 --- a/admin/hooks/register-activation-hook.php +++ b/admin/hooks/register-activation-hook.php @@ -77,11 +77,12 @@ function sportspress_activation_hook() { ); // Flush rewrite rules - sportspress_event_post_init(); sportspress_result_post_init(); sportspress_outcome_post_init(); sportspress_column_post_init(); sportspress_statistic_post_init(); + sportspress_event_post_init(); + sportspress_calendar_post_init(); sportspress_team_post_init(); sportspress_table_post_init(); sportspress_player_post_init(); @@ -89,6 +90,7 @@ function sportspress_activation_hook() { sportspress_staff_post_init(); sportspress_position_term_init(); sportspress_season_term_init(); + sportspress_league_term_init(); flush_rewrite_rules(); } register_activation_hook( SPORTSPRESS_PLUGIN_FILE, 'sportspress_activation_hook' ); diff --git a/admin/post-types/calendar.php b/admin/post-types/calendar.php index 246f416d..ae70d6f6 100644 --- a/admin/post-types/calendar.php +++ b/admin/post-types/calendar.php @@ -28,6 +28,7 @@ function sportspress_calendar_edit_columns() { 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_venue' => __( 'Venues', 'sportspress' ), + 'sp_events' => __( 'Events', 'sportspress' ), 'sp_views' => __( 'Views', 'sportspress' ), ); return $columns; @@ -44,7 +45,7 @@ function sportspress_calendar_meta_init( $post ) { function sportspress_calendar_events_meta( $post ) { $seasons = get_the_terms( $post->ID, 'sp_season' ); - $data = sportspress_get_calendar_data( $post->ID, true ); + $data = sportspress_get_calendar_data( $post->ID ); sportspress_edit_calendar_table( $data ); diff --git a/admin/post-types/event.php b/admin/post-types/event.php index 48d72a13..2eeee116 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -198,7 +198,7 @@ function sportspress_event_edit_columns() { 'sp_league' => __( 'League', 'sportspress' ), 'sp_season' => __( 'Season', 'sportspress' ), 'sp_venue' => __( 'Venue', 'sportspress' ), - 'sp_kickoff' => __( 'Date/Time', 'sportspress' ), + 'sp_datetime' => __( 'Date/Time', 'sportspress' ), 'sp_views' => __( 'Views', 'sportspress' ), ); return $columns; @@ -206,7 +206,7 @@ function sportspress_event_edit_columns() { add_filter( 'manage_edit-sp_event_columns', 'sportspress_event_edit_columns' ); function sportspress_event_edit_sortable_columns( $columns ) { - $columns['sp_kickoff'] = 'sp_kickoff'; + $columns['sp_datetime'] = 'sp_datetime'; return $columns; } add_filter( 'manage_edit-sp_event_sortable_columns', 'sportspress_event_edit_sortable_columns' ); diff --git a/admin/templates/events-calendar.php b/admin/templates/events-calendar.php index 4a652b81..167ff6a2 100644 --- a/admin/templates/events-calendar.php +++ b/admin/templates/events-calendar.php @@ -5,7 +5,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { if ( ! $id ) $id = get_the_ID(); - global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; + global $wpdb, $m, $wp_locale, $posts; + $initial = false; $echo = 1; @@ -16,6 +17,10 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); + // Get year and month from query vars + $year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : 0; + $monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : 0; + // Let's figure out when we are if ( !empty($monthnum) && !empty($year) ) { $thismonth = ''.zeroise(intval($monthnum), 2); @@ -43,20 +48,20 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' - AND post_type = 'sp_event' AND post_status = 'publish' + AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' ) ORDER BY post_date DESC LIMIT 1"); $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' - AND post_type = 'sp_event' AND post_status = 'publish' + AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' ) ORDER BY post_date ASC LIMIT 1"); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption', 'sportspress'); - $calendar_output = ' - + $calendar_output = '

' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '

+
' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '
'; @@ -80,7 +85,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { '; if ( $previous ) { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t".''; } else { $calendar_output .= "\n\t\t".''; } @@ -88,7 +93,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { $calendar_output .= "\n\t\t".''; if ( $next ) { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t".''; } else { $calendar_output .= "\n\t\t".''; } @@ -103,7 +108,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { // Get days with posts $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' - AND post_type = 'sp_event' AND post_status = 'publish' + AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' ) AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { @@ -123,7 +128,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { ."FROM $wpdb->posts " ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " - ."AND post_type = 'sp_event' AND post_status = 'publish'" + ."AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )" ); if ( $ak_post_titles ) { foreach ( (array) $ak_post_titles as $ak_post_title ) { @@ -157,7 +162,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) { $calendar_output .= ''; diff --git a/functions.php b/functions.php index b4d0b0db..f69ec236 100644 --- a/functions.php +++ b/functions.php @@ -135,6 +135,21 @@ if ( !function_exists( 'sportspress_set_post_views' ) ) { } } +if ( !function_exists( 'sportspress_get_post_datetime' ) ) { + function sportspress_get_post_datetime( $post ) { + if ( $post->post_status == 'future' ): + $status = __( 'Scheduled', 'sportspress' ); + elseif( $post->post_status == 'publish' ): + $status = __( 'Played', 'sportspress' ); + elseif( $post->post_status == 'draft' ): + $status = __( 'Draft', 'sportspress' ); + else: + $status = __( 'Pending Review', 'sportspress' ); + endif; + return $status . '
' . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ); + } +} + if ( !function_exists( 'sportspress_get_post_precision' ) ) { function sportspress_get_post_precision( $post_id ) { $precision = get_post_meta ( $post_id, 'sp_precision', true ); @@ -594,7 +609,7 @@ if ( !function_exists( 'sportspress_edit_calendar_table' ) ) { ?>
« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '  ' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' » '; if ( in_array($day, $daywithpost) ) // any posts today? - $calendar_output .= '$day"; + $calendar_output .= '$day"; else $calendar_output .= $day; $calendar_output .= '
- post_title; ?> + post_title, null, null, $event->ID ); ?> ID ); ?> @@ -1161,24 +1176,6 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) { $seasons = get_the_terms( $post_id, 'sp_season' ); $venues = get_the_terms( $post_id, 'sp_venue' ); - if ( ! $leagues || ! $seasons || ! $venues ) - return array(); - - $league_ids = array(); - foreach( $leagues as $league ): - $league_ids[] = $league->term_id; - endforeach; - - $season_ids = array(); - foreach( $seasons as $season ): - $season_ids[] = $season->term_id; - endforeach; - - $venue_ids = array(); - foreach( $venues as $venue ): - $venue_ids[] = $venue->term_id; - endforeach; - $args = array( 'post_type' => 'sp_event', 'numberposts' => -1, @@ -1187,24 +1184,46 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) { 'order' => 'ASC', 'post_status' => 'any', 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_ids - ), - array( - 'taxonomy' => 'sp_season', - 'field' => 'id', - 'terms' => $season_ids - ), - array( - 'taxonomy' => 'sp_venue', - 'field' => 'id', - 'terms' => $venue_ids - ), + 'relation' => 'AND' ), ); + + if ( $leagues ): + $league_ids = array(); + foreach( $leagues as $league ): + $league_ids[] = $league->term_id; + endforeach; + $args['tax_query'][] = array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_ids + ); + endif; + + if ( $seasons ): + $season_ids = array(); + foreach( $seasons as $season ): + $season_ids[] = $season->term_id; + endforeach; + $args['tax_query'][] = array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $season_ids + ); + endif; + + if ( $venues ): + $venue_ids = array(); + foreach( $venues as $venue ): + $venue_ids[] = $venue->term_id; + endforeach; + $args['tax_query'][] = array( + 'taxonomy' => 'sp_venue', + 'field' => 'id', + 'terms' => $venue_ids + ); + endif; + $events = get_posts( $args ); return $events; diff --git a/sportspress.php b/sportspress.php index 8830fd56..fcbb3a35 100644 --- a/sportspress.php +++ b/sportspress.php @@ -59,7 +59,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/metric.php'; require_once dirname( __FILE__ ) . '/admin/post-types/result.php'; require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php'; require_once dirname( __FILE__ ) . '/admin/post-types/event.php'; -#require_once dirname( __FILE__ ) . '/admin/post-types/calendar.php'; +require_once dirname( __FILE__ ) . '/admin/post-types/calendar.php'; require_once dirname( __FILE__ ) . '/admin/post-types/team.php'; require_once dirname( __FILE__ ) . '/admin/post-types/table.php'; require_once dirname( __FILE__ ) . '/admin/post-types/player.php';