From 9cde21de71c226797371f3c8cc4e823b9536fd78 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 21 Jan 2014 20:35:13 +1100 Subject: [PATCH] Add positions to statistics and metrics --- admin-functions.php | 2005 --------------- admin/hooks/admin-head.php | 2 +- admin/hooks/gettext.php | 2 +- admin/hooks/manage-posts-custom-column.php | 9 +- admin/hooks/post-updated-messages.php | 45 + admin/hooks/save-post.php | 46 +- admin/post-types/column.php | 28 +- admin/post-types/event.php | 1 + admin/post-types/metric.php | 76 +- admin/post-types/player.php | 4 +- admin/post-types/result.php | 11 - admin/post-types/statistic.php | 55 +- admin/post-types/team.php | 2 +- admin/settings/events.php | 61 + admin/settings/players.php | 64 + admin/settings/settings.php | 15 +- admin/settings/tables.php | 36 + admin/templates/event-details.php | 46 + admin/templates/event-players.php | 105 + admin/templates/event-results.php | 66 + admin/templates/event-staff.php | 17 + admin/templates/event-venue.php | 29 + admin/templates/events-calendar.php | 180 ++ admin/templates/league-table.php | 72 + admin/templates/player-league-statistics.php | 48 + admin/templates/player-list.php | 59 + admin/templates/player-metrics.php | 42 + admin/templates/player-statistics.php | 24 + admin/templates/team-columns.php | 63 + admin/terms/position.php | 4 +- functions.php | 2364 ++++++++++++++---- readme.txt | 10 +- sportspress.php | 16 +- 33 files changed, 2922 insertions(+), 2685 deletions(-) delete mode 100644 admin-functions.php create mode 100644 admin/hooks/post-updated-messages.php create mode 100644 admin/settings/events.php create mode 100644 admin/settings/players.php create mode 100644 admin/settings/tables.php create mode 100644 admin/templates/event-details.php create mode 100644 admin/templates/event-players.php create mode 100644 admin/templates/event-results.php create mode 100644 admin/templates/event-staff.php create mode 100644 admin/templates/event-venue.php create mode 100644 admin/templates/events-calendar.php create mode 100644 admin/templates/league-table.php create mode 100644 admin/templates/player-league-statistics.php create mode 100644 admin/templates/player-list.php create mode 100644 admin/templates/player-metrics.php create mode 100644 admin/templates/player-statistics.php create mode 100644 admin/templates/team-columns.php diff --git a/admin-functions.php b/admin-functions.php deleted file mode 100644 index c24613fe..00000000 --- a/admin-functions.php +++ /dev/null @@ -1,2005 +0,0 @@ -'; - } -} - -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, - 'hide_empty' => false, - 'value' => 'slug', - ); - $args = array_merge( $defaults, $args ); - $terms = get_terms( $args['taxonomy'], $args ); - $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', - 'values' => 'post_name', - ); - $args = array_merge( $defaults, $args ); - $name = $args['name']; - unset( $args['name'] ); - $values = $args['values']; - unset( $args['values'] ); - $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 ); - $keys = array_keys( $parents ); - $values = array_reverse( array_values( $parents ) ); - if ( ! empty( $keys ) && ! empty( $values ) ): - $parents = array_combine( $keys, $values ); - foreach ( $parents as $parent ): - if ( !in_array( $parent, $ids ) ) - edit_post_link( get_the_title( $parent ), '', '', $parent ); - echo ' - '; - endforeach; - endif; - $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' ); - $options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' ); - break; - case 'column': - $options[ __( 'Columns', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_column' ); - break; - case 'statistic': - $options[ __( 'Player 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', - ); - - $vars = get_posts( $args ); - - $output = array(); - foreach ( $vars as $var ): - $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_calendar_table' ) ) { - function sportspress_edit_calendar_table( $data = array() ) { - if ( empty( $data ) ): - printf( __( 'No %s found.', 'sportspress' ), __( 'events', 'sportspress' ) ); - return false; - endif; - ?> -
- - - - - - - - - - - - - - - - - -
- post_title; ?> - - ID ); ?> - - ID ); ?> -
-
- -
- - - - - - - - - - - $team_stats ): - if ( !$team_id ) continue; - $div = get_term( $team_id, 'sp_season' ); - ?> - - - $label ): - $value = sportspress_array_value( $team_stats, $column, '' ); - $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $team_id, array() ), $column, 0 ); - ?> - - - - - -
- -
-
- -
- - - - - - - - - - - $player_stats ): - if ( !$player_id ) continue; - $div = get_term( $player_id, 'sp_season' ); - ?> - - - $label ): - $value = sportspress_array_value( $player_stats, $column, '' ); - $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $player_id, array() ), $column, 0 ); - ?> - - - - - -
- -
-
- -
- - - - - - - - - - - - $div_stats ): - if ( !$div_id ) continue; - $div = get_term( $div_id, 'sp_season' ); - ?> - - - - $label ): - $value = sportspress_array_value( sportspress_array_value( $data, $div_id, array() ), $column, 0 ); - ?> - - - - - -
- > - - - '; - ?>
-
- -
- - - - - - - - - - - - $div_stats ): - if ( !$div_id || $div_id == 'statistics' ) continue; - $div = get_term( $div_id, 'sp_season' ); - ?> - - - - $label ): - ?> - - - - - -
- name; ?> - - 'sp_team', - 'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']', - 'show_option_none' => __( '-- Select --', 'sportspress' ), - 'sort_order' => 'ASC', - 'sort_column' => 'menu_order', - 'selected' => $value, - 'values' => 'ID', - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'terms' => $league_id, - 'field' => 'id', - ), - array( - 'taxonomy' => 'sp_season', - 'terms' => $div_id, - 'field' => 'id', - ), - ), - ); - sportspress_dropdown_pages( $args ); - ?> - '; - ?>
-
- -
- - - - - - - - - - - - $team_results ): - if ( !$team_id ) continue; - ?> - - - $label ): - $value = sportspress_array_value( $team_results, $column, '' ); - ?> - - - - - - -
- - - 'sp_outcome', - 'name' => 'sp_results[' . $team_id . '][outcome]', - 'show_option_none' => __( '-- Not set --', 'sportspress' ), - 'option_none_value' => 0, - 'sort_order' => 'ASC', - 'sort_column' => 'menu_order', - 'selected' => $value - ); - sportspress_dropdown_pages( $args ); - ?> -
-
- __( '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_edit_event_players_table' ) ) { - function sportspress_edit_event_players_table( $columns = array(), $data = array(), $team_id ) { - ?> -
- - - - - - - - - - - - - $player_statistics ): - if ( !$player_id ) continue; - $number = get_post_meta( $player_id, 'sp_number', true ); - ?> - - - - $label ): - $value = sportspress_array_value( $player_statistics, $column, '' ); - ?> - - - - - - - - - $label ): - $player_id = 0; - $player_statistics = sportspress_array_value( $data, 0, array() ); - $value = sportspress_array_value( $player_statistics, $column, '' ); - ?> - - - - - -
#
- - - - -
  
