$max_depth ) $max_depth = $depth; endif; endforeach; return $max_depth; else: return 0; endif; } } if ( !function_exists( 'sp_array_between' ) ) { function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) { $keys = array_keys( $array, $delimiter ); if ( array_key_exists( $index, $keys ) ): $offset = $keys[ $index ]; $end = sizeof( $array ); if ( array_key_exists( $index + 1, $keys ) ) $end = $keys[ $index + 1 ]; $length = $end - $offset; $array = array_slice( $array, $offset, $length ); endif; return $array; } } if ( !function_exists( 'sp_array_value' ) ) { function sp_array_value( $arr = array(), $key = 0, $default = null ) { if ( is_array( $arr ) && array_key_exists( $key, $arr ) ) $subset = $arr[ $key ]; else $subset = $default; return $subset; } } if ( !function_exists( 'sp_array_combine' ) ) { function sp_array_combine( $keys = array(), $values = array() ) { $output = array(); foreach ( $keys as $key ): if ( is_array( $values ) && array_key_exists( $key, $values ) ) $output[ $key ] = $values[ $key ]; else $output[ $key ] = array(); endforeach; return $output; } } if ( !function_exists( 'sp_num_to_letter' ) ) { function sp_num_to_letter( $num, $uppercase = false ) { $num -= 0; $letter = chr( ( $num % 26 ) + 97 ); $letter .= ( floor( $num / 26 ) > 0 ) ? str_repeat( $letter, floor( $num / 26 ) ) : ''; return ( $uppercase ? strtoupper( $letter ) : $letter ); } } if ( !function_exists( 'sp_cpt_labels' ) ) { function sp_cpt_labels( $name, $singular_name, $lowercase_name = null ) { if ( !$lowercase_name ) $lowercase_name = $name; $labels = array( 'name' => $name, 'singular_name' => $singular_name, 'all_items' => sprintf( __( 'All %s', 'sportspress' ), $name ), 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ), 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ), 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ), 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ), 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ), 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':' ); return $labels; } } if ( !function_exists( 'sp_tax_labels' ) ) { function sp_tax_labels( $name, $singular_name, $lowercase_name = null ) { if ( !$lowercase_name ) $lowercase_name = $name; $labels = array( 'name' => $name, 'singular_name' => $singular_name, 'all_items' => sprintf( __( 'All %s', 'sportspress' ), $name ), 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ), 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ), 'update_item' => sprintf( __( 'Update %s', 'sportspress' ), $singular_name ), 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ), 'new_item_name' => sprintf( __( 'New %s Name', 'sportspress' ), $singular_name ), 'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':', 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ) ); return $labels; } } if ( !function_exists( 'sp_get_the_term_id' ) ) { function sp_get_the_term_id( $post_id, $taxonomy, $index ) { $terms = get_the_terms( $post_id, $taxonomy ); if ( is_array( $terms ) && array_key_exists( $index, $terms ) ): $term = $terms[0]; if ( is_object( $term ) && property_exists( $term, 'term_id' ) ) return $term->term_id; else return 0; else: return 0; endif; } } if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { function sp_dropdown_taxonomies( $args = array() ) { $defaults = array( 'show_option_all' => false, 'show_option_none' => false, 'taxonomy' => null, 'name' => null, 'selected' => null ); $args = array_merge( $defaults, $args ); $terms = get_terms( $args['taxonomy'] ); $name = ( $args['name'] ) ? $args['name'] : $args['taxonomy']; if ( $terms ) { printf( '' ); } } } if ( !function_exists( 'sp_the_posts' ) ) { function sp_the_posts( $post_id = null, $meta = 'post', $before = '', $sep = ', ', $after = '', $delimiter = ' - ' ) { 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; if ( !empty( $before ) ): if ( is_array( $before ) && array_key_exists( $i, $before ) ) echo $before[ $i ] . ' - '; else echo $before; endif; $parents = get_post_ancestors( $id ); $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) ); foreach ( $parents as $parent ): if ( !in_array( $parent, $ids ) ) edit_post_link( get_the_title( $parent ), '', '', $parent ); echo $delimiter; endforeach; $title = get_the_title( $id ); if ( empty( $title ) ) $title = __( '(no title)', 'sportspress' ); edit_post_link( $title, '', '', $id ); if ( !empty( $after ) ): if ( is_array( $after ) ): if ( array_key_exists( $i, $after ) && $after[ $i ] != '' ): echo ' - ' . $after[ $i ]; endif; else: echo $after; endif; endif; if ( ++$i !== $count ) echo $sep; endforeach; endif; } } if ( !function_exists( 'sp_post_checklist' ) ) { function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) { if ( ! isset( $post_id ) ) global $post_id; ?>
', sizeof( $parents ) ); ?>
-1 ), (array)$args ); $posts = (array)get_posts( $args ); // Equation Operating System $eos = new eqEOS(); $vars = array(); $stats_settings = get_option( 'sportspress_stats' ); // Get dynamic stats switch ($post_type): case 'sp_team': // Get stats settings columns $columns = sp_get_eos_rows( $stats_settings['event'] ); // Setup variables $results = array(); foreach ( $columns as $key => $value ): $column = explode( ':', $value ); $var_name = preg_replace("/[^A-Za-z0-9 ]/", '', sp_array_value( $column, 1 ) ); $results[] = $var_name; $vars[ $var_name ] = 0; endforeach; foreach( $posts as $post ): // Add object properties needed for retreiving event stats $post->sp_team = get_post_meta( $post->ID, 'sp_team', false ); $post->sp_team_index = array_search( $args['meta_query'][0]['value'], $post->sp_team ); $post->sp_result = get_post_meta( $post->ID, 'sp_result', false ); $post->sp_results = sp_array_value( sp_array_value( sp_array_value( get_post_meta( $post->ID, 'sp_results', false ), 0, array() ), 0, array() ), $args['meta_query'][0]['value'], array() ); // Add event stats to vars as sum foreach( $results as $key => $value ): if ( !array_key_exists( $value, $vars ) ) $vars[ $value ] = 0; $vars[ $value ] += sp_array_value( $post->sp_results, $key, 0 ); endforeach; endforeach; // All events attended by the team $vars['appearances'] = sizeof( $posts ); // Events with a aesult value greater than at least one competitor $vars['greater'] = sizeof( array_filter( $posts, function( $post ) { return array_count_values( $post->sp_result ) > 1 && max( $post->sp_result ) == $post->sp_result[ $post->sp_team_index ] && min( $post->sp_result ) < $post->sp_result[ $post->sp_team_index ]; } ) ); // Events with a aesult value equal to all competitors $vars['equal'] = sizeof( array_filter( $posts, function( $post ) { return max( $post->sp_result ) == min( $post->sp_result ); } ) ); // Events with a aesult value less than at least one competitor $vars['less'] = sizeof( array_filter( $posts, function( $post ) { return array_count_values( $post->sp_result ) > 1 && min( $post->sp_result ) == $post->sp_result[ $post->sp_team_index ] && max( $post->sp_result ) > $post->sp_result[ $post->sp_team_index ]; } ) ); // Sum of the team's result values $vars['for'] = 0; foreach( $posts as $post ): $vars['for'] += $post->sp_result[ $post->sp_team_index ]; endforeach; // Sum of opposing result values $vars['against'] = 0; foreach( $posts as $post ): $result = $post->sp_result; unset( $result[ $post->sp_team_index ] ); $vars['against'] += array_sum( $result ); endforeach; // Get EOS array $rows = sp_get_eos_rows( $stats_settings['team'] ); break; case 'sp_player': // Get stats settings keys $keys = sp_get_eos_keys( $stats_settings['player'] ); // Add object properties needed for retreiving event stats foreach( $posts as $post ): $post->sp_player = get_post_meta( $post->ID, 'sp_team', false ); $post->sp_player_index = array_search( $args['meta_query'][0]['value'], $post->sp_player ); endforeach; // Create array of event stats columns $columns = sp_get_eos_rows( get_option( 'sp_event_stats_columns' ) ); foreach ( $columns as $key => $value ): $row = explode( ':', $value ); $var_name = strtolower( preg_replace( '~[^\p{L}]++~u', '', end( $row ) ) ); $vars[ $var_name ] = 0; $stats_keys[ $key ] = $var_name; endforeach; // Populate columns with player stats from events foreach ( $posts as $post ): $team_stats = get_post_meta( $post->ID, 'sp_stats', true ); foreach ( $team_stats as $team_id => $stat ): if ( array_key_exists( 1, $args['meta_query'] ) && $team_id != sp_array_value( $args['meta_query'][1], 'value', 0 ) ) continue; $player_id = sp_array_value( $args['meta_query'][0], 'value', 0 ); if ( !array_key_exists( $player_id, $stat ) ) continue; foreach ( $stat[ $player_id ] as $key => $value ): if ( !array_key_exists( $key, $stats_keys ) || !array_key_exists( $stats_keys[ $key ], $vars ) ) continue; $vars[ $stats_keys[ $key ] ] += $value; endforeach; endforeach; endforeach; // Add appearances event count to vars $vars['appearances'] = sizeof( $posts ); // Get EOS array $rows = sp_get_eos_rows( get_option( 'sp_player_stats_columns' ) ); break; default: $rows = array(); break; endswitch; // Get dynamic stats $dynamic = array(); foreach ( $rows as $key => $value ): $row = explode( ':', $value ); $dynamic[ $key ] = $eos->solveIF( sp_array_value( $row, 1, '$appearances'), $vars ); endforeach; if ( $static ): // Get static stats $static = (array)get_post_meta( $args['meta_query'][0]['value'], 'sp_stats', true ); $table = sp_array_value( $static, 0, array() ); if ( array_key_exists( 'tax_query', $args ) ) $row_id = $args['tax_query'][0]['terms']; else $row_id = 0; $static = sp_array_value( $table, $row_id, array() ); // Combine static and dynamic stats $output = array_filter( $static ) + $dynamic; ksort( $output ); else: $output = $dynamic; endif; return $output; } } if ( !function_exists( 'sp_stats_table' ) ) { function sp_stats_table( $stats = array(), $placeholders = array(), $index = 0, $columns = array(), $total = true, $rowtype = 'post', $slug = 'sp_stats' ) { global $pagenow; if ( !is_array( $stats ) ) $stats = array( __( 'Name', 'sportspress' ) ); ?> $values ): if ( !$key ) continue; ?>
name; break; endswitch; if ( empty( $title ) ) $title = __( '(no title)' ); echo $title; ?>

+ labels->singular_name ); ?>

' . $value . ''; break; default: echo ''; break; endswitch; } } ?>