Replace event time with status when not on time

This commit is contained in:
Brian Miyaji
2016-09-09 23:45:43 +10:00
parent 664647dac6
commit 5b3880ba1b
8 changed files with 39 additions and 21 deletions

View File

@@ -144,7 +144,7 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
endif;
break;
case 'sp_time':
echo get_post_time( 'H:i', false, $post_id, true );
echo apply_filters( 'sportspress_event_time_admin', get_post_time( 'H:i', false, $post_id, true ) );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );

View File

@@ -163,7 +163,7 @@ class SP_Meta_Box_Calendar_Data {
</td>
<?php if ( 'separate' == $time_format ) { ?>
<td>
<?php echo get_post_time( get_option( 'time_format' ), false, $event, true ); ?>
<?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?>
</td>
<td>
<?php
@@ -180,7 +180,7 @@ class SP_Meta_Box_Calendar_Data {
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo get_post_time( get_option( 'time_format' ), false, $event, true );
echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID );
endif;
?>
</td>

View File

@@ -36,6 +36,10 @@ class SportsPress_Event_Status {
add_action( 'init', array( $this, 'get_statuses' ) );
add_action( 'post_submitbox_misc_actions', array( $this, 'section' ) );
add_action( 'sportspress_process_sp_event_meta', array( $this, 'save' ), 10, 1 );
add_filter( 'sportspress_event_time', array( $this, 'filter' ), 10, 2 );
add_filter( 'sportspress_event_time_admin', array( $this, 'filter' ), 10, 2 );
add_filter( 'sportspress_main_results_or_time', array( $this, 'filter_array' ), 10, 2 );
add_filter( 'sportspress_event_blocks_team_result_or_time', array( $this, 'filter_array' ), 10, 2 );
}
/**
@@ -58,9 +62,9 @@ class SportsPress_Event_Status {
public function get_statuses() {
$this->statuses = apply_filters( 'sportspress_event_statuses', array(
'ok' => __( 'On time', 'sportspress' ),
'tbd' => __( 'To be determined', 'sportspress' ) . ' (' . __( 'TBD', 'sportspress' ) . ')',
'cancelled' => __( 'Cancelled', 'sportspress' ),
'tbd' => __( 'TBD', 'sportspress' ),
'postponed' => __( 'Postponed', 'sportspress' ),
'cancelled' => __( 'Cancelled', 'sportspress' ),
) );
}
@@ -84,12 +88,6 @@ class SportsPress_Event_Status {
<a href="#" class="sp-cancel-event-status hide-if-no-js button-cancel">Cancel</a>
</p>
</div>
<?php if ( false ) { ?>
<label>
<input type="checkbox" name="sp_tbd" value="1" <?php checked( $checked ); ?>></input>
<?php _e( 'To be determined', 'sportspress' ); ?> (<?php _e( 'TBD', 'sportspress' ); ?>)
</label>
<?php } ?>
</div>
<?php
}
@@ -100,6 +98,26 @@ class SportsPress_Event_Status {
public function save( $post_id ) {
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 'ok' ) );
}
/**
* Event time filter.
*/
public function filter( $time, $post_id = 0 ) {
if ( ! $post_id ) $post_id = get_the_ID();
$status = get_post_meta( $post_id, 'sp_status', true );
if ( ! $status || 'ok' === $status || ! array_key_exists( $status, $this->statuses ) ) return $time;
return $this->statuses[ $status ];
}
/**
* Event time array filter.
*/
public function filter_array( $array, $post_id = 0 ) {
if ( ! $post_id ) $post_id = get_the_ID();
$status = get_post_meta( $post_id, 'sp_status', true );
if ( ! $status || 'ok' === $status || ! array_key_exists( $status, $this->statuses ) ) return $array;
return array( $this->statuses[ $status ] );
}
}
endif;

View File

@@ -191,7 +191,7 @@ if ( $ak_post_titles ) {
foreach ( (array) $ak_post_titles as $ak_post_title ) {
/** This filter is documented in wp-includes/post-template.php */
$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) . ' @ ' . date_i18n( get_option( 'time_format' ), strtotime( $ak_post_title->post_date ) ) );
$post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) . ' @ ' . apply_filters( 'sportspress_event_time', date_i18n( get_option( 'time_format' ), strtotime( $ak_post_title->post_date ) ), $ak_post_title->ID ) );
if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
$ak_titles_for_day['day_'.$ak_post_title->dom] = '';

View File

@@ -24,7 +24,7 @@ if ( 'yes' === get_option( 'sportspress_event_show_date', 'yes' ) ) {
if ( 'yes' === get_option( 'sportspress_event_show_time', 'yes' ) ) {
$time = get_the_time( get_option('time_format'), $id );
$data[ __( 'Time', 'sportspress' ) ] = $time;
$data[ __( 'Time', 'sportspress' ) ] = apply_filters( 'sportspress_event_time', $time, $id );
}
$taxonomies = apply_filters( 'sportspress_event_taxonomies', array( 'sp_league' => null, 'sp_season' => null ) );

View File

@@ -209,7 +209,7 @@ endif;
echo '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . ' sp-row-no-' . $i . '">';
$date_html = '<date>' . get_post_time( 'Y-m-d H:i:s', false, $event ) . '</date>' . get_post_time( get_option( 'date_format' ), false, $event, true );
$date_html = '<date>' . get_post_time( 'Y-m-d H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', get_post_time( get_option( 'date_format' ), false, $event, true ), $event->ID );
if ( $link_events ) $date_html = '<a href="' . get_post_permalink( $event->ID, false, true ) . '">' . $date_html . '</a>';
@@ -227,7 +227,7 @@ endif;
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
endif;
if ( $link_events ) echo '</a>';
echo '</td>';
@@ -249,7 +249,7 @@ endif;
if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time">';
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
if ( $link_events ) echo '</a>';
echo '</td>';
}
@@ -271,7 +271,7 @@ endif;
if ( sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time">';
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
if ( $link_events ) echo '</a>';
echo '</td>';
}
@@ -291,7 +291,7 @@ endif;
if ( sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time">';
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
if ( $link_events ) echo '</a>';
echo '</td>';
}
@@ -316,7 +316,7 @@ endif;
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
endif;
if ( $link_events ) echo '</a>';
echo '</td>';

View File

@@ -50,7 +50,7 @@
if ( $show_time ) {
?>
<h5 class="sp-event-results">
<?php echo '<span class="sp-result">' . apply_filters( 'sportspress_event_blocks_team_result_or_time', sp_get_time( $id ), $id ) . '</span>'; ?>
<?php echo '<span class="sp-result">' . apply_filters( 'sportspress_event_time', sp_get_time( $id ), $id ) . '</span>'; ?>
</h5>
<span class="sp-event-status">
<?php _e( 'Preview', 'sportspress' ); ?>

View File

@@ -53,7 +53,7 @@ if ( ! empty( $team_logos ) ):
// Assign delimiter
if ( $show_time && sizeof( $teams ) <= 2 ) {
$delimiter = '<strong class="sp-event-logos-time sp-team-result">' . get_the_time( get_option('time_format'), $id ) . '</strong>';
$delimiter = '<strong class="sp-event-logos-time sp-team-result">' . apply_filters( 'sportspress_event_time', get_the_time( get_option('time_format'), $id ), $id ) . '</strong>';
} else {
$delimiter = get_option( 'sportspress_event_teams_delimiter', 'vs' );
}