-
- __( 'Starting Lineup', 'sportspress' ), - 'sub' => __( 'Substitute', 'sportspress' ), - ); - - $output = ''; - - return $output; - - } -} - -if ( !function_exists( 'sportspress_post_adder' ) ) { - function sportspress_post_adder( $meta = 'post' ) { - $obj = get_post_type_object( $meta ); - ?> -
-

- - + labels->singular_name ); ?> - -

-
- ' . $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 ) { - - if ( str_replace( ' ', '', $equation ) == '$streak' ): - - // Return direct value - return sportspress_array_value( $vars, 'streak', 0 ); - - elseif ( str_replace( ' ', '', $equation ) == '$last10' ): - - // Return imploded string - $last10 = sportspress_array_value( $vars, 'last10', array( 0 ) ); - if ( array_sum( $last10 ) > 0 ): - return implode( '-', $last10 ); - else: - return '—'; - endif; - - else: - - // Remove unnecessary variables from vars before calculating - unset( $vars['streak'] ); - unset( $vars['last10'] ); - - endif; - - // 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_calendar_data' ) ) { - function sportspress_get_calendar_data( $post_id ) { - $leagues = get_the_terms( $post_id, 'sp_league' ); - $seasons = get_the_terms( $post_id, 'sp_season' ); - $venues = get_the_terms( $post_id, 'sp_venue' ); - - if ( ! $leagues || ! $seasons || ! $venues ) - return array(); - - $league_ids = array(); - foreach( $leagues as $league ): - $league_ids[] = $league->term_id; - endforeach; - - $season_ids = array(); - foreach( $seasons as $season ): - $season_ids[] = $season->term_id; - endforeach; - - $venue_ids = array(); - foreach( $venues as $venue ): - $venue_ids[] = $venue->term_id; - endforeach; - - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'orderby' => 'post_date', - 'order' => 'ASC', - 'post_status' => 'any', - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_ids - ), - array( - 'taxonomy' => 'sp_season', - 'field' => 'id', - 'terms' => $season_ids - ), - array( - 'taxonomy' => 'sp_venue', - 'field' => 'id', - 'terms' => $venue_ids - ), - ), - ); - $events = get_posts( $args ); - - return $events; - - } -} - -if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { - function sportspress_get_team_columns_data( $post_id, $league_id, $admin = false ) { - - $seasons = (array)get_the_terms( $post_id, 'sp_season' ); - $columns = (array)get_post_meta( $post_id, 'sp_columns', true ); - $leagues_seasons = sportspress_array_value( (array)get_post_meta( $post_id, 'sp_leagues_seasons', true ), $league_id, array() ); - - // 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' ); - - // Generate array of all season ids and season names - $div_ids = array(); - $season_names = array(); - foreach ( $seasons as $season ): - if ( is_object( $season ) && property_exists( $season, 'term_id' ) && property_exists( $season, 'name' ) ): - $div_ids[] = $season->term_id; - $season_names[ $season->term_id ] = $season->name; - endif; - endforeach; - - $data = array(); - - // Get all seasons populated with data where available - $data = sportspress_array_combine( $div_ids, sportspress_array_value( $columns, $league_id, array() ) ); - - // Get equations from column variables - $equations = sportspress_get_var_equations( 'sp_column' ); - - // Initialize placeholders array - $placeholders = array(); - - foreach ( $div_ids as $div_id ): - - $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null ); - - foreach ( $result_labels as $key => $value ): - $totals[ $key . 'for' ] = 0; - $totals[ $key . 'against' ] = 0; - endforeach; - - foreach ( $outcome_labels as $key => $value ): - $totals[ $key ] = 0; - endforeach; - - // Initialize streaks counter - $streak = array( 'name' => '', 'count' => 0, 'fire' => 1 ); - - // Initialize last 10 counter - $last10 = array(); - - // Add outcome types to last 10 counter - foreach( $outcome_labels as $key => $value ): - $last10[ $key ] = 0; - endforeach; - - // Get all events involving the team in current season - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'order' => 'ASC', - 'meta_query' => array( - array( - 'key' => 'sp_team', - 'value' => $post_id - ) - ), - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_id - ), - array( - 'taxonomy' => 'sp_season', - 'field' => 'id', - 'terms' => $div_id - ) - ) - ); - $events = get_posts( $args ); - - 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 ( $team_id == $post_id ): - if ( $key == 'outcome' ): - - // Increment events played and outcome count - if ( array_key_exists( $value, $totals ) ): - $totals['eventsplayed']++; - $totals[ $value ]++; - endif; - - if ( $value && $value != '-1' ): - - // Add to streak counter - if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $value ) ): - $streak['name'] = $value; - $streak['count'] ++; - else: - $streak['fire'] = 0; - endif; - - // Add to last 10 counter if sum is less than 10 - if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ): - $last10[ $value ] ++; - endif; - - endif; - - else: - if ( array_key_exists( $key . 'for', $totals ) ): - $totals[ $key . 'for' ] += $value; - endif; - endif; - else: - if ( $key != 'outcome' ): - if ( array_key_exists( $key . 'against', $totals ) ): - $totals[ $key . 'against' ] += $value; - endif; - endif; - endif; - endforeach; - endforeach; - endforeach; - - // 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['streak'] = $outcome->post_title . $streak['count']; - endif; - - // Add last 10 to totals - $totals['last10'] = $last10; - - // Generate array of placeholder values for each league - $placeholders[ $div_id ] = array(); - foreach ( $equations as $key => $value ): - if ( $totals['eventsplayed'] > 0 ): - $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); - else: - $placeholders[ $div_id ][ $key ] = 0; - endif; - endforeach; - - endforeach; - - // Get columns from column variables - $columns = sportspress_get_var_labels( 'sp_column' ); - - // Merge the data and placeholders arrays - $merged = array(); - - foreach( $placeholders as $season_id => $season_data ): - - if ( ! sportspress_array_value( $leagues_seasons, $season_id, 0 ) ) - continue; - - $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); - - // Add season name to row - $merged[ $season_id ] = array( - 'name' => $season_name - ); - - foreach( $season_data as $key => $value ): - - // Use static data if key exists and value is not empty, else use placeholder - if ( array_key_exists( $season_id, $data ) && array_key_exists( $key, $data[ $season_id ] ) && $data[ $season_id ][ $key ] != '' ): - $merged[ $season_id ][ $key ] = $data[ $season_id ][ $key ]; - else: - $merged[ $season_id ][ $key ] = $value; - endif; - - endforeach; - - endforeach; - - if ( $admin ): - return array( $columns, $data, $placeholders, $merged, $leagues_seasons ); - else: - $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns ); - $merged[0] = $labels; - return $merged; - endif; - - } - -} - -if ( !function_exists( 'sportspress_get_league_table_data' ) ) { - function sportspress_get_league_table_data( $post_id, $breakdown = false ) { - $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); - $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(); - - // Initialize last 10s counter - $last10s = array(); - - foreach ( $team_ids as $team_id ): - if ( ! $team_id ) - continue; - - // Initialize team streaks counter - $streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 ); - - // Initialize team last 10 counter - $last10s[ $team_id ] = array(); - - // Add outcome types to team last 10 counter - foreach( $outcome_labels as $key => $value ): - $last10s[ $team_id ][ $key ] = 0; - endforeach; - - // Initialize team totals - $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 ); - - // Add static stats to placeholders - $placeholders[ $team_id ] = sportspress_array_value( $static, $div_id, array() ); - - endforeach; - - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'order' => 'ASC', - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_id - ), - 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 ): - - if ( ! in_array( $team_id, $team_ids ) ) - continue; - - foreach ( $team_result as $key => $value ): - - if ( $key == 'outcome' ): - - // Increment events played and outcome count - if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $value, $totals[ $team_id ] ) ): - $totals[ $team_id ]['eventsplayed']++; - $totals[ $team_id ][ $value ]++; - endif; - - if ( $value && $value != '-1' ): - - // Add to streak counter - if ( $streaks[ $team_id ]['fire'] && ( $streaks[ $team_id ]['name'] == '' || $streaks[ $team_id ]['name'] == $value ) ): - $streaks[ $team_id ]['name'] = $value; - $streaks[ $team_id ]['count'] ++; - else: - $streaks[ $team_id ]['fire'] = 0; - endif; - - // Add to last 10 counter if sum is less than 10 - if ( array_key_exists( $team_id, $last10s ) && array_key_exists( $value, $last10s[ $team_id ] ) && array_sum( $last10s[ $team_id ] ) < 10 ): - $last10s[ $team_id ][ $value ] ++; - endif; - - endif; - - else: - if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ): - $totals[ $team_id ][ $key . 'for' ] += $value; - foreach( $results as $other_team_id => $other_result ): - if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ): - $totals[ $team_id ][ $key . 'against' ] += sportspress_array_value( $other_result, $key, 0 ); - endif; - endforeach; - endif; - endif; - - endforeach; - - endforeach; - - endforeach; - - foreach ( $streaks as $team_id => $streak ): - // Compile streaks counter and add to totals - if ( $streak['name'] ): - $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']; - else: - $totals[ $team_id ]['streak'] = '—'; - endif; - else: - $totals[ $team_id ]['streak'] = '—'; - endif; - endforeach; - - foreach ( $last10s as $team_id => $last10 ): - // Add last 10 to totals - $totals[ $team_id ]['last10'] = $last10; - 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(); - - $team_data['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: - $labels = array_merge( array( 'name' => __( 'Team', 'sportspress' ) ), $columns ); - $merged[0] = $labels; - return $merged; - endif; - } -} - -if ( !function_exists( 'sportspress_get_player_list_data' ) ) { - function sportspress_get_player_list_data( $post_id, $admin = false ) { - $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); - $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 ); - - // 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( $league_id, $static ) && array_key_exists( $div_id, $static[ $league_id ] ) ): - $placeholders[ $player_id ] = $static[ $league_id ][ $div_id ]; - endif; - endforeach; - - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_id - ), - 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 ): - - if ( ! $player_id || ! in_array( $player_id, $player_ids ) ) - continue; - - // 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', - ); - $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, '' ) == '' ): - - // Reflect totals - $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_array_value( sportspress_array_value( $totals, $player_id, array() ), $statistic->post_name, 0 ); - - endif; - endforeach; - endforeach; - - // Merge the data and placeholders arrays - $merged = array(); - - foreach( $placeholders as $player_id => $player_data ): - - // Add player 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 ( $admin ): - return array( $columns, $tempdata, $placeholders, $merged ); - else: - $labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns ); - $merged[0] = $labels; - return $merged; - endif; - } -} - -if ( !function_exists( 'sportspress_get_player_metrics_data' ) ) { - function sportspress_get_player_metrics_data( $post_id ) { - - $metrics = (array)get_post_meta( $post_id, 'sp_metrics', true ); - - // Get labels from metric variables - $metric_labels = (array)sportspress_get_var_labels( 'sp_metric' ); - - $data = array(); - - foreach( $metric_labels as $key => $value ): - - $data[ $value ] = sportspress_array_value( $metrics, $key, ' ' ); - - endforeach; - - return $data; - - } -} - -if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { - function sportspress_get_player_statistics_data( $post_id, $league_id, $admin = false ) { - - $seasons = (array)get_the_terms( $post_id, 'sp_season' ); - $stats = (array)get_post_meta( $post_id, 'sp_statistics', true ); - $seasons_teams = sportspress_array_value( (array)get_post_meta( $post_id, 'sp_leagues', true ), $league_id, array() ); - - // Get labels from statistic variables - $statistic_labels = (array)sportspress_get_var_labels( 'sp_statistic' ); - - // Generate array of all season ids and season names - $div_ids = array(); - $season_names = array(); - foreach ( $seasons as $season ): - if ( is_object( $season ) && property_exists( $season, 'term_id' ) && property_exists( $season, 'name' ) ): - $div_ids[] = $season->term_id; - $season_names[ $season->term_id ] = $season->name; - endif; - endforeach; - - $tempdata = array(); - - // Get all seasons populated with stats where available - $tempdata = sportspress_array_combine( $div_ids, sportspress_array_value( $stats, $league_id, array() ) ); - - // Get equations from statistics variables - $equations = sportspress_get_var_equations( 'sp_statistic' ); - - foreach ( $div_ids as $div_id ): - - $team_id = sportspress_array_value( $seasons_teams, $div_id, '-1' ); - - $totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 ); - - foreach ( $statistic_labels as $key => $value ): - $totals[ $key ] = 0; - endforeach; - - $args = array( - 'post_type' => 'sp_event', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'meta_query' => array( - 'relation' => 'AND', - array( - 'key' => 'sp_team', - 'value' => $team_id - ), - array( - 'key' => 'sp_player', - 'value' => $post_id - ) - ), - 'tax_query' => array( - 'relation' => 'AND', - array( - 'taxonomy' => 'sp_league', - 'field' => 'id', - 'terms' => $league_id - ), - array( - 'taxonomy' => 'sp_season', - 'field' => 'id', - 'terms' => $div_id - ) - ) - ); - $events = get_posts( $args ); - - foreach( $events as $event ): - $totals['eventsattended']++; - $totals['eventsplayed']++; - $team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true ); - if ( array_key_exists( $team_id, $team_statistics ) ): - $players = sportspress_array_value( $team_statistics, $team_id, array() ); - if ( array_key_exists( $post_id, $players ) ): - $player_statistics = sportspress_array_value( $players, $post_id, array() ); - foreach ( $player_statistics as $key => $value ): - if ( array_key_exists( $key, $totals ) ): - $totals[ $key ] += $value; - endif; - endforeach; - endif; - endif; - endforeach; - - // Generate array of placeholder values for each league - $placeholders[ $div_id ] = array(); - foreach ( $equations as $key => $value ): - - if ( empty( $value ) ): - - // Reflect totals - $placeholders[ $div_id ][ $key ] = sportspress_array_value( $totals, $key, 0 ); - - else: - - // Calculate value - if ( sizeof( $events ) > 0 ): - $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); - else: - $placeholders[ $div_id ][ $key ] = 0; - endif; - - endif; - - endforeach; - - endforeach; - - // Get columns from statistics variables - $columns = sportspress_get_var_labels( 'sp_statistic' ); - - // Merge the data and placeholders arrays - $merged = array(); - - foreach( $placeholders as $season_id => $season_data ): - - $team_id = sportspress_array_value( $seasons_teams, $season_id, array() ); - - if ( ! $team_id || $team_id == '-1' ) - continue; - - $team_name = get_the_title( $team_id ); - - $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); - - // Add season name to row - $merged[ $season_id ] = array( - 'name' => $season_name, - 'team' => $team_name - ); - - foreach( $season_data as $key => $value ): - - // Use static data if key exists and value is not empty, else use placeholder - if ( array_key_exists( $season_id, $tempdata ) && array_key_exists( $key, $tempdata[ $season_id ] ) && $tempdata[ $season_id ][ $key ] != '' ): - $merged[ $season_id ][ $key ] = $tempdata[ $season_id ][ $key ]; - else: - $merged[ $season_id ][ $key ] = $value; - endif; - - endforeach; - - endforeach; - - if ( $admin ): - return array( $columns, $tempdata, $placeholders, $merged, $seasons_teams ); - else: - $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ) ), $columns ); - $merged[0] = $labels; - 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/admin/hooks/admin-head.php b/admin/hooks/admin-head.php index 3da39558..3bda120b 100644 --- a/admin/hooks/admin-head.php +++ b/admin/hooks/admin-head.php @@ -2,7 +2,7 @@ function sportspress_admin_head() { global $typenow; - if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ): + if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic', 'sp_metric' ) ) ): sportspress_highlight_admin_menu(); endif; } diff --git a/admin/hooks/gettext.php b/admin/hooks/gettext.php index 7d68fc25..48d0538f 100644 --- a/admin/hooks/gettext.php +++ b/admin/hooks/gettext.php @@ -23,7 +23,7 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) { case 'sp_event': switch ( $untranslated_text ): case 'Enter title here': - $translated_text = __( '(no title)', 'sportspress' ); + $translated_text = __( '(auto)', 'sportspress' ); break; case 'Scheduled for: %1$s': $translated_text = __( 'Date/Time: %1$s', 'sportspress' ); diff --git a/admin/hooks/manage-posts-custom-column.php b/admin/hooks/manage-posts-custom-column.php index 6dda282e..1955bd3d 100644 --- a/admin/hooks/manage-posts-custom-column.php +++ b/admin/hooks/manage-posts-custom-column.php @@ -6,7 +6,10 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) { edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-icon' ), '', '', $post_id ); break; case 'sp_position': - echo get_the_terms ( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—'; + echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—'; + break; + case 'sp_positions': + echo get_the_terms ( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : sprintf( __( 'All %s', 'sportspress' ), __( 'positions', 'sportspress' ) ); break; case 'sp_team': $post_type = get_post_type( $post ); @@ -60,8 +63,8 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) { case 'sp_key': echo $post->post_name; break; - case 'sp_format': - echo sportspress_get_post_format( $post_id ); + case 'sp_precision': + echo sportspress_get_post_precision( $post_id ); break; case 'sp_player': echo sportspress_the_posts( $post_id, 'sp_player' ); diff --git a/admin/hooks/post-updated-messages.php b/admin/hooks/post-updated-messages.php new file mode 100644 index 00000000..b846e904 --- /dev/null +++ b/admin/hooks/post-updated-messages.php @@ -0,0 +1,45 @@ +labels->singular_name ) . + ' ' . + sprintf( __( 'Edit %s', 'sportspress' ), $obj->labels->name ) . ''; + + elseif ( in_array( $typenow, array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) ) ): + $obj = get_post_type_object( $typenow ); + + $messages['post'][1] = sprintf( __( '%s updated.', 'sportspress' ), $obj->labels->singular_name ) . + ' ' . $obj->labels->view_item . ''; + + $messages['post'][4] = sprintf( __( '%s updated.', 'sportspress' ), $obj->labels->singular_name ); + + $messages['post'][6] = sprintf( __( '%s published.', 'sportspress' ), $obj->labels->singular_name ) . + ' ' . $obj->labels->view_item . ''; + + $messages['post'][7] = sprintf( __( '%s saved.'), $obj->labels->singular_name ); + + $messages['post'][8] = sprintf( __( '%s submitted.', 'sportspress' ), $obj->labels->singular_name ) . + ' ' . + sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; + + $messages['post'][9] = sprintf( + __( '%s scheduled for: %s.', 'sportspress' ), + date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ) . + ' ' . + sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; + + $messages['post'][8] = sprintf( __( '%s draft updated.', 'sportspress' ), $obj->labels->singular_name ) . + ' ' . + sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . ''; + + endif; + + return $messages; +} + +add_filter('post_updated_messages', 'sportspress_post_updated_messages'); +?> \ No newline at end of file diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index 57a1ddff..3aa859c7 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -48,15 +48,12 @@ function sportspress_save_post( $post_id ) { break; case ( 'sp_column' ): - - // Update format as string - update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) ); - - // Update precision as integer - update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) ); - + // Update equation as string update_post_meta( $post_id, 'sp_equation', implode( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) ); + + // Update precision as integer + update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) ); // Update sort order as string update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) ); @@ -68,43 +65,8 @@ function sportspress_save_post( $post_id ) { case ( 'sp_statistic' ): - // Update format as string - update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) ); - - // Update precision as integer - update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) ); - - // Update sort order as string - update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) ); - - // Update sort order as string - update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) ); - - break; - - case ( 'sp_metric' ): - - // Update format as string - update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) ); - - // Update precision as integer - update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) ); - // Update equation as string update_post_meta( $post_id, 'sp_equation', implode( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) ); - - // Update sort order as string - update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) ); - - // Update sort order as string - update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) ); - - break; - - case ( 'sp_result' ): - - // Update format as string - update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) ); break; diff --git a/admin/post-types/column.php b/admin/post-types/column.php index ffefd110..b3c9c85a 100644 --- a/admin/post-types/column.php +++ b/admin/post-types/column.php @@ -1,8 +1,8 @@ $name, @@ -24,8 +24,8 @@ function sportspress_column_edit_columns() { 'cb' => '', 'title' => __( 'Label', 'sportspress' ), 'sp_key' => __( 'Key', 'sportspress' ), - 'sp_format' => __( 'Format', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), + 'sp_precision' => __( 'Precision', 'sportspress' ), 'sp_order' => __( 'Sort Order', 'sportspress' ), ); return $columns; @@ -37,8 +37,6 @@ function sportspress_column_meta_init() { } function sportspress_column_details_meta( $post ) { - $formats = sportspress_get_config_formats(); - $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); $order = get_post_meta( $post->ID, 'sp_order', true ); $priority = get_post_meta( $post->ID, 'sp_priority', true ); @@ -51,20 +49,6 @@ function sportspress_column_details_meta( $post ) {

-

-

- -

-

-

- -

+

+

+ +

', 'title' => __( 'Label', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ), - 'sp_format' => __( 'Format', 'sportspress' ), - 'sp_equation' => __( 'Equation', 'sportspress' ), - 'sp_order' => __( 'Sort Order', 'sportspress' ), + 'sp_positions' => __( 'Positions', 'sportspress' ), ); return $columns; } add_filter( 'manage_edit-sp_metric_columns', 'sportspress_metric_edit_columns' ); - -function sportspress_metric_meta_init() { - add_meta_box( 'sp_equationdiv', __( 'Details', 'sportspress' ), 'sportspress_metric_equation_meta', 'sp_metric', 'normal', 'high' ); -} - -function sportspress_metric_equation_meta( $post ) { - $formats = sportspress_get_config_formats(); - - $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); - $order = get_post_meta( $post->ID, 'sp_order', true ); - $priority = get_post_meta( $post->ID, 'sp_priority', true ); - $precision = get_post_meta( $post->ID, 'sp_precision', true ); - - // Defaults - if ( $precision == '' ) $precision = 1; - ?> -

-

- -

-

-

- -

-

-

- -

-

-

- ID, $piece, array( 'player_event' ) ); - endforeach; - ?> -

-

-

- - -

- '', 'title' => __( 'Label', 'sportspress' ), 'sp_key' => __( 'Key', 'sportspress' ), - 'sp_format' => __( 'Format', 'sportspress' ), ); return $columns; } @@ -41,16 +40,6 @@ function sportspress_result_details_meta( $post ) {

-

-

- -

$name, @@ -23,10 +23,8 @@ function sportspress_statistic_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ), - 'sp_format' => __( 'Format', 'sportspress' ), + 'sp_positions' => __( 'Positions', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), - 'sp_order' => __( 'Sort Order', 'sportspress' ), ); return $columns; } @@ -37,34 +35,8 @@ function sportspress_statistic_meta_init() { } function sportspress_statistic_equation_meta( $post ) { - $formats = sportspress_get_config_formats(); - $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); - $order = get_post_meta( $post->ID, 'sp_order', true ); - $priority = get_post_meta( $post->ID, 'sp_priority', true ); - $precision = get_post_meta( $post->ID, 'sp_precision', true ); - - // Defaults - if ( $precision == '' ) $precision = 1; ?> -

