$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_cpt_labels' ) ) { function sp_cpt_labels( $name, $singular_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' ), $name ), 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $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 ) { $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' ), $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)' ); 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 ) ); ?>
0, 'posts_per_page' => -1 ), (array)$args ); $posts = (array)get_posts( $args ); foreach( $posts as $post ): $post->sp_team = get_post_meta( $post->ID, 'sp_team', false ); $post->sp_team_index = array_search( $args['meta_value'], $post->sp_team ); $post->sp_result = get_post_meta( $post->ID, 'sp_result', false ); endforeach; switch ($post_type): case 'sp_team': $row = array( sizeof( $posts ), sizeof( array_filter( $posts, function( $var ) { return max( $var->sp_result ) == $var->sp_result[ $var->sp_team_index ]; } ) ), 99, 99, 93, 99, 99, 99 ); break; default: $row = array(); break; endswitch; return $row; } } if ( !function_exists( 'sp_get_stats' ) ) { function sp_get_stats( $post_id, $set_id = 0, $subset_id = 0, $slug = 'sp_stats' ) { if ( isset( $post_id ) && $post_id ): $stats = (array)get_post_meta( $post_id, $slug, true ); $set = sp_array_value( $stats, $set_id, array() ); $subset = sp_array_value( $set, $subset_id, array() ); // If empty columns exist in subset if ( empty( $subset ) || in_array( '', $subset ) ): // If subset is total row if ( $subset_id == 0 ): // Get fallback if empty columns exist in row foreach ( $set as $index => $row ): if ( !$index ) continue; if ( in_array( '', $row ) ): echo 'shit!'; endif; endforeach; // Add values from each row where missing in total foreach( $subset as $key => $value ): if ( $value != '' ) continue; foreach ( $set as $row ): $value += $row[ $key ]; endforeach; $subset[ $key ] = $value; endforeach; else: // Get current post type $post_type = get_post_type( $post_id ); // Get fallback values switch ( $post_type ): // Teams: all events attended in the league case 'sp_team': $args = array( 'post_type' => 'sp_event', 'meta_key' => 'sp_team', 'meta_value' => $post_id, 'taxonomy' => 'sp_league', 'terms' => $subset_id ); $fallback = sp_get_stats_row( $args ); break; endswitch; // Merge fallback values with current subset $subset = array_merge( $fallback, $subset ); endif; endif; return $subset; else: return array(); endif; } } if ( !function_exists( 'sp_stats_table' ) ) { function sp_stats_table( $stats = array(), $placeholders = array(), $index = 0, $columns = array( 'Name' ), $total = true, $rowtype = 'post', $slug = 'sp_stats' ) { global $pagenow; if ( !is_array( $stats ) ) $stats = array(); ?> $values ): if ( !$key ) continue; ?>
name;; break; endswitch; if ( empty( $title ) ) $title = __( '(no title)' ); echo $title; ?>

+ labels->singular_name ); ?>