Group sports into more categories
This commit is contained in:
@@ -419,6 +419,7 @@ class SP_Admin_Settings {
|
||||
case 'sport' :
|
||||
|
||||
$option_value = self::get_option( $value['id'], $value['default'] );
|
||||
$categories = SP_Admin_Sports::sport_category_names();
|
||||
|
||||
?><tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
@@ -430,14 +431,14 @@ class SP_Admin_Settings {
|
||||
name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
|
||||
id="<?php echo esc_attr( $value['id'] ); ?>"
|
||||
style="<?php echo esc_attr( $value['css'] ); ?>"
|
||||
class="chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?> <?php echo esc_attr( $value['class'] ); ?>"
|
||||
class="sp-select-sport chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?> <?php echo esc_attr( $value['class'] ); ?>"
|
||||
<?php echo implode( ' ', $custom_attributes ); ?>
|
||||
<?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
|
||||
>
|
||||
<?php
|
||||
foreach ( $value['options'] as $group => $options ) {
|
||||
?>
|
||||
<optgroup label="<?php _e( $group, 'sportspress' ); ?>">
|
||||
<optgroup label="<?php echo sp_array_value( $categories, $group, $group ); ?>">
|
||||
<?php
|
||||
foreach ( $options as $key => $val ) {
|
||||
?>
|
||||
@@ -456,7 +457,7 @@ class SP_Admin_Settings {
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select> <?php echo $description; ?>
|
||||
</select> <?php echo $description; ?> <a class="button button-small sp-configure-sport" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress-config' ), 'admin.php' ) ) ); ?>"><?php _e( 'Configure', 'sportspress' ); ?></a>
|
||||
<p>
|
||||
<label>
|
||||
<input type="checkbox" name="add_sample_data" id="add_sample_data" <?php checked( sp_array_value( $value, 'welcome' ) ); ?>>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The SportsPress admin sports class stores preset sport data.
|
||||
*
|
||||
* @class SP_Admin_Sports
|
||||
* @version 1.7
|
||||
* @version 1.8
|
||||
* @package SportsPress/Admin
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
@@ -22,50 +22,35 @@ class SP_Admin_Sports {
|
||||
if ( empty( self::$presets ) ) {
|
||||
$presets = array();
|
||||
self::$options = array(
|
||||
__( 'Sports', 'sportspress' ) => array(),
|
||||
__( 'Esports', 'sportspress' ) => array(),
|
||||
__( 'Other', 'sportspress' ) => array( 'custom' => __( 'Custom', 'sportspress' ) ),
|
||||
'team-sports' => array(),
|
||||
'racket-sports' => array(),
|
||||
'water-sports' => array(),
|
||||
'target-sports' => array(),
|
||||
'esports' => array(),
|
||||
'other' => array(),
|
||||
);
|
||||
|
||||
$dir = scandir( SP()->plugin_path() . '/presets' );
|
||||
$files = array();
|
||||
if ( $dir ) {
|
||||
foreach ( $dir as $key => $value ) {
|
||||
if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) !== false ) {
|
||||
$files[] = $value;
|
||||
foreach ( self::$options as $slug => $options ) {
|
||||
$dir = scandir( SP()->plugin_path() . '/presets/' . $slug );
|
||||
$files = array();
|
||||
if ( $dir ) {
|
||||
foreach ( $dir as $key => $value ) {
|
||||
if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) !== false ) {
|
||||
$files[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach( $files as $file ) {
|
||||
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $file );
|
||||
$data = json_decode( $json_data, true );
|
||||
if ( ! is_array( $data ) ) continue;
|
||||
$id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file );
|
||||
$presets[ $id ] = $data;
|
||||
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
|
||||
self::$options[ __( 'Sports', 'sportspress' ) ][ $id ] = $name;
|
||||
}
|
||||
asort( self::$options[ __( 'Sports', 'sportspress' ) ] );
|
||||
|
||||
$dir = scandir( SP()->plugin_path() . '/presets/esports' );
|
||||
$files = array();
|
||||
if ( $dir ) {
|
||||
foreach ( $dir as $key => $value ) {
|
||||
if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) !== false ) {
|
||||
$files[] = $value;
|
||||
}
|
||||
foreach( $files as $file ) {
|
||||
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $slug . '/' . $file );
|
||||
$data = json_decode( $json_data, true );
|
||||
if ( ! is_array( $data ) ) continue;
|
||||
$id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file );
|
||||
$presets[ $id ] = $data;
|
||||
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
|
||||
self::$options[ $slug ][ $id ] = $name;
|
||||
}
|
||||
asort( self::$options[ $slug ] );
|
||||
}
|
||||
foreach( $files as $file ) {
|
||||
$json_data = file_get_contents( SP()->plugin_path() . '/presets/esports/' . $file );
|
||||
$data = json_decode( $json_data, true );
|
||||
if ( ! is_array( $data ) ) continue;
|
||||
$id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file );
|
||||
$presets[ $id ] = $data;
|
||||
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
|
||||
self::$options[ __( 'Esports', 'sportspress' ) ][ $id ] = $name;
|
||||
}
|
||||
asort( self::$options[ __( 'Esports', 'sportspress' ) ] );
|
||||
|
||||
self::$presets = apply_filters( 'sportspress_get_presets', $presets );
|
||||
}
|
||||
@@ -100,17 +85,34 @@ class SP_Admin_Sports {
|
||||
* @return void
|
||||
*/
|
||||
public static function apply_preset( $id ) {
|
||||
if ( 'custom' == $id ) {
|
||||
$preset = array();
|
||||
} else {
|
||||
$preset = self::get_preset( $id );
|
||||
}
|
||||
$preset = self::get_preset( $id );
|
||||
|
||||
// Positions
|
||||
$positions = sp_array_value( $preset, 'positions', array() );
|
||||
foreach ( $positions as $index => $term ) {
|
||||
$slug = $index . '-' . sanitize_title( $term );
|
||||
wp_insert_term( $term, 'sp_position', array( 'slug' => $slug ) );
|
||||
$i = 0;
|
||||
foreach ( $positions as $parent => $position ) {
|
||||
if ( is_array( $position ) ) {
|
||||
|
||||
if ( ! term_exists( $parent, 'sp_position' ) ) {
|
||||
// Insert parent position
|
||||
$slug = $i . '-' . sanitize_title( $parent );
|
||||
wp_insert_term( $parent, 'sp_position', array( 'slug' => $slug ) );
|
||||
}
|
||||
|
||||
// Insert positions with parent
|
||||
foreach ( $position as $index => $child ) {
|
||||
$parent_term = term_exists( $parent, 'sp_position' );
|
||||
$parent_id = $parent_term['term_id'];
|
||||
$slug = $index . '-' . sanitize_title( $child );
|
||||
wp_insert_term( $child, 'sp_position', array( 'slug' => $slug, 'parent' => $parent_id ) );
|
||||
}
|
||||
} else {
|
||||
|
||||
// Insert single position
|
||||
$slug = $i . '-' . sanitize_title( $position );
|
||||
wp_insert_term( $position, 'sp_position', array( 'slug' => $slug ) );
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Outcomes
|
||||
@@ -259,6 +261,21 @@ class SP_Admin_Sports {
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sport category names
|
||||
* @return null
|
||||
*/
|
||||
public static function sport_category_names() {
|
||||
return apply_filters( 'sportspress_sport_categories', array(
|
||||
'team-sports' => __( 'Team Sports', 'sportspress' ),
|
||||
'racket-sports' => __( 'Racket Sports', 'sportspress' ),
|
||||
'water-sports' => __( 'Water Sports', 'sportspress' ),
|
||||
'target-sports' => __( 'Target Sports', 'sportspress' ),
|
||||
'esports' => __( 'Esports', 'sportspress' ),
|
||||
'other' => __( 'Other', 'sportspress' ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sport preset names for localization
|
||||
* @return null
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"name": "Baseball",
|
||||
"positions": [
|
||||
"Pitcher",
|
||||
"Catcher",
|
||||
"Infielder",
|
||||
"Outfielder"
|
||||
],
|
||||
"outcomes": [
|
||||
{ "name" : "Win", "condition" : ">" },
|
||||
{ "name" : "Loss", "condition" : "<" },
|
||||
{ "name" : "Tie", "condition" : "=" }
|
||||
],
|
||||
"results": [
|
||||
{ "name" : "1", "description" : "1st inning runs" },
|
||||
{ "name" : "2", "description" : "2nd inning runs" },
|
||||
{ "name" : "3", "description" : "3rd inning runs" },
|
||||
{ "name" : "4", "description" : "4th inning runs" },
|
||||
{ "name" : "5", "description" : "5th inning runs" },
|
||||
{ "name" : "6", "description" : "6th inning runs" },
|
||||
{ "name" : "7", "description" : "7th inning runs" },
|
||||
{ "name" : "8", "description" : "8th inning runs" },
|
||||
{ "name" : "9", "description" : "9th inning runs" },
|
||||
{ "name" : "X", "id" : "extra", "description" : "Extra inning runs" },
|
||||
{ "name" : "R", "description" : "Total runs", "primary" : 1 },
|
||||
{ "name" : "H", "description" : "Hits" },
|
||||
{ "name" : "E", "description" : "Errors" }
|
||||
],
|
||||
"performance": [
|
||||
{ "name" : "AB", "description" : "At bat" },
|
||||
{ "name" : "R", "description" : "Runs" },
|
||||
{ "name" : "H", "description" : "Hits" },
|
||||
{ "name" : "RBI", "description" : "Runs batted in" },
|
||||
{ "name" : "BB", "description" : "Base on balls" },
|
||||
{ "name" : "SO", "description" : "Strike outs" },
|
||||
{ "name" : "1B", "description" : "Singles" },
|
||||
{ "name" : "2B", "description" : "Doubles" },
|
||||
{ "name" : "3B", "description" : "Triples" },
|
||||
{ "name" : "HR", "description" : "Home runs" }
|
||||
],
|
||||
"columns": [
|
||||
{ "name" : "W", "equation" : "$win", "description" : "Wins" },
|
||||
{ "name" : "L", "equation" : "$loss", "description" : "Losses" },
|
||||
{ "name" : "PCT", "equation" : "$win / $eventsplayed", "precision" : 3, "priority" : 1, "description" : "Win percentage" },
|
||||
{ "name" : "RS", "equation" : "$rfor", "description" : "Runs scored" },
|
||||
{ "name" : "RA", "equation" : "$ragainst", "description" : "Runs allowed" },
|
||||
{ "name" : "DIFF", "equation" : "$rfor - $ragainst", "description" : "Run differential" },
|
||||
{ "name" : "L10", "equation" : "$last10", "description" : "Last 10 games" },
|
||||
{ "name" : "STRK", "equation" : "$streak", "description" : "Current streak" }
|
||||
],
|
||||
"metrics": [
|
||||
{ "name" : "B/T", "description": "Bats / Throws" },
|
||||
{ "name" : "Ht", "description": "Height" },
|
||||
{ "name" : "Wt", "description": "Weight" }
|
||||
],
|
||||
"statistics": [
|
||||
{ "name" : "G", "equation" : "$eventsplayed", "description" : "Games played" },
|
||||
{ "name" : "AVG", "equation" : "$h / $ab", "precision" : 3, "description" : "Batting average" }
|
||||
]
|
||||
}
|
||||
17
presets/other/custom.json
Normal file
17
presets/other/custom.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Custom",
|
||||
"positions": [
|
||||
],
|
||||
"outcomes": [
|
||||
],
|
||||
"results": [
|
||||
],
|
||||
"performance": [
|
||||
],
|
||||
"columns": [
|
||||
],
|
||||
"metrics": [
|
||||
],
|
||||
"statistics": [
|
||||
]
|
||||
}
|
||||
91
presets/team-sports/baseball.json
Normal file
91
presets/team-sports/baseball.json
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "Baseball",
|
||||
"positions": {
|
||||
"Batter" : [],
|
||||
"Pitcher" : [],
|
||||
"Fielder" : [
|
||||
"Catcher",
|
||||
"First base",
|
||||
"Second base",
|
||||
"Third base",
|
||||
"Shortstop",
|
||||
"Left field",
|
||||
"Center field",
|
||||
"Right field"
|
||||
]
|
||||
},
|
||||
"outcomes": [
|
||||
{ "name" : "Win", "condition" : ">" },
|
||||
{ "name" : "Loss", "condition" : "<" }
|
||||
],
|
||||
"results": [
|
||||
{ "name" : "1", "description" : "1st inning runs" },
|
||||
{ "name" : "2", "description" : "2nd inning runs" },
|
||||
{ "name" : "3", "description" : "3rd inning runs" },
|
||||
{ "name" : "4", "description" : "4th inning runs" },
|
||||
{ "name" : "5", "description" : "5th inning runs" },
|
||||
{ "name" : "6", "description" : "6th inning runs" },
|
||||
{ "name" : "7", "description" : "7th inning runs" },
|
||||
{ "name" : "8", "description" : "8th inning runs" },
|
||||
{ "name" : "9", "description" : "9th inning runs" },
|
||||
{ "name" : " ", "id" : "extra", "description" : "Extra inning runs" },
|
||||
{ "name" : "R", "description" : "Total runs", "primary" : 1 },
|
||||
{ "name" : "H", "description" : "Hits" },
|
||||
{ "name" : "E", "description" : "Errors" }
|
||||
],
|
||||
"performance": [
|
||||
{ "name" : "AB", "position" : "Batter", "description" : "At bat" },
|
||||
{ "name" : "R", "position" : "Batter", "description" : "Runs" },
|
||||
{ "name" : "H", "position" : "Batter", "description" : "Hits" },
|
||||
{ "name" : "RBI", "position" : "Batter", "description" : "Runs batted in" },
|
||||
{ "name" : "2B", "id" : "doubles", "position" : "Batter", "description" : "Doubles" },
|
||||
{ "name" : "3B", "id" : "triples", "position" : "Batter", "description" : "Triples" },
|
||||
{ "name" : "HR", "position" : "Batter", "description" : "Home runs" },
|
||||
{ "name" : "SB", "position" : "Batter", "description" : "Stolen bases" },
|
||||
{ "name" : "BB", "position" : "Batter", "description" : "Base on balls" },
|
||||
{ "name" : "SO", "position" : "Batter", "description" : "Strike outs" },
|
||||
{ "name" : "LOB", "position" : "Batter", "description" : "Left on base" },
|
||||
{ "name" : "IP", "id" : "pitcher_ip", "position" : "Pitcher", "description" : "Innings pitched" },
|
||||
{ "name" : "H", "id" : "pitcher_h", "position" : "Pitcher", "description" : "Hits allowed" },
|
||||
{ "name" : "R", "id" : "pitcher_r", "position" : "Pitcher", "description" : "Runs allowed" },
|
||||
{ "name" : "ER", "id" : "pitcher_er", "position" : "Pitcher", "description" : "Earned runs allowed" },
|
||||
{ "name" : "BB", "id" : "pitcher_bb", "position" : "Pitcher", "description" : "Base on balls allowed" },
|
||||
{ "name" : "SO", "id" : "pitcher_so", "position" : "Pitcher", "description" : "Strike outs pitched" },
|
||||
{ "name" : "HR", "id" : "pitcher_hr", "position" : "Pitcher", "description" : "Home runs allowed" }
|
||||
],
|
||||
"columns": [
|
||||
{ "name" : "W", "equation" : "$win", "description" : "Wins" },
|
||||
{ "name" : "L", "equation" : "$loss", "description" : "Losses" },
|
||||
{ "name" : "Pct", "equation" : "$win / $eventsplayed", "precision" : 3, "priority" : 1, "description" : "Win percentage" },
|
||||
{ "name" : "GB", "equation" : "$gamesback", "precision" : 1, "description" : "Games back" },
|
||||
{ "name" : "RS", "equation" : "$rfor", "description" : "Runs scored" },
|
||||
{ "name" : "RA", "equation" : "$ragainst", "description" : "Runs allowed" },
|
||||
{ "name" : "Diff", "equation" : "$rfor - $ragainst", "description" : "Run differential" },
|
||||
{ "name" : "Home", "equation" : "$homerecord", "description" : "Home record" },
|
||||
{ "name" : "Road", "equation" : "$awayrecord", "description" : "Road record" },
|
||||
{ "name" : "L10", "equation" : "$last10", "description" : "Last 10 games" },
|
||||
{ "name" : "Strk", "equation" : "$streak", "description" : "Current streak" }
|
||||
],
|
||||
"metrics": [
|
||||
{ "name" : "B/T", "description": "Bats / Throws" },
|
||||
{ "name" : "Ht", "description": "Height" },
|
||||
{ "name" : "Wt", "description": "Weight" }
|
||||
],
|
||||
"statistics": [
|
||||
{ "name" : "G", "equation" : "$eventsplayed", "description" : "Games played" },
|
||||
{ "name" : "AVG", "equation" : "$h / $ab", "precision" : 3, "description" : "Batting average" }
|
||||
],
|
||||
"options": {
|
||||
"event_teams" : "2",
|
||||
"event_show_players" : "yes",
|
||||
"event_show_extras" : "no",
|
||||
"event_show_total" : "yes",
|
||||
"sportspress_event_results_reverse_teams" : "yes",
|
||||
"sportspress_event_performance_mode" : "values",
|
||||
"sportspress_event_performance_reverse_teams" : "yes",
|
||||
"event_show_player_numbers" : "no",
|
||||
"event_split_players_by_team" : "yes",
|
||||
"event_split_players_by_position" : "yes",
|
||||
"sportspress_event_total_performance" : "all"
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
{ "name" : "W", "equation" : "$win", "description" : "Wins" },
|
||||
{ "name" : "L", "equation" : "$loss", "description" : "Losses" },
|
||||
{ "name" : "PCT", "equation" : "$win / $eventsplayed", "precision" : 3, "priority" : 1, "description" : "Win percentage" },
|
||||
{ "name" : "GB", "equation" : "$gamesback", "precision" : 1, "description" : "Games back" },
|
||||
{ "name" : "PF", "equation" : "$pointsfor / $eventsplayed", "priority" : 3, "description" : "Average points for" },
|
||||
{ "name" : "PA", "equation" : "$pointsagainst / $eventsplayed", "description" : "Average points against" },
|
||||
{ "name" : "DIFF", "equation" : "( $pointsfor - $pointsagainst ) / $eventsplayed", "priority" : 2, "description" : "Average point differential" },
|
||||
Reference in New Issue
Block a user