-

- -

-

-

- -

-

-

- -

-

-

- - -

'sp_result', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' +); +$data = get_posts( $args ); +?> +

+ + + + + + + + + > + + + + + + + + + +
post_title; ?>post_name; ?>for / post_name; ?>against
+ + 'sp_outcome', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' +); +$data = get_posts( $args ); +?> +

+ + + + + + + + + > + + + + + + + + + +
post_title; ?>post_name; ?>
\ No newline at end of file diff --git a/admin/settings/players.php b/admin/settings/players.php new file mode 100644 index 00000000..1275aa7d --- /dev/null +++ b/admin/settings/players.php @@ -0,0 +1,64 @@ + 'sp_metric', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' +); +$data = get_posts( $args ); +?> +

+ + + + + + + + + + > + + + + + + + + + + +
 
post_title; ?>ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : sprintf( __( 'All %s', 'sportspress' ), __( 'positions', 'sportspress' ) ); ?> 
+ 'sp_statistic', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' +); +$data = get_posts( $args ); +?> +

+ + + + + + + + + + > + + + + + + + + + + +
post_title; ?>ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : sprintf( __( 'All %s', 'sportspress' ), __( 'positions', 'sportspress' ) ); ?>ID ); ?>
\ No newline at end of file diff --git a/admin/settings/settings.php b/admin/settings/settings.php index fbb8331c..d70e4d36 100644 --- a/admin/settings/settings.php +++ b/admin/settings/settings.php @@ -9,18 +9,21 @@ function sportspress_settings() {
'sp_column', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' +); +$data = get_posts( $args ); +?> +

+ + + + + + + + + + + + > + + + + + + + + + + + + +
post_title; ?>post_name; ?>ID, $row->post_name ); ?>ID ); ?>ID ); ?>
\ No newline at end of file diff --git a/admin/templates/event-details.php b/admin/templates/event-details.php new file mode 100644 index 00000000..e9c172ea --- /dev/null +++ b/admin/templates/event-details.php @@ -0,0 +1,46 @@ +ID; + endif; + + $date = get_the_time( get_option('date_format'), $id ); + $time = get_the_time( get_option('time_format'), $id ); + $leagues = get_the_terms( $id, 'sp_league' ); + $seasons = get_the_terms( $id, 'sp_season' ); + + $data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time ); + + if ( $leagues ) + $data[ __( 'League', 'sportspress' ) ] = sportspress_array_value( $leagues, 0, '—' )->name; + + if ( $seasons ) + $data[ __( 'Season', 'sportspress' ) ] = sportspress_array_value( $seasons, 0, '—' )->name; + + + $output = '

