From 388817111acb73890ed4f8d3711d70d215078566 Mon Sep 17 00:00:00 2001
From: Brian Miyaji
Date: Fri, 2 May 2014 17:27:18 +1000
Subject: [PATCH] Move presets to json objects
---
includes/admin/class-sp-admin-settings.php | 89 ----------
includes/admin/class-sp-admin-sports.php | 167 +++++++++++++++---
includes/admin/class-sp-admin-welcome.php | 6 +-
.../presets/class-sp-preset-baseball.php | 33 ----
.../admin/presets/class-sp-preset-soccer.php | 33 ----
.../admin/presets/class-sp-preset-sport.php | 33 ----
.../settings/class-sp-settings-config.php | 98 +++++-----
.../settings/class-sp-settings-general.php | 8 +-
includes/class-sp-install.php | 3 +-
includes/class-sp-post-types.php | 12 +-
includes/class-sp-sports.php | 52 ------
includes/sp-core-functions.php | 9 -
includes/sp-template-hooks.php | 6 +
presets/baseball.json | 40 +++++
presets/basketball.json | 61 +++++++
presets/cricket.json | 21 +++
presets/football.json | 20 +++
presets/footy.json | 19 ++
presets/racing.json | 19 ++
presets/rugby.json | 20 +++
presets/soccer.json | 47 +++--
sportspress.php | 7 -
22 files changed, 438 insertions(+), 365 deletions(-)
delete mode 100644 includes/admin/presets/class-sp-preset-baseball.php
delete mode 100644 includes/admin/presets/class-sp-preset-soccer.php
delete mode 100644 includes/admin/presets/class-sp-preset-sport.php
delete mode 100644 includes/class-sp-sports.php
create mode 100644 presets/baseball.json
create mode 100644 presets/basketball.json
create mode 100644 presets/cricket.json
create mode 100644 presets/football.json
create mode 100644 presets/footy.json
create mode 100644 presets/racing.json
create mode 100644 presets/rugby.json
diff --git a/includes/admin/class-sp-admin-settings.php b/includes/admin/class-sp-admin-settings.php
index c525f946..99fcae39 100644
--- a/includes/admin/class-sp-admin-settings.php
+++ b/includes/admin/class-sp-admin-settings.php
@@ -599,95 +599,6 @@ class SP_Admin_Settings {
return true;
}
-
- /**
- * Configure sport
- *
- * @access public
- * @return void
- */
- public static function configure_sport( $sport ) {
- // Get array of taxonomies to insert
- $term_groups = sp_array_value( $sport, 'term', array() );
-
- foreach( $term_groups as $taxonomy => $terms ):
- // Find empty terms and destroy
- $allterms = get_terms( $taxonomy, 'hide_empty=0' );
-
- foreach( $allterms as $term ):
- if ( $term->count == 0 )
- wp_delete_term( $term->term_id, $taxonomy );
- endforeach;
-
- // Insert terms
- foreach( $terms as $term ):
- wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
- endforeach;
- endforeach;
-
- // Get array of post types to insert
- $post_groups = sp_array_value( $sport, 'posts', array() );
-
- // Loop through each post type
- foreach( $post_groups as $post_type => $posts ):
-
- $args = array(
- 'post_type' => $post_type,
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'meta_query' => array(
- array(
- 'key' => '_sp_preset',
- 'value' => 1
- )
- )
- );
-
- // Delete posts
- $old_posts = get_posts( $args );
-
- foreach( $old_posts as $post ):
- wp_delete_post( $post->ID, true);
- endforeach;
-
- // Add posts
- foreach( $posts as $index => $post ):
-
- // Make sure post doesn't overlap
- if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
-
- // Translate post title
- $post['post_title'] = __( $post['post_title'], 'sportspress' );
-
- // Set post type
- $post['post_type'] = $post_type;
-
- // Increment menu order by 2 and publish post
- $post['menu_order'] = $index * 2 + 2;
- $post['post_status'] = 'publish';
- $id = wp_insert_post( $post );
-
- // Flag as preset
- update_post_meta( $id, '_sp_preset', 1 );
-
- // Update meta
- if ( array_key_exists( 'meta', $post ) ):
- foreach ( $post['meta'] as $key => $value ):
- update_post_meta( $id, $key, $value );
- endforeach;
- endif;
-
- // Update terms
- if ( array_key_exists( 'tax_input', $post ) ):
- foreach ( $post['tax_input'] as $taxonomy => $terms ):
- wp_set_object_terms( $id, $terms, $taxonomy, false );
- endforeach;
- endif;
- endif;
- endforeach;
- endforeach;
- update_option( 'sportspress_primary_result', 0 );
- }
}
endif;
diff --git a/includes/admin/class-sp-admin-sports.php b/includes/admin/class-sp-admin-sports.php
index 2393f3c9..96aa78f6 100644
--- a/includes/admin/class-sp-admin-sports.php
+++ b/includes/admin/class-sp-admin-sports.php
@@ -11,7 +11,9 @@
* @author ThemeBoy
*/
class SP_Admin_Sports {
- private static $presets = array();
+
+ public static $presets = array();
+ public static $options = array();
/**
* Include the preset classes
@@ -19,14 +21,11 @@ class SP_Admin_Sports {
public static function get_presets() {
if ( empty( self::$presets ) ) {
$presets = array();
-
- include( 'presets/class-sp-preset-sport.php' );
-
$dir = scandir( SP()->plugin_path() . '/presets' );
$files = array();
if ( $dir ) {
foreach ( $dir as $key => $value ) {
- if ( ! in_array( $value, array( ".",".." ) ) ) {
+ if ( substr( $value, 0, 1 ) !== '.' ) {
$files[] = $value;
}
}
@@ -34,41 +33,163 @@ class SP_Admin_Sports {
foreach( $files as $file ) {
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $file );
$data = json_decode( $json_data, true );
- pr( $data );
+ if ( ! is_array( $data ) ) continue;
+ $id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file );
+ $presets[ $id ] = $data;
+ $name = array_key_exists( 'name', $data ) ? $data['name'] : $id;
+ self::$options[ $id ] = $name;
}
-
- //$presets[] = include( 'presets/class-sp-preset-soccer.php' );
- //$presets[] = include( 'presets/class-sp-preset-baseball.php' );SP_TEMPLATE_PATH
-
+ self::$options[ 'custom' ] = __( 'Custom', 'sportspress' );
self::$presets = apply_filters( 'sportspress_get_presets', $presets );
}
return self::$presets;
}
- public static function get_preset_options() {
- $presets = self::get_presets();
- $options = apply_filters( 'sportspress_sport_presets_array', array() );
- return $options;
+ public static function get_preset( $id ) {
+ $json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $id . '.json' );
+ return json_decode( $json_data, true );
}
- /** @var array Array of sports */
- private $data;
+ public static function get_preset_options() {
+ $presets = self::get_presets();
+ return self::$options;
+ }
/**
- * Constructor for the sports class - defines all preset sports.
+ * Apply preset
*
* @access public
* @return void
*/
- public function __construct() {
- $this->data = sp_get_sport_presets();
+ public static function apply_preset( $id ) {
+ if ( 'custom' == $id ) {
+ $preset = array();
+ } else {
+ $preset = self::get_preset( $id );
+ }
+
+ // Outcomes
+ $post_type = 'sp_outcome';
+ $outcomes = sp_array_value( $preset, 'outcomes', array() );
+ self::delete_preset_posts( $post_type );
+ foreach ( $outcomes as $index => $outcome ) {
+ $post = self::get_post_array( $outcome, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ }
+
+ // Results
+ $post_type = 'sp_result';
+ $results = sp_array_value( $preset, 'results', array() );
+ self::delete_preset_posts( $post_type );
+ $main_result = 0;
+ foreach ( $results as $index => $result ) {
+ $post = self::get_post_array( $result, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ if ( array_key_exists( 'main', $result ) ) $main_result = $post['post_name'];
+ }
+
+ // Performance
+ $post_type = 'sp_performance';
+ $performances = sp_array_value( $preset, 'performance', array() );
+ self::delete_preset_posts( $post_type );
+ foreach ( $performances as $index => $performance ) {
+ $post = self::get_post_array( $performance, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ }
+
+ // Columns
+ $post_type = 'sp_column';
+ $columns = sp_array_value( $preset, 'columns', array() );
+ self::delete_preset_posts( $post_type );
+ foreach ( $columns as $index => $column ) {
+ $post = self::get_post_array( $column, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ update_post_meta( $id, 'sp_equation', sp_array_value( $column, 'equation', null ) );
+ update_post_meta( $id, 'sp_precision', sp_array_value( $column, 'precision', 0 ) );
+ update_post_meta( $id, 'sp_priority', sp_array_value( $column, 'priority', null ) );
+ update_post_meta( $id, 'sp_order', sp_array_value( $column, 'order', 'DESC' ) );
+ }
+
+ // Metrics
+ $post_type = 'sp_metric';
+ $metrics = sp_array_value( $preset, 'metrics', array() );
+ self::delete_preset_posts( $post_type );
+ foreach ( $metrics as $index => $metric ) {
+ $post = self::get_post_array( $metric, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ }
+
+ // Statistics
+ $post_type = 'sp_statistic';
+ $statistics = sp_array_value( $preset, 'statistics', array() );
+ self::delete_preset_posts( $post_type );
+ foreach ( $statistics as $index => $statistic ) {
+ $post = self::get_post_array( $statistic, $post_type );
+ if ( empty( $post ) ) continue;
+ $id = self::insert_preset_post( $post, $index );
+ update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) );
+ update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) );
+ }
+ update_option( 'sportspress_primary_result', $main_result );
}
- public function __get( $key ) {
- return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
+ public static function delete_preset_posts( $post_type = null ) {
+ $args = array(
+ 'post_type' => $post_type,
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'meta_query' => array(
+ array(
+ 'key' => '_sp_preset',
+ 'value' => 1
+ )
+ )
+ );
+
+ // Delete posts
+ $old_posts = get_posts( $args );
+ foreach( $old_posts as $post ):
+ wp_delete_post( $post->ID, true);
+ endforeach;
}
- public function __set( $key, $value ){
- $this->data[ $key ] = $value;
+ public static function get_post_array( $post = array(), $post_type = null ) {
+ $post_array = array();
+ if ( is_string( $post ) ) {
+ $post_array['post_title'] = $post;
+ $post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] );
+ } elseif ( is_array( $post ) ) {
+ if ( ! array_key_exists( 'name', $post ) ) $post_array = array();
+ $post_array['post_title'] = $post['name'];
+ $post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) );
+ }
+
+ // Return empty array if post with same slug already exists
+ if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) return array();
+
+ // Set post type
+ $post_array['post_type'] = $post_type;
+
+ // Add post excerpt
+ $post_array['post_excerpt'] = sp_array_value( $post, 'description', $post_array['post_title'] );
+
+ return $post_array;
+ }
+
+ public static function insert_preset_post( $post, $index = 0 ) {
+ // Increment menu order by 10 and publish post
+ $post['menu_order'] = $index * 10 + 10;
+ $post['post_status'] = 'publish';
+ $id = wp_insert_post( $post );
+
+ // Flag as preset
+ update_post_meta( $id, '_sp_preset', 1 );
+
+ return $id;
}
}
diff --git a/includes/admin/class-sp-admin-welcome.php b/includes/admin/class-sp-admin-welcome.php
index 5b7840d0..ae383747 100644
--- a/includes/admin/class-sp-admin-welcome.php
+++ b/includes/admin/class-sp-admin-welcome.php
@@ -195,8 +195,8 @@ class SP_Admin_Welcome {
sports->$_POST['sportspress_sport'];
- SP_Admin_Settings::configure_sport( $sport );
+ $sport = $_POST['sportspress_sport'];
+ SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $_POST['sportspress_sport'] );
endif;
if ( isset( $_POST['sportspress_default_country'] ) ):
@@ -222,7 +222,7 @@ class SP_Admin_Welcome {
'sportspress_sport',
diff --git a/includes/admin/presets/class-sp-preset-baseball.php b/includes/admin/presets/class-sp-preset-baseball.php
deleted file mode 100644
index a475e501..00000000
--- a/includes/admin/presets/class-sp-preset-baseball.php
+++ /dev/null
@@ -1,33 +0,0 @@
-id = 'baseball';
- $this->label = __( 'Baseball', 'sportspress' );
-
- add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
- }
-}
-
-endif;
-
-return new SP_Preset_Baseball();
diff --git a/includes/admin/presets/class-sp-preset-soccer.php b/includes/admin/presets/class-sp-preset-soccer.php
deleted file mode 100644
index 6d041d5d..00000000
--- a/includes/admin/presets/class-sp-preset-soccer.php
+++ /dev/null
@@ -1,33 +0,0 @@
-id = 'soccer';
- $this->label = __( 'Association Football (Soccer)', 'sportspress' );
-
- add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
- }
-}
-
-endif;
-
-return new SP_Preset_Soccer();
diff --git a/includes/admin/presets/class-sp-preset-sport.php b/includes/admin/presets/class-sp-preset-sport.php
deleted file mode 100644
index 99d43803..00000000
--- a/includes/admin/presets/class-sp-preset-sport.php
+++ /dev/null
@@ -1,33 +0,0 @@
-id ] = $this->label;
-
- return $presets;
- }
-}
-
-endif;
diff --git a/includes/admin/settings/class-sp-settings-config.php b/includes/admin/settings/class-sp-settings-config.php
index bde943ca..b779da20 100644
--- a/includes/admin/settings/class-sp-settings-config.php
+++ b/includes/admin/settings/class-sp-settings-config.php
@@ -102,6 +102,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|
+ |
|
@@ -109,6 +110,7 @@ class SP_Settings_Config extends SP_Settings_Page {
>
| post_title; ?> |
post_name; ?> |
+ post_excerpt; ?> |
|
@@ -149,50 +151,50 @@ class SP_Settings_Config extends SP_Settings_Page {
- |
|
|
+ |
|
@@ -232,6 +235,7 @@ class SP_Settings_Config extends SP_Settings_Page {
>
| post_title; ?> |
post_name; ?> |
+ post_excerpt; ?> |
|
@@ -278,6 +282,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|
|
+ |
|
@@ -288,6 +293,7 @@ class SP_Settings_Config extends SP_Settings_Page {
ID ); ?> |
ID ); ?> |
ID ); ?> |
+ post_excerpt; ?> |
|
@@ -332,7 +338,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|
- |
+ |
|
@@ -340,7 +346,7 @@ class SP_Settings_Config extends SP_Settings_Page {
>
| post_title; ?> |
post_name; ?> |
- |
+ post_excerpt; ?> |
|
@@ -386,6 +392,7 @@ class SP_Settings_Config extends SP_Settings_Page {
|
|
|
+ |
|
@@ -395,6 +402,7 @@ class SP_Settings_Config extends SP_Settings_Page {
post_name; ?> |
ID ); ?> |
ID ); ?> |
+ post_excerpt; ?> |
|
diff --git a/includes/admin/settings/class-sp-settings-general.php b/includes/admin/settings/class-sp-settings-general.php
index 1f0ff559..08726dd7 100644
--- a/includes/admin/settings/class-sp-settings-general.php
+++ b/includes/admin/settings/class-sp-settings-general.php
@@ -40,9 +40,7 @@ class SP_Settings_General extends SP_Settings_Page {
*/
public function get_settings() {
- $sports = new SP_Admin_Sports();
-
- $presets = $sports->get_preset_options();
+ $presets = SP_Admin_Sports::get_preset_options();
return apply_filters( 'sportspress_general_settings', array(
@@ -109,8 +107,8 @@ class SP_Settings_General extends SP_Settings_Page {
*/
public function save() {
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ):
- $sport = SP()->sports->$_POST['sportspress_sport'];
- SP_Admin_Settings::configure_sport( $sport );
+ $sport = $_POST['sportspress_sport'];
+ SP_Admin_Sports::apply_preset( $sport );
update_option( '_sp_needs_welcome', 0 );
endif;
diff --git a/includes/class-sp-install.php b/includes/class-sp-install.php
index ba080ed7..547a1821 100644
--- a/includes/class-sp-install.php
+++ b/includes/class-sp-install.php
@@ -135,8 +135,7 @@ class SP_Install {
if ( ! get_option( 'sportspress_installed' ) ) {
// Configure default sport
$sport = 'soccer';
- $options = sp_get_sport_presets();
- SP_Admin_Settings::configure_sport( $options[ $sport ] );
+ SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $sport );
update_option( 'sportspress_installed', 1 );
}
diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php
index eacadab2..b326cb4f 100644
--- a/includes/class-sp-post-types.php
+++ b/includes/class-sp-post-types.php
@@ -175,7 +175,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
@@ -205,7 +205,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
@@ -235,7 +235,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
@@ -265,7 +265,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
@@ -295,7 +295,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
@@ -325,7 +325,7 @@ class SP_Post_types {
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
- 'supports' => array( 'title', 'page-attributes' ),
+ 'supports' => array( 'title', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'can_export' => false,
diff --git a/includes/class-sp-sports.php b/includes/class-sp-sports.php
deleted file mode 100644
index 50697814..00000000
--- a/includes/class-sp-sports.php
+++ /dev/null
@@ -1,52 +0,0 @@
-data = sp_get_sport_presets();
- }
-
- public function __get( $key ) {
- return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
- }
-
- public function __set( $key, $value ){
- $this->data[ $key ] = $value;
- }
-}
diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php
index 133e392c..e173d99b 100644
--- a/includes/sp-core-functions.php
+++ b/includes/sp-core-functions.php
@@ -2407,15 +2407,6 @@ function sp_get_sport_presets() {
));
}
-function sp_get_sport_options() {
- $sports = sp_get_sport_presets();
- $options = array();
- foreach ( $sports as $slug => $data ):
- $options[ $slug ] = $data['name'];
- endforeach;
- return $options;
-}
-
/**
* Get an array of text options per context.
* @return array
diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php
index c8b86587..a3422a82 100644
--- a/includes/sp-template-hooks.php
+++ b/includes/sp-template-hooks.php
@@ -110,6 +110,12 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
if ( is_admin() ):
if ( is_sp_config_type( $typenow ) ):
switch ( $untranslated_text ):
+ case 'Excerpt':
+ $translated_text = __( 'Description', 'sportspress' );
+ break;
+ case 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme. Learn more about manual excerpts.':
+ $translated_text = __( 'The description is not prominent by default; however, some themes may show it.', 'sportspress' );
+ break;
case 'Slug':
$translated_text = ( in_array( $typenow, array( 'sp_column', 'sp_statistic' ) ) ) ? __( 'Key', 'sportspress' ) : __( 'Variable', 'sportspress' );
break;
diff --git a/presets/baseball.json b/presets/baseball.json
new file mode 100644
index 00000000..ecc10698
--- /dev/null
+++ b/presets/baseball.json
@@ -0,0 +1,40 @@
+{
+ "name": "Baseball - coming soon",
+ "outcomes": [
+ "Win",
+ "Loss"
+ ],
+ "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", "main" : 1 },
+ { "name" : "H", "description" : "Hits" },
+ { "name" : "E", "description" : "Errors" }
+ ],
+ "performance": [
+ ],
+ "columns": [
+ { "name" : "W", "equation" : "$win", "description" : "Wins" },
+ { "name" : "L", "equation" : "$loss", "description" : "Losses" },
+ { "name" : "PCT", "equation" : "$win / $eventsplayed", "precision" : 3, "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": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/basketball.json b/presets/basketball.json
new file mode 100644
index 00000000..11302e13
--- /dev/null
+++ b/presets/basketball.json
@@ -0,0 +1,61 @@
+{
+ "name": "Basketball",
+ "outcomes": [
+ "Win",
+ "Loss"
+ ],
+ "results": [
+ { "name" : "1", "description" : "1st quarter points" },
+ { "name" : "2", "description" : "2nd quarter points" },
+ { "name" : "3", "description" : "3rd quarter points" },
+ { "name" : "4", "description" : "4th quarter points" },
+ { "name" : "", "id" : "ot", "description" : "Overtime points" },
+ { "name" : "T", "description" : "Total points", "main" : 1 }
+ ],
+ "performance": [
+ { "name" : "MIN", "description" : "Minutes" },
+ { "name" : "FGM", "description" : "Field goals made" },
+ { "name" : "FGA", "description" : "Field goals attempted" },
+ { "name" : "FTM", "description" : "Free throws made" },
+ { "name" : "FTA", "description" : "Free throws attempted" },
+ { "name" : "3PM", "description" : "3-pointers made" },
+ { "name" : "3PA", "description" : "3-pointers attempted" },
+ { "name" : "OFF REB", "description" : "Offensive rebounds" },
+ { "name" : "DEF REB", "description" : "Defensive rebounds" },
+ { "name" : "AST", "description" : "Assists" },
+ { "name" : "PF", "description" : "Personal fouls" },
+ { "name" : "TF", "description" : "Technical fouls" },
+ { "name" : "STL", "description" : "Steals" },
+ { "name" : "TO", "description" : "Turnovers" },
+ { "name" : "BLK", "description" : "Blocks" },
+ { "name" : "PTS", "description" : "Points" }
+ ],
+ "columns": [
+ { "name" : "W", "equation" : "$win", "description" : "Wins" },
+ { "name" : "L", "equation" : "$loss", "description" : "Losses" },
+ { "name" : "PCT", "equation" : "$win / $eventsplayed", "precision" : 3, "description" : "Win percentage" },
+ { "name" : "PF", "equation" : "$tfor / $eventsplayed", "precision" : 1, "description" : "Average points for" },
+ { "name" : "PA", "equation" : "$tagainst / $eventsplayed", "precision" : 1, "description" : "Average points against" },
+ { "name" : "DIFF", "equation" : "( $tfor - $tagainst ) / $eventsplayed", "precision" : 1, "description" : "Average point differential" },
+ { "name" : "L10", "equation" : "$last10", "description" : "Last 10 games" },
+ { "name" : "STRK", "equation" : "$streak", "description" : "Current streak" }
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ { "name" : "G", "equation" : "$eventsplayed", "description" : "Games played" },
+ { "name" : "GS", "equation" : "$eventsstarted", "description" : "Games started" },
+ { "name" : "MPG", "equation" : "$min / $eventsplayed", "precision" : 1, "description" : "Minutes per game" },
+ { "name" : "FG%", "equation" : "$fgm / $fga", "precision" : 3, "description" : "Field goal percentage" },
+ { "name" : "FT%", "equation" : "$ftm / $fta", "precision" : 3, "description" : "Free throw percentage" },
+ { "name" : "3P%", "equation" : "$threepm / $threepa", "precision" : 3, "description" : "3-pointer percentage" },
+ { "name" : "RPG", "equation" : "( $offreb + $defreb ) / $eventsplayed", "precision" : 1, "description" : "Rebounds per game" },
+ { "name" : "APG", "equation" : "$ast / $eventsplayed", "precision" : 1, "description" : "Assists per game" },
+ { "name" : "SPG", "equation" : "$stl / $eventsplayed", "precision" : 1, "description" : "Steals per game" },
+ { "name" : "BPG", "equation" : "$blk / $eventsplayed", "precision" : 1, "description" : "Blocks per game" },
+ { "name" : "PPG", "equation" : "$pts / $eventsplayed", "precision" : 1, "description" : "Points per game" },
+ { "name" : "EFF", "equation" : "$pts + $offreb + $defreb + $ast + $stl + $blk - $fga + $fgm - $fta + $ftm + $to", "description" : "Efficiency rating" }
+ ]
+}
\ No newline at end of file
diff --git a/presets/cricket.json b/presets/cricket.json
new file mode 100644
index 00000000..4c879863
--- /dev/null
+++ b/presets/cricket.json
@@ -0,0 +1,21 @@
+{
+ "name": "Cricket - coming soon",
+ "outcomes": [
+ "Win",
+ "Loss",
+ "Tie",
+ "Draw"
+ ],
+ "results": [
+ ],
+ "performance": [
+ ],
+ "columns": [
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/football.json b/presets/football.json
new file mode 100644
index 00000000..654e7d26
--- /dev/null
+++ b/presets/football.json
@@ -0,0 +1,20 @@
+{
+ "name": "Football - coming soon",
+ "outcomes": [
+ "Win",
+ "Loss",
+ "Tie"
+ ],
+ "results": [
+ ],
+ "performance": [
+ ],
+ "columns": [
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/footy.json b/presets/footy.json
new file mode 100644
index 00000000..57f8dcb6
--- /dev/null
+++ b/presets/footy.json
@@ -0,0 +1,19 @@
+{
+ "name": "Footy - coming soon",
+ "outcomes": [
+ "Win",
+ "Loss"
+ ],
+ "results": [
+ ],
+ "performance": [
+ ],
+ "columns": [
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/racing.json b/presets/racing.json
new file mode 100644
index 00000000..82d53404
--- /dev/null
+++ b/presets/racing.json
@@ -0,0 +1,19 @@
+{
+ "name": "Racing - coming soon",
+ "outcomes": [
+ "Win",
+ "Loss"
+ ],
+ "results": [
+ ],
+ "performance": [
+ ],
+ "columns": [
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/rugby.json b/presets/rugby.json
new file mode 100644
index 00000000..a093b0f2
--- /dev/null
+++ b/presets/rugby.json
@@ -0,0 +1,20 @@
+{
+ "name": "Rugby - coming soon",
+ "outcomes": [
+ "Win",
+ "Draw",
+ "Loss"
+ ],
+ "results": [
+ ],
+ "performance": [
+ ],
+ "columns": [
+ ],
+ "metrics": [
+ "Height",
+ "Weight"
+ ],
+ "statistics": [
+ ]
+}
\ No newline at end of file
diff --git a/presets/soccer.json b/presets/soccer.json
index b9cf8f0b..8f424643 100644
--- a/presets/soccer.json
+++ b/presets/soccer.json
@@ -1,46 +1,43 @@
{
- "sport": "soccer",
- "id": "premier-league",
- "name": "Premier League",
+ "name": "Soccer (Association Football)",
"outcomes": [
- "W",
- "D",
- "L"
+ "Win",
+ "Draw",
+ "Loss"
],
"results": [
- "1st Half",
- "2nd Half",
- "Goals"
+ { "name" : "1st Half", "description" : "1st half goals" },
+ { "name" : "2nd Half", "description" : "2nd half goals" },
+ { "name" : "Goals", "description" : "Total goals", "main" : 1 }
],
"performance": [
"Goals",
+ "Shots on Goal",
"Assists",
"Fouls",
+ "Fouled",
"Yellow Cards",
"Red Cards"
],
"columns": [
- { "name" : "P", "equation" : "$events" },
- { "name" : "W", "equation" : "$w" },
- { "name" : "D", "equation" : "$d" },
- { "name" : "L", "equation" : "$l" },
- { "name" : "GF", "equation" : "$goalsfor" },
- { "name" : "GA", "equation" : "$goalsagainst" },
- { "name" : "GD", "equation" : "$goalsfor - $goalsagainst" },
- { "name" : "Pts", "equation" : "$w * 3 + $d" }
+ { "name" : "P", "equation" : "$eventsplayed", "description" : "Matches played" },
+ { "name" : "W", "equation" : "$win", "description" : "Wins" },
+ { "name" : "D", "equation" : "$draw", "description" : "Draws" },
+ { "name" : "L", "equation" : "$loss", "description" : "Losses" },
+ { "name" : "F", "equation" : "$goalsfor", "priority" : 3, "description" : "Goals for" },
+ { "name" : "A", "equation" : "$goalsagainst", "description" : "Goals against" },
+ { "name" : "GD", "equation" : "$goalsfor - $goalsagainst", "priority" : 2, "description" : "Goal difference" },
+ { "name" : "PTS", "equation" : "$win * 3 + $draw", "priority" : 1, "description" : "Team points" }
],
"metrics": [
"Height",
"Weight"
],
"statistics": [
- { "name" : "Appearances", "equation" : "$events" }
- { "name" : "Average Goals per Match", "equation" : "$goals / $events" }
- { "name" : "Win Ratio", "equation" : "$w / $events" }
- { "name" : "Played", "equation" : "$eventsplayed" }
- { "name" : "Played", "equation" : "$eventsplayed" }
- { "name" : "Played", "equation" : "$eventsplayed" }
- { "name" : "Played", "equation" : "$eventsplayed" }
- { "name" : "Played", "equation" : "$eventsplayed" }
+ { "name" : "Appearances", "equation" : "$eventsplayed", "description" : "Matches played" },
+ { "name" : "Average Goals per Match", "id" : "averagegoals", "equation" : "$goals / $eventsplayed", "precision" : 2 },
+ { "name" : "Win Ratio", "equation" : "$win / $eventsplayed * 100", "precision" : 2 },
+ { "name" : "Draw Ratio", "equation" : "$draw / $eventsplayed * 100", "precision" : 2 },
+ { "name" : "Loss Ratio", "equation" : "$loss / $eventsplayed * 100", "precision" : 2 }
]
}
\ No newline at end of file
diff --git a/sportspress.php b/sportspress.php
index 3f0393f7..c4e4d982 100644
--- a/sportspress.php
+++ b/sportspress.php
@@ -46,11 +46,6 @@ final class SportsPress {
*/
public $countries = null;
- /**
- * @var SP_Sports $sports
- */
- public $sports = null;
-
/**
* @var SP_Formats $formats
*/
@@ -214,7 +209,6 @@ final class SportsPress {
// Classes (used on all pages)
include_once( 'includes/class-sp-countries.php' ); // Defines continents and countries
include_once( 'includes/class-sp-formats.php' ); // Defines custom post type formats
- include_once( 'includes/class-sp-sports.php' ); // Defines custom post type formats
include_once( 'includes/class-sp-text.php' ); // Defines editable strings
// Include template hooks in time for themes to remove/modify them
@@ -263,7 +257,6 @@ final class SportsPress {
// Load class instances
$this->countries = new SP_Countries(); // Countries class
$this->formats = new SP_Formats(); // Formats class
- $this->sports = new SP_Sports(); // Formats class
$this->text = new SP_Text(); // Text class
// Init action