Add more front end glory

This commit is contained in:
Brian Miyaji
2014-01-15 17:24:50 +11:00
parent e3a04bc8c9
commit 5bbd3a179f
8 changed files with 276 additions and 111 deletions

View File

@@ -526,10 +526,10 @@ if ( !function_exists( 'sportspress_edit_calendar_table' ) ) {
<?php echo $event->post_title; ?>
</td>
<td>
<?php echo mysql2date( get_option('date_format'), $event->post_date ); ?>
<?php echo get_the_time( get_option('date_format'), $event->ID ); ?>
</td>
<td>
<?php echo mysql2date( get_option('time_format'), $event->post_date ); ?>
<?php echo get_the_time( get_option('time_format'), $event->ID ); ?>
</td>
</tr>
<?php
@@ -834,13 +834,14 @@ if ( !function_exists( 'sportspress_event_player_sub_selector' ) ) {
}
}
if ( !function_exists( 'sportspress_event_players_table' ) ) {
function sportspress_event_players_table( $columns = array(), $data = array(), $team_id ) {
if ( !function_exists( 'sportspress_edit_event_players_table' ) ) {
function sportspress_edit_event_players_table( $columns = array(), $data = array(), $team_id ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table">
<thead>
<tr>
<th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
@@ -856,9 +857,8 @@ if ( !function_exists( 'sportspress_event_players_table' ) ) {
$number = get_post_meta( $player_id, 'sp_number', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo ( $number ? $number . '. ' : '' ) . get_the_title( $player_id ); ?>
</td>
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td><?php echo get_the_title( $player_id ); ?></td>
<?php foreach( $columns as $column => $label ):
$value = sportspress_array_value( $player_statistics, $column, '' );
?>

View File

@@ -5,44 +5,59 @@ function sportspress_the_content( $content ) {
global $post;
// Display event details
$content = sportspress_event_details( $post->ID ) . $content;
$details = sportspress_event_details( $post->ID );
$results = sportspress_event_results( $post->ID );
$players = sportspress_event_players( $post->ID );
$staff = sportspress_event_staff( $post->ID );
if ( ! empty( $results ) ):
$content = $results . $details . $players . $staff . $content;
else:
$venue = sportspress_event_venue( $post->ID );
$content = $details . $venue . $players . $staff . $content;
endif;
elseif ( is_singular( 'sp_calendar' ) && in_the_loop() ):
global $post;
// Display events calendar
$content = sportspress_events_calendar( $post->ID ) . $content;
$calendar = sportspress_events_calendar( $post->ID );
$content = $calendar . $content;
elseif ( is_singular( 'sp_team' ) && in_the_loop() ):
global $post;
// Display team columns
$content = sportspress_team_columns( $post->ID ) . $content;
$columns = sportspress_team_columns( $post->ID );
$content = $columns . $content;
elseif ( is_singular( 'sp_table' ) && in_the_loop() ):
global $post;
// Display league table
$content = sportspress_league_table( $post->ID ) . $content;
sportspress_league_table( $post->ID );
$content = $table . $content;
elseif ( is_singular( 'sp_list' ) && in_the_loop() ):
global $post;
// Display player list
$content = sportspress_player_list( $post->ID ) . $content;
$list = sportspress_player_list( $post->ID );
$content = $list . $content;
elseif ( is_singular( 'sp_player' ) && in_the_loop() ):
global $post;
// Display player metrics and statistics
$content = sportspress_player_metrics( $post->ID ) . sportspress_player_statistics( $post->ID ) . $content;
$metrics = sportspress_player_metrics( $post->ID );
$statistics = sportspress_player_statistics( $post->ID );
$content = $metrics . $statistics . $content;
endif;

View File

@@ -6,6 +6,7 @@ function sportspress_enqueue_scripts() {
// Scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.exp', true );
wp_enqueue_script( 'jquery-datatables', SPORTSPRESS_PLUGIN_URL .'/assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
wp_enqueue_script( 'sportspress', SPORTSPRESS_PLUGIN_URL .'/assets/js/sportspress.js', array( 'jquery' ), time(), true );
}

View File

@@ -38,8 +38,8 @@ function sportspress_event_meta_init( $post ) {
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', 'high' );
if ( sizeof( $teams ) > 0 ):
add_meta_box( 'sp_playersdiv', __( 'Players', 'sportspress' ), 'sportspress_event_players_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sportspress_event_results_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_playersdiv', __( 'Players', 'sportspress' ), 'sportspress_event_players_meta', 'sp_event', 'normal', 'high' );
endif;
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sportspress_event_article_meta', 'sp_event', 'normal', 'high' );
}
@@ -157,7 +157,7 @@ function sportspress_event_players_meta( $post ) {
?>
<div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php sportspress_event_players_table( $columns, $data, $team_id ); ?>
<?php sportspress_edit_event_players_table( $columns, $data, $team_id ); ?>
</div>
<?php

View File

@@ -33,4 +33,9 @@
vertical-align: middle;
height: 2em;
width: auto;
}
/* Google Maps */
.sp-google-map {
height: 320px;
}

23
assets/js/google-maps.js Normal file
View File

@@ -0,0 +1,23 @@
window.google = window.google || {};
google.maps = google.maps || {};
(function() {
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
var modules = google.maps.modules = {};
google.maps.__gjsload__ = function(name, text) {
modules[name] = text;
};
google.maps.Load = function(apiLoad) {
delete google.maps.Load;
apiLoad([0.009999999776482582,[[["https://mts0.googleapis.com/vt?lyrs=m@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=m@248000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@248000000",["https://mts0.google.com/vt?lyrs=m@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.google.com/vt?lyrs=m@248000000\u0026src=api\u0026hl=en-US\u0026"]],[["https://khms0.googleapis.com/kh?v=144\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=144\u0026hl=en-US\u0026"],null,null,null,1,"144",["https://khms0.google.com/kh?v=144\u0026hl=en-US\u0026","https://khms1.google.com/kh?v=144\u0026hl=en-US\u0026"]],[["https://mts0.googleapis.com/vt?lyrs=h@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=h@248000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"h@248000000",["https://mts0.google.com/vt?lyrs=h@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.google.com/vt?lyrs=h@248000000\u0026src=api\u0026hl=en-US\u0026"]],[["https://mts0.googleapis.com/vt?lyrs=t@132,r@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=t@132,r@248000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@132,r@248000000",["https://mts0.google.com/vt?lyrs=t@132,r@248000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.google.com/vt?lyrs=t@132,r@248000000\u0026src=api\u0026hl=en-US\u0026"]],null,null,[["https://cbks0.googleapis.com/cbk?","https://cbks1.googleapis.com/cbk?"]],[["https://khms0.googleapis.com/kh?v=83\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=83\u0026hl=en-US\u0026"],null,null,null,null,"83",["https://khms0.google.com/kh?v=83\u0026hl=en-US\u0026","https://khms1.google.com/kh?v=83\u0026hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["https://mts0.googleapis.com/vt?hl=en-US\u0026","https://mts1.googleapis.com/vt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/loom?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/loom?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"https://maps.gstatic.com/mapfiles/","https://csi.gstatic.com","https://maps.googleapis.com","https://maps.googleapis.com"],["https://maps.gstatic.com/intl/en_us/mapfiles/api-3/15/6","3.15.6"],[2178329814],1,null,null,null,null,0,"",null,null,1,"https://khms.googleapis.com/mz?v=144\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"https://mts.googleapis.com/vt/icon",[["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],[null,[[0,"m",248000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],0],[null,[[0,"m",248000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],3],[null,[[0,"m",248000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],0],[null,[[0,"m",248000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],3],[null,[[4,"t",132],[0,"r",132000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],0],[null,[[4,"t",132],[0,"r",132000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],3],[null,null,[null,"en-US","US",null,18],0],[null,null,[null,"en-US","US",null,18],3],[null,null,[null,"en-US","US",null,18],6],[null,null,[null,"en-US","US",null,18],0],["https://mts0.google.com/vt","https://mts1.google.com/vt"],"/maps/vt"],2,500], loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("https://maps.gstatic.com/intl/en_us/mapfiles/api-3/15/6/main.js");
})();

View File

@@ -54,4 +54,29 @@
}
});
// Google Maps
function initialize_google_maps() {
$maps = $('.sp-google-map');
$maps.each(function() {
$self = $(this);
address = $self.attr('data-address');
latitude = $self.attr('data-latitude');
longitude = $self.attr('data-longitude');
var ll = new google.maps.LatLng(latitude,longitude);
var mapOptions = {
zoom: 16,
center: ll
};
var map = new google.maps.Map($self[0], mapOptions)
var marker = new google.maps.Marker({
position: ll,
map: map,
animation: google.maps.Animation.DROP,
flat: true,
title: address
});
});
}
google.maps.event.addDomListener(window, "load", initialize_google_maps);
})(jQuery);

View File

@@ -2,100 +2,53 @@
if ( !function_exists( 'sportspress_event_details' ) ) {
function sportspress_event_details( $id ) {
$date = get_the_time( get_option('date_format'), $id );
$time = get_the_time( get_option('time_format'), $id );
$leagues = get_the_terms( $id, 'sp_league' );
$seasons = get_the_terms( $id, 'sp_season' );
$data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time );
if ( $leagues )
$data[ __( 'League', 'sportspress' ) ] = sportspress_array_value( $leagues, 0, '—' )->name;
if ( $seasons )
$data[ __( 'Season', 'sportspress' ) ] = sportspress_array_value( $seasons, 0, '—' )->name;
$output = '<h3>' . __( 'Details', 'sportspress' ) . '</h3>';
$output .= '<table class="sp-event-details sp-data-table"><tbody>';
$i = 0;
foreach( $data as $label => $value ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$output .= '<th>' . $label . '</th>';
$output .= '<td>' . $value . '</td>';
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody></table>';
return $output;
}
}
if ( !function_exists( 'sportspress_event_results' ) ) {
function sportspress_event_results( $id ) {
$teams = (array)get_post_meta( $id, 'sp_team', false );
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$stats = (array)get_post_meta( $id, 'sp_players', true );
$results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) );
$statistic_labels = sportspress_get_var_labels( 'sp_statistic' );
$result_labels = sportspress_get_var_labels( 'sp_result' );
$output = '';
foreach( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
// Get results for players in the team
$players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
$data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
$output .= '<table class="sp-event-statistics sp-data-table">' . '<thead>' . '<tr>';
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
$output .= '<th class="column-number">' . __( 'Player', 'sportspress' ) . '</th>';
foreach( $statistic_labels as $key => $label ):
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $player_id => $row ):
if ( ! $player_id )
continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="column-number">' . $number . '</td>';
// Name as link
$permalink = get_post_permalink( $player_id );
$name = get_the_title( $player_id );
$output .= '<td class="column-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
foreach( $statistic_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
$output .= '<td class="column-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>';
if ( array_key_exists( 0, $data ) ):
$output .= '</tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<th class="column-number">&nbsp;</th>';
$output .= '<th class="column-name">' . __( 'Total', 'sportspress' ) . '</th>';
$row = $data[0];
foreach( $statistic_labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
$output .= '<th class="column-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</th>';
endforeach;
$output .= '</tr></tfoot>';
endif;
$output .= '</table>';
endforeach;
// Initialize and check
$table_rows = '';
@@ -148,6 +101,149 @@ if ( !function_exists( 'sportspress_event_details' ) ) {
}
}
if ( !function_exists( 'sportspress_event_players' ) ) {
function sportspress_event_players( $id ) {
$teams = (array)get_post_meta( $id, 'sp_team', false );
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$stats = (array)get_post_meta( $id, 'sp_players', true );
$statistic_labels = sportspress_get_var_labels( 'sp_statistic' );
$output = '';
foreach( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
// Get results for players in the team
$players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
$data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
$output .= '<table class="sp-event-statistics sp-data-table">' . '<thead>' . '<tr>';
$output .= '<th class="column-number">#</th>';
$output .= '<th class="column-number">' . __( 'Player', 'sportspress' ) . '</th>';
foreach( $statistic_labels as $key => $label ):
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $player_id => $row ):
if ( ! $player_id )
continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="column-number">' . $number . '</td>';
// Name as link
$permalink = get_post_permalink( $player_id );
$name = get_the_title( $player_id );
$output .= '<td class="column-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
foreach( $statistic_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
$output .= '<td class="column-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>';
if ( array_key_exists( 0, $data ) ):
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="column-number">&nbsp;</td>';
$output .= '<td class="column-name">' . __( 'Total', 'sportspress' ) . '</td>';
$row = $data[0];
foreach( $statistic_labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
$output .= '<td class="column-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
endforeach;
$output .= '</tr></tfoot>';
endif;
$output .= '</table>';
endforeach;
return $output;
}
}
if ( !function_exists( 'sportspress_event_staff' ) ) {
function sportspress_event_staff( $id ) {
$staff = (array)get_post_meta( $id, 'sp_staff', false );
$output = '';
return $output;
}
}
if ( !function_exists( 'sportspress_event_venue' ) ) {
function sportspress_event_venue( $id ) {
$venues = get_the_terms( $id, 'sp_venue' );
$output = '';
if ( ! $venues )
return $output;
foreach( $venues as $venue ):
$t_id = $venue->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$address = sportspress_array_value( $term_meta, 'sp_address', '' );
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', 0 );
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', 0 );
$output .= '<h3>' . $venue->name . '</h3>';
$output .= '<div class="sp-google-map" data-address="' . $address . '" data-latitude="' . $latitude . '" data-longitude="' . $longitude . '"></div>';
endforeach;
return $output;
}
}
if ( !function_exists( 'sportspress_league_table' ) ) {
function sportspress_league_table( $id ) {
@@ -161,7 +257,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
$output .= '<th class="column-number">#</th>';
foreach( $labels as $key => $label ):
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
endforeach;
@@ -274,7 +370,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
$output .= '<th class="column-number">#</th>';
foreach( $labels as $key => $label ):
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
endforeach;