' . __( 'Details', 'sportspress' ) . '

'; + + $output .= ''; + + $i = 0; + + foreach( $data as $label => $value ): + + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + + $i++; + + endforeach; + + $output .= '
' . $label . '' . $value . '
'; + + return apply_filters( 'sportspress_event_details', $output ); + + } +} diff --git a/admin/templates/event-players.php b/admin/templates/event-players.php new file mode 100644 index 00000000..a75ca82b --- /dev/null +++ b/admin/templates/event-players.php @@ -0,0 +1,105 @@ +ID; + endif; + + $teams = (array)get_post_meta( $id, 'sp_team', false ); + $staff = (array)get_post_meta( $id, 'sp_staff', false ); + $stats = (array)get_post_meta( $id, 'sp_players', true ); + $statistic_labels = sportspress_get_var_labels( 'sp_statistic' ); + + $output = ''; + + foreach( $teams as $key => $team_id ): + if ( ! $team_id ) continue; + + // Get results for players in the team + $players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key ); + $data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) ); + + $output .= '

' . get_the_title( $team_id ) . '

'; + + $output .= '' . '' . ''; + + $output .= ''; + $output .= ''; + + foreach( $statistic_labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $player_id => $row ): + + if ( ! $player_id ) + continue; + + $output .= ''; + + $number = get_post_meta( $player_id, 'sp_number', true ); + + // Player number + $output .= ''; + + // Name as link + $permalink = get_post_permalink( $player_id ); + $name = get_the_title( $player_id ); + $output .= ''; + + foreach( $statistic_labels as $key => $label ): + if ( $key == 'name' ) + continue; + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = 0; + endif; + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= ''; + + if ( array_key_exists( 0, $data ) ): + + $output .= ''; + + $number = get_post_meta( $player_id, 'sp_number', true ); + + // Player number + $output .= ''; + $output .= ''; + + $row = $data[0]; + + foreach( $statistic_labels as $key => $label ): + if ( $key == 'name' ): + continue; + endif; + $output .= ''; + endforeach; + + $output .= ''; + + endif; + + $output .= '
#' . __( 'Player', 'sportspress' ) . '' . $label . '
' . $number . '' . '' . $name . '' . $value . '
 ' . __( 'Total', 'sportspress' ) . '' . sportspress_array_value( $row, $key, '—' ) . '
'; + + endforeach; + + return apply_filters( 'sportspress_event_players', $output ); + + } +} diff --git a/admin/templates/event-results.php b/admin/templates/event-results.php new file mode 100644 index 00000000..16cf1d9e --- /dev/null +++ b/admin/templates/event-results.php @@ -0,0 +1,66 @@ +ID; + endif; + + $teams = (array)get_post_meta( $id, 'sp_team', false ); + $results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ); + $result_labels = sportspress_get_var_labels( 'sp_result' ); + + $output = ''; + + // Initialize and check + $table_rows = ''; + + $i = 0; + + foreach( $results as $team_id => $result ): + if ( sportspress_array_value( $result, 'outcome', '-1' ) != '-1' ): + + unset( $result['outcome'] ); + + $table_rows .= ''; + + $table_rows .= '' . get_the_title( $team_id ) . ''; + + foreach( $result_labels as $key => $label ): + if ( $key == 'name' ) + continue; + if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ): + $value = $result[ $key ]; + else: + $value = '—'; + endif; + $table_rows .= '' . $value . ''; + endforeach; + + $table_rows .= ''; + + $i++; + + endif; + endforeach; + + if ( ! empty( $table_rows ) ): + + $output .= '

' . __( 'Results', 'sportspress' ) . '

'; + + $output .= ''; + $output .= ''; + foreach( $result_labels as $key => $label ): + $output .= ''; + endforeach; + $output .= '' . '' . ''; + $output .= $table_rows; + $output .= '
' . __( 'Team', 'sportspress' ) . '' . $label . '
'; + + endif; + + return apply_filters( 'sportspress_event_results', $output ); + + } +} diff --git a/admin/templates/event-staff.php b/admin/templates/event-staff.php new file mode 100644 index 00000000..252557fc --- /dev/null +++ b/admin/templates/event-staff.php @@ -0,0 +1,17 @@ +ID; + endif; + + $staff = (array)get_post_meta( $id, 'sp_staff', false ); + + $output = ''; + + return apply_filters( 'sportspress_event_staff', $output ); + + } +} diff --git a/admin/templates/event-venue.php b/admin/templates/event-venue.php new file mode 100644 index 00000000..98cf1715 --- /dev/null +++ b/admin/templates/event-venue.php @@ -0,0 +1,29 @@ +term_id; + $term_meta = get_option( "taxonomy_$t_id" ); + + $address = sportspress_array_value( $term_meta, 'sp_address', '' ); + $latitude = sportspress_array_value( $term_meta, 'sp_latitude', 0 ); + $longitude = sportspress_array_value( $term_meta, 'sp_longitude', 0 ); + + $output .= '

' . $venue->name . '

