From 0dd53482b6408ee51857549bc8af8a9fd8cee0a4 Mon Sep 17 00:00:00 2001
From: Brian Miyaji
Date: Tue, 7 Jan 2014 17:44:33 +1100
Subject: [PATCH] Expand theme prefix and clean up file structure
---
admin/actions/admin-enqueue-scripts.php | 6 +
admin/actions/admin-head.php | 10 +
admin/actions/admin-init.php | 162 ++
admin/actions/admin-menu.php | 12 +-
admin/actions/after-setup-theme.php | 5 +
admin/actions/after-theme-setup.php | 5 -
admin/actions/manage-posts-columns.php | 4 +
admin/actions/manage-posts-custom-column.php | 18 +-
admin/actions/plugins-loaded.php | 6 +-
admin/actions/post-thumbnail-html.php | 4 +-
admin/actions/restrict-manage-posts.php | 10 +-
admin/actions/save-post.php | 62 +-
admin/filters/admin-post-thumbnail-html.php | 4 +-
admin/filters/gettext.php | 4 +-
admin/filters/pre-get-posts.php | 4 +-
admin/filters/sanitize-title.php | 6 +-
admin/filters/the-content.php | 4 +-
admin/filters/wp-insert-post-data.php | 4 +-
admin/post-types/column.php | 12 +-
admin/post-types/event.php | 28 +-
admin/post-types/list.php | 22 +-
admin/post-types/outcome.php | 8 +-
admin/post-types/player.php | 32 +-
admin/post-types/result.php | 10 +-
admin/post-types/separator.php | 4 +-
admin/post-types/staff.php | 12 +-
admin/post-types/statistic.php | 12 +-
admin/post-types/table.php | 22 +-
admin/post-types/team.php | 22 +-
admin/settings/config.php | 14 +-
admin/settings/settings.php | 43 +-
admin/terms/position.php | 6 +-
admin/terms/season.php | 6 +-
functions.php | 1458 +----------------
helpers.php | 1423 ++++++++++++++++
install.php | 160 --
.../languages => languages}/sportspress-ja.mo | Bin
.../languages => languages}/sportspress-ja.po | 0
sportspress.php | 57 +-
i18n/strings.php => strings.php | 8 +-
40 files changed, 1838 insertions(+), 1851 deletions(-)
create mode 100644 admin/actions/admin-enqueue-scripts.php
create mode 100644 admin/actions/admin-head.php
create mode 100644 admin/actions/admin-init.php
create mode 100644 admin/actions/after-setup-theme.php
delete mode 100644 admin/actions/after-theme-setup.php
create mode 100644 admin/actions/manage-posts-columns.php
create mode 100644 helpers.php
delete mode 100644 install.php
rename {i18n/languages => languages}/sportspress-ja.mo (100%)
rename {i18n/languages => languages}/sportspress-ja.po (100%)
rename i18n/strings.php => strings.php (91%)
diff --git a/admin/actions/admin-enqueue-scripts.php b/admin/actions/admin-enqueue-scripts.php
new file mode 100644
index 00000000..99675197
--- /dev/null
+++ b/admin/actions/admin-enqueue-scripts.php
@@ -0,0 +1,6 @@
+add_cap( 'edit_sp_event' );
+ $role->add_cap( 'edit_sp_events' );
+ $role->add_cap( 'edit_others_sp_events' );
+ $role->add_cap( 'delete_sp_event' );
+ $role->add_cap( 'publish_sp_events' );
+ $role->add_cap( 'read_sp_events' );
+ $role->add_cap( 'read_private_sp_events' );
+
+ // Teams
+ $role->add_cap( 'edit_sp_team' );
+ $role->add_cap( 'edit_sp_teams' );
+ $role->add_cap( 'edit_others_sp_teams' );
+ $role->add_cap( 'delete_sp_team' );
+ $role->add_cap( 'publish_sp_teams' );
+ $role->add_cap( 'read_sp_teams' );
+ $role->add_cap( 'read_private_sp_teams' );
+
+ // League Tables
+ $role->add_cap( 'edit_sp_table' );
+ $role->add_cap( 'edit_sp_tables' );
+ $role->add_cap( 'edit_others_sp_tables' );
+ $role->add_cap( 'delete_sp_table' );
+ $role->add_cap( 'publish_sp_tables' );
+ $role->add_cap( 'read_sp_tables' );
+ $role->add_cap( 'read_private_sp_tables' );
+
+ // Players
+ $role->add_cap( 'edit_sp_player' );
+ $role->add_cap( 'edit_sp_players' );
+ $role->add_cap( 'edit_others_sp_players' );
+ $role->add_cap( 'delete_sp_player' );
+ $role->add_cap( 'publish_sp_players' );
+ $role->add_cap( 'read_sp_players' );
+ $role->add_cap( 'read_private_sp_players' );
+
+ // Player Lists
+ $role->add_cap( 'edit_sp_list' );
+ $role->add_cap( 'edit_sp_lists' );
+ $role->add_cap( 'edit_others_sp_lists' );
+ $role->add_cap( 'delete_sp_list' );
+ $role->add_cap( 'publish_sp_lists' );
+ $role->add_cap( 'read_sp_lists' );
+ $role->add_cap( 'read_private_sp_lists' );
+
+ // Staff
+ $role->add_cap( 'edit_sp_staff' );
+ $role->add_cap( 'edit_sp_staffs' );
+ $role->add_cap( 'edit_others_sp_staffs' );
+ $role->add_cap( 'delete_sp_staff' );
+ $role->add_cap( 'publish_sp_staffs' );
+ $role->add_cap( 'read_sp_staffs' );
+ $role->add_cap( 'read_private_sp_staffs' );
+
+ // Settings
+ $role->add_cap( 'read_sp_configs' );
+ $role->add_cap( 'read_private_sp_configs' );
+ $role->add_cap( 'edit_sp_config' );
+ $role->add_cap( 'edit_sp_configs' );
+ $role->add_cap( 'edit_published_sp_configs' );
+ $role->add_cap( 'edit_private_sp_configs' );
+ $role->add_cap( 'edit_others_sp_configs' );
+ $role->add_cap( 'delete_sp_config' );
+ $role->add_cap( 'delete_published_sp_configs' );
+ $role->add_cap( 'delete_private_sp_configs' );
+ $role->add_cap( 'delete_others_sp_configs' );
+ $role->add_cap( 'publish_sp_configs' );
+
+ // Team Manager
+ remove_role( 'sp_team_manager' );
+ add_role(
+ 'sp_team_manager',
+ __( 'Team Manager', 'sportspress' ),
+ array(
+ 'read' => true,
+ 'edit_posts' => true,
+ 'delete_posts' => true,
+ 'read_sp_players' => true,
+ 'edit_sp_players' => true,
+ 'edit_others_sp_players' => true,
+ 'delete_sp_player' => true,
+ 'publish_sp_players' => true,
+ 'read_sp_staffs' => true,
+ 'edit_sp_staffs' => true,
+ 'edit_others_sp_staffs' => true,
+ 'delete_sp_staff' => true,
+ 'publish_sp_staffs' => true
+ )
+ );
+
+ // Staff
+ remove_role( 'sp_staff' );
+ add_role(
+ 'sp_staff',
+ __( 'Staff', 'sportspress' ),
+ array(
+ 'read' => true,
+ 'edit_posts' => true,
+ 'delete_posts' => true,
+ 'read_sp_staffs' => true,
+ 'edit_sp_staffs' => true,
+ 'delete_sp_staff' => true
+ )
+ );
+
+ // Player
+ remove_role( 'sp_player' );
+ add_role(
+ 'sp_player',
+ __( 'Player', 'sportspress' ),
+ array(
+ 'read' => true,
+ 'edit_posts' => true,
+ 'delete_posts' => true,
+ 'read_sp_players' => true,
+ 'edit_sp_players' => true,
+ 'delete_sp_player' => true
+ )
+ );
+
+ update_option( 'sportspress_installed', 1 );
+
+ endif;
+
+ // Load admin styles
+ wp_register_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), '1.0' );
+ wp_enqueue_style( 'sportspress-admin');
+
+ // Add settings sections
+ register_setting(
+ 'sportspress_general',
+ 'sportspress',
+ 'sportspress_validate'
+ );
+
+ add_settings_section(
+ 'general',
+ '',
+ '',
+ 'sportspress_general'
+ );
+
+ add_settings_field(
+ 'sport',
+ __( 'Sport', 'sportspress' ),
+ 'sportspress_sport_callback',
+ 'sportspress_general',
+ 'general'
+ );
+
+}
+add_action( 'admin_init', 'sportspress_admin_init', 1 );
diff --git a/admin/actions/admin-menu.php b/admin/actions/admin-menu.php
index 58c7f2f1..7876525a 100644
--- a/admin/actions/admin-menu.php
+++ b/admin/actions/admin-menu.php
@@ -1,5 +1,13 @@
$outcome_slug,
@@ -32,7 +32,7 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
- $outcome_slug = sp_array_value( sp_array_value( $results, $team_id, null ), 'outcome', null );
+ $outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
$args=array(
'name' => $outcome_slug,
@@ -51,19 +51,19 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
endif;
break;
case 'sp_equation':
- echo sp_get_post_equation( $post_id );
+ echo sportspress_get_post_equation( $post_id );
break;
case 'sp_order':
- echo sp_get_post_order( $post_id );
+ echo sportspress_get_post_order( $post_id );
break;
case 'sp_key':
echo $post->post_name;
break;
case 'sp_format':
- echo sp_get_post_format( $post_id );
+ echo sportspress_get_post_format( $post_id );
break;
case 'sp_player':
- echo sp_the_posts( $post_id, 'sp_player' );
+ echo sportspress_the_posts( $post_id, 'sp_player' );
break;
case 'sp_event':
echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—';
@@ -82,5 +82,5 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
break;
endswitch;
}
-add_action( 'manage_posts_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
-add_action( 'manage_pages_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
+add_action( 'manage_posts_custom_column', 'sportspress_manage_posts_custom_column', 10, 2 );
+add_action( 'manage_pages_custom_column', 'sportspress_manage_posts_custom_column', 10, 2 );
diff --git a/admin/actions/plugins-loaded.php b/admin/actions/plugins-loaded.php
index c0be686d..bce2246d 100644
--- a/admin/actions/plugins-loaded.php
+++ b/admin/actions/plugins-loaded.php
@@ -1,6 +1,6 @@
'sp_position',
'selected' => $selected
);
- sp_dropdown_taxonomies( $args );
+ sportspress_dropdown_taxonomies( $args );
endif;
if ( in_array( $typenow, array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
@@ -30,7 +30,7 @@ function sp_restrict_manage_posts() {
'name' => 'sp_season',
'selected' => $selected
);
- sp_dropdown_taxonomies( $args );
+ sportspress_dropdown_taxonomies( $args );
endif;
}
-add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' );
+add_action( 'restrict_manage_posts', 'sportspress_restrict_manage_posts' );
diff --git a/admin/actions/save-post.php b/admin/actions/save-post.php
index 961898c0..f810a795 100644
--- a/admin/actions/save-post.php
+++ b/admin/actions/save-post.php
@@ -1,5 +1,5 @@
array(
'Set featured image' => 'Select Logo',
@@ -23,4 +23,4 @@ function sp_admin_post_thumbnail_html( $translated_text, $post_id ) {
endif;
return $translated_text;
}
-add_filter( 'admin_post_thumbnail_html', 'sp_admin_post_thumbnail_html', 10, 2 );
+add_filter( 'admin_post_thumbnail_html', 'sportspress_admin_post_thumbnail_html', 10, 2 );
diff --git a/admin/filters/gettext.php b/admin/filters/gettext.php
index 8f6c07ec..a8a3ad42 100644
--- a/admin/filters/gettext.php
+++ b/admin/filters/gettext.php
@@ -1,5 +1,5 @@
query['post_type'];
@@ -12,4 +12,4 @@ function sp_pre_get_posts( $wp_query ) {
endif;
endif;
}
-add_filter('pre_get_posts', 'sp_pre_get_posts');
+add_filter('pre_get_posts', 'sportspress_pre_get_posts');
diff --git a/admin/filters/sanitize-title.php b/admin/filters/sanitize-title.php
index 170cd917..01c736aa 100644
--- a/admin/filters/sanitize-title.php
+++ b/admin/filters/sanitize-title.php
@@ -1,5 +1,5 @@
' . sp_get_table_html( $post->ID ) . '
';
+ $content .= '' . sportspress_league_table( $post->ID ) . '
';
elseif ( is_singular( 'sp_list' ) && in_the_loop() ):
global $post;
// Display player list
- $content .= '' . sp_get_list_html( $post->ID ) . '
';
+ $content .= '' . sportspress_player_list( $post->ID ) . '
';
endif;
diff --git a/admin/filters/wp-insert-post-data.php b/admin/filters/wp-insert-post-data.php
index 0ebc1ddf..6873e288 100644
--- a/admin/filters/wp-insert-post-data.php
+++ b/admin/filters/wp-insert-post-data.php
@@ -1,5 +1,5 @@
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_column_cpt_init() {
);
register_post_type( 'sp_column', $args );
}
-add_action( 'init', 'sp_column_cpt_init' );
+add_action( 'init', 'sportspress_column_post_init' );
function sp_column_edit_columns() {
$columns = array(
@@ -37,7 +37,7 @@ function sp_column_meta_init() {
}
function sp_column_details_meta( $post ) {
- $formats = sp_get_config_formats();
+ $formats = sportspress_get_config_formats();
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
@@ -69,7 +69,7 @@ function sp_column_details_meta( $post ) {
ID, $piece, array( 'team_event', 'result', 'outcome' ) );
+ sportspress_get_equation_selector( $post->ID, $piece, array( 'team_event', 'result', 'outcome' ) );
endforeach;
?>
@@ -93,5 +93,5 @@ function sp_column_details_meta( $post ) {
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_event_cpt_init() {
);
register_post_type( 'sp_event', $args );
}
-add_action( 'init', 'sp_event_cpt_init' );
+add_action( 'init', 'sportspress_event_post_init' );
function sp_event_display_scheduled( $posts ) {
global $wp_query, $wpdb;
@@ -65,8 +65,8 @@ function sp_event_team_meta( $post ) {
ID, 'sp_player', 'block', 'sp_team', $key );
- sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $key );
+ sportspress_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $key );
+ sportspress_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $key );
?>
@@ -85,8 +85,8 @@ function sp_event_team_meta( $post ) {
ID, 'sp_players', true );
// Get columns from result variables
- $columns = sp_get_var_labels( 'sp_statistic', true );
+ $columns = sportspress_get_var_labels( 'sp_statistic', true );
foreach ( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
// Get results for players in the team
- $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
- $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
+ $players = sportspress_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
+ $data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
?>
ID, 'sp_results', true );
// Get columns from result variables
- $columns = sp_get_var_labels( 'sp_result' );
+ $columns = sportspress_get_var_labels( 'sp_result' );
// Get results for all teams
- $data = sp_array_combine( $teams, $results );
+ $data = sportspress_array_combine( $teams, $results );
?>
-
+
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_list_cpt_init() {
);
register_post_type( 'sp_list', $args );
}
-add_action( 'init', 'sp_list_cpt_init' );
+add_action( 'init', 'sportspress_list_post_init' );
function sp_list_edit_columns() {
$columns = array(
@@ -42,7 +42,7 @@ function sp_list_meta_init( $post ) {
}
function sp_list_player_meta( $post ) {
- $season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
+ $season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
?>
@@ -54,7 +54,7 @@ function sp_list_player_meta( $post ) {
'selected' => $season_id,
'value' => 'term_id'
);
- sp_dropdown_taxonomies( $args );
+ sportspress_dropdown_taxonomies( $args );
?>
@@ -68,18 +68,18 @@ function sp_list_player_meta( $post ) {
?>
ID, 'sp_player', 'block', 'sp_team' );
- sp_post_adder( 'sp_player' );
+ sportspress_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' );
+ sportspress_post_adder( 'sp_player' );
?>
ID, true );
+ list( $columns, $data, $placeholders, $merged ) = sportspress_get_list( $post->ID, true );
- sp_player_table( $columns, $data, $placeholders );
- sp_nonce();
+ sportspress_edit_player_table( $columns, $data, $placeholders );
+ sportspress_nonce();
}
diff --git a/admin/post-types/outcome.php b/admin/post-types/outcome.php
index ac84d22a..81531e5a 100644
--- a/admin/post-types/outcome.php
+++ b/admin/post-types/outcome.php
@@ -1,9 +1,9 @@
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_outcome_cpt_init() {
);
register_post_type( 'sp_outcome', $args );
}
-add_action( 'init', 'sp_outcome_cpt_init' );
+add_action( 'init', 'sportspress_outcome_post_init' );
function sp_outcome_edit_columns() {
$columns = array(
@@ -40,5 +40,5 @@ function sp_outcome_details_meta( $post ) {
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_player_cpt_init() {
);
register_post_type( 'sp_player', $args );
}
-add_action( 'init', 'sp_player_cpt_init' );
+add_action( 'init', 'sportspress_player_post_init' );
function sp_player_edit_columns() {
$columns = array(
@@ -51,8 +51,8 @@ function sp_player_meta_init( $post ) {
}
function sp_player_team_meta( $post ) {
- sp_post_checklist( $post->ID, 'sp_team' );
- sp_post_adder( 'sp_team' );
+ sportspress_post_checklist( $post->ID, 'sp_team' );
+ sportspress_post_adder( 'sp_team' );
}
function sp_player_stats_meta( $post ) {
@@ -64,7 +64,7 @@ function sp_player_stats_meta( $post ) {
$eos = new eqEOS();
// Get labels from statistic variables
- $statistic_labels = (array)sp_get_var_labels( 'sp_statistic' );
+ $statistic_labels = (array)sportspress_get_var_labels( 'sp_statistic' );
// Generate array of all league ids
$div_ids = array();
@@ -93,10 +93,10 @@ function sp_player_stats_meta( $post ) {
$data = array();
// Get all leagues populated with stats where available
- $data[ $team_id ] = sp_array_combine( $div_ids, sp_array_value( $stats, $team_id, array() ) );
+ $data[ $team_id ] = sportspress_array_combine( $div_ids, sportspress_array_value( $stats, $team_id, array() ) );
// Get equations from statistics variables
- $equations = sp_get_var_equations( 'sp_statistic' );
+ $equations = sportspress_get_var_equations( 'sp_statistic' );
foreach ( $div_ids as $div_id ):
@@ -135,9 +135,9 @@ function sp_player_stats_meta( $post ) {
$totals['eventsplayed']++; // TODO: create tab for substitutes in sidebar
$team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true );
if ( array_key_exists( $team_id, $team_statistics ) ):
- $players = sp_array_value( $team_statistics, $team_id, array() );
+ $players = sportspress_array_value( $team_statistics, $team_id, array() );
if ( array_key_exists( $post->ID, $players ) ):
- $player_statistics = sp_array_value( $players, $post->ID, array() );
+ $player_statistics = sportspress_array_value( $players, $post->ID, array() );
foreach ( $player_statistics as $key => $value ):
if ( array_key_exists( $key, $totals ) ):
$totals[ $key ] += $value;
@@ -154,13 +154,13 @@ function sp_player_stats_meta( $post ) {
if ( empty( $value ) ):
// Reflect totals
- $placeholders[ $team_id ][ $div_id ][ $key ] = sp_array_value( $totals, $key, 0 );
+ $placeholders[ $team_id ][ $div_id ][ $key ] = sportspress_array_value( $totals, $key, 0 );
else:
// Calculate value
if ( sizeof( $events ) > 0 ):
- $placeholders[ $team_id ][ $div_id ][ $key ] = sp_solve( $value, $totals );
+ $placeholders[ $team_id ][ $div_id ][ $key ] = sportspress_solve( $value, $totals );
else:
$placeholders[ $team_id ][ $div_id ][ $key ] = 0;
endif;
@@ -172,7 +172,7 @@ function sp_player_stats_meta( $post ) {
endforeach;
// Get columns from statistics variables
- $columns = sp_get_var_labels( 'sp_statistic' );
+ $columns = sportspress_get_var_labels( 'sp_statistic' );
if ( $team_num > 1 ):
?>
@@ -180,7 +180,7 @@ function sp_player_stats_meta( $post ) {
post_title; ?>
-
+
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_result_cpt_init() {
);
register_post_type( 'sp_result', $args );
}
-add_action( 'init', 'sp_result_cpt_init' );
+add_action( 'init', 'sportspress_result_post_init' );
function sp_result_edit_columns() {
$columns = array(
@@ -35,7 +35,7 @@ function sp_result_meta_init() {
}
function sp_result_details_meta( $post ) {
- $formats = sp_get_config_formats();
+ $formats = sportspress_get_config_formats();
?>
@@ -52,5 +52,5 @@ function sp_result_details_meta( $post ) {
false,
'show_ui' => true,
@@ -7,4 +7,4 @@ function sp_separator_cpt_init() {
);
register_post_type( 'sp_separator', $args );
}
-add_action( 'init', 'sp_separator_cpt_init' );
+add_action( 'init', 'sportspress_separator_post_init' );
diff --git a/admin/post-types/staff.php b/admin/post-types/staff.php
index fe0b193b..87896717 100644
--- a/admin/post-types/staff.php
+++ b/admin/post-types/staff.php
@@ -1,9 +1,9 @@
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_staff_cpt_init() {
);
register_post_type( 'sp_staff', $args );
}
-add_action( 'init', 'sp_staff_cpt_init' );
+add_action( 'init', 'sportspress_staff_post_init' );
function sp_staff_meta_init() {
remove_meta_box( 'submitdiv', 'sp_staff', 'side' );
@@ -28,9 +28,9 @@ function sp_staff_meta_init() {
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_staff_profile_meta', 'sp_staff', 'normal', 'high' );
}
function sp_staff_team_meta( $post ) {
- sp_post_checklist( $post->ID, 'sp_team' );
- sp_post_adder( 'sp_team' );
- sp_nonce();
+ sportspress_post_checklist( $post->ID, 'sp_team' );
+ sportspress_post_adder( 'sp_team' );
+ sportspress_nonce();
}
function sp_staff_profile_meta( $post ) {
diff --git a/admin/post-types/statistic.php b/admin/post-types/statistic.php
index d0ddfbfc..f7e5efc4 100644
--- a/admin/post-types/statistic.php
+++ b/admin/post-types/statistic.php
@@ -1,9 +1,9 @@
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_statistic_cpt_init() {
);
register_post_type( 'sp_statistic', $args );
}
-add_action( 'init', 'sp_statistic_cpt_init' );
+add_action( 'init', 'sportspress_statistic_post_init' );
function sp_statistic_edit_columns() {
$columns = array(
@@ -37,7 +37,7 @@ function sp_statistic_meta_init() {
}
function sp_statistic_equation_meta( $post ) {
- $formats = sp_get_config_formats();
+ $formats = sportspress_get_config_formats();
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
@@ -69,7 +69,7 @@ function sp_statistic_equation_meta( $post ) {
ID, $piece, array( 'player_event' ) );
+ sportspress_get_equation_selector( $post->ID, $piece, array( 'player_event' ) );
endforeach;
?>
@@ -93,5 +93,5 @@ function sp_statistic_equation_meta( $post ) {
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_table_cpt_init() {
);
register_post_type( 'sp_table', $args );
}
-add_action( 'init', 'sp_table_cpt_init' );
+add_action( 'init', 'sportspress_table_post_init' );
function sp_table_edit_columns() {
$columns = array(
@@ -41,7 +41,7 @@ function sp_table_meta_init( $post ) {
}
function sp_table_team_meta( $post, $test ) {
- $league_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
+ $league_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
?>
@@ -52,23 +52,23 @@ function sp_table_team_meta( $post, $test ) {
'selected' => $league_id,
'value' => 'term_id'
);
- sp_dropdown_taxonomies( $args );
+ sportspress_dropdown_taxonomies( $args );
?>
ID, 'sp_team', 'block', 'sp_season' );
- sp_post_adder( 'sp_team' );
+ sportspress_post_checklist( $post->ID, 'sp_team', 'block', 'sp_season' );
+ sportspress_post_adder( 'sp_team' );
?>
ID, true );
+ list( $columns, $data, $placeholders, $merged ) = sportspress_get_table( $post->ID, true );
- sp_league_table( $columns, $data, $placeholders );
+ sportspress_edit_league_table( $columns, $data, $placeholders );
- sp_nonce();
+ sportspress_nonce();
}
diff --git a/admin/post-types/team.php b/admin/post-types/team.php
index 23894cb3..cbf52ce9 100644
--- a/admin/post-types/team.php
+++ b/admin/post-types/team.php
@@ -1,9 +1,9 @@
$name,
'labels' => $labels,
@@ -17,7 +17,7 @@ function sp_team_cpt_init() {
);
register_post_type( 'sp_team', $args );
}
-add_action( 'init', 'sp_team_cpt_init' );
+add_action( 'init', 'sportspress_team_post_init' );
function sp_team_meta_init( $post ) {
$leagues = (array)get_the_terms( $post->ID, 'sp_season' );
@@ -51,10 +51,10 @@ function sp_team_columns_meta( $post ) {
$eos = new eqEOS();
// Get labels from result variables
- $result_labels = (array)sp_get_var_labels( 'sp_result' );
+ $result_labels = (array)sportspress_get_var_labels( 'sp_result' );
// Get labels from outcome variables
- $outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
+ $outcome_labels = (array)sportspress_get_var_labels( 'sp_outcome' );
// Generate array of all league ids
$div_ids = array();
@@ -64,10 +64,10 @@ function sp_team_columns_meta( $post ) {
endforeach;
// Get all leagues populated with columns where available
- $data = sp_array_combine( $div_ids, $columns );
+ $data = sportspress_array_combine( $div_ids, $columns );
// Get equations from column variables
- $equations = sp_get_var_equations( 'sp_column' );
+ $equations = sportspress_get_var_equations( 'sp_column' );
// Initialize placeholders array
$placeholders = array();
@@ -161,7 +161,7 @@ function sp_team_columns_meta( $post ) {
$placeholders[ $div_id ] = array();
foreach ( $equations as $key => $value ):
if ( $totals['eventsplayed'] > 0 ):
- $placeholders[ $div_id ][ $key ] = sp_solve( $value, $totals );
+ $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals );
else:
$placeholders[ $div_id ][ $key ] = 0;
endif;
@@ -170,8 +170,8 @@ function sp_team_columns_meta( $post ) {
endforeach;
// Get columns from statistics variables
- $columns = sp_get_var_labels( 'sp_column' );
+ $columns = sportspress_get_var_labels( 'sp_column' );
- sp_team_columns_table( $columns, $data, $placeholders );
- sp_nonce();
+ sportspress_edit_team_columns_table( $columns, $data, $placeholders );
+ sportspress_nonce();
}
diff --git a/admin/settings/config.php b/admin/settings/config.php
index 230e4da0..32e851d8 100644
--- a/admin/settings/config.php
+++ b/admin/settings/config.php
@@ -23,9 +23,9 @@
>
| post_title; ?> |
post_name; ?> |
- ID ); ?> |
- ID ); ?> |
- ID ); ?> |
+ ID ); ?> |
+ ID ); ?> |
+ ID ); ?> |
@@ -60,9 +60,9 @@
>
| post_title; ?> |
post_name; ?> |
- ID ); ?> |
- ID ); ?> |
- ID ); ?> |
+ ID ); ?> |
+ ID ); ?> |
+ ID ); ?> |
@@ -97,7 +97,7 @@
>
| post_title; ?> |
post_name; ?> |
- ID ); ?> |
+ ID ); ?> |
— |
— |
diff --git a/admin/settings/settings.php b/admin/settings/settings.php
index 9655f209..a03ee9c1 100644
--- a/admin/settings/settings.php
+++ b/admin/settings/settings.php
@@ -1,17 +1,4 @@
$posts ):
@@ -117,32 +104,6 @@ function sportspress_validate( $input ) {
return $input;
}
-function sportspress_register_settings() {
-
- register_setting(
- 'sportspress_general',
- 'sportspress',
- 'sportspress_validate'
- );
-
- add_settings_section(
- 'general',
- '',
- '',
- 'sportspress_general'
- );
-
- add_settings_field(
- 'sport',
- __( 'Sport', 'sportspress' ),
- 'sportspress_sport_callback',
- 'sportspress_general',
- 'general'
- );
-
-}
-add_action( 'admin_init', 'sportspress_register_settings' );
-
function sportspress_sport_callback() {
global $sportspress_sports;
$options = get_option( 'sportspress' );
diff --git a/admin/terms/position.php b/admin/terms/position.php
index 648df0fb..95ed8cc4 100644
--- a/admin/terms/position.php
+++ b/admin/terms/position.php
@@ -1,10 +1,10 @@
$name,
'labels' => $labels,
@@ -15,4 +15,4 @@ function sp_position_term_init() {
register_taxonomy( 'sp_position', $object_type, $args );
register_taxonomy_for_object_type( 'sp_position', 'sp_player' );
}
-add_action( 'init', 'sp_position_term_init' );
+add_action( 'init', 'sportspress_position_term_init' );
diff --git a/admin/terms/season.php b/admin/terms/season.php
index 3d2c89db..6528c656 100644
--- a/admin/terms/season.php
+++ b/admin/terms/season.php
@@ -1,10 +1,10 @@
$name,
'labels' => $labels,
@@ -18,4 +18,4 @@ function sp_season_term_init() {
register_taxonomy_for_object_type( 'sp_season', 'sp_player' );
register_taxonomy_for_object_type( 'sp_season', 'sp_staff' );
}
-add_action( 'init', 'sp_season_term_init' );
+add_action( 'init', 'sportspress_season_term_init' );
diff --git a/functions.php b/functions.php
index c7cf9ee0..63723e13 100644
--- a/functions.php
+++ b/functions.php
@@ -1,1434 +1,8 @@
';
- }
-}
+if ( !function_exists( 'sportspress_league_table' ) ) {
+ function sportspress_league_table( $id ) {
-if ( !function_exists( 'sp_array_between' ) ) {
- function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) {
- $keys = array_keys( $array, $delimiter );
- if ( array_key_exists( $index, $keys ) ):
- $offset = $keys[ $index ];
- $end = sizeof( $array );
- if ( array_key_exists( $index + 1, $keys ) )
- $end = $keys[ $index + 1 ];
- $length = $end - $offset;
- $array = array_slice( $array, $offset, $length );
- endif;
- return $array;
- }
-}
-
-if ( !function_exists( 'sp_array_value' ) ) {
- function sp_array_value( $arr = array(), $key = 0, $default = null ) {
- if ( is_array( $arr ) && array_key_exists( $key, $arr ) )
- $subset = $arr[ $key ];
- else
- $subset = $default;
- return $subset;
- }
-}
-
-if ( !function_exists( 'sp_array_combine' ) ) {
- function sp_array_combine( $keys = array(), $values = array() ) {
- $output = array();
- foreach ( $keys as $key ):
- if ( is_array( $values ) && array_key_exists( $key, $values ) )
- $output[ $key ] = $values[ $key ];
- else
- $output[ $key ] = array();
- endforeach;
- return $output;
- }
-}
-
-if ( !function_exists( 'sp_numbers_to_words' ) ) {
- function sp_numbers_to_words( $str ) {
- $output = str_replace( array( '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str );
- return $output;
- }
-}
-
-if ( !function_exists( 'sp_cpt_labels' ) ) {
- function sp_cpt_labels( $name, $singular_name, $lowercase_name = null ) {
- if ( !$lowercase_name ) $lowercase_name = $name;
- $labels = array(
- 'name' => $name,
- 'singular_name' => $singular_name,
- 'all_items' => $name,
- 'add_new' => sprintf( __( 'Add %s', 'sportspress' ), $singular_name ),
- 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ),
- 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ),
- 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ),
- 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
- 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
- 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ),
- 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ),
- 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':'
- );
- return $labels;
- }
-}
-
-if ( !function_exists( 'sp_tax_labels' ) ) {
- function sp_tax_labels( $name, $singular_name, $lowercase_name = null ) {
- if ( !$lowercase_name ) $lowercase_name = $name;
- $labels = array(
- 'name' => $name,
- 'singular_name' => $singular_name,
- 'all_items' => sprintf( __( 'All %s', 'sportspress' ), $name ),
- 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ),
- 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
- 'update_item' => sprintf( __( 'Update %s', 'sportspress' ), $singular_name ),
- 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ),
- 'new_item_name' => sprintf( __( 'New %s Name', 'sportspress' ), $singular_name ),
- 'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ),
- 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':',
- 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
- 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name )
- );
- return $labels;
- }
-}
-
-if ( !function_exists( 'sp_get_the_term_id' ) ) {
- function sp_get_the_term_id( $post_id, $taxonomy, $index ) {
- $terms = get_the_terms( $post_id, $taxonomy );
- if ( is_array( $terms ) && array_key_exists( $index, $terms ) ):
- $term = $terms[0];
- if ( is_object( $term ) && property_exists( $term, 'term_id' ) )
- return $term->term_id;
- else
- return 0;
- else:
- return 0;
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_post_format' ) ) {
- function sp_get_post_format( $post_id ) {
- $format = get_post_meta ( $post_id, 'sp_format', true );
- if ( $format ):
- $formats = sp_get_config_formats();
- $format_str = sp_array_value( $formats, $format, '—' );
- if ( in_array( $format, array( 'decimal', 'time' ) ) ):
- return $format_str . ' (' . sp_get_post_precision( $post_id ) . ')';
- else:
- return $format_str;
- endif;
- else:
- return '—';
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_post_precision' ) ) {
- function sp_get_post_precision( $post_id ) {
- $precision = get_post_meta ( $post_id, 'sp_precision', true );
- if ( $precision ):
- return $precision;
- else:
- return '1';
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_post_equation' ) ) {
- function sp_get_post_equation( $post_id ) {
- $equation = get_post_meta ( $post_id, 'sp_equation', true );
- if ( $equation ):
- return str_replace(
- array( '$', '+', '-', '*', '/' ),
- array( '', '+', '−', '×', '÷' ),
- $equation
- );
- else:
- return '—';
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_post_order' ) ) {
- function sp_get_post_order( $post_id ) {
- $priority = get_post_meta ( $post_id, 'sp_priority', true );
- if ( $priority ):
- return $priority . ' ' . str_replace(
- array( 'DESC', 'ASC' ),
- array( '↓', '↑' ),
- get_post_meta ( $post_id, 'sp_order', true )
- );
- else:
- return '—';
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_config_formats' ) ) {
- function sp_get_config_formats() {
- $arr = array(
- 'integer' => __( 'Integer', 'sportspress' ),
- 'decimal' => __( 'Decimal', 'sportspress' ),
- 'time' => __( 'Time', 'sportspress' ),
- 'custom' => __( 'Custom Field', 'sportspress' ),
- );
- return $arr;
- }
-}
-
-if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
- function sp_dropdown_taxonomies( $args = array() ) {
- $defaults = array(
- 'show_option_all' => false,
- 'show_option_none' => false,
- 'taxonomy' => null,
- 'name' => null,
- 'selected' => null,
- 'value' => 'slug'
- );
- $args = array_merge( $defaults, $args );
- $terms = get_terms( $args['taxonomy'] );
- $name = ( $args['name'] ) ? $args['name'] : $args['taxonomy'];
- if ( $terms ) {
- printf( '' );
- }
- }
-}
-
-if ( !function_exists( 'sp_dropdown_pages' ) ) {
- function sp_dropdown_pages( $args = array() ) {
- $defaults = array(
- 'show_option_all' => false,
- 'show_option_none' => false,
- 'name' => 'page_id',
- 'selected' => null,
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'child_of' => 0,
- 'sort_order' => 'ASC',
- 'sort_column' => 'post_title',
- 'hierarchical' => 1,
- 'exclude' => null,
- 'include' => null,
- 'meta_key' => null,
- 'meta_value' => null,
- 'authors' => null,
- 'exclude_tree' => null,
- 'post_type' => 'page'
- );
- $args = array_merge( $defaults, $args );
- $name = $args['name'];
- unset( $args['name'] );
- $posts = get_posts( $args );
- if ( $posts ) {
- printf( '' );
- }
- }
-}
-
-if ( !function_exists( 'sp_the_posts' ) ) {
- function sp_the_posts( $post_id = null, $meta = 'post' ) {
- if ( ! isset( $post_id ) )
- global $post_id;
- $ids = get_post_meta( $post_id, $meta, false );
- if ( ( $key = array_search( 0, $ids ) ) !== false )
- unset( $ids[ $key ] );
- $i = 0;
- $count = count( $ids );
- if ( isset( $ids ) && $ids && is_array( $ids ) && !empty( $ids ) ):
- foreach ( $ids as $id ):
- if ( !$id ) continue;
- $parents = get_post_ancestors( $id );
- $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) );
- foreach ( $parents as $parent ):
- if ( !in_array( $parent, $ids ) )
- edit_post_link( get_the_title( $parent ), '', '', $parent );
- echo ' - ';
- endforeach;
- $title = get_the_title( $id );
- if ( empty( $title ) )
- $title = __( '(no title)', 'sportspress' );
- edit_post_link( $title, '', '', $id );
- if ( ++$i !== $count )
- echo ', ';
- endforeach;
- endif;
- }
-}
-
-if ( !function_exists( 'sp_the_plain_terms' ) ) {
- function sp_the_plain_terms( $id, $taxonomy ) {
- $terms = get_the_terms( $id, $taxonomy );
- $arr = array();
- foreach( $terms as $term ):
- $arr[] = $term->name;
- endforeach;
- echo implode( ', ', $arr );
- }
-}
-
-if ( !function_exists( 'sp_post_checklist' ) ) {
- function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) {
- if ( ! isset( $post_id ) )
- global $post_id;
- ?>
-
-
-
', sizeof( $parents ) ); ?>
-
-
-
-
- $type,
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'exclude' => $postid
- );
- $vars = get_posts( $args );
-
- // Add extra vars to the array
- if ( isset( $defaults ) && is_array( $defaults ) ):
- foreach ( $defaults as $key => $value ):
- $arr[ $key ] = $value;
- endforeach;
- endif;
-
- // Add vars to the array
- if ( isset( $variations ) && is_array( $variations ) ):
- foreach ( $vars as $var ):
- if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
- foreach ( $variations as $key => $value ):
- $arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
- endforeach;
- endforeach;
- else:
- foreach ( $vars as $var ):
- '$' . $arr[ $var->post_name ] = $var->post_title;
- endforeach;
- endif;
-
- return (array) $arr;
- }
-}
-
-if ( !function_exists( 'sp_get_equation_selector' ) ) {
- function sp_get_equation_selector( $postid, $selected = null, $groups = array() ) {
-
- if ( ! isset( $postid ) )
- return;
-
- // Initialize options array
- $options = array();
-
- // Add groups to options
- foreach ( $groups as $group ):
- switch ( $group ):
- case 'player_event':
- $options[ __( 'Events', 'sportspress' ) ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ) );
- break;
- case 'team_event':
- $options[ __( 'Events', 'sportspress' ) ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ) );
- break;
- case 'result':
- $options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ), null, false );
- break;
- case 'outcome':
- $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
- $options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
- break;
- case 'column':
- $options[ __( 'Columns', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
- break;
- case 'statistic':
- $options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_statistic' );
- break;
- endswitch;
- endforeach;
-
- // Create array of operators
- $operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '(' => '(', ')' => ')' );
-
- // Add operators to options
- $options[ __( 'Operators', 'sportspress' ) ] = $operators;
-
- // Create array of constants
- $max = 10;
- $constants = array();
- for ( $i = 1; $i <= $max; $i ++ ):
- $constants[$i] = $i;
- endfor;
-
- // Add constants to options
- $options[ __( 'Constants', 'sportspress' ) ] = (array) $constants;
-
- ?>
-
- $post_type,
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'sp_format',
- 'value' => 'custom',
- 'compare' => '!=',
- ),
- ),
- );
-
- $vars = get_posts( $args );
-
- $output = array();
- foreach ( $vars as $var ):
- if ( $independent ):
- $equation = get_post_meta( $var->ID, 'sp_equation', true );
- if ( $equation && $equation != '' ):
- continue;
- endif;
- endif;
- $output[ $var->post_name ] = $var->post_title;
- endforeach;
-
- return $output;
- }
-}
-
-if ( !function_exists( 'sp_get_var_equations' ) ) {
- function sp_get_var_equations( $post_type ) {
- $args = array(
- 'post_type' => $post_type,
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC'
- );
-
- $vars = get_posts( $args );
-
- $output = array();
- foreach ( $vars as $var ):
- $equation = get_post_meta( $var->ID, 'sp_equation', true );
- $output[ $var->post_name ] = $equation;
- endforeach;
-
- return $output;
- }
-}
-
-if ( !function_exists( 'sp_league_table' ) ) {
- function sp_league_table( $columns = array(), $data = array(), $placeholders = array() ) {
- ?>
-
-
-
-
-
-
-
-
-
- __( 'Starting Lineup', 'sportspress' ),
- 'sub' => __( 'Substitute', 'sportspress' ),
- );
-
- $output = '';
-
- return $output;
-
- }
-}
-
-if ( !function_exists( 'sp_event_player_sub_selector' ) ) {
- function sp_event_player_sub_selector( $team_id, $player_id, $value, $data = array() ) {
-
- if ( ! $team_id || ! $player_id )
- return '—';
-
- $output = '';
-
- return $output;
-
- }
-}
-
-if ( !function_exists( 'sp_event_players_table' ) ) {
- function sp_event_players_table( $columns = array(), $data = array(), $team_id ) {
- ?>
-
-
-
- ' . $value . '';
- break;
- case 'checkbox':
- echo '';
- break;
- default:
- echo '';
- break;
- endswitch;
-
- }
-}
-
-if ( !function_exists( 'sp_get_eos_safe_slug' ) ) {
- function sp_get_eos_safe_slug( $title, $post_id = 'var' ) {
-
- // String to lowercase
- $title = strtolower( $title );
-
- // Replace all numbers with words
- $title = sp_numbers_to_words( $title );
-
- // Remove all other non-alphabet characters
- $title = preg_replace( "/[^a-z]/", '', $title );
-
- // Convert post ID to words if title is empty
- if ( $title == '' ):
-
- $title = sp_numbers_to_words( $post_id );
-
- endif;
-
- return $title;
-
- }
-}
-
-if ( !function_exists( 'sp_solve' ) ) {
- function sp_solve( $equation, $vars ) {
-
- // Return direct value if streak
- if ( str_replace( ' ', '', $equation ) == '$streak' )
- return sp_array_value( $vars, 'streak', 0 );
-
- // Clearance to begin calculating remains true if all equation variables are in vars
- $clearance = true;
-
- // Check if each variable part is in vars
- $parts = explode( ' ', $equation );
- foreach( $parts as $key => $value ):
- if ( substr( $value, 0, 1 ) == '$' ):
- if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) )
- $clearance = false;
- endif;
- endforeach;
-
- if ( $clearance ):
- // Equation Operating System
- $eos = new eqEOS();
-
- // Solve using EOS
- return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), 3 ); // TODO: add precision setting to each column with default set to 3
- else:
- return 0;
- endif;
-
- }
-
-}
-
-if ( !function_exists( 'sp_get_table' ) ) {
- function sp_get_table( $post_id, $breakdown = false ) {
- $div_id = sp_get_the_term_id( $post_id, 'sp_season', 0 );
- $team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
- $table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
-
- // Get labels from result variables
- $result_labels = (array)sp_get_var_labels( 'sp_result' );
-
- // Get labels from outcome variables
- $outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
-
- // Get all leagues populated with stats where available
- $tempdata = sp_array_combine( $team_ids, $table_stats );
-
- // Create entry for each team in totals
- $totals = array();
- $placeholders = array();
-
- // Initialize streaks counter
- $streaks = array();
-
- foreach ( $team_ids as $team_id ):
- if ( ! $team_id )
- continue;
-
- $streaks[ $team_id ] = array( 'name' => '', 'count' => 0 );
-
- $totals[ $team_id ] = array( 'eventsplayed' => 0, 'streak' => 0 );
-
- foreach ( $result_labels as $key => $value ):
- $totals[ $team_id ][ $key . 'for' ] = 0;
- $totals[ $team_id ][ $key . 'against' ] = 0;
- endforeach;
-
- foreach ( $outcome_labels as $key => $value ):
- $totals[ $team_id ][ $key ] = 0;
- endforeach;
-
- // Get static stats
- $static = get_post_meta( $team_id, 'sp_columns', true );
-
- // Create placeholders entry for the team
- $placeholders[ $team_id ] = array();
-
- // Add static stats to placeholders
- if ( array_key_exists( $div_id, $static ) ):
- $placeholders[ $team_id ] = $static[ $div_id ];
- endif;
-
- endforeach;
-
- $args = array(
- 'post_type' => 'sp_event',
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'order' => 'ASC',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'sp_season',
- 'field' => 'id',
- 'terms' => $div_id
- )
- )
- );
- $events = get_posts( $args );
-
- // Event loop
- foreach ( $events as $event ):
-
- $results = (array)get_post_meta( $event->ID, 'sp_results', true );
-
- foreach ( $results as $team_id => $team_result ):
-
- foreach ( $team_result as $key => $value ):
-
- if ( $key == 'outcome' ):
- if ( array_key_exists( $value, $totals[ $team_id ] ) ):
- $totals[ $team_id ]['eventsplayed']++;
- $totals[ $team_id ][ $value ]++;
- endif;
- if ( $value && $value != '-1' ):
- if ( $streaks[ $team_id ]['name'] == $value ):
- $streaks[ $team_id ]['count'] ++;
- else:
- $streaks[ $team_id ]['name'] = $value;
- $streaks[ $team_id ]['count'] = 1;
- endif;
- endif;
- else:
- if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
- $totals[ $team_id ][ $key . 'for' ] += $value;
- endif;
- endif;
-
- endforeach;
-
- endforeach;
-
- endforeach;
-
- foreach ( $streaks as $team_id => $streak ):
- // Compile streaks counter and add to totals
- $args=array(
- 'name' => $streak['name'],
- 'post_type' => 'sp_outcome',
- 'post_status' => 'publish',
- 'posts_per_page' => 1
- );
- $outcomes = get_posts( $args );
-
- if ( $outcomes ):
- $outcome = $outcomes[0];
- $totals[ $team_id ]['streak'] = $outcome->post_title . $streak['count'];
- endif;
- endforeach;
-
- $args = array(
- 'post_type' => 'sp_column',
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC'
- );
- $stats = get_posts( $args );
-
- $columns = array();
- $priorities = array();
-
- foreach ( $stats as $stat ):
-
- // Get post meta
- $meta = get_post_meta( $stat->ID );
-
- // Add equation to object
- $stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 );
-
- // Add column name to columns
- $columns[ $stat->post_name ] = $stat->post_title;
-
- // Add order to priorities if priority is set and does not exist in array already
- $priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 );
- if ( $priority && ! array_key_exists( $priority, $priorities ) ):
- $priorities[ $priority ] = array(
- 'column' => $stat->post_name,
- 'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
- );
- endif;
-
- endforeach;
-
- // Sort priorities in descending order
- ksort( $priorities );
-
- // Fill in empty placeholder values for each team
- foreach ( $team_ids as $team_id ):
- if ( ! $team_id )
- continue;
-
- foreach ( $stats as $stat ):
- if ( sp_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
- if ( sizeof( $events ) > 0 ):
- $placeholders[ $team_id ][ $stat->post_name ] = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ) );
- else:
- $placeholders[ $team_id ][ $stat->post_name ] = 0;
- endif;
- endif;
- endforeach;
- endforeach;
-
- // Merge the data and placeholders arrays
- $merged = array();
-
- foreach( $placeholders as $team_id => $team_data ):
-
- // Add team name to row
- $merged[ $team_id ] = array( 'name' => get_the_title( $team_id ) );
-
- foreach( $team_data as $key => $value ):
-
- // Use static data if key exists and value is not empty, else use placeholder
- if ( array_key_exists( $team_id, $tempdata ) && array_key_exists( $key, $tempdata[ $team_id ] ) && $tempdata[ $team_id ][ $key ] != '' ):
- $merged[ $team_id ][ $key ] = $tempdata[ $team_id ][ $key ];
- else:
- $merged[ $team_id ][ $key ] = $value;
- endif;
-
- endforeach;
- endforeach;
-
- uasort( $merged, function( $a, $b ) use ( $priorities ) {
-
- // Loop through priorities
- foreach( $priorities as $priority ):
-
- // Proceed if columns are not equal
- if ( sp_array_value( $a, $priority['column'], 0 ) != sp_array_value( $b, $priority['column'], 0 ) ):
-
- // Compare column values
- $output = sp_array_value( $a, $priority['column'], 0 ) - sp_array_value( $b, $priority['column'], 0 );
-
- // Flip value if descending order
- if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
-
- return $output;
-
- endif;
-
- endforeach;
-
- // Default sort by alphabetical
- return strcmp( sp_array_value( $a, 'name', '' ), sp_array_value( $b, 'name', '' ) );
- });
-
- // Rearrange data array to reflect statistics
- $data = array();
- foreach( $merged as $key => $value ):
- $data[ $key ] = $tempdata[ $key ];
- endforeach;
-
- if ( $breakdown ):
- return array( $columns, $data, $placeholders, $merged );
- else:
- array_unshift( $columns, __( 'Team', 'sportspress' ) );
- $merged[0] = $columns;
- return $merged;
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_list' ) ) {
- function sp_get_list( $post_id, $breakdown = false ) {
- $div_id = sp_get_the_term_id( $post_id, 'sp_season', 0 );
- $team_id = get_post_meta( $post_id, 'sp_team', true );
- $player_ids = (array)get_post_meta( $post_id, 'sp_player', false );
- $stats = (array)get_post_meta( $post_id, 'sp_players', true );
-
- // Equation Operating System
- $eos = new eqEOS();
-
- // Get labels from result variables
- $columns = (array)sp_get_var_labels( 'sp_statistic' );
-
- // Get all leagues populated with stats where available
- $tempdata = sp_array_combine( $player_ids, $stats );
-
- // Get equations from statistics variables
- $equations = sp_get_var_equations( 'sp_statistic' );
-
- // Create entry for each player in totals
- $totals = array();
- $placeholders = array();
-
- foreach ( $player_ids as $player_id ):
- if ( ! $player_id )
- continue;
-
- $totals[ $player_id ] = array( 'eventsattended' => 0, 'eventsplayed' => 0 );
-
- foreach ( $columns as $key => $value ):
- $totals[ $player_id ][ $key ] = 0;
- endforeach;
-
- // Get static statistics
- $static = get_post_meta( $player_id, 'sp_statistics', true );
-
- // Create placeholders entry for the player
- $placeholders[ $player_id ] = array();
-
- // Add static statistics to placeholders
- if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ):
- $placeholders[ $player_id ] = $static[ $team_id ][ $div_id ];
- endif;
- endforeach;
-
- $args = array(
- 'post_type' => 'sp_event',
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'sp_season',
- 'field' => 'id',
- 'terms' => $div_id
- )
- ),
- 'meta_query' => array(
- array(
- 'key' => 'sp_team',
- 'value' => $team_id,
- )
- )
- );
- $events = get_posts( $args );
-
- // Event loop
- foreach( $events as $event ):
-
- $teams = (array)get_post_meta( $event->ID, 'sp_players', true );
-
- if ( ! array_key_exists( $team_id, $teams ) )
- continue;
-
- $players = sp_array_value( $teams, $team_id, array() );
-
- foreach ( $players as $player_id => $player_statistics ):
-
- // Increment events played
- $totals[ $player_id ]['eventsplayed']++;
-
- foreach ( $player_statistics as $key => $value ):
-
- if ( array_key_exists( $key, $totals[ $player_id ] ) ):
- $totals[ $player_id ][ $key ] += $value;
- endif;
-
- endforeach;
-
- endforeach;
-
- endforeach;
-
- $args = array(
- 'post_type' => 'sp_statistic',
- 'numberposts' => -1,
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'sp_format',
- 'value' => 'custom',
- 'compare' => '!=',
- ),
- ),
- );
- $statistics = get_posts( $args );
-
- $columns = array();
- $priorities = array();
-
- foreach ( $statistics as $statistic ):
-
- // Get post meta
- $meta = get_post_meta( $statistic->ID );
-
- // Add equation to object
- $statistic->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 );
-
- // Add column name to columns
- $columns[ $statistic->post_name ] = $statistic->post_title;
-
- // Add order to priorities if priority is set and does not exist in array already
- $priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 );
- if ( $priority && ! array_key_exists( $priority, $priorities ) ):
- $priorities[ $priority ] = array(
- 'column' => $statistic->post_name,
- 'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
- );
- endif;
-
- endforeach;
-
- // Sort priorities in descending order
- ksort( $priorities );
-
- // Fill in empty placeholder values for each player
- foreach ( $player_ids as $player_id ):
-
- if ( ! $player_id )
- continue;
-
- foreach ( $statistics as $statistic ):
- if ( sp_array_value( $placeholders[ $player_id ], $statistic->post_name, '' ) == '' ):
-
- if ( empty( $statistic->equation ) ):
-
- // Reflect totals
- $placeholders[ $player_id ][ $statistic->post_name ] = sp_array_value( sp_array_value( $totals, $player_id, array() ), $key, 0 );
-
- else:
-
- // Calculate value
- if ( sizeof( $events ) > 0 ):
- $placeholders[ $player_id ][ $statistic->post_name ] = sp_solve( $statistic->equation, sp_array_value( $totals, $player_id, array() ) );
- else:
- $placeholders[ $player_id ][ $statistic->post_name ] = 0;
- endif;
- endif;
- endif;
- endforeach;
- endforeach;
-
- // Merge the data and placeholders arrays
- $merged = array();
-
- foreach( $placeholders as $player_id => $player_data ):
-
- // Add team name to row
- $merged[ $player_id ] = array( 'name' => get_the_title( $player_id ) );
-
- foreach( $player_data as $key => $value ):
-
- // Use static data if key exists and value is not empty, else use placeholder
- if ( array_key_exists( $player_id, $tempdata ) && array_key_exists( $key, $tempdata[ $player_id ] ) && $tempdata[ $player_id ][ $key ] != '' ):
- $merged[ $player_id ][ $key ] = $tempdata[ $player_id ][ $key ];
- else:
- $merged[ $player_id ][ $key ] = $value;
- endif;
-
- endforeach;
- endforeach;
-
- uasort( $merged, function( $a, $b ) use ( $priorities ) {
-
- // Loop through priorities
- foreach( $priorities as $priority ):
-
- // Proceed if columns are not equal
- if ( sp_array_value( $a, $priority['column'], 0 ) != sp_array_value( $b, $priority['column'], 0 ) ):
-
- // Compare column values
- $output = sp_array_value( $a, $priority['column'], 0 ) - sp_array_value( $b, $priority['column'], 0 );
-
- // Flip value if descending order
- if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
-
- return $output;
-
- endif;
-
- endforeach;
-
- // Default sort by alphabetical
- return strcmp( sp_array_value( $a, 'name', '' ), sp_array_value( $b, 'name', '' ) );
- });
-
- // Rearrange data array to reflect statistics
- $data = array();
- foreach( $merged as $key => $value ):
- $data[ $key ] = $tempdata[ $key ];
- endforeach;
-
- if ( $breakdown ):
- return array( $columns, $data, $placeholders, $merged );
- else:
- array_unshift( $columns, __( 'Player', 'sportspress' ) );
- $merged[0] = $columns;
- return $merged;
- endif;
- }
-}
-
-if ( !function_exists( 'sp_get_table_html' ) ) {
- function sp_get_table_html( $id ) {
-
- $data = sp_get_table( $id );
+ $data = sportspress_get_table( $id );
$output = '' . '' . '';
@@ -1448,17 +22,17 @@ if ( !function_exists( 'sp_get_table_html' ) ) {
foreach( $data as $team_id => $row ):
- $output .= '
';
+ $output .= '
';
// Thumbnail and name as link
$permalink = get_post_permalink( $team_id );
$thumbnail = get_the_post_thumbnail( $team_id, 'sp_icon' );
- $output .= '| ' . $i . '. ' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . sp_array_value( $row, 'name', ' ' ) . ' | ';
+ $output .= '' . $i . '. ' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . sportspress_array_value( $row, 'name', ' ' ) . ' | ';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
- $output .= '' . sp_array_value( $row, $key, '—' ) . ' | ';
+ $output .= '' . sportspress_array_value( $row, $key, '—' ) . ' | ';
endforeach;
$output .= '
';
@@ -1474,10 +48,10 @@ if ( !function_exists( 'sp_get_table_html' ) ) {
}
}
-if ( !function_exists( 'sp_get_list_html' ) ) {
- function sp_get_list_html( $id ) {
+if ( !function_exists( 'sportspress_player_list' ) ) {
+ function sportspress_player_list( $id ) {
- $data = sp_get_list( $id );
+ $data = sportspress_get_list( $id );
$output = '' . '' . '';
@@ -1500,12 +74,12 @@ if ( !function_exists( 'sp_get_list_html' ) ) {
// Name as link
$permalink = get_post_permalink( $player_id );
$number = get_post_meta( $player_id, 'sp_number', true );
- $output .= '| ' . ( $number ? $number . '. ' : '' ) . '' . sp_array_value( $row, 'name', ' ' ) . ' | ';
+ $output .= '' . ( $number ? $number . '. ' : '' ) . '' . sportspress_array_value( $row, 'name', ' ' ) . ' | ';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
- $output .= '' . sp_array_value( $row, $key, '—' ) . ' | ';
+ $output .= '' . sportspress_array_value( $row, $key, '—' ) . ' | ';
endforeach;
$output .= '
';
@@ -1517,12 +91,4 @@ if ( !function_exists( 'sp_get_list_html' ) ) {
return $output;
}
-}
-
-if ( !function_exists( 'sp_highlight_admin_menu' ) ) {
- function sp_highlight_admin_menu() {
- global $parent_file, $submenu_file;
- $parent_file = 'options-general.php';
- $submenu_file = 'sportspress';
- }
-}
+}
\ No newline at end of file
diff --git a/helpers.php b/helpers.php
new file mode 100644
index 00000000..8f6b6dcd
--- /dev/null
+++ b/helpers.php
@@ -0,0 +1,1423 @@
+';
+ }
+}
+
+if ( !function_exists( 'sportspress_array_between' ) ) {
+ function sportspress_array_between ( $array = array(), $delimiter = 0, $index = 0 ) {
+ $keys = array_keys( $array, $delimiter );
+ if ( array_key_exists( $index, $keys ) ):
+ $offset = $keys[ $index ];
+ $end = sizeof( $array );
+ if ( array_key_exists( $index + 1, $keys ) )
+ $end = $keys[ $index + 1 ];
+ $length = $end - $offset;
+ $array = array_slice( $array, $offset, $length );
+ endif;
+ return $array;
+ }
+}
+
+if ( !function_exists( 'sportspress_array_value' ) ) {
+ function sportspress_array_value( $arr = array(), $key = 0, $default = null ) {
+ if ( is_array( $arr ) && array_key_exists( $key, $arr ) )
+ $subset = $arr[ $key ];
+ else
+ $subset = $default;
+ return $subset;
+ }
+}
+
+if ( !function_exists( 'sportspress_array_combine' ) ) {
+ function sportspress_array_combine( $keys = array(), $values = array() ) {
+ $output = array();
+ foreach ( $keys as $key ):
+ if ( is_array( $values ) && array_key_exists( $key, $values ) )
+ $output[ $key ] = $values[ $key ];
+ else
+ $output[ $key ] = array();
+ endforeach;
+ return $output;
+ }
+}
+
+if ( !function_exists( 'sportspress_numbers_to_words' ) ) {
+ function sportspress_numbers_to_words( $str ) {
+ $output = str_replace( array( '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str );
+ return $output;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_post_labels' ) ) {
+ function sportspress_get_post_labels( $name, $singular_name, $lowercase_name = null ) {
+ if ( !$lowercase_name ) $lowercase_name = $name;
+ $labels = array(
+ 'name' => $name,
+ 'singular_name' => $singular_name,
+ 'all_items' => $name,
+ 'add_new' => sprintf( __( 'Add %s', 'sportspress' ), $singular_name ),
+ 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ),
+ 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ),
+ 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ),
+ 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
+ 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
+ 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ),
+ 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ),
+ 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':'
+ );
+ return $labels;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_term_labels' ) ) {
+ function sportspress_get_term_labels( $name, $singular_name, $lowercase_name = null ) {
+ if ( !$lowercase_name ) $lowercase_name = $name;
+ $labels = array(
+ 'name' => $name,
+ 'singular_name' => $singular_name,
+ 'all_items' => sprintf( __( 'All %s', 'sportspress' ), $name ),
+ 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ),
+ 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
+ 'update_item' => sprintf( __( 'Update %s', 'sportspress' ), $singular_name ),
+ 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ),
+ 'new_item_name' => sprintf( __( 'New %s Name', 'sportspress' ), $singular_name ),
+ 'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ),
+ 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':',
+ 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
+ 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name )
+ );
+ return $labels;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_the_term_id' ) ) {
+ function sportspress_get_the_term_id( $post_id, $taxonomy, $index ) {
+ $terms = get_the_terms( $post_id, $taxonomy );
+ if ( is_array( $terms ) && array_key_exists( $index, $terms ) ):
+ $term = $terms[0];
+ if ( is_object( $term ) && property_exists( $term, 'term_id' ) )
+ return $term->term_id;
+ else
+ return 0;
+ else:
+ return 0;
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_post_format' ) ) {
+ function sportspress_get_post_format( $post_id ) {
+ $format = get_post_meta ( $post_id, 'sp_format', true );
+ if ( $format ):
+ $formats = sportspress_get_config_formats();
+ $format_str = sportspress_array_value( $formats, $format, '—' );
+ if ( in_array( $format, array( 'decimal', 'time' ) ) ):
+ return $format_str . ' (' . sportspress_get_post_precision( $post_id ) . ')';
+ else:
+ return $format_str;
+ endif;
+ else:
+ return '—';
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_post_precision' ) ) {
+ function sportspress_get_post_precision( $post_id ) {
+ $precision = get_post_meta ( $post_id, 'sp_precision', true );
+ if ( $precision ):
+ return $precision;
+ else:
+ return '1';
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_post_equation' ) ) {
+ function sportspress_get_post_equation( $post_id ) {
+ $equation = get_post_meta ( $post_id, 'sp_equation', true );
+ if ( $equation ):
+ return str_replace(
+ array( '$', '+', '-', '*', '/' ),
+ array( '', '+', '−', '×', '÷' ),
+ $equation
+ );
+ else:
+ return '—';
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_post_order' ) ) {
+ function sportspress_get_post_order( $post_id ) {
+ $priority = get_post_meta ( $post_id, 'sp_priority', true );
+ if ( $priority ):
+ return $priority . ' ' . str_replace(
+ array( 'DESC', 'ASC' ),
+ array( '↓', '↑' ),
+ get_post_meta ( $post_id, 'sp_order', true )
+ );
+ else:
+ return '—';
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_config_formats' ) ) {
+ function sportspress_get_config_formats() {
+ $arr = array(
+ 'integer' => __( 'Integer', 'sportspress' ),
+ 'decimal' => __( 'Decimal', 'sportspress' ),
+ 'time' => __( 'Time', 'sportspress' ),
+ 'custom' => __( 'Custom Field', 'sportspress' ),
+ );
+ return $arr;
+ }
+}
+
+if ( !function_exists( 'sportspress_dropdown_taxonomies' ) ) {
+ function sportspress_dropdown_taxonomies( $args = array() ) {
+ $defaults = array(
+ 'show_option_all' => false,
+ 'show_option_none' => false,
+ 'taxonomy' => null,
+ 'name' => null,
+ 'selected' => null,
+ 'value' => 'slug'
+ );
+ $args = array_merge( $defaults, $args );
+ $terms = get_terms( $args['taxonomy'] );
+ $name = ( $args['name'] ) ? $args['name'] : $args['taxonomy'];
+ if ( $terms ) {
+ printf( '' );
+ }
+ }
+}
+
+if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
+ function sportspress_dropdown_pages( $args = array() ) {
+ $defaults = array(
+ 'show_option_all' => false,
+ 'show_option_none' => false,
+ 'name' => 'page_id',
+ 'selected' => null,
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'child_of' => 0,
+ 'sort_order' => 'ASC',
+ 'sort_column' => 'post_title',
+ 'hierarchical' => 1,
+ 'exclude' => null,
+ 'include' => null,
+ 'meta_key' => null,
+ 'meta_value' => null,
+ 'authors' => null,
+ 'exclude_tree' => null,
+ 'post_type' => 'page'
+ );
+ $args = array_merge( $defaults, $args );
+ $name = $args['name'];
+ unset( $args['name'] );
+ $posts = get_posts( $args );
+ if ( $posts ) {
+ printf( '' );
+ }
+ }
+}
+
+if ( !function_exists( 'sportspress_the_posts' ) ) {
+ function sportspress_the_posts( $post_id = null, $meta = 'post' ) {
+ if ( ! isset( $post_id ) )
+ global $post_id;
+ $ids = get_post_meta( $post_id, $meta, false );
+ if ( ( $key = array_search( 0, $ids ) ) !== false )
+ unset( $ids[ $key ] );
+ $i = 0;
+ $count = count( $ids );
+ if ( isset( $ids ) && $ids && is_array( $ids ) && !empty( $ids ) ):
+ foreach ( $ids as $id ):
+ if ( !$id ) continue;
+ $parents = get_post_ancestors( $id );
+ $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) );
+ foreach ( $parents as $parent ):
+ if ( !in_array( $parent, $ids ) )
+ edit_post_link( get_the_title( $parent ), '', '', $parent );
+ echo ' - ';
+ endforeach;
+ $title = get_the_title( $id );
+ if ( empty( $title ) )
+ $title = __( '(no title)', 'sportspress' );
+ edit_post_link( $title, '', '', $id );
+ if ( ++$i !== $count )
+ echo ', ';
+ endforeach;
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_post_checklist' ) ) {
+ function sportspress_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) {
+ if ( ! isset( $post_id ) )
+ global $post_id;
+ ?>
+
+
+
', sizeof( $parents ) ); ?>
+
+
+
+
+ $type,
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'orderby' => 'menu_order',
+ 'order' => 'ASC',
+ 'exclude' => $postid
+ );
+ $vars = get_posts( $args );
+
+ // Add extra vars to the array
+ if ( isset( $defaults ) && is_array( $defaults ) ):
+ foreach ( $defaults as $key => $value ):
+ $arr[ $key ] = $value;
+ endforeach;
+ endif;
+
+ // Add vars to the array
+ if ( isset( $variations ) && is_array( $variations ) ):
+ foreach ( $vars as $var ):
+ if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
+ foreach ( $variations as $key => $value ):
+ $arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
+ endforeach;
+ endforeach;
+ else:
+ foreach ( $vars as $var ):
+ '$' . $arr[ $var->post_name ] = $var->post_title;
+ endforeach;
+ endif;
+
+ return (array) $arr;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_equation_selector' ) ) {
+ function sportspress_get_equation_selector( $postid, $selected = null, $groups = array() ) {
+
+ if ( ! isset( $postid ) )
+ return;
+
+ // Initialize options array
+ $options = array();
+
+ // Add groups to options
+ foreach ( $groups as $group ):
+ switch ( $group ):
+ case 'player_event':
+ $options[ __( 'Events', 'sportspress' ) ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ) );
+ break;
+ case 'team_event':
+ $options[ __( 'Events', 'sportspress' ) ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ) );
+ break;
+ case 'result':
+ $options[ __( 'Results', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ), null, false );
+ break;
+ case 'outcome':
+ $options[ __( 'Outcomes', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
+ $options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' );
+ break;
+ case 'column':
+ $options[ __( 'Columns', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_column' );
+ break;
+ case 'statistic':
+ $options[ __( 'Statistics', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_statistic' );
+ break;
+ endswitch;
+ endforeach;
+
+ // Create array of operators
+ $operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '(' => '(', ')' => ')' );
+
+ // Add operators to options
+ $options[ __( 'Operators', 'sportspress' ) ] = $operators;
+
+ // Create array of constants
+ $max = 10;
+ $constants = array();
+ for ( $i = 1; $i <= $max; $i ++ ):
+ $constants[$i] = $i;
+ endfor;
+
+ // Add constants to options
+ $options[ __( 'Constants', 'sportspress' ) ] = (array) $constants;
+
+ ?>
+
+ $post_type,
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'orderby' => 'menu_order',
+ 'order' => 'ASC',
+ 'meta_query' => array(
+ array(
+ 'key' => 'sp_format',
+ 'value' => 'custom',
+ 'compare' => '!=',
+ ),
+ ),
+ );
+
+ $vars = get_posts( $args );
+
+ $output = array();
+ foreach ( $vars as $var ):
+ if ( $independent ):
+ $equation = get_post_meta( $var->ID, 'sp_equation', true );
+ if ( $equation && $equation != '' ):
+ continue;
+ endif;
+ endif;
+ $output[ $var->post_name ] = $var->post_title;
+ endforeach;
+
+ return $output;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_var_equations' ) ) {
+ function sportspress_get_var_equations( $post_type ) {
+ $args = array(
+ 'post_type' => $post_type,
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'orderby' => 'menu_order',
+ 'order' => 'ASC'
+ );
+
+ $vars = get_posts( $args );
+
+ $output = array();
+ foreach ( $vars as $var ):
+ $equation = get_post_meta( $var->ID, 'sp_equation', true );
+ $output[ $var->post_name ] = $equation;
+ endforeach;
+
+ return $output;
+ }
+}
+
+if ( !function_exists( 'sportspress_edit_league_table' ) ) {
+ function sportspress_edit_league_table( $columns = array(), $data = array(), $placeholders = array() ) {
+ ?>
+
+
+
+
+
+
+
+
+
+ __( 'Starting Lineup', 'sportspress' ),
+ 'sub' => __( 'Substitute', 'sportspress' ),
+ );
+
+ $output = '';
+
+ return $output;
+
+ }
+}
+
+if ( !function_exists( 'sportspress_event_player_sub_selector' ) ) {
+ function sportspress_event_player_sub_selector( $team_id, $player_id, $value, $data = array() ) {
+
+ if ( ! $team_id || ! $player_id )
+ return '—';
+
+ $output = '';
+
+ return $output;
+
+ }
+}
+
+if ( !function_exists( 'sportspress_event_players_table' ) ) {
+ function sportspress_event_players_table( $columns = array(), $data = array(), $team_id ) {
+ ?>
+
+
+
+ ' . $value . '';
+ break;
+ case 'checkbox':
+ echo '';
+ break;
+ default:
+ echo '';
+ break;
+ endswitch;
+
+ }
+}
+
+if ( !function_exists( 'sportspress_get_eos_safe_slug' ) ) {
+ function sportspress_get_eos_safe_slug( $title, $post_id = 'var' ) {
+
+ // String to lowercase
+ $title = strtolower( $title );
+
+ // Replace all numbers with words
+ $title = sportspress_numbers_to_words( $title );
+
+ // Remove all other non-alphabet characters
+ $title = preg_replace( "/[^a-z]/", '', $title );
+
+ // Convert post ID to words if title is empty
+ if ( $title == '' ):
+
+ $title = sportspress_numbers_to_words( $post_id );
+
+ endif;
+
+ return $title;
+
+ }
+}
+
+if ( !function_exists( 'sportspress_solve' ) ) {
+ function sportspress_solve( $equation, $vars ) {
+
+ // Return direct value if streak
+ if ( str_replace( ' ', '', $equation ) == '$streak' )
+ return sportspress_array_value( $vars, 'streak', 0 );
+
+ // Clearance to begin calculating remains true if all equation variables are in vars
+ $clearance = true;
+
+ // Check if each variable part is in vars
+ $parts = explode( ' ', $equation );
+ foreach( $parts as $key => $value ):
+ if ( substr( $value, 0, 1 ) == '$' ):
+ if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) )
+ $clearance = false;
+ endif;
+ endforeach;
+
+ if ( $clearance ):
+ // Equation Operating System
+ $eos = new eqEOS();
+
+ // Solve using EOS
+ return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), 3 ); // TODO: add precision setting to each column with default set to 3
+ else:
+ return 0;
+ endif;
+
+ }
+
+}
+
+if ( !function_exists( 'sportspress_get_table' ) ) {
+ function sportspress_get_table( $post_id, $breakdown = false ) {
+ $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
+ $team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
+ $table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
+
+ // Get labels from result variables
+ $result_labels = (array)sportspress_get_var_labels( 'sp_result' );
+
+ // Get labels from outcome variables
+ $outcome_labels = (array)sportspress_get_var_labels( 'sp_outcome' );
+
+ // Get all leagues populated with stats where available
+ $tempdata = sportspress_array_combine( $team_ids, $table_stats );
+
+ // Create entry for each team in totals
+ $totals = array();
+ $placeholders = array();
+
+ // Initialize streaks counter
+ $streaks = array();
+
+ foreach ( $team_ids as $team_id ):
+ if ( ! $team_id )
+ continue;
+
+ $streaks[ $team_id ] = array( 'name' => '', 'count' => 0 );
+
+ $totals[ $team_id ] = array( 'eventsplayed' => 0, 'streak' => 0 );
+
+ foreach ( $result_labels as $key => $value ):
+ $totals[ $team_id ][ $key . 'for' ] = 0;
+ $totals[ $team_id ][ $key . 'against' ] = 0;
+ endforeach;
+
+ foreach ( $outcome_labels as $key => $value ):
+ $totals[ $team_id ][ $key ] = 0;
+ endforeach;
+
+ // Get static stats
+ $static = get_post_meta( $team_id, 'sp_columns', true );
+
+ // Create placeholders entry for the team
+ $placeholders[ $team_id ] = array();
+
+ // Add static stats to placeholders
+ if ( array_key_exists( $div_id, $static ) ):
+ $placeholders[ $team_id ] = $static[ $div_id ];
+ endif;
+
+ endforeach;
+
+ $args = array(
+ 'post_type' => 'sp_event',
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'order' => 'ASC',
+ 'tax_query' => array(
+ array(
+ 'taxonomy' => 'sp_season',
+ 'field' => 'id',
+ 'terms' => $div_id
+ )
+ )
+ );
+ $events = get_posts( $args );
+
+ // Event loop
+ foreach ( $events as $event ):
+
+ $results = (array)get_post_meta( $event->ID, 'sp_results', true );
+
+ foreach ( $results as $team_id => $team_result ):
+
+ foreach ( $team_result as $key => $value ):
+
+ if ( $key == 'outcome' ):
+ if ( array_key_exists( $value, $totals[ $team_id ] ) ):
+ $totals[ $team_id ]['eventsplayed']++;
+ $totals[ $team_id ][ $value ]++;
+ endif;
+ if ( $value && $value != '-1' ):
+ if ( $streaks[ $team_id ]['name'] == $value ):
+ $streaks[ $team_id ]['count'] ++;
+ else:
+ $streaks[ $team_id ]['name'] = $value;
+ $streaks[ $team_id ]['count'] = 1;
+ endif;
+ endif;
+ else:
+ if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
+ $totals[ $team_id ][ $key . 'for' ] += $value;
+ endif;
+ endif;
+
+ endforeach;
+
+ endforeach;
+
+ endforeach;
+
+ foreach ( $streaks as $team_id => $streak ):
+ // Compile streaks counter and add to totals
+ $args=array(
+ 'name' => $streak['name'],
+ 'post_type' => 'sp_outcome',
+ 'post_status' => 'publish',
+ 'posts_per_page' => 1
+ );
+ $outcomes = get_posts( $args );
+
+ if ( $outcomes ):
+ $outcome = $outcomes[0];
+ $totals[ $team_id ]['streak'] = $outcome->post_title . $streak['count'];
+ endif;
+ endforeach;
+
+ $args = array(
+ 'post_type' => 'sp_column',
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'orderby' => 'menu_order',
+ 'order' => 'ASC'
+ );
+ $stats = get_posts( $args );
+
+ $columns = array();
+ $priorities = array();
+
+ foreach ( $stats as $stat ):
+
+ // Get post meta
+ $meta = get_post_meta( $stat->ID );
+
+ // Add equation to object
+ $stat->equation = sportspress_array_value( sportspress_array_value( $meta, 'sp_equation', array() ), 0, 0 );
+
+ // Add column name to columns
+ $columns[ $stat->post_name ] = $stat->post_title;
+
+ // Add order to priorities if priority is set and does not exist in array already
+ $priority = sportspress_array_value( sportspress_array_value( $meta, 'sp_priority', array() ), 0, 0 );
+ if ( $priority && ! array_key_exists( $priority, $priorities ) ):
+ $priorities[ $priority ] = array(
+ 'column' => $stat->post_name,
+ 'order' => sportspress_array_value( sportspress_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
+ );
+ endif;
+
+ endforeach;
+
+ // Sort priorities in descending order
+ ksort( $priorities );
+
+ // Fill in empty placeholder values for each team
+ foreach ( $team_ids as $team_id ):
+ if ( ! $team_id )
+ continue;
+
+ foreach ( $stats as $stat ):
+ if ( sportspress_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
+ if ( sizeof( $events ) > 0 ):
+ $placeholders[ $team_id ][ $stat->post_name ] = sportspress_solve( $stat->equation, sportspress_array_value( $totals, $team_id, array() ) );
+ else:
+ $placeholders[ $team_id ][ $stat->post_name ] = 0;
+ endif;
+ endif;
+ endforeach;
+ endforeach;
+
+ // Merge the data and placeholders arrays
+ $merged = array();
+
+ foreach( $placeholders as $team_id => $team_data ):
+
+ // Add team name to row
+ $merged[ $team_id ] = array( 'name' => get_the_title( $team_id ) );
+
+ foreach( $team_data as $key => $value ):
+
+ // Use static data if key exists and value is not empty, else use placeholder
+ if ( array_key_exists( $team_id, $tempdata ) && array_key_exists( $key, $tempdata[ $team_id ] ) && $tempdata[ $team_id ][ $key ] != '' ):
+ $merged[ $team_id ][ $key ] = $tempdata[ $team_id ][ $key ];
+ else:
+ $merged[ $team_id ][ $key ] = $value;
+ endif;
+
+ endforeach;
+ endforeach;
+
+ uasort( $merged, function( $a, $b ) use ( $priorities ) {
+
+ // Loop through priorities
+ foreach( $priorities as $priority ):
+
+ // Proceed if columns are not equal
+ if ( sportspress_array_value( $a, $priority['column'], 0 ) != sportspress_array_value( $b, $priority['column'], 0 ) ):
+
+ // Compare column values
+ $output = sportspress_array_value( $a, $priority['column'], 0 ) - sportspress_array_value( $b, $priority['column'], 0 );
+
+ // Flip value if descending order
+ if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
+
+ return $output;
+
+ endif;
+
+ endforeach;
+
+ // Default sort by alphabetical
+ return strcmp( sportspress_array_value( $a, 'name', '' ), sportspress_array_value( $b, 'name', '' ) );
+ });
+
+ // Rearrange data array to reflect statistics
+ $data = array();
+ foreach( $merged as $key => $value ):
+ $data[ $key ] = $tempdata[ $key ];
+ endforeach;
+
+ if ( $breakdown ):
+ return array( $columns, $data, $placeholders, $merged );
+ else:
+ array_unshift( $columns, __( 'Team', 'sportspress' ) );
+ $merged[0] = $columns;
+ return $merged;
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_get_list' ) ) {
+ function sportspress_get_list( $post_id, $breakdown = false ) {
+ $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
+ $team_id = get_post_meta( $post_id, 'sp_team', true );
+ $player_ids = (array)get_post_meta( $post_id, 'sp_player', false );
+ $stats = (array)get_post_meta( $post_id, 'sp_players', true );
+
+ // Equation Operating System
+ $eos = new eqEOS();
+
+ // Get labels from result variables
+ $columns = (array)sportspress_get_var_labels( 'sp_statistic' );
+
+ // Get all leagues populated with stats where available
+ $tempdata = sportspress_array_combine( $player_ids, $stats );
+
+ // Get equations from statistics variables
+ $equations = sportspress_get_var_equations( 'sp_statistic' );
+
+ // Create entry for each player in totals
+ $totals = array();
+ $placeholders = array();
+
+ foreach ( $player_ids as $player_id ):
+ if ( ! $player_id )
+ continue;
+
+ $totals[ $player_id ] = array( 'eventsattended' => 0, 'eventsplayed' => 0 );
+
+ foreach ( $columns as $key => $value ):
+ $totals[ $player_id ][ $key ] = 0;
+ endforeach;
+
+ // Get static statistics
+ $static = get_post_meta( $player_id, 'sp_statistics', true );
+
+ // Create placeholders entry for the player
+ $placeholders[ $player_id ] = array();
+
+ // Add static statistics to placeholders
+ if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ):
+ $placeholders[ $player_id ] = $static[ $team_id ][ $div_id ];
+ endif;
+ endforeach;
+
+ $args = array(
+ 'post_type' => 'sp_event',
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'tax_query' => array(
+ array(
+ 'taxonomy' => 'sp_season',
+ 'field' => 'id',
+ 'terms' => $div_id
+ )
+ ),
+ 'meta_query' => array(
+ array(
+ 'key' => 'sp_team',
+ 'value' => $team_id,
+ )
+ )
+ );
+ $events = get_posts( $args );
+
+ // Event loop
+ foreach( $events as $event ):
+
+ $teams = (array)get_post_meta( $event->ID, 'sp_players', true );
+
+ if ( ! array_key_exists( $team_id, $teams ) )
+ continue;
+
+ $players = sportspress_array_value( $teams, $team_id, array() );
+
+ foreach ( $players as $player_id => $player_statistics ):
+
+ // Increment events played
+ $totals[ $player_id ]['eventsplayed']++;
+
+ foreach ( $player_statistics as $key => $value ):
+
+ if ( array_key_exists( $key, $totals[ $player_id ] ) ):
+ $totals[ $player_id ][ $key ] += $value;
+ endif;
+
+ endforeach;
+
+ endforeach;
+
+ endforeach;
+
+ $args = array(
+ 'post_type' => 'sp_statistic',
+ 'numberposts' => -1,
+ 'posts_per_page' => -1,
+ 'orderby' => 'menu_order',
+ 'order' => 'ASC',
+ 'meta_query' => array(
+ array(
+ 'key' => 'sp_format',
+ 'value' => 'custom',
+ 'compare' => '!=',
+ ),
+ ),
+ );
+ $statistics = get_posts( $args );
+
+ $columns = array();
+ $priorities = array();
+
+ foreach ( $statistics as $statistic ):
+
+ // Get post meta
+ $meta = get_post_meta( $statistic->ID );
+
+ // Add equation to object
+ $statistic->equation = sportspress_array_value( sportspress_array_value( $meta, 'sp_equation', array() ), 0, 0 );
+
+ // Add column name to columns
+ $columns[ $statistic->post_name ] = $statistic->post_title;
+
+ // Add order to priorities if priority is set and does not exist in array already
+ $priority = sportspress_array_value( sportspress_array_value( $meta, 'sp_priority', array() ), 0, 0 );
+ if ( $priority && ! array_key_exists( $priority, $priorities ) ):
+ $priorities[ $priority ] = array(
+ 'column' => $statistic->post_name,
+ 'order' => sportspress_array_value( sportspress_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
+ );
+ endif;
+
+ endforeach;
+
+ // Sort priorities in descending order
+ ksort( $priorities );
+
+ // Fill in empty placeholder values for each player
+ foreach ( $player_ids as $player_id ):
+
+ if ( ! $player_id )
+ continue;
+
+ foreach ( $statistics as $statistic ):
+ if ( sportspress_array_value( $placeholders[ $player_id ], $statistic->post_name, '' ) == '' ):
+
+ if ( empty( $statistic->equation ) ):
+
+ // Reflect totals
+ $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_array_value( sportspress_array_value( $totals, $player_id, array() ), $key, 0 );
+
+ else:
+
+ // Calculate value
+ if ( sizeof( $events ) > 0 ):
+ $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_solve( $statistic->equation, sportspress_array_value( $totals, $player_id, array() ) );
+ else:
+ $placeholders[ $player_id ][ $statistic->post_name ] = 0;
+ endif;
+ endif;
+ endif;
+ endforeach;
+ endforeach;
+
+ // Merge the data and placeholders arrays
+ $merged = array();
+
+ foreach( $placeholders as $player_id => $player_data ):
+
+ // Add team name to row
+ $merged[ $player_id ] = array( 'name' => get_the_title( $player_id ) );
+
+ foreach( $player_data as $key => $value ):
+
+ // Use static data if key exists and value is not empty, else use placeholder
+ if ( array_key_exists( $player_id, $tempdata ) && array_key_exists( $key, $tempdata[ $player_id ] ) && $tempdata[ $player_id ][ $key ] != '' ):
+ $merged[ $player_id ][ $key ] = $tempdata[ $player_id ][ $key ];
+ else:
+ $merged[ $player_id ][ $key ] = $value;
+ endif;
+
+ endforeach;
+ endforeach;
+
+ uasort( $merged, function( $a, $b ) use ( $priorities ) {
+
+ // Loop through priorities
+ foreach( $priorities as $priority ):
+
+ // Proceed if columns are not equal
+ if ( sportspress_array_value( $a, $priority['column'], 0 ) != sportspress_array_value( $b, $priority['column'], 0 ) ):
+
+ // Compare column values
+ $output = sportspress_array_value( $a, $priority['column'], 0 ) - sportspress_array_value( $b, $priority['column'], 0 );
+
+ // Flip value if descending order
+ if ( $priority['order'] == 'DESC' ) $output = 0 - $output;
+
+ return $output;
+
+ endif;
+
+ endforeach;
+
+ // Default sort by alphabetical
+ return strcmp( sportspress_array_value( $a, 'name', '' ), sportspress_array_value( $b, 'name', '' ) );
+ });
+
+ // Rearrange data array to reflect statistics
+ $data = array();
+ foreach( $merged as $key => $value ):
+ $data[ $key ] = $tempdata[ $key ];
+ endforeach;
+
+ if ( $breakdown ):
+ return array( $columns, $data, $placeholders, $merged );
+ else:
+ array_unshift( $columns, __( 'Player', 'sportspress' ) );
+ $merged[0] = $columns;
+ return $merged;
+ endif;
+ }
+}
+
+if ( !function_exists( 'sportspress_highlight_admin_menu' ) ) {
+ function sportspress_highlight_admin_menu() {
+ global $parent_file, $submenu_file;
+ $parent_file = 'options-general.php';
+ $submenu_file = 'sportspress';
+ }
+}
diff --git a/install.php b/install.php
deleted file mode 100644
index ff3a9b28..00000000
--- a/install.php
+++ /dev/null
@@ -1,160 +0,0 @@
-add_cap( 'edit_sp_event' );
- $role->add_cap( 'edit_sp_events' );
- $role->add_cap( 'edit_others_sp_events' );
- $role->add_cap( 'delete_sp_event' );
- $role->add_cap( 'publish_sp_events' );
- $role->add_cap( 'read_sp_events' );
- $role->add_cap( 'read_private_sp_events' );
-
- // Teams
- $role->add_cap( 'edit_sp_team' );
- $role->add_cap( 'edit_sp_teams' );
- $role->add_cap( 'edit_others_sp_teams' );
- $role->add_cap( 'delete_sp_team' );
- $role->add_cap( 'publish_sp_teams' );
- $role->add_cap( 'read_sp_teams' );
- $role->add_cap( 'read_private_sp_teams' );
-
- // League Tables
- $role->add_cap( 'edit_sp_table' );
- $role->add_cap( 'edit_sp_tables' );
- $role->add_cap( 'edit_others_sp_tables' );
- $role->add_cap( 'delete_sp_table' );
- $role->add_cap( 'publish_sp_tables' );
- $role->add_cap( 'read_sp_tables' );
- $role->add_cap( 'read_private_sp_tables' );
-
- // Players
- $role->add_cap( 'edit_sp_player' );
- $role->add_cap( 'edit_sp_players' );
- $role->add_cap( 'edit_others_sp_players' );
- $role->add_cap( 'delete_sp_player' );
- $role->add_cap( 'publish_sp_players' );
- $role->add_cap( 'read_sp_players' );
- $role->add_cap( 'read_private_sp_players' );
-
- // Player Lists
- $role->add_cap( 'edit_sp_list' );
- $role->add_cap( 'edit_sp_lists' );
- $role->add_cap( 'edit_others_sp_lists' );
- $role->add_cap( 'delete_sp_list' );
- $role->add_cap( 'publish_sp_lists' );
- $role->add_cap( 'read_sp_lists' );
- $role->add_cap( 'read_private_sp_lists' );
-
- // Staff
- $role->add_cap( 'edit_sp_staff' );
- $role->add_cap( 'edit_sp_staffs' );
- $role->add_cap( 'edit_others_sp_staffs' );
- $role->add_cap( 'delete_sp_staff' );
- $role->add_cap( 'publish_sp_staffs' );
- $role->add_cap( 'read_sp_staffs' );
- $role->add_cap( 'read_private_sp_staffs' );
-
- // Settings
- $role->add_cap( 'read_sp_configs' );
- $role->add_cap( 'read_private_sp_configs' );
- $role->add_cap( 'edit_sp_config' );
- $role->add_cap( 'edit_sp_configs' );
- $role->add_cap( 'edit_published_sp_configs' );
- $role->add_cap( 'edit_private_sp_configs' );
- $role->add_cap( 'edit_others_sp_configs' );
- $role->add_cap( 'delete_sp_config' );
- $role->add_cap( 'delete_published_sp_configs' );
- $role->add_cap( 'delete_private_sp_configs' );
- $role->add_cap( 'delete_others_sp_configs' );
- $role->add_cap( 'publish_sp_configs' );
-
- // Team Manager
- remove_role( 'sp_team_manager' );
- add_role(
- 'sp_team_manager',
- __( 'Team Manager', 'sportspress' ),
- array(
- 'read' => true,
- 'edit_posts' => true,
- 'delete_posts' => true,
- 'read_sp_players' => true,
- 'edit_sp_players' => true,
- 'edit_others_sp_players' => true,
- 'delete_sp_player' => true,
- 'publish_sp_players' => true,
- 'read_sp_staffs' => true,
- 'edit_sp_staffs' => true,
- 'edit_others_sp_staffs' => true,
- 'delete_sp_staff' => true,
- 'publish_sp_staffs' => true
- )
- );
-
- // Staff
- remove_role( 'sp_staff' );
- add_role(
- 'sp_staff',
- __( 'Staff', 'sportspress' ),
- array(
- 'read' => true,
- 'edit_posts' => true,
- 'delete_posts' => true,
- 'read_sp_staffs' => true,
- 'edit_sp_staffs' => true,
- 'delete_sp_staff' => true
- )
- );
-
- // Player
- remove_role( 'sp_player' );
- add_role(
- 'sp_player',
- __( 'Player', 'sportspress' ),
- array(
- 'read' => true,
- 'edit_posts' => true,
- 'delete_posts' => true,
- 'read_sp_players' => true,
- 'edit_sp_players' => true,
- 'delete_sp_player' => true
- )
- );
-
- update_option( 'sportspress_installed', 1 );
- endif;
-
- }
-}
-add_action( 'admin_init', 'sportspress_install', 1 );
-
-// Flush rewrite rules on activation
-function sp_rewrite_flush() {
- sp_event_cpt_init();
- sp_result_cpt_init();
- sp_outcome_cpt_init();
- sp_column_cpt_init();
- sp_statistic_cpt_init();
- sp_team_cpt_init();
- sp_table_cpt_init();
- sp_player_cpt_init();
- sp_list_cpt_init();
- sp_staff_cpt_init();
- flush_rewrite_rules();
-}
-register_activation_hook( __FILE__, 'sp_rewrite_flush' );
-
-function sp_admin_head_edit() {
- global $typenow;
-
- if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
- sp_highlight_admin_menu();
- endif;
-}
-add_action( 'admin_head-edit.php', 'sp_admin_head_edit', 10, 2 );
-add_action( 'admin_head-post.php', 'sp_admin_head_edit', 10, 2 );
diff --git a/i18n/languages/sportspress-ja.mo b/languages/sportspress-ja.mo
similarity index 100%
rename from i18n/languages/sportspress-ja.mo
rename to languages/sportspress-ja.mo
diff --git a/i18n/languages/sportspress-ja.po b/languages/sportspress-ja.po
similarity index 100%
rename from i18n/languages/sportspress-ja.po
rename to languages/sportspress-ja.po
diff --git a/sportspress.php b/sportspress.php
index 966215b1..8fe35ea7 100644
--- a/sportspress.php
+++ b/sportspress.php
@@ -25,16 +25,17 @@ define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
// Libraries
include dirname( __FILE__ ) . '/lib/eos/eos.class.php' ;
-// Internationalization
-include dirname( __FILE__ ) . '/i18n/strings.php';
+// Strings
+include dirname( __FILE__ ) . '/strings.php';
// Functions
+require_once dirname( __FILE__ ) . '/helpers.php';
require_once dirname( __FILE__ ) . '/functions.php';
// Settings
include dirname( __FILE__ ) . '/admin/settings/settings.php' ;
-// Custom Post Types
+// Custom post types
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';
require_once dirname( __FILE__ ) . '/admin/post-types/event.php';
require_once dirname( __FILE__ ) . '/admin/post-types/result.php';
@@ -68,36 +69,42 @@ include_once dirname( __FILE__ ) . '/admin/presets/swimming.php';
include_once dirname( __FILE__ ) . '/admin/presets/tennis.php';
include_once dirname( __FILE__ ) . '/admin/presets/volleyball.php';
-// Install
-include dirname( __FILE__ ) . '/install.php';
-
-// Actions
+// Typical request actions
require_once dirname( __FILE__ ) . '/admin/actions/plugins-loaded.php';
-require_once dirname( __FILE__ ) . '/admin/actions/post-thumbnail-html.php';
-require_once dirname( __FILE__ ) . '/admin/actions/after-theme-setup.php';
+require_once dirname( __FILE__ ) . '/admin/actions/after-setup-theme.php';
require_once dirname( __FILE__ ) . '/admin/actions/admin-menu.php';
+require_once dirname( __FILE__ ) . '/admin/actions/admin-init.php';
+require_once dirname( __FILE__ ) . '/admin/actions/admin-enqueue-scripts.php';
+require_once dirname( __FILE__ ) . '/admin/actions/admin-head.php';
+
+// Administrative actions
require_once dirname( __FILE__ ) . '/admin/actions/manage-posts-custom-column.php';
+require_once dirname( __FILE__ ) . '/admin/actions/post-thumbnail-html.php';
require_once dirname( __FILE__ ) . '/admin/actions/restrict-manage-posts.php';
require_once dirname( __FILE__ ) . '/admin/actions/save-post.php';
// Filters
-require_once dirname( __FILE__ ) . '/admin/filters/gettext.php';
require_once dirname( __FILE__ ) . '/admin/filters/admin-post-thumbnail-html.php';
-require_once dirname( __FILE__ ) . '/admin/filters/the-content.php';
-require_once dirname( __FILE__ ) . '/admin/filters/sanitize-title.php';
-require_once dirname( __FILE__ ) . '/admin/filters/wp-insert-post-data.php';
+require_once dirname( __FILE__ ) . '/admin/filters/gettext.php';
require_once dirname( __FILE__ ) . '/admin/filters/pre-get-posts.php';
+require_once dirname( __FILE__ ) . '/admin/filters/sanitize-title.php';
+require_once dirname( __FILE__ ) . '/admin/filters/the-content.php';
+require_once dirname( __FILE__ ) . '/admin/filters/wp-insert-post-data.php';
-// Admin Styles
-function sp_admin_styles() {
- wp_register_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), '1.0' );
- wp_enqueue_style( 'sportspress-admin');
+// Flush rewrite rules on activation
+function sportspress_rewrite_flush() {
+ sportspress_event_post_init();
+ sportspress_result_post_init();
+ sportspress_outcome_post_init();
+ sportspress_column_post_init();
+ sportspress_statistic_post_init();
+ sportspress_team_post_init();
+ sportspress_table_post_init();
+ sportspress_player_post_init();
+ sportspress_list_post_init();
+ sportspress_staff_post_init();
+ sportspress_position_term_init();
+ sportspress_season_term_init();
+ flush_rewrite_rules();
}
-add_action( 'admin_init', 'sp_admin_styles' );
-
-// Admin Scripts
-function sp_admin_enqueue_scripts() {
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'/assets/js/admin.js', array( 'jquery' ), time(), true );
-}
-add_action( 'admin_enqueue_scripts', 'sp_admin_enqueue_scripts' );
+register_activation_hook( __FILE__, 'sportspress_rewrite_flush' );
\ No newline at end of file
diff --git a/i18n/strings.php b/strings.php
similarity index 91%
rename from i18n/strings.php
rename to strings.php
index bb6e4c7a..279d161f 100644
--- a/i18n/strings.php
+++ b/strings.php
@@ -1,5 +1,5 @@
%1$s', 'sportspress' );
@@ -33,7 +33,7 @@ __( 'Joined: %1$s', 'sportspress' );
__( 'Select Photo', 'sportspress' );
__( 'Remove Photo', 'sportspress' );
-// Localize configuration formats
+// Configuration formats
__( 'Integer', 'sportspress' );
__( 'Decimal', 'sportspress' );
__( 'Time', 'sportspress' );