Add events list template

This commit is contained in:
Brian Miyaji
2014-03-17 19:12:12 +11:00
parent a7eb732933
commit e39b938d6e
12 changed files with 286 additions and 26 deletions

View File

@@ -67,7 +67,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
endif;
if ( $team_result != null ):
echo '<strong>' . $team_result . '</strong> ';
echo '<strong class="result">' . $team_result . '</strong> ';
endif;
echo $team->post_title;

View File

@@ -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() ) );

View File

@@ -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() ):

View File

@@ -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();

View File

@@ -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 ):
?>
<fieldset class="sp-video-embed">
<?php echo apply_filters( 'the_content', '[embed width="254"]' . $video . '[/embed]' ); ?>
<p><a href="#" class="sp-remove-video"><?php _e( 'Remove video', 'sportspress' ); ?></a></p>
</fieldset>
<?php endif; ?>
<fieldset class="sp-video-field hidden">
<p><strong><?php _e( 'URL', 'sportspress' ); ?></strong></p>
<p><input class="widefat" type="text" name="sp_video" id="sp_video" value="<?php echo $video; ?>"></p>
<p><a href="#" class="sp-remove-video"><?php _e( 'Cancel', 'sportspress' ); ?></a></p>
</fieldset>
<fieldset class="sp-video-adder<?php if ( $video ): ?> hidden<?php endif; ?>">
<p><a href="#" class="sp-add-video"><?php _e( 'Add video', 'sportspress' ); ?></a></p>
</fieldset>
<?php
}
function sportspress_event_statistics_meta( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );

View File

@@ -1,6 +1,6 @@
<?php
if ( !function_exists( 'sportspress_events_calendar' ) ) {
function sportspress_events_calendar( $initial = true ) {
function sportspress_events_calendar( $id = null, $single = false, $initial = true ) {
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
@@ -8,6 +8,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
if ( !$posts )
return;
$caption_tag = ( $single ? 'h4' : 'caption' );
// week_begins = 0 stands for Sunday
$week_begins = intval(get_option('start_of_week'));
@@ -56,7 +58,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_caption = _x('%1$s %2$s', 'calendar caption', 'sportspress');
$calendar_output = '
<table id="wp-calendar">
<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
<' . $caption_tag . ' class="sp-table-caption">' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</' . $caption_tag . '>
<thead>
<tr>';

View File

@@ -0,0 +1,121 @@
<?php
if ( !function_exists( 'sportspress_events_list' ) ) {
function sportspress_events_list( $id = null, $args = '' ) {
if ( ! $id )
$id = get_the_ID();
$options = get_option( 'sportspress' );
$main_result = sportspress_array_value( $options, 'main_result', null );
$defaults = array(
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-events-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
$output .= '<th class="column-date">' . __( 'Date', 'sportspress' ). '</th>';
if ( in_array( 'event', $usecolumns ) )
$output .= '<th class="column-event">' . __( 'Event', 'sportspress' ). '</th>';
if ( in_array( 'teams', $usecolumns ) )
$output .= '<th class="column-teams">' . __( 'Teams', 'sportspress' ). '</th>';
if ( in_array( 'time', $usecolumns ) )
$output .= '<th class="column-time">' . __( 'Time', 'sportspress' ). '</th>';
if ( in_array( 'article', $usecolumns ) )
$output .= '<th class="column-article">' . __( 'Article', 'sportspress' ). '</th>';
$output .= '</tr>' . '</thead>' . '<tbody>';
$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 .= '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . '">';
$output .= '<td class="column-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
if ( in_array( 'event', $usecolumns ) )
$output .= '<td class="column-event">' . $event->post_title . '</td>';
if ( in_array( 'teams', $usecolumns ) ):
$output .= '<td class="column-teams">';
$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 .= '<br>';
endif;
endforeach;
else:
$output .= '&mdash;';
endif;
$output .= '</td>';
endif;
if ( in_array( 'time', $usecolumns ) )
$output .= '<td class="column-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
if ( in_array( 'article', $usecolumns ) ):
$output .= '<td class="column-article">
<a href="' . get_permalink( $event->ID ) . '#sp_articlediv">';
if ( $video ):
$output .= '<div class="dashicons dashicons-video-alt"></div>';
elseif ( has_post_thumbnail( $event->ID ) ):
$output .= '<div class="dashicons dashicons-camera"></div>';
endif;
if ( $event->post_content !== null ):
if ( $event->post_status == 'publish' ):
$output .= __( 'Recap', 'sportspress' );
else:
$output .= __( 'Preview', 'sportspress' );
endif;
endif;
$output .= '</a>
</td>';
endif;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
return apply_filters( 'sportspress_events_list', $output );
}
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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 );
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-calendar-table">
<thead>
<tr>
<th class="column-date"><?php _e( 'Date', 'sportspress' ); ?></th>
<th class="column-event"><?php _e( 'Event', 'sportspress' ); ?></th>
<th class="column-time"><?php _e( 'Time', 'sportspress' ); ?></th>
<th class="column-article"><?php _e( 'Article', 'sportspress' ); ?></th>
<th class="column-date">
<?php _e( 'Date', 'sportspress' ); ?>
</th>
<th class="column-event">
<label for="sp_columns_event">
<input type="checkbox" name="sp_columns[]" value="event" id="sp_columns_event" <?php checked( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ); ?>>
<?php _e( 'Event', 'sportspress' ); ?>
</label>
</th>
<th class="column-teams">
<label for="sp_columns_teams">
<input type="checkbox" name="sp_columns[]" value="teams" id="sp_columns_teams" <?php checked( ! is_array( $usecolumns ) || in_array( 'teams', $usecolumns ) ); ?>>
<?php _e( 'Teams', 'sportspress' ); ?>
</label>
</th>
<th class="column-time">
<label for="sp_columns_time">
<input type="checkbox" name="sp_columns[]" value="time" id="sp_columns_time" <?php checked( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ); ?>>
<?php _e( 'Time', 'sportspress' ); ?>
</label>
</th>
<th class="column-article">
<label for="sp_columns_article">
<input type="checkbox" name="sp_columns[]" value="article" id="sp_columns_article" <?php checked( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ); ?>>
<?php _e( 'Article', 'sportspress' ); ?>
</label>
</th>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 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 );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event ); ?></td>
<td><?php echo $event->post_title; ?></td>
<td>
<?php
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;
if ( $team_result != null ):
echo '<strong class="result">' . $team_result . '</strong> ';
endif;
echo $name . '<br>';
endif;
endforeach;
?>
</td>
<td><?php echo get_post_time( get_option( 'time_format' ), false, $event ); ?></td>
<td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
@@ -832,7 +888,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_columns_<?php echo $key; ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns) || in_array( $key, $usecolumns ) ); ?>>
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php echo $label; ?>
</label></th>
<?php endforeach; ?>
@@ -902,8 +958,8 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) {
<th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_statistics_<?php echo $key; ?>">
<input type="checkbox" name="sp_statistics[]" value="<?php echo $key; ?>" id="sp_statistics_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns) || in_array( $key, $usecolumns ) ); ?>>
<th><label for="sp_columns_<?php echo $key; ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php echo $label; ?>
</label></th>
<?php endforeach; ?>
@@ -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' );

View File

@@ -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';