'; + $output .= '
'; + + endforeach; + + return apply_filters( 'sportspress_event_venue', $output ); + + } +} diff --git a/admin/templates/events-calendar.php b/admin/templates/events-calendar.php new file mode 100644 index 00000000..1dec33e1 --- /dev/null +++ b/admin/templates/events-calendar.php @@ -0,0 +1,180 @@ +ID; + endif; + + global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; + $initial = false; + $echo = 1; + + // Quick check. If we have no posts at all, abort! + if ( !$posts ) + return; + + // week_begins = 0 stands for Sunday + $week_begins = intval(get_option('start_of_week')); + + // Let's figure out when we are + if ( !empty($monthnum) && !empty($year) ) { + $thismonth = ''.zeroise(intval($monthnum), 2); + $thisyear = ''.intval($year); + } elseif ( !empty($w) ) { + // We need to get the month from MySQL + $thisyear = ''.intval(substr($m, 0, 4)); + $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's + $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); + } elseif ( !empty($m) ) { + $thisyear = ''.intval(substr($m, 0, 4)); + if ( strlen($m) < 6 ) + $thismonth = '01'; + else + $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); + } else { + $thisyear = gmdate('Y', current_time('timestamp')); + $thismonth = gmdate('m', current_time('timestamp')); + } + + $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); + $last_day = date('t', $unixmonth); + + // Get the next and previous month and year with at least one post + $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + FROM $wpdb->posts + WHERE post_date < '$thisyear-$thismonth-01' + AND post_type = 'sp_event' AND post_status = 'publish' + ORDER BY post_date DESC + LIMIT 1"); + $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + FROM $wpdb->posts + WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' + AND post_type = 'sp_event' AND post_status = 'publish' + ORDER BY post_date ASC + LIMIT 1"); + + /* translators: Calendar caption: 1: month name, 2: 4-digit year */ + $calendar_caption = _x('%1$s %2$s', 'calendar caption'); + $calendar_output = ' + + + '; + + $myweek = array(); + + for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { + $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); + } + + foreach ( $myweek as $wd ) { + $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); + $wd = esc_attr($wd); + $calendar_output .= "\n\t\t"; + } + + $calendar_output .= ' + + + + + '; + + if ( $previous ) { + $calendar_output .= "\n\t\t".''; + } else { + $calendar_output .= "\n\t\t".''; + } + + $calendar_output .= "\n\t\t".''; + + if ( $next ) { + $calendar_output .= "\n\t\t".''; + } else { + $calendar_output .= "\n\t\t".''; + } + + $calendar_output .= ' + + + + + '; + + // Get days with posts + $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) + FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' + AND post_type = 'sp_event' AND post_status = 'publish' + AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); + if ( $dayswithposts ) { + foreach ( (array) $dayswithposts as $daywith ) { + $daywithpost[] = $daywith[0]; + } + } else { + $daywithpost = array(); + } + + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) + $ak_title_separator = "\n"; + else + $ak_title_separator = ', '; + + $ak_titles_for_day = array(); + $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " + ."FROM $wpdb->posts " + ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " + ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " + ."AND post_type = 'sp_event' AND post_status = 'publish'" + ); + if ( $ak_post_titles ) { + foreach ( (array) $ak_post_titles as $ak_post_title ) { + + /** This filter is documented in wp-includes/post-template.php */ + $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) ); + + if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) + $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; + if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one + $ak_titles_for_day["$ak_post_title->dom"] = $post_title; + else + $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title; + } + } + + // See how much we should pad in the beginning + $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); + if ( 0 != $pad ) + $calendar_output .= "\n\t\t".''; + + $daysinmonth = intval(date('t', $unixmonth)); + for ( $day = 1; $day <= $daysinmonth; ++$day ) { + if ( isset($newrow) && $newrow ) + $calendar_output .= "\n\t\n\t\n\t\t"; + $newrow = false; + + if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) ) + $calendar_output .= ''; + + if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) + $newrow = true; + } + + $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); + if ( $pad != 0 && $pad != 7 ) + $calendar_output .= "\n\t\t".''; + + $calendar_output .= "\n\t\n\t\n\t
' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '
$day_name
« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '  ' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' » 
 
'; + else + $calendar_output .= ''; + + if ( in_array($day, $daywithpost) ) // any posts today? + $calendar_output .= '$day"; + else + $calendar_output .= $day; + $calendar_output .= ' 
"; + + return apply_filters( 'sportspress_events_calendar', $calendar_output ); + + } +} diff --git a/admin/templates/league-table.php b/admin/templates/league-table.php new file mode 100644 index 00000000..2c18e76e --- /dev/null +++ b/admin/templates/league-table.php @@ -0,0 +1,72 @@ +ID; + endif; + + $defaults = array( + 'number_label' => __( 'Pos', 'sportspress' ), + 'thumbnails' => 1, + 'thumbnail_size' => 'thumbnail' + ); + + $r = wp_parse_args( $args, $defaults ); + + $data = sportspress_get_league_table_data( $id ); + + $output = '' . + '' . '' . ''; + + // The first row should be column labels + $labels = $data[0]; + + // Remove the first row to leave us with the actual data + unset( $data[0] ); + + $output .= ''; + foreach( $labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $team_id => $row ): + + $output .= ''; + + // Position as number + $output .= ''; + + // Thumbnail and name as link + $permalink = get_post_permalink( $team_id ); + if ( $r['thumbnails'] ): + $thumbnail = get_the_post_thumbnail( $team_id, $r['thumbnail_size'], array( 'class' => 'logo' ) ); + else: + $thumbnail = null; + endif; + $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); + $output .= ''; + + foreach( $labels as $key => $value ): + if ( $key == 'name' ) + continue; + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
' . get_the_title( $id ) . '
' . $r['number_label'] . '' . $label . '
' . $i . '' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '
'; + + return apply_filters( 'sportspress_league_table', $output ); + + } +} diff --git a/admin/templates/player-league-statistics.php b/admin/templates/player-league-statistics.php new file mode 100644 index 00000000..fa417cb9 --- /dev/null +++ b/admin/templates/player-league-statistics.php @@ -0,0 +1,48 @@ +ID; + endif; + + $data = sportspress_get_player_statistics_data( $id, $league->term_id ); + + // The first row should be column labels + $labels = $data[0]; + + // Remove the first row to leave us with the actual data + unset( $data[0] ); + + $output = '' . + '' . '' . ''; + + foreach( $labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $season_id => $row ): + + $output .= ''; + + foreach( $labels as $key => $value ): + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
' . $league->name . '
' . $label . '
' . sportspress_array_value( $row, $key, '—' ) . '
'; + + return apply_filters( 'sportspress_player_league_statistics', $output ); + + } +} diff --git a/admin/templates/player-list.php b/admin/templates/player-list.php new file mode 100644 index 00000000..fd8577e3 --- /dev/null +++ b/admin/templates/player-list.php @@ -0,0 +1,59 @@ +ID; + endif; + + $data = sportspress_get_player_list_data( $id ); + + $output = '' . '' . ''; + + // The first row should be column labels + $labels = $data[0]; + + // Remove the first row to leave us with the actual data + unset( $data[0] ); + + $output .= ''; + foreach( $labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $player_id => $row ): + + $output .= ''; + + // Player number + $number = get_post_meta( $player_id, 'sp_number', true ); + $output .= ''; + + // Name as link + $permalink = get_post_permalink( $player_id ); + $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); + $output .= ''; + + foreach( $labels as $key => $value ): + if ( $key == 'name' ) + continue; + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
#' . $label . '
' . ( $number ? $number : ' ' ) . '' . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '
'; + + return apply_filters( 'sportspress_player_list', $output ); + + } +} diff --git a/admin/templates/player-metrics.php b/admin/templates/player-metrics.php new file mode 100644 index 00000000..30e7faf5 --- /dev/null +++ b/admin/templates/player-metrics.php @@ -0,0 +1,42 @@ +ID; + endif; + + global $sportspress_countries; + + $number = get_post_meta( $id, 'sp_number', true ); + $nationality = get_post_meta( $id, 'sp_nationality', true ); + $metrics = sportspress_get_player_metrics_data( $id ); + + $flag_image = ''; + + $common = array( + __( 'Number', 'sportspress' ) => $number, + __( 'Nationality', 'sportspress' ) => $flag_image . ' ' . sportspress_array_value( $sportspress_countries, $nationality, '—' ), + ); + + $data = array_merge( $common, $metrics ); + + $output = '' . ''; + + $i = 0; + + foreach( $data as $label => $value ): + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
' . $label . '' . $value . '
'; + + return apply_filters( 'sportspress_player_metrics', $output ); + + } +} diff --git a/admin/templates/player-statistics.php b/admin/templates/player-statistics.php new file mode 100644 index 00000000..2717c910 --- /dev/null +++ b/admin/templates/player-statistics.php @@ -0,0 +1,24 @@ +ID; + endif; + + $leagues = get_the_terms( $id, 'sp_league' ); + + $output = ''; + + // Loop through statistics for each league + foreach ( $leagues as $league ): + + $output .= sportspress_player_league_statistics( $league, $id ); + + endforeach; + + return apply_filters( 'sportspress_player_statistics', $output ); + + } +} diff --git a/admin/templates/team-columns.php b/admin/templates/team-columns.php new file mode 100644 index 00000000..53f80d93 --- /dev/null +++ b/admin/templates/team-columns.php @@ -0,0 +1,63 @@ +ID; + endif; + + $leagues = get_the_terms( $id, 'sp_league' ); + + $output = ''; + + // Loop through data for each league + foreach ( $leagues as $league ): + + $data = sportspress_get_team_columns_data( $id, $league->term_id ); + + if ( sizeof( $data ) <= 1 ) + continue; + + if ( sizeof( $leagues ) > 1 ) + $output .= '

' . $league->name . '

'; + + // The first row should be column labels + $labels = $data[0]; + + // Remove the first row to leave us with the actual data + unset( $data[0] ); + + $output .= '' . '' . ''; + + foreach( $labels as $key => $label ): + $output .= ''; + endforeach; + + $output .= '' . '' . ''; + + $i = 0; + + foreach( $data as $season_id => $row ): + + $output .= ''; + + foreach( $labels as $key => $value ): + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + + endforeach; + + $output .= '' . '
' . $label . '
' . sportspress_array_value( $row, $key, '—' ) . '
'; + + + endforeach; + + return apply_filters( 'sportspress_team_columns', $output ); + + } +} diff --git a/admin/terms/position.php b/admin/terms/position.php index 30b45c77..fb9edae9 100644 --- a/admin/terms/position.php +++ b/admin/terms/position.php @@ -3,7 +3,7 @@ function sportspress_position_term_init() { $name = __( 'Positions', 'sportspress' ); $singular_name = __( 'Position', 'sportspress' ); $lowercase_name = __( 'position', 'sportspress' ); - $object_type = array( 'sp_player', 'attachment' ); + $object_type = array( 'sp_player', 'sp_statistic', 'sp_metric', 'attachment' ); $labels = sportspress_get_term_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, @@ -14,6 +14,8 @@ function sportspress_position_term_init() { ); register_taxonomy( 'sp_position', $object_type, $args ); register_taxonomy_for_object_type( 'sp_position', 'sp_player' ); + register_taxonomy_for_object_type( 'sp_position', 'sp_statistic' ); + register_taxonomy_for_object_type( 'sp_position', 'sp_metric' ); register_taxonomy_for_object_type( 'sp_position', 'attachment' ); } add_action( 'init', 'sportspress_position_term_init' ); diff --git a/functions.php b/functions.php index 9b87afa8..c24613fe 100644 --- a/functions.php +++ b/functions.php @@ -1,575 +1,2005 @@ ID; - endif; - - $date = get_the_time( get_option('date_format'), $id ); - $time = get_the_time( get_option('time_format'), $id ); - $leagues = get_the_terms( $id, 'sp_league' ); - $seasons = get_the_terms( $id, 'sp_season' ); - - $data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time ); - - if ( $leagues ) - $data[ __( 'League', 'sportspress' ) ] = sportspress_array_value( $leagues, 0, '—' )->name; - - if ( $seasons ) - $data[ __( 'Season', 'sportspress' ) ] = sportspress_array_value( $seasons, 0, '—' )->name; - - - $output = '

' . __( 'Details', 'sportspress' ) . '

'; - - $output .= ''; - - $i = 0; - - foreach( $data as $label => $value ): - - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - - $i++; - - endforeach; - - $output .= '
' . $label . '' . $value . '
'; - - return $output; - +if ( !function_exists( 'sportspress_nonce' ) ) { + function sportspress_nonce() { + echo ''; } } -if ( !function_exists( 'sportspress_event_results' ) ) { - function sportspress_event_results( $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; +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; + } +} - $teams = (array)get_post_meta( $id, 'sp_team', false ); - $results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) ); - $result_labels = sportspress_get_var_labels( 'sp_result' ); +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; + } +} - $output = ''; +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; + } +} - // Initialize and check - $table_rows = ''; +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; + } +} - $i = 0; +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; + } +} - foreach( $results as $team_id => $result ): - if ( sportspress_array_value( $result, 'outcome', '-1' ) != '-1' ): +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; + } +} - unset( $result['outcome'] ); - - $table_rows .= ''; - - $table_rows .= '' . get_the_title( $team_id ) . ''; - - foreach( $result_labels as $key => $label ): - if ( $key == 'name' ) - continue; - if ( array_key_exists( $key, $result ) && $result[ $key ] != '' ): - $value = $result[ $key ]; - else: - $value = '—'; - endif; - $table_rows .= '' . $value . ''; - endforeach; - - $table_rows .= ''; - - $i++; +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; - endforeach; - - if ( ! empty( $table_rows ) ): - - $output .= '

' . __( 'Results', 'sportspress' ) . '

'; - - $output .= ''; - $output .= ''; - foreach( $result_labels as $key => $label ): - $output .= ''; - endforeach; - $output .= '' . '' . ''; - $output .= $table_rows; - $output .= '
' . __( 'Team', 'sportspress' ) . '' . $label . '
'; - + else: + return '—'; endif; - - return $output; - } } -if ( !function_exists( 'sportspress_event_players' ) ) { - function sportspress_event_players( $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; +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; - - $teams = (array)get_post_meta( $id, 'sp_team', false ); - $staff = (array)get_post_meta( $id, 'sp_staff', false ); - $stats = (array)get_post_meta( $id, 'sp_players', true ); - $statistic_labels = sportspress_get_var_labels( 'sp_statistic' ); - - $output = ''; - - foreach( $teams as $key => $team_id ): - if ( ! $team_id ) continue; - - // Get results for players in the team - $players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key ); - $data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) ); - - $output .= '

' . get_the_title( $team_id ) . '

'; - - $output .= '' . '' . ''; - - $output .= ''; - $output .= ''; - - foreach( $statistic_labels as $key => $label ): - $output .= ''; - endforeach; - - $output .= '' . '' . ''; - - $i = 0; - - foreach( $data as $player_id => $row ): - - if ( ! $player_id ) - continue; - - $output .= ''; - - $number = get_post_meta( $player_id, 'sp_number', true ); - - // Player number - $output .= ''; - - // Name as link - $permalink = get_post_permalink( $player_id ); - $name = get_the_title( $player_id ); - $output .= ''; - - foreach( $statistic_labels as $key => $label ): - if ( $key == 'name' ) - continue; - if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $value = $row[ $key ]; - else: - $value = 0; - endif; - $output .= ''; - endforeach; - - $output .= ''; - - $i++; - - endforeach; - - $output .= ''; - - if ( array_key_exists( 0, $data ) ): - - $output .= ''; - - $number = get_post_meta( $player_id, 'sp_number', true ); - - // Player number - $output .= ''; - $output .= ''; - - $row = $data[0]; - - foreach( $statistic_labels as $key => $label ): - if ( $key == 'name' ): - continue; - endif; - $output .= ''; - endforeach; - - $output .= ''; - - endif; - - $output .= '
#' . __( 'Player', 'sportspress' ) . '' . $label . '
' . $number . '' . '' . $name . '' . $value . '
 ' . __( 'Total', 'sportspress' ) . '' . sportspress_array_value( $row, $key, '—' ) . '
'; - - endforeach; - - return $output; - } } - -if ( !function_exists( 'sportspress_event_staff' ) ) { - function sportspress_event_staff( $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; +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; - - $staff = (array)get_post_meta( $id, 'sp_staff', false ); - - $output = ''; - - return $output; - } } - -if ( !function_exists( 'sportspress_event_venue' ) ) { - function sportspress_event_venue( $id ) { - - $venues = get_the_terms( $id, 'sp_venue' ); - - $output = ''; - - if ( ! $venues ) - return $output; - - foreach( $venues as $venue ): - - $t_id = $venue->term_id; - $term_meta = get_option( "taxonomy_$t_id" ); - - $address = sportspress_array_value( $term_meta, 'sp_address', '' ); - $latitude = sportspress_array_value( $term_meta, 'sp_latitude', 0 ); - $longitude = sportspress_array_value( $term_meta, 'sp_longitude', 0 ); - - $output .= '

' . $venue->name . '

'; - $output .= '
'; - - endforeach; - - return $output; - +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_league_table' ) ) { - function sportspress_league_table( $id = null, $args = '' ) { - - if ( ! $id ): - global $post; - $id = $post->ID; - 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( - 'number_label' => __( 'Pos', 'sportspress' ), - 'thumbnails' => 1, - 'thumbnail_size' => 'thumbnail' + 'show_option_all' => false, + 'show_option_none' => false, + 'taxonomy' => null, + 'name' => null, + 'selected' => null, + 'hide_empty' => false, + 'value' => 'slug', + ); + $args = array_merge( $defaults, $args ); + $terms = get_terms( $args['taxonomy'], $args ); + $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', + 'values' => 'post_name', + ); + $args = array_merge( $defaults, $args ); + $name = $args['name']; + unset( $args['name'] ); + $values = $args['values']; + unset( $args['values'] ); + $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 ); + $keys = array_keys( $parents ); + $values = array_reverse( array_values( $parents ) ); + if ( ! empty( $keys ) && ! empty( $values ) ): + $parents = array_combine( $keys, $values ); + foreach ( $parents as $parent ): + if ( !in_array( $parent, $ids ) ) + edit_post_link( get_the_title( $parent ), '', '', $parent ); + echo ' - '; + endforeach; + endif; + $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; + ?> +
+ +
    + $meta, 'number' => 0 ) ); + if ( empty( $posts ) ) + $posts = get_posts( array( 'post_type' => $meta, 'numberposts' => -1, 'post_per_page' => -1 ) ); + foreach ( $posts as $post ): + $parents = get_post_ancestors( $post ); + if ( $filter ): + $filter_values = (array)get_post_meta( $post->ID, $filter, false ); + $terms = (array)get_the_terms( $post->ID, 'sp_season' ); + foreach ( $terms as $term ): + if ( is_object( $term ) && property_exists( $term, 'term_id' ) ) + $filter_values[] = $term->term_id; + endforeach; + endif; + ?> +
  • +
  • ', sizeof( $parents ) ); ?> + +
