Add main result, last 5 counter, and fix countdown direction
This commit is contained in:
@@ -29,12 +29,28 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
break;
|
||||
elseif ( $post_type == 'sp_event' ):
|
||||
$results = get_post_meta( $post_id, 'sp_results', true );
|
||||
$options = get_option( 'sportspress' );
|
||||
$main_result = sportspress_array_value( $options, 'main_result', null );
|
||||
foreach( $teams as $team_id ):
|
||||
if ( ! $team_id ) continue;
|
||||
$team = get_post( $team_id );
|
||||
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
|
||||
|
||||
echo $team->post_title;
|
||||
|
||||
$team_results = sportspress_array_value( $results, $team_id, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sportspress_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
echo ' — ' . $team_result;
|
||||
endif;
|
||||
|
||||
$outcome_slug = sportspress_array_value( $team_results, 'outcome', null );
|
||||
if ( $outcome_slug && $outcome_slug != '-1' ):
|
||||
$args=array(
|
||||
'name' => $outcome_slug,
|
||||
@@ -46,9 +62,10 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
|
||||
if ( sizeof( $outcomes ) ):
|
||||
$outcome = reset( $outcomes );
|
||||
echo ' — ' . $outcome->post_title;
|
||||
echo ' (' . $outcome->post_title . ')';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
echo '<br>';
|
||||
endforeach;
|
||||
elseif ( $post_type == 'sp_player' ):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
?>
|
||||
<?php if ( false ): ?>
|
||||
<div id="message" class="error sportspress-message">
|
||||
<h4><?php _e( '<strong>Your theme does not declare SportsPress support</strong> – if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></h4>
|
||||
<p class="submit">
|
||||
@@ -8,3 +9,4 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
<a class="button-secondary" href="<?php echo add_query_arg( 'hide_sportspress_theme_support_check', 'true' ); ?>"><?php _e( 'Hide this notice', 'sportspress' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif;
|
||||
|
||||
@@ -20,6 +20,13 @@ $sportspress_sports['football'] = array(
|
||||
'sp_equation' => '$l',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'T',
|
||||
'post_name' => 't',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$t',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Pct',
|
||||
'post_name' => 'pct',
|
||||
@@ -31,26 +38,123 @@ $sportspress_sports['football'] = array(
|
||||
'post_title' => 'PF',
|
||||
'post_name' => 'pf',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$ptsfor',
|
||||
'sp_equation' => '$pointsfor',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'PA',
|
||||
'post_name' => 'pa',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$ptsagainst',
|
||||
'sp_equation' => '$pointsagainst',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Str',
|
||||
'post_title' => 'Net Pts',
|
||||
'post_name' => 'netpts',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$pointsfor - $pointsagainst',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'TD',
|
||||
'post_name' => 'td',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$touchdown',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Strk',
|
||||
'post_name' => 'strk',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$streak',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Last 5',
|
||||
'post_name' => 'last5',
|
||||
'meta' => array(
|
||||
'sp_equation' => '$last5',
|
||||
),
|
||||
),
|
||||
),
|
||||
// Statistics
|
||||
'sp_statistic' => array(
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp', // QB
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Comp',
|
||||
'post_name' => 'comp',
|
||||
),
|
||||
),
|
||||
// Results
|
||||
'sp_result' => array(
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<h3 class="title"><?php _e( 'Event Settings', 'sportspress' ); ?></h3>
|
||||
<?php
|
||||
settings_fields( 'sportspress_events' );
|
||||
do_settings_sections( 'sportspress_events' );
|
||||
submit_button();
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'numberposts' => -1,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<h3 class="title"><?php _e( 'General Settings', 'sportspress' ); ?></h3>
|
||||
<?php
|
||||
settings_fields( 'sportspress_general' );
|
||||
do_settings_sections( 'sportspress_general' );
|
||||
submit_button();
|
||||
settings_fields( 'sportspress_general' );
|
||||
do_settings_sections( 'sportspress_general' );
|
||||
submit_button();
|
||||
|
||||
@@ -38,15 +38,31 @@ function sportspress_settings() {
|
||||
function sportspress_sport_callback() {
|
||||
global $sportspress_sports;
|
||||
$options = get_option( 'sportspress' );
|
||||
|
||||
$selected = sportspress_array_value( $options, 'sport', null );
|
||||
?>
|
||||
<select id="sportspress_sport" name="sportspress[sport]">
|
||||
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
|
||||
<option value="<?php echo $slug; ?>" <?php selected( $options['sport'], $slug ); ?>><?php echo $sport['name']; ?></option>
|
||||
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
function sportspress_result_callback() {
|
||||
$options = get_option( 'sportspress' );
|
||||
|
||||
$selected = sportspress_array_value( $options, 'main_result', null );
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'name' => 'sportspress[main_result]',
|
||||
'show_option_all' => __( '(Auto)', 'sportspress' ),
|
||||
'selected' => $selected,
|
||||
'values' => 'slug',
|
||||
);
|
||||
sportspress_dropdown_pages( $args );
|
||||
}
|
||||
|
||||
function sportspress_team_stats_callback() {
|
||||
sportspress_render_option_field( 'sportspress_stats', 'team', 'textarea' );
|
||||
}
|
||||
@@ -88,8 +104,7 @@ function sportspress_settings_init() {
|
||||
// Event Settings
|
||||
register_setting(
|
||||
'sportspress_events',
|
||||
'sportspress',
|
||||
'sportspress_validate'
|
||||
'sportspress'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
@@ -100,9 +115,9 @@ function sportspress_settings_init() {
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
'sportspress_sport_callback',
|
||||
'result',
|
||||
__( 'Main Result', 'sportspress' ),
|
||||
'sportspress_result_callback',
|
||||
'sportspress_events',
|
||||
'events'
|
||||
);
|
||||
|
||||
@@ -37,13 +37,13 @@ if ( !function_exists( 'sportspress_countdown' ) ) {
|
||||
|
||||
$now = new DateTime( current_time( 'mysql', 0 ) );
|
||||
$date = new DateTime( $post->post_date );
|
||||
$interval = $date->diff( $now );
|
||||
$interval = date_diff( $now, $date );
|
||||
|
||||
$output .= '<h3 class="countdown sp-countdown"><time datetime="' . $post->post_date . '" data-countdown="' . str_replace( '-', '/', $post->post_date ) . '">' .
|
||||
'<span>' . sprintf( '%02s', $interval->d ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', $interval->h ) . ' <small>' . __( 'hours', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', $interval->i ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', $interval->s ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' .
|
||||
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->d ) ) . ' <small>' . __( 'days', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->h ) ) . ' <small>' . __( 'hours', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->i ) ) . ' <small>' . __( 'mins', 'sportspress' ) . '</small></span> ' .
|
||||
'<span>' . sprintf( '%02s', ( $interval->invert ? 0 : $interval->s ) ) . ' <small>' . __( 'secs', 'sportspress' ) . '</small></span>' .
|
||||
'</time></h3>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
@@ -40,7 +40,7 @@ class SP_Widget_Countdown extends WP_Widget {
|
||||
'name' => $this->get_field_name('id'),
|
||||
'id' => $this->get_field_id('id'),
|
||||
'selected' => $id,
|
||||
'show_option_all' => '(' . __( 'Next Event', 'premier' ) . ')',
|
||||
'show_option_all' => __( '(Auto)', 'sportspress' ),
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
'show_dates' => true,
|
||||
|
||||
@@ -491,6 +491,7 @@ if ( !function_exists( 'sportspress_equation_selector' ) ) {
|
||||
case 'outcome':
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$last5'] = __( 'Last 5', 'sportspress' );
|
||||
$options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' );
|
||||
break;
|
||||
case 'column':
|
||||
@@ -1151,6 +1152,16 @@ if ( !function_exists( 'sportspress_solve' ) ) {
|
||||
// Return direct value
|
||||
return sportspress_array_value( $vars, 'streak', 0 );
|
||||
|
||||
elseif ( str_replace( ' ', '', $equation ) == '$last5' ):
|
||||
|
||||
// Return imploded string
|
||||
$last5 = sportspress_array_value( $vars, 'last5', array( 0 ) );
|
||||
if ( array_sum( $last5 ) > 0 ):
|
||||
return implode( '-', $last5 );
|
||||
else:
|
||||
return '—';
|
||||
endif;
|
||||
|
||||
elseif ( str_replace( ' ', '', $equation ) == '$last10' ):
|
||||
|
||||
// Return imploded string
|
||||
@@ -1306,7 +1317,7 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
|
||||
|
||||
foreach ( $div_ids as $div_id ):
|
||||
|
||||
$totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null );
|
||||
$totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last5' => null, 'last10' => null );
|
||||
|
||||
foreach ( $result_labels as $key => $value ):
|
||||
$totals[ $key . 'for' ] = 0;
|
||||
@@ -1320,11 +1331,13 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
|
||||
// Initialize streaks counter
|
||||
$streak = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
||||
|
||||
// Initialize last 10 counter
|
||||
// Initialize last counters
|
||||
$last5 = array();
|
||||
$last10 = array();
|
||||
|
||||
// Add outcome types to last 10 counter
|
||||
// Add outcome types to last counters
|
||||
foreach( $outcome_labels as $key => $value ):
|
||||
$last5[ $key ] = 0;
|
||||
$last10[ $key ] = 0;
|
||||
endforeach;
|
||||
|
||||
@@ -1379,6 +1392,11 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
|
||||
$streak['fire'] = 0;
|
||||
endif;
|
||||
|
||||
// Add to last 5 counter if sum is less than 5
|
||||
if ( array_key_exists( $value, $last5 ) && array_sum( $last5 ) < 5 ):
|
||||
$last5[ $value ] ++;
|
||||
endif;
|
||||
|
||||
// Add to last 10 counter if sum is less than 10
|
||||
if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ):
|
||||
$last10[ $value ] ++;
|
||||
@@ -1416,7 +1434,8 @@ if ( !function_exists( 'sportspress_get_team_columns_data' ) ) {
|
||||
$totals['streak'] = $outcome->post_title . $streak['count'];
|
||||
endif;
|
||||
|
||||
// Add last 10 to totals
|
||||
// Add last counters to totals
|
||||
$totals['last5'] = $last5;
|
||||
$totals['last10'] = $last10;
|
||||
|
||||
// Generate array of placeholder values for each league
|
||||
@@ -1497,7 +1516,8 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
// Initialize streaks counter
|
||||
$streaks = array();
|
||||
|
||||
// Initialize last 10s counter
|
||||
// Initialize last counters
|
||||
$last5s = array();
|
||||
$last10s = array();
|
||||
|
||||
foreach ( $team_ids as $team_id ):
|
||||
@@ -1507,11 +1527,13 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
// Initialize team streaks counter
|
||||
$streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
||||
|
||||
// Initialize team last 10 counter
|
||||
// Initialize team last counters
|
||||
$last5s[ $team_id ] = array();
|
||||
$last10s[ $team_id ] = array();
|
||||
|
||||
// Add outcome types to team last 10 counter
|
||||
// Add outcome types to team last counters
|
||||
foreach( $outcome_labels as $key => $value ):
|
||||
$last5s[ $team_id ][ $key ] = 0;
|
||||
$last10s[ $team_id ][ $key ] = 0;
|
||||
endforeach;
|
||||
|
||||
@@ -1586,6 +1608,11 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
$streaks[ $team_id ]['fire'] = 0;
|
||||
endif;
|
||||
|
||||
// Add to last 5 counter if sum is less than 5
|
||||
if ( array_key_exists( $team_id, $last5s ) && array_key_exists( $value, $last5s[ $team_id ] ) && array_sum( $last5s[ $team_id ] ) < 5 ):
|
||||
$last5s[ $team_id ][ $value ] ++;
|
||||
endif;
|
||||
|
||||
// Add to last 10 counter if sum is less than 10
|
||||
if ( array_key_exists( $team_id, $last10s ) && array_key_exists( $value, $last10s[ $team_id ] ) && array_sum( $last10s[ $team_id ] ) < 10 ):
|
||||
$last10s[ $team_id ][ $value ] ++;
|
||||
@@ -1632,6 +1659,11 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
foreach ( $last5s as $team_id => $last5 ):
|
||||
// Add last 5 to totals
|
||||
$totals[ $team_id ]['last5'] = $last5;
|
||||
endforeach;
|
||||
|
||||
foreach ( $last10s as $team_id => $last10 ):
|
||||
// Add last 10 to totals
|
||||
$totals[ $team_id ]['last10'] = $last10;
|
||||
|
||||
@@ -74,9 +74,11 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
|
||||
|
||||
= 0.2.2 =
|
||||
* Feature - League Table widget added.
|
||||
* Feature - Events widget added.
|
||||
* Feature - Recent Events widget added.
|
||||
* Feature - Future Events widget added.
|
||||
* Feature - Countdown widget added.
|
||||
* Fix - Syntax error fixed for PHP version 5.2 and below.
|
||||
* Tweak - Editor section added to League Tables and Player Lists.
|
||||
|
||||
= 0.2.1 =
|
||||
* Feature - Events Calendar widget added.
|
||||
|
||||
Reference in New Issue
Block a user