From e39b938d6eb35f787685adcfd96f98965f1a76eb Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Mon, 17 Mar 2014 19:12:12 +1100 Subject: [PATCH] Add events list template --- admin/hooks/manage-posts-columns.php | 2 +- admin/hooks/save-post.php | 8 +- admin/hooks/the-content.php | 32 ++++++- admin/post-types/calendar.php | 4 +- admin/post-types/event.php | 21 +++++ admin/templates/events-calendar.php | 6 +- admin/templates/events-list.php | 121 +++++++++++++++++++++++++++ assets/css/admin.css | 13 +-- assets/css/sportspress.css | 9 ++ assets/js/admin.js | 12 +++ functions.php | 83 +++++++++++++++--- sportspress.php | 1 + 12 files changed, 286 insertions(+), 26 deletions(-) create mode 100644 admin/templates/events-list.php diff --git a/admin/hooks/manage-posts-columns.php b/admin/hooks/manage-posts-columns.php index a591c45f..66bdd8e4 100644 --- a/admin/hooks/manage-posts-columns.php +++ b/admin/hooks/manage-posts-columns.php @@ -67,7 +67,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) { endif; if ( $team_result != null ): - echo '' . $team_result . ' '; + echo '' . $team_result . ' '; endif; echo $team->post_title; diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index eb473994..6b3c5cd6 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -49,9 +49,15 @@ function sportspress_save_post( $post_id ) { // Update venue taxonomy wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' ); + // Update video + update_post_meta( $post_id, 'sp_video', sportspress_array_value( $_POST, 'sp_video', null ) ); + break; case ( 'sp_calendar' ): + + // Update columns array + update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) ); // Update format update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'calendar' ) ); @@ -171,7 +177,7 @@ function sportspress_save_post( $post_id ) { case ( 'sp_list' ): // Update statistics array - update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) ); + update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) ); // Update players array update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) ); diff --git a/admin/hooks/the-content.php b/admin/hooks/the-content.php index 4cae20cf..bba6ade7 100644 --- a/admin/hooks/the-content.php +++ b/admin/hooks/the-content.php @@ -13,16 +13,42 @@ function sportspress_default_event_content( $content ) { $results = sportspress_event_results(); $players = sportspress_event_players(); $staff = sportspress_event_staff(); + $id = get_the_ID(); + $video_url = get_post_meta( $id, 'sp_video', true ); + if ( $video_url ): + global $wp_embed; + $video = $wp_embed->autoembed( $video_url ); + else: + $video = ''; + endif; if ( $results ): - $content = $results . $details . $players . $staff . $content; + $content = $video . $results . $details . $players . $staff . $content; else: $venue = sportspress_event_venue(); - $content = $details . $venue . $players . $staff . $content; + $content = $video . $details . $venue . $players . $staff . $content; endif; endif; return $content; } -add_filter( 'the_content', 'sportspress_default_event_content' ); +add_filter( 'the_content', 'sportspress_default_event_content', 7 ); + +function sportspress_default_calendar_content( $content ) { + if ( is_singular( 'sp_calendar' ) && in_the_loop() ): + $id = get_the_ID(); + $format = get_post_meta( $id, 'sp_format', true ); + switch ( $format ): + case 'list': + $calendar = sportspress_events_list( $id ); + break; + default: + $calendar = sportspress_events_calendar( $id, true, false ); + break; + endswitch; + $content = $calendar . $content; + endif; + return $content; +} +add_filter( 'the_content', 'sportspress_default_calendar_content' ); function sportspress_default_team_content( $content ) { if ( is_singular( 'sp_team' ) && in_the_loop() ): diff --git a/admin/post-types/calendar.php b/admin/post-types/calendar.php index 407a5676..1d207158 100644 --- a/admin/post-types/calendar.php +++ b/admin/post-types/calendar.php @@ -143,9 +143,9 @@ function sportspress_calendar_details_meta( $post, $test ) { function sportspress_calendar_events_meta( $post ) { - $data = sportspress_get_calendar_data( $post->ID ); + list( $data, $usecolumns ) = sportspress_get_calendar_data( $post->ID, true ); - sportspress_edit_calendar_table( $data ); + sportspress_edit_calendar_table( $data, $usecolumns ); sportspress_nonce(); diff --git a/admin/post-types/event.php b/admin/post-types/event.php index 39435087..c81873fb 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -67,6 +67,7 @@ function sportspress_event_meta_init( $post ) { add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_event_format_meta', 'sp_event', 'side', 'high' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_event_details_meta', 'sp_event', 'side', 'high' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_event_team_meta', 'sp_event', 'side', 'default' ); + add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'sportspress_event_video_meta', 'sp_event', 'side', 'low' ); if ( sizeof( $teams ) > 0 ) add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sportspress_event_results_meta', 'sp_event', 'normal', 'high' ); @@ -193,6 +194,26 @@ function sportspress_event_team_meta( $post ) { sportspress_nonce(); } +function sportspress_event_video_meta( $post ) { + $video = get_post_meta( $post->ID, 'sp_video', true ); + if ( $video ): + ?> +
+ +

+
+ + +
+

+
+ ID, 'sp_team', false ); $stats = (array)get_post_meta( $post->ID, 'sp_players', true ); diff --git a/admin/templates/events-calendar.php b/admin/templates/events-calendar.php index 89dea273..466764d0 100644 --- a/admin/templates/events-calendar.php +++ b/admin/templates/events-calendar.php @@ -1,6 +1,6 @@ - ' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . ' + <' . $caption_tag . ' class="sp-table-caption">' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . ' '; diff --git a/admin/templates/events-list.php b/admin/templates/events-list.php new file mode 100644 index 00000000..975a0155 --- /dev/null +++ b/admin/templates/events-list.php @@ -0,0 +1,121 @@ +' . + '' . '' . ''; + + list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true ); + + $output .= ''; + + if ( in_array( 'event', $usecolumns ) ) + $output .= ''; + + if ( in_array( 'teams', $usecolumns ) ) + $output .= ''; + + if ( in_array( 'time', $usecolumns ) ) + $output .= ''; + + if ( in_array( 'article', $usecolumns ) ) + $output .= ''; + + $output .= '' . '' . ''; + + $i = 0; + foreach ( $data as $event ): + $teams = get_post_meta( $event->ID, 'sp_team' ); + $results = get_post_meta( $event->ID, 'sp_results', true ); + $video = get_post_meta( $event->ID, 'sp_video', true ); + + $output .= ''; + + $output .= ''; + + if ( in_array( 'event', $usecolumns ) ) + $output .= ''; + + if ( in_array( 'teams', $usecolumns ) ): + $output .= ''; + endif; + + if ( in_array( 'time', $usecolumns ) ) + $output .= ''; + + if ( in_array( 'article', $usecolumns ) ): + $output .= ''; + endif; + + $output .= ''; + + $i++; + endforeach; + + $output .= '' . '
' . __( 'Date', 'sportspress' ). '' . __( 'Event', 'sportspress' ). '' . __( 'Teams', 'sportspress' ). '' . __( 'Time', 'sportspress' ). '' . __( 'Article', 'sportspress' ). '
' . get_post_time( get_option( 'date_format' ), false, $event ) . '' . $event->post_title . ''; + + $teams = get_post_meta( $event->ID, 'sp_team', false ); + if ( $teams ): + foreach ( $teams as $team ): + $name = get_the_title( $team ); + if ( $name ): + $team_results = sportspress_array_value( $results, $team, null ); + + if ( $main_result ): + $team_result = sportspress_array_value( $team_results, $main_result, null ); + else: + if ( is_array( $team_results ) ): + end( $team_results ); + $team_result = prev( $team_results ); + else: + $team_result = null; + endif; + endif; + + $output .= $name; + + if ( $team_result != null ): + $output .= ' (' . $team_result . ')'; + endif; + + $output .= '
'; + endif; + endforeach; + else: + $output .= '—'; + endif; + + $output .= '
' . get_post_time( get_option( 'time_format' ), false, $event ) . ' + '; + + if ( $video ): + $output .= '
'; + elseif ( has_post_thumbnail( $event->ID ) ): + $output .= '
'; + endif; + if ( $event->post_content !== null ): + if ( $event->post_status == 'publish' ): + $output .= __( 'Recap', 'sportspress' ); + else: + $output .= __( 'Preview', 'sportspress' ); + endif; + endif; + + $output .= '
+
' . ''; + + return apply_filters( 'sportspress_events_list', $output ); + + } +} diff --git a/assets/css/admin.css b/assets/css/admin.css index 42d061c5..da16c4b8 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -83,7 +83,12 @@ content: "\f163"; } -.fixed .column-sp_team strong { +#sp_videodiv .inside > fieldset > p:last-child { + margin-bottom: 1px !important; +} + +.fixed .column-sp_team strong.result, +.sp-calendar-table strong.result { background: #888; color: #fff; font-size: 11px; @@ -280,10 +285,6 @@ table.widefat.sp-data-table th.column-outcome { width: 10em; } -table.widefat.sp-data-table th.column-event { - width: 40%; -} - table.widefat.sp-data-table td { line-height: 2; overflow: visible; @@ -322,7 +323,7 @@ table.widefat.sp-data-table tr:hover a.sp-edit-name { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; } -table.widefat.sp-league-table th input[type=checkbox] { +table.widefat.sp-data-table th:not(.check-column) input[type=checkbox] { margin: -4px 1px 0; vertical-align: middle; } diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index efc70ba5..2418dc81 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -32,6 +32,15 @@ width: auto; } +/* Events List */ +.sp-events-list .column-article { + white-space: nowrap; +} +.sp-events-list .column-article a .dashicons { + padding-right: 3px; + text-decoration: none; +} + /* Google Maps */ .sp-google-map { height: 320px; diff --git a/assets/js/admin.js b/assets/js/admin.js index 840b7b5e..017b421b 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -212,6 +212,18 @@ jQuery(document).ready(function($){ // Trigger check check $(".sp-data-table").trigger("checkCheck"); + // Video embed + $(".sp-add-video").click(function() { + $(this).closest("fieldset").hide().siblings(".sp-video-field").show(); + return false; + }); + + // Removing video embed + $(".sp-remove-video").click(function() { + $(this).closest("fieldset").hide().siblings(".sp-video-adder").show().siblings(".sp-video-field").find("input").val(null); + return false; + }); + // Equation selector $(".sp-equation-selector select:last").change(function() { $(this).siblings().change(function() { diff --git a/functions.php b/functions.php index c989bac8..58ec4084 100644 --- a/functions.php +++ b/functions.php @@ -758,28 +758,84 @@ if ( !function_exists( 'sportspress_get_var_calculates' ) ) { } if ( !function_exists( 'sportspress_edit_calendar_table' ) ) { - function sportspress_edit_calendar_table( $data = array() ) { + function sportspress_edit_calendar_table( $data = array(), $usecolumns = null ) { + if ( is_array( $usecolumns ) ) + $usecolumns = array_filter( $usecolumns ); ?>
- - - - + + + + + 0 ): + $options = get_option( 'sportspress' ); + $main_result = sportspress_array_value( $options, 'main_result', null ); $i = 0; foreach ( $data as $event ): + $teams = get_post_meta( $event->ID, 'sp_team' ); + $results = get_post_meta( $event->ID, 'sp_results', true ); $video = get_post_meta( $event->ID, 'sp_video', true ); ?> + $label ): ?> @@ -902,8 +958,8 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) { $label ): ?> - @@ -1438,11 +1494,12 @@ if ( !function_exists( 'sportspress_event_players_sub_filter' ) ) { if ( !function_exists( 'sportspress_get_calendar_data' ) ) { - function sportspress_get_calendar_data( $post_id ) { + function sportspress_get_calendar_data( $post_id, $admin = false ) { $leagues = get_the_terms( $post_id, 'sp_league' ); $seasons = get_the_terms( $post_id, 'sp_season' ); $venues = get_the_terms( $post_id, 'sp_venue' ); $team = get_post_meta( $post_id, 'sp_team', true ); + $usecolumns = get_post_meta( $post_id, 'sp_columns', true ); $args = array( 'post_type' => 'sp_event', @@ -1503,7 +1560,11 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) { $events = get_posts( $args ); - return $events; + if ( $admin ): + return array( $events, $usecolumns ); + else: + return $events; + endif; } } @@ -2057,7 +2118,7 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { $stats = (array)get_post_meta( $post_id, 'sp_players', true ); $orderby = get_post_meta( $post_id, 'sp_orderby', true ); $order = get_post_meta( $post_id, 'sp_order', true ); - $usecolumns = get_post_meta( $post_id, 'sp_statistics', true ); + $usecolumns = get_post_meta( $post_id, 'sp_columns', true ); // Get labels from result variables $columns = (array)sportspress_get_var_labels( 'sp_statistic' ); diff --git a/sportspress.php b/sportspress.php index 0259c5a8..eb1c98e9 100644 --- a/sportspress.php +++ b/sportspress.php @@ -44,6 +44,7 @@ require_once dirname( __FILE__ ) . '/admin/templates/event-staff.php'; require_once dirname( __FILE__ ) . '/admin/templates/event-venue.php'; require_once dirname( __FILE__ ) . '/admin/templates/events.php'; require_once dirname( __FILE__ ) . '/admin/templates/events-calendar.php'; +require_once dirname( __FILE__ ) . '/admin/templates/events-list.php'; require_once dirname( __FILE__ ) . '/admin/templates/league-table.php'; require_once dirname( __FILE__ ) . '/admin/templates/player-league-statistics.php'; require_once dirname( __FILE__ ) . '/admin/templates/player-list.php';
+ + + + + + + + + +
post_title; ?> + ' . $team_result . ' '; + endif; + + echo $name . '
'; + endif; + endforeach; + ?> +
@@ -832,7 +888,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) { #