', 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' ); + $options[ __( 'Outcomes', 'sportspress' ) ]['$last10'] = __( 'Last 10', 'sportspress' ); + break; + case 'column': + $options[ __( 'Columns', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_column' ); + break; + case 'statistic': + $options[ __( 'Player 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', ); - $r = wp_parse_args( $args, $defaults ); + $vars = get_posts( $args ); - $data = sportspress_get_league_table_data( $id ); - - $output = '' . '' . ''; - - // The first row should be column labels - $labels = $data[0]; - - // Remove the first row to leave us with the actual data - unset( $data[0] ); - - $output .= ''; - foreach( $labels as $key => $label ): - $output .= ''; + $output = array(); + foreach ( $vars as $var ): + $output[ $var->post_name ] = $var->post_title; endforeach; - $output .= '' . '' . ''; + return $output; + } +} - $i = 0; +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' + ); - foreach( $data as $team_id => $row ): - - $output .= ''; - - // Position as number - $output .= ''; - - // Thumbnail and name as link - $permalink = get_post_permalink( $team_id ); - if ( $r['thumbnails'] ): - $thumbnail = get_the_post_thumbnail( $team_id, $r['thumbnail_size'], array( 'class' => 'logo' ) ); - else: - $thumbnail = null; - endif; - $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); - $output .= ''; - - foreach( $labels as $key => $value ): - if ( $key == 'name' ) - continue; - $output .= ''; - endforeach; - - $output .= ''; - - $i++; + $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; - $output .= '' . '
' . $r['number_label'] . '' . $label . '
' . $i . '' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '
'; + return $output; + } +} + +if ( !function_exists( 'sportspress_edit_calendar_table' ) ) { + function sportspress_edit_calendar_table( $data = array() ) { + if ( empty( $data ) ): + printf( __( 'No %s found.', 'sportspress' ), __( 'events', 'sportspress' ) ); + return false; + endif; + ?> +
+ + + + + + + + + + + + + + + + + +
+ post_title; ?> + + ID ); ?> + + ID ); ?> +
+
+ +
+ + + + + + + + + + + $team_stats ): + if ( !$team_id ) continue; + $div = get_term( $team_id, 'sp_season' ); + ?> + + + $label ): + $value = sportspress_array_value( $team_stats, $column, '' ); + $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $team_id, array() ), $column, 0 ); + ?> + + + + + +
+ +
+
+ +
+ + + + + + + + + + + $player_stats ): + if ( !$player_id ) continue; + $div = get_term( $player_id, 'sp_season' ); + ?> + + + $label ): + $value = sportspress_array_value( $player_stats, $column, '' ); + $placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $player_id, array() ), $column, 0 ); + ?> + + + + + +
+ +
+
+ +
+ + + + + + + + + + + + $div_stats ): + if ( !$div_id ) continue; + $div = get_term( $div_id, 'sp_season' ); + ?> + + + + $label ): + $value = sportspress_array_value( sportspress_array_value( $data, $div_id, array() ), $column, 0 ); + ?> + + + + + +
+ > + + + '; + ?>
+
+ +
+ + + + + + + + + + + + $div_stats ): + if ( !$div_id || $div_id == 'statistics' ) continue; + $div = get_term( $div_id, 'sp_season' ); + ?> + + + + $label ): + ?> + + + + + +
+ name; ?> + + 'sp_team', + 'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']', + 'show_option_none' => __( '-- Select --', 'sportspress' ), + 'sort_order' => 'ASC', + 'sort_column' => 'menu_order', + 'selected' => $value, + 'values' => 'ID', + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'terms' => $league_id, + 'field' => 'id', + ), + array( + 'taxonomy' => 'sp_season', + 'terms' => $div_id, + 'field' => 'id', + ), + ), + ); + sportspress_dropdown_pages( $args ); + ?> + '; + ?>
+
+ +
+ + + + + + + + + + + + $team_results ): + if ( !$team_id ) continue; + ?> + + + $label ): + $value = sportspress_array_value( $team_results, $column, '' ); + ?> + + + + + + +
+ + + 'sp_outcome', + 'name' => 'sp_results[' . $team_id . '][outcome]', + 'show_option_none' => __( '-- Not set --', 'sportspress' ), + 'option_none_value' => 0, + 'sort_order' => 'ASC', + 'sort_column' => 'menu_order', + 'selected' => $value + ); + sportspress_dropdown_pages( $args ); + ?> +
+
+ __( '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 ( !function_exists( 'sportspress_team_columns' ) ) { - function sportspress_team_columns( $id = null ) { + if ( ! $team_id || ! $player_id ) + return '—'; - if ( ! $id ): - global $post; - $id = $post->ID; + $output = ''; + + return $output; + + } +} + +if ( !function_exists( 'sportspress_edit_event_players_table' ) ) { + function sportspress_edit_event_players_table( $columns = array(), $data = array(), $team_id ) { + ?> +
+ + + + + + + + + + + + + $player_statistics ): + if ( !$player_id ) continue; + $number = get_post_meta( $player_id, 'sp_number', true ); + ?> + + + + $label ): + $value = sportspress_array_value( $player_statistics, $column, '' ); + ?> + + + + + + + + + $label ): + $player_id = 0; + $player_statistics = sportspress_array_value( $data, 0, array() ); + $value = sportspress_array_value( $player_statistics, $column, '' ); + ?> + + + + + +
#
+ + + + +
  
