diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index c8ba8c37..3d3f772c 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -176,15 +176,17 @@ .sp-league-table td.has-logo { line-height: 2em; } -.sp-league-table .data-name .team-logo { +.sp-league-table .team-logo { width: 2em; height: 2em; - margin-right: 0.5em; display: inline-block; vertical-align: middle; text-align: center; } -.sp-league-table .data-name .team-logo img { +.sp-league-table .data-name .team-logo { + margin-right: 0.5em; +} +.sp-league-table .team-logo img { width: auto; height: auto; max-width: 2em; diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index fbc1ed32..ba695566 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -618,12 +618,12 @@ class SP_League_Table extends SP_Secondary_Post { endif; else: // Solve - $placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision ); + $placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision, 0, $team_id ); if ( '$gamesback' == $stat->equation ) $gb_column = $stat->post_name; - if ( ! in_array( $stat->equation, array( '$gamesback', '$streak', '$form', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ): + if ( ! in_array( $stat->equation, apply_filters( 'sportspress_equation_presets', array( '$gamesback', '$streak', '$form', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ) ): // Adjustments $adjustment = sp_array_value( $adjustments, $team_id, array() ); diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index b1e07140..6f02de81 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1290,10 +1290,10 @@ if ( !function_exists( 'sp_get_eos_safe_slug' ) ) { } if ( !function_exists( 'sp_solve' ) ) { - function sp_solve( $equation, $vars, $precision = 0, $default = 0 ) { + function sp_solve( $equation, $vars, $precision = 0, $default = 0, $post_id = 0 ) { // Add a hook to alter $equation - $equation = apply_filters( 'sportspress_equation_alter', $equation, $vars ); + $equation = apply_filters( 'sportspress_equation_alter', $equation, $vars, $precision, $default ); if ( $equation == null ) return $default; @@ -1347,6 +1347,10 @@ if ( !function_exists( 'sp_solve' ) ) { endif; + if ( $solution = apply_filters( 'sportspress_equation_solve_for_presets', null, $equation, $post_id ) ): + return $solution; + endif; + // Remove unnecessary variables from vars before calculating unset( $vars['gamesback'] ); unset( $vars['streak'] ); diff --git a/modules/sportspress-next-team-preset.php b/modules/sportspress-next-team-preset.php new file mode 100644 index 00000000..47ead7a2 --- /dev/null +++ b/modules/sportspress-next-team-preset.php @@ -0,0 +1,127 @@ +define_constants(); + + // Filters + add_filter( 'sportspress_equation_options', array( $this, 'add_options' ) ); + add_filter( 'sportspress_equation_presets', array( $this, 'presets' ) ); + add_filter( 'sportspress_equation_solve_for_presets', array( $this, 'solve' ), 10, 3 ); + + } + + /** + * Define constants. + */ + private function define_constants() { + if ( !defined( 'SP_NEXT_TEAM_PRESET_VERSION' ) ) + define( 'SP_NEXT_TEAM_PRESET_VERSION', '2.6' ); + + if ( !defined( 'SP_NEXT_TEAM_PRESET_URL' ) ) + define( 'SP_NEXT_TEAM_PRESET_URL', plugin_dir_url( __FILE__ ) ); + + if ( !defined( 'SP_NEXT_TEAM_PRESET_DIR' ) ) + define( 'SP_NEXT_TEAM_PRESET_DIR', plugin_dir_path( __FILE__ ) ); + } + + /** + * Add additional options. + * + * @return array + */ + public function add_options( $options ) { + $options[ 'Presets' ]['$nextteam'] = __( 'Next Team', 'sportspress' ); + return $options; + } + + /** + * Add preset + * + * @return array + */ + public function presets( $presets ) { + $presets[] = '$nextteam'; + return $presets; + } + + /** + * Solve preset + * + * @return mixed + */ + public function solve( $input, $equation, $post_id ) { + if ( strpos( $equation, '$nextteam' ) !== false ) { + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => 1, + 'posts_per_page' => 1, + 'post_status' => 'future', + 'meta_query' => array( + array( + 'key' => 'sp_team', + 'value' => $post_id, + 'compare' => 'IN', + ), + ), + ); + $events = get_posts( $args ); + + if ( $events ) { + $event = reset( $events ); + $teams = array_filter( (array) get_post_meta( $event->ID, 'sp_team', false ) ); + if ( ( $key = array_search( $post_id, $teams ) ) !== false ) { + unset( $teams[ $key ] ); + } else { + return '-'; + } + + $team_id = reset( $teams ); + + if ( ! $team_id ) return '-'; + + if ( has_post_thumbnail( $team_id ) ) { + $logo = get_the_post_thumbnail( $team_id, 'sportspress-fit-icon' ); + $icon = ''; + } else { + $icon = get_the_title( $team_id ); + } + + return '' . $icon . ''; + } else { + return '-'; + } + } else { + return $input; + } + } +} + +endif; + +new SportsPress_Next_Team_Preset();