+
+ __( 'Starting Lineup', 'sportspress' ), + 'sub' => __( 'Substitute', 'sportspress' ), + ); + + $output = ''; + + return $output; + + } +} + +if ( !function_exists( 'sportspress_post_adder' ) ) { + function sportspress_post_adder( $meta = 'post' ) { + $obj = get_post_type_object( $meta ); + ?> + + ' . $value . ''; + break; + case 'checkbox': + echo ''; + break; + default: + echo ''; + break; + endswitch; - $output = ''; + } +} - // Loop through data for each league - foreach ( $leagues as $league ): +if ( !function_exists( 'sportspress_get_eos_safe_slug' ) ) { + function sportspress_get_eos_safe_slug( $title, $post_id = 'var' ) { - $data = sportspress_get_team_columns_data( $id, $league->term_id ); + // String to lowercase + $title = strtolower( $title ); - if ( sizeof( $data ) <= 1 ) + // 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 ) { + + if ( str_replace( ' ', '', $equation ) == '$streak' ): + + // Return direct value + return sportspress_array_value( $vars, 'streak', 0 ); + + elseif ( str_replace( ' ', '', $equation ) == '$last10' ): + + // Return imploded string + $last10 = sportspress_array_value( $vars, 'last10', array( 0 ) ); + if ( array_sum( $last10 ) > 0 ): + return implode( '-', $last10 ); + else: + return '—'; + endif; + + else: + + // Remove unnecessary variables from vars before calculating + unset( $vars['streak'] ); + unset( $vars['last10'] ); + + endif; + + // 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_calendar_data' ) ) { + function sportspress_get_calendar_data( $post_id ) { + $leagues = get_the_terms( $post_id, 'sp_league' ); + $seasons = get_the_terms( $post_id, 'sp_season' ); + $venues = get_the_terms( $post_id, 'sp_venue' ); + + if ( ! $leagues || ! $seasons || ! $venues ) + return array(); + + $league_ids = array(); + foreach( $leagues as $league ): + $league_ids[] = $league->term_id; + endforeach; + + $season_ids = array(); + foreach( $seasons as $season ): + $season_ids[] = $season->term_id; + endforeach; + + $venue_ids = array(); + foreach( $venues as $venue ): + $venue_ids[] = $venue->term_id; + endforeach; + + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'post_date', + 'order' => 'ASC', + 'post_status' => 'any', + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_ids + ), + array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $season_ids + ), + array( + 'taxonomy' => 'sp_venue', + 'field' => 'id', + 'terms' => $venue_ids + ), + ), + ); + $events = get_posts( $args ); + + return $events; + + } +} + +if ( !function_exists( 'sportspress_get_team_columns_data' ) ) { + function sportspress_get_team_columns_data( $post_id, $league_id, $admin = false ) { + + $seasons = (array)get_the_terms( $post_id, 'sp_season' ); + $columns = (array)get_post_meta( $post_id, 'sp_columns', true ); + $leagues_seasons = sportspress_array_value( (array)get_post_meta( $post_id, 'sp_leagues_seasons', true ), $league_id, array() ); + + // 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' ); + + // Generate array of all season ids and season names + $div_ids = array(); + $season_names = array(); + foreach ( $seasons as $season ): + if ( is_object( $season ) && property_exists( $season, 'term_id' ) && property_exists( $season, 'name' ) ): + $div_ids[] = $season->term_id; + $season_names[ $season->term_id ] = $season->name; + endif; + endforeach; + + $data = array(); + + // Get all seasons populated with data where available + $data = sportspress_array_combine( $div_ids, sportspress_array_value( $columns, $league_id, array() ) ); + + // Get equations from column variables + $equations = sportspress_get_var_equations( 'sp_column' ); + + // Initialize placeholders array + $placeholders = array(); + + foreach ( $div_ids as $div_id ): + + $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last10' => null ); + + foreach ( $result_labels as $key => $value ): + $totals[ $key . 'for' ] = 0; + $totals[ $key . 'against' ] = 0; + endforeach; + + foreach ( $outcome_labels as $key => $value ): + $totals[ $key ] = 0; + endforeach; + + // Initialize streaks counter + $streak = array( 'name' => '', 'count' => 0, 'fire' => 1 ); + + // Initialize last 10 counter + $last10 = array(); + + // Add outcome types to last 10 counter + foreach( $outcome_labels as $key => $value ): + $last10[ $key ] = 0; + endforeach; + + // Get all events involving the team in current season + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'order' => 'ASC', + 'meta_query' => array( + array( + 'key' => 'sp_team', + 'value' => $post_id + ) + ), + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), + array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $div_id + ) + ) + ); + $events = get_posts( $args ); + + 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 ( $team_id == $post_id ): + if ( $key == 'outcome' ): + + // Increment events played and outcome count + if ( array_key_exists( $value, $totals ) ): + $totals['eventsplayed']++; + $totals[ $value ]++; + endif; + + if ( $value && $value != '-1' ): + + // Add to streak counter + if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $value ) ): + $streak['name'] = $value; + $streak['count'] ++; + else: + $streak['fire'] = 0; + endif; + + // Add to last 10 counter if sum is less than 10 + if ( array_key_exists( $value, $last10 ) && array_sum( $last10 ) < 10 ): + $last10[ $value ] ++; + endif; + + endif; + + else: + if ( array_key_exists( $key . 'for', $totals ) ): + $totals[ $key . 'for' ] += $value; + endif; + endif; + else: + if ( $key != 'outcome' ): + if ( array_key_exists( $key . 'against', $totals ) ): + $totals[ $key . 'against' ] += $value; + endif; + endif; + endif; + endforeach; + endforeach; + endforeach; + + // 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['streak'] = $outcome->post_title . $streak['count']; + endif; + + // Add last 10 to totals + $totals['last10'] = $last10; + + // Generate array of placeholder values for each league + $placeholders[ $div_id ] = array(); + foreach ( $equations as $key => $value ): + if ( $totals['eventsplayed'] > 0 ): + $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); + else: + $placeholders[ $div_id ][ $key ] = 0; + endif; + endforeach; + + endforeach; + + // Get columns from column variables + $columns = sportspress_get_var_labels( 'sp_column' ); + + // Merge the data and placeholders arrays + $merged = array(); + + foreach( $placeholders as $season_id => $season_data ): + + if ( ! sportspress_array_value( $leagues_seasons, $season_id, 0 ) ) continue; - if ( sizeof( $leagues ) > 1 ) - $output .= '

' . $league->name . '

'; + $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); - // The first row should be column labels - $labels = $data[0]; + // Add season name to row + $merged[ $season_id ] = array( + 'name' => $season_name + ); - // Remove the first row to leave us with the actual data - unset( $data[0] ); + foreach( $season_data as $key => $value ): - $output .= '' . '' . ''; + // Use static data if key exists and value is not empty, else use placeholder + if ( array_key_exists( $season_id, $data ) && array_key_exists( $key, $data[ $season_id ] ) && $data[ $season_id ][ $key ] != '' ): + $merged[ $season_id ][ $key ] = $data[ $season_id ][ $key ]; + else: + $merged[ $season_id ][ $key ] = $value; + endif; - foreach( $labels as $key => $label ): - $output .= ''; endforeach; - $output .= '' . '' . ''; + endforeach; - $i = 0; + if ( $admin ): + return array( $columns, $data, $placeholders, $merged, $leagues_seasons ); + else: + $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns ); + $merged[0] = $labels; + return $merged; + endif; - foreach( $data as $season_id => $row ): + } - $output .= ''; +} + +if ( !function_exists( 'sportspress_get_league_table_data' ) ) { + function sportspress_get_league_table_data( $post_id, $breakdown = false ) { + $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); + $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(); + + // Initialize last 10s counter + $last10s = array(); + + foreach ( $team_ids as $team_id ): + if ( ! $team_id ) + continue; + + // Initialize team streaks counter + $streaks[ $team_id ] = array( 'name' => '', 'count' => 0, 'fire' => 1 ); + + // Initialize team last 10 counter + $last10s[ $team_id ] = array(); + + // Add outcome types to team last 10 counter + foreach( $outcome_labels as $key => $value ): + $last10s[ $team_id ][ $key ] = 0; + endforeach; + + // Initialize team totals + $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 ); + + // Add static stats to placeholders + $placeholders[ $team_id ] = sportspress_array_value( $static, $div_id, array() ); + + endforeach; + + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'order' => 'ASC', + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), + 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 ): + + if ( ! in_array( $team_id, $team_ids ) ) + continue; + + foreach ( $team_result as $key => $value ): + + if ( $key == 'outcome' ): + + // Increment events played and outcome count + if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $value, $totals[ $team_id ] ) ): + $totals[ $team_id ]['eventsplayed']++; + $totals[ $team_id ][ $value ]++; + endif; + + if ( $value && $value != '-1' ): + + // Add to streak counter + if ( $streaks[ $team_id ]['fire'] && ( $streaks[ $team_id ]['name'] == '' || $streaks[ $team_id ]['name'] == $value ) ): + $streaks[ $team_id ]['name'] = $value; + $streaks[ $team_id ]['count'] ++; + else: + $streaks[ $team_id ]['fire'] = 0; + endif; + + // Add to last 10 counter if sum is less than 10 + if ( array_key_exists( $team_id, $last10s ) && array_key_exists( $value, $last10s[ $team_id ] ) && array_sum( $last10s[ $team_id ] ) < 10 ): + $last10s[ $team_id ][ $value ] ++; + endif; + + endif; + + else: + if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ): + $totals[ $team_id ][ $key . 'for' ] += $value; + foreach( $results as $other_team_id => $other_result ): + if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ): + $totals[ $team_id ][ $key . 'against' ] += sportspress_array_value( $other_result, $key, 0 ); + endif; + endforeach; + endif; + endif; - foreach( $labels as $key => $value ): - $output .= ''; endforeach; - $output .= ''; - - $i++; - endforeach; - $output .= '' . '
' . $label . '
' . sportspress_array_value( $row, $key, '—' ) . '
'; - - endforeach; - return $output; + foreach ( $streaks as $team_id => $streak ): + // Compile streaks counter and add to totals + if ( $streak['name'] ): + $args = array( + 'name' => $streak['name'], + 'post_type' => 'sp_outcome', + 'post_status' => 'publish', + 'posts_per_page' => 1 + ); + $outcomes = get_posts( $args ); - } -} - -if ( !function_exists( 'sportspress_player_list' ) ) { - function sportspress_player_list( $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; - endif; - - $data = sportspress_get_player_list_data( $id ); - - $output = '' . '' . ''; - - // The first row should be column labels - $labels = $data[0]; - - // Remove the first row to leave us with the actual data - unset( $data[0] ); - - $output .= ''; - foreach( $labels as $key => $label ): - $output .= ''; + if ( $outcomes ): + $outcome = $outcomes[0]; + $totals[ $team_id ]['streak'] = $outcome->post_title . $streak['count']; + else: + $totals[ $team_id ]['streak'] = '—'; + endif; + else: + $totals[ $team_id ]['streak'] = '—'; + endif; endforeach; - $output .= '' . '' . ''; - - $i = 0; - - foreach( $data as $player_id => $row ): - - $output .= ''; - - // Player number - $number = get_post_meta( $player_id, 'sp_number', true ); - $output .= ''; - - // Name as link - $permalink = get_post_permalink( $player_id ); - $name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) ); - $output .= ''; - - foreach( $labels as $key => $value ): - if ( $key == 'name' ) - continue; - $output .= ''; - endforeach; - - $output .= ''; - - $i++; - + foreach ( $last10s as $team_id => $last10 ): + // Add last 10 to totals + $totals[ $team_id ]['last10'] = $last10; endforeach; - $output .= '' . '
#' . $label . '
' . ( $number ? $number : ' ' ) . '' . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '
'; - - return $output; - - } -} - -if ( !function_exists( 'sportspress_player_metrics' ) ) { - function sportspress_player_metrics( $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; - endif; - - global $sportspress_countries; - - $number = get_post_meta( $id, 'sp_number', true ); - $nationality = get_post_meta( $id, 'sp_nationality', true ); - $metrics = sportspress_get_player_metrics_data( $id ); - - $flag_image = ''; - - $common = array( - __( 'Number', 'sportspress' ) => $number, - __( 'Nationality', 'sportspress' ) => $flag_image . ' ' . sportspress_array_value( $sportspress_countries, $nationality, '—' ), + $args = array( + 'post_type' => 'sp_column', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' ); + $stats = get_posts( $args ); - $data = array_merge( $common, $metrics ); + $columns = array(); + $priorities = array(); - $output = '' . ''; + foreach ( $stats as $stat ): - $i = 0; + // Get post meta + $meta = get_post_meta( $stat->ID ); - foreach( $data as $label => $value ): + // Add equation to object + $stat->equation = sportspress_array_value( sportspress_array_value( $meta, 'sp_equation', array() ), 0, 0 ); - $output .= ''; + // Add column name to columns + $columns[ $stat->post_name ] = $stat->post_title; - $i++; + // 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; - $output .= '' . '
' . $label . '' . $value . '
'; + // 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; - return $output; - - } -} - -if ( !function_exists( 'sportspress_player_league_statistics' ) ) { - function sportspress_player_league_statistics( $league_id, $id = null ) { - - if ( ! $id ): - global $post; - $id = $post->ID; - endif; - - $data = sportspress_get_player_statistics_data( $id, $league_id ); - - // The first row should be column labels - $labels = $data[0]; - - // Remove the first row to leave us with the actual data - unset( $data[0] ); - - $output = '' . '' . ''; - - foreach( $labels as $key => $label ): - $output .= ''; + 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; - $output .= '' . '' . ''; + // Merge the data and placeholders arrays + $merged = array(); - $i = 0; + foreach( $placeholders as $team_id => $team_data ): - foreach( $data as $season_id => $row ): + // Add team name to row + $merged[ $team_id ] = array(); - $output .= ''; + $team_data['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; - foreach( $labels as $key => $value ): - $output .= ''; endforeach; - $output .= ''; - - $i++; + // 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; - $output .= '' . '
' . $label . '
' . sportspress_array_value( $row, $key, '—' ) . '
'; - - return $output; + if ( $breakdown ): + return array( $columns, $data, $placeholders, $merged ); + else: + $labels = array_merge( array( 'name' => __( 'Team', 'sportspress' ) ), $columns ); + $merged[0] = $labels; + return $merged; + endif; } } -if ( !function_exists( 'sportspress_player_statistics' ) ) { - function sportspress_player_statistics( $id = null ) { +if ( !function_exists( 'sportspress_get_player_list_data' ) ) { + function sportspress_get_player_list_data( $post_id, $admin = false ) { + $league_id = sportspress_get_the_term_id( $post_id, 'sp_league', 0 ); + $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 ); - if ( ! $id ): - global $post; - $id = $post->ID; + // 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( $league_id, $static ) && array_key_exists( $div_id, $static[ $league_id ] ) ): + $placeholders[ $player_id ] = $static[ $league_id ][ $div_id ]; + endif; + endforeach; + + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), + 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 ): + + if ( ! $player_id || ! in_array( $player_id, $player_ids ) ) + continue; + + // 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', + ); + $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, '' ) == '' ): + + // Reflect totals + $placeholders[ $player_id ][ $statistic->post_name ] = sportspress_array_value( sportspress_array_value( $totals, $player_id, array() ), $statistic->post_name, 0 ); + + endif; + endforeach; + endforeach; + + // Merge the data and placeholders arrays + $merged = array(); + + foreach( $placeholders as $player_id => $player_data ): + + // Add player 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 ( $admin ): + return array( $columns, $tempdata, $placeholders, $merged ); + else: + $labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns ); + $merged[0] = $labels; + return $merged; + endif; + } +} + +if ( !function_exists( 'sportspress_get_player_metrics_data' ) ) { + function sportspress_get_player_metrics_data( $post_id ) { + + $metrics = (array)get_post_meta( $post_id, 'sp_metrics', true ); + + // Get labels from metric variables + $metric_labels = (array)sportspress_get_var_labels( 'sp_metric' ); + + $data = array(); + + foreach( $metric_labels as $key => $value ): + + $data[ $value ] = sportspress_array_value( $metrics, $key, ' ' ); + + endforeach; + + return $data; + + } +} + +if ( !function_exists( 'sportspress_get_player_statistics_data' ) ) { + function sportspress_get_player_statistics_data( $post_id, $league_id, $admin = false ) { + + $seasons = (array)get_the_terms( $post_id, 'sp_season' ); + $stats = (array)get_post_meta( $post_id, 'sp_statistics', true ); + $seasons_teams = sportspress_array_value( (array)get_post_meta( $post_id, 'sp_leagues', true ), $league_id, array() ); + + // Get labels from statistic variables + $statistic_labels = (array)sportspress_get_var_labels( 'sp_statistic' ); + + // Generate array of all season ids and season names + $div_ids = array(); + $season_names = array(); + foreach ( $seasons as $season ): + if ( is_object( $season ) && property_exists( $season, 'term_id' ) && property_exists( $season, 'name' ) ): + $div_ids[] = $season->term_id; + $season_names[ $season->term_id ] = $season->name; + endif; + endforeach; + + $tempdata = array(); + + // Get all seasons populated with stats where available + $tempdata = sportspress_array_combine( $div_ids, sportspress_array_value( $stats, $league_id, array() ) ); + + // Get equations from statistics variables + $equations = sportspress_get_var_equations( 'sp_statistic' ); + + foreach ( $div_ids as $div_id ): + + $team_id = sportspress_array_value( $seasons_teams, $div_id, '-1' ); + + $totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 ); + + foreach ( $statistic_labels as $key => $value ): + $totals[ $key ] = 0; + endforeach; + + $args = array( + 'post_type' => 'sp_event', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'meta_query' => array( + 'relation' => 'AND', + array( + 'key' => 'sp_team', + 'value' => $team_id + ), + array( + 'key' => 'sp_player', + 'value' => $post_id + ) + ), + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league_id + ), + array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $div_id + ) + ) + ); + $events = get_posts( $args ); + + foreach( $events as $event ): + $totals['eventsattended']++; + $totals['eventsplayed']++; + $team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true ); + if ( array_key_exists( $team_id, $team_statistics ) ): + $players = sportspress_array_value( $team_statistics, $team_id, array() ); + if ( array_key_exists( $post_id, $players ) ): + $player_statistics = sportspress_array_value( $players, $post_id, array() ); + foreach ( $player_statistics as $key => $value ): + if ( array_key_exists( $key, $totals ) ): + $totals[ $key ] += $value; + endif; + endforeach; + endif; + endif; + endforeach; + + // Generate array of placeholder values for each league + $placeholders[ $div_id ] = array(); + foreach ( $equations as $key => $value ): + + if ( empty( $value ) ): + + // Reflect totals + $placeholders[ $div_id ][ $key ] = sportspress_array_value( $totals, $key, 0 ); + + else: + + // Calculate value + if ( sizeof( $events ) > 0 ): + $placeholders[ $div_id ][ $key ] = sportspress_solve( $value, $totals ); + else: + $placeholders[ $div_id ][ $key ] = 0; + endif; + + endif; + + endforeach; + + endforeach; + + // Get columns from statistics variables + $columns = sportspress_get_var_labels( 'sp_statistic' ); + + // Merge the data and placeholders arrays + $merged = array(); + + foreach( $placeholders as $season_id => $season_data ): + + $team_id = sportspress_array_value( $seasons_teams, $season_id, array() ); + + if ( ! $team_id || $team_id == '-1' ) + continue; + + $team_name = get_the_title( $team_id ); + + $season_name = sportspress_array_value( $season_names, $season_id, ' ' ); + + // Add season name to row + $merged[ $season_id ] = array( + 'name' => $season_name, + 'team' => $team_name + ); + + foreach( $season_data as $key => $value ): + + // Use static data if key exists and value is not empty, else use placeholder + if ( array_key_exists( $season_id, $tempdata ) && array_key_exists( $key, $tempdata[ $season_id ] ) && $tempdata[ $season_id ][ $key ] != '' ): + $merged[ $season_id ][ $key ] = $tempdata[ $season_id ][ $key ]; + else: + $merged[ $season_id ][ $key ] = $value; + endif; + + endforeach; + + endforeach; + + if ( $admin ): + return array( $columns, $tempdata, $placeholders, $merged, $seasons_teams ); + else: + $labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ) ), $columns ); + $merged[0] = $labels; + return $merged; endif; - $leagues = get_the_terms( $id, 'sp_league' ); - - $output = ''; - - // Loop through statistics for each league - foreach ( $leagues as $league ): - - if ( sizeof( $leagues ) > 1 ) - $output .= '

' . $league->name . '

'; - - $output .= sportspress_player_league_statistics( $league->term_id, $id ); - - endforeach; - - return $output; - + } +} + +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/readme.txt b/readme.txt index 71d867a1..6f73ce82 100644 --- a/readme.txt +++ b/readme.txt @@ -12,7 +12,15 @@ SportsPress is a flexible sports management plugin that adds team management fun == Changelog == = 0.1.3 = -* Feature - Lots of features. To be updated. +* Fix - Style conflict with Foundation framework in table columns. +* Feature - HTML output added to custom post types with data table sorting. +* Feature - Enable metrics and statistics per player position. +* Feature - Save team played per season per league in player edit screen. +* Feature - Give teams the option to show and hide past seasons. +* Feature - Venues, Seasons, and Leagues added as taxonomies. +* Feature - Add L10 counter to report last 10 outcomes. +* Feature - Add STRK counter to report current outcome streak. +* Localization - Add country names in Czech, German, Spanish, French, Italian, Japanese, Polish, Russian, and Slovak. = 0.1.2 = * Tweak - Use custom post types for metrics and statistics configuration. diff --git a/sportspress.php b/sportspress.php index 52473d19..6562f26a 100644 --- a/sportspress.php +++ b/sportspress.php @@ -32,9 +32,22 @@ include_once dirname( __FILE__ ) . '/admin/globals/countries.php'; include_once dirname( __FILE__ ) . '/admin/globals/sports.php'; // Functions -require_once dirname( __FILE__ ) . '/admin-functions.php'; require_once dirname( __FILE__ ) . '/functions.php'; +// Templates +require_once dirname( __FILE__ ) . '/admin/templates/event-details.php'; +require_once dirname( __FILE__ ) . '/admin/templates/event-players.php'; +require_once dirname( __FILE__ ) . '/admin/templates/event-results.php'; +require_once dirname( __FILE__ ) . '/admin/templates/event-staff.php'; +require_once dirname( __FILE__ ) . '/admin/templates/event-venue.php'; +require_once dirname( __FILE__ ) . '/admin/templates/events-calendar.php'; +require_once dirname( __FILE__ ) . '/admin/templates/league-table.php'; +require_once dirname( __FILE__ ) . '/admin/templates/player-league-statistics.php'; +require_once dirname( __FILE__ ) . '/admin/templates/player-list.php'; +require_once dirname( __FILE__ ) . '/admin/templates/player-metrics.php'; +require_once dirname( __FILE__ ) . '/admin/templates/player-statistics.php'; +require_once dirname( __FILE__ ) . '/admin/templates/team-columns.php'; + // Settings include dirname( __FILE__ ) . '/admin/settings/settings.php' ; @@ -84,6 +97,7 @@ require_once dirname( __FILE__ ) . '/admin/hooks/sanitize-title.php'; require_once dirname( __FILE__ ) . '/admin/hooks/the-content.php'; require_once dirname( __FILE__ ) . '/admin/hooks/wp-insert-post-data.php'; require_once dirname( __FILE__ ) . '/admin/hooks/plugin-action-links.php'; +require_once dirname( __FILE__ ) . '/admin/hooks/post-updated-messages.php'; // Register activation hook require_once dirname( __FILE__ ) . '/admin/hooks/register-activation-hook.php';