diff --git a/event.php b/admin/post-types/event.php similarity index 98% rename from event.php rename to admin/post-types/event.php index 472368ca..16ab2cda 100644 --- a/event.php +++ b/admin/post-types/event.php @@ -12,8 +12,9 @@ function sp_event_cpt_init() { 'supports' => array( 'title', 'author', 'comments' ), 'register_meta_box_cb' => 'sp_event_meta_init', 'rewrite' => array( 'slug' => 'event' ), - 'menu_position' => 44 + 'menu_position' => 42 ); + $args['labels']['menu_name'] = __( 'SportsPress', 'sportspress' ); register_post_type( 'sp_event', $args ); } add_action( 'init', 'sp_event_cpt_init' ); @@ -31,9 +32,9 @@ function sp_event_meta_init() { remove_meta_box( 'submitdiv', 'sp_event', 'side' ); add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' ); - add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' ); - add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' ); add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_event_stats_meta', 'sp_event', 'normal', 'high' ); + add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' ); + add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' ); } function sp_event_team_meta( $post ) { diff --git a/list.php b/admin/post-types/list.php similarity index 100% rename from list.php rename to admin/post-types/list.php diff --git a/admin/post-types/metric.php b/admin/post-types/metric.php new file mode 100644 index 00000000..ad969bed --- /dev/null +++ b/admin/post-types/metric.php @@ -0,0 +1,24 @@ + $name, + 'labels' => $labels, + 'public' => true, + 'show_in_nav_menus' => false, + 'hierarchical' => false, + 'supports' => array( 'title', 'page-attributes' ), + 'register_meta_box_cb' => 'sp_metric_meta_init', + 'rewrite' => array( 'slug' => 'metric' ), + 'show_in_menu' => 'edit.php?post_type=sp_player' + ); + register_post_type( 'sp_metric', $args ); +} +add_action( 'init', 'sp_metric_cpt_init' ); + +function sp_metric_meta_init() { +} +?> \ No newline at end of file diff --git a/player.php b/admin/post-types/player.php similarity index 99% rename from player.php rename to admin/post-types/player.php index 49ae292b..314edb48 100644 --- a/player.php +++ b/admin/post-types/player.php @@ -12,7 +12,7 @@ function sp_player_cpt_init() { 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sp_player_meta_init', 'rewrite' => array( 'slug' => 'player' ), - 'menu_position' => 45 + 'menu_position' => 44 ); register_post_type( 'sp_player', $args ); } diff --git a/staff.php b/admin/post-types/staff.php similarity index 98% rename from staff.php rename to admin/post-types/staff.php index 60e5f147..27b25de8 100644 --- a/staff.php +++ b/admin/post-types/staff.php @@ -12,7 +12,7 @@ function sp_staff_cpt_init() { 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sp_staff_meta_init', 'rewrite' => array( 'slug' => 'staff' ), - 'menu_position' => 46 + 'menu_position' => 45 ); register_post_type( 'sp_staff', $args ); } diff --git a/admin/post-types/stat.php b/admin/post-types/stat.php new file mode 100644 index 00000000..fadfec98 --- /dev/null +++ b/admin/post-types/stat.php @@ -0,0 +1,100 @@ + $name, + 'labels' => $labels, + 'public' => true, + 'show_in_nav_menus' => false, + 'hierarchical' => false, + 'supports' => array( 'title', 'page-attributes' ), + 'register_meta_box_cb' => 'sp_stat_meta_init', + 'rewrite' => array( 'slug' => 'stat' ), + 'show_in_menu' => 'edit.php?post_type=sp_team' + ); + register_post_type( 'sp_stat', $args ); +} +add_action( 'init', 'sp_stat_cpt_init' ); + +function sp_stat_edit_columns() { + $columns = array( + 'cb' => '', + 'title' => __( 'Label', 'sportspress' ), + 'sp_sport' => __( 'Sport', 'sportspress' ), + 'sp_equation' => __( 'Equation', 'sportspress' ), + ); + return $columns; +} +add_filter( 'manage_edit-sp_stat_columns', 'sp_stat_edit_columns' ); + +function sp_stat_meta_init() { + add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_stat_equation_meta', 'sp_stat', 'normal', 'high' ); +} + +function sp_stat_equation_meta( $post ) { + $args = array( + 'post_type' => 'sp_stat', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'exclude' => $post->ID + ); + $sports = get_the_terms( $post->ID, 'sp_sport' ); + if ( ! empty( $sports ) ): + $terms = array(); + foreach ( $sports as $sport ): + $terms[] = $sport->slug; + endforeach; + $args['tax_query'] = array( + array( + 'taxonomy' => 'sp_sport', + 'field' => 'slug', + 'terms' => $terms + ) + ); + endif; + $stats = get_posts( $args ); + ?> +
+

+ +

+
+ \ No newline at end of file diff --git a/table.php b/admin/post-types/table.php similarity index 100% rename from table.php rename to admin/post-types/table.php diff --git a/team.php b/admin/post-types/team.php similarity index 100% rename from team.php rename to admin/post-types/team.php diff --git a/division.php b/admin/terms/div.php similarity index 87% rename from division.php rename to admin/terms/div.php index ab233d47..5ae38446 100644 --- a/division.php +++ b/admin/terms/div.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/position.php b/admin/terms/pos.php similarity index 64% rename from position.php rename to admin/terms/pos.php index 79632b96..fe36e3de 100644 --- a/position.php +++ b/admin/terms/pos.php @@ -1,5 +1,5 @@ $labels, 'public' => true, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'position' ), + 'rewrite' => array( 'slug' => 'position' ) ); register_taxonomy( 'sp_pos', $object_type, $args ); + register_taxonomy_for_object_type( 'sp_pos', 'sp_player' ); + register_taxonomy_for_object_type( 'sp_pos', 'sp_staff' ); } -add_action( 'init', 'sp_pos_tax_init' ); +add_action( 'init', 'sp_pos_term_init' ); ?> \ No newline at end of file diff --git a/admin/terms/sport.php b/admin/terms/sport.php new file mode 100644 index 00000000..ff2c0f5a --- /dev/null +++ b/admin/terms/sport.php @@ -0,0 +1,18 @@ + $name, + 'labels' => $labels, + 'public' => true, + 'hierarchical' => true, + 'rewrite' => array( 'slug' => 'sport' ) + ); + register_taxonomy( 'sp_sport', $object_type, $args ); +} +add_action( 'init', 'sp_sport_term_init' ); +?> \ No newline at end of file diff --git a/sportspress-admin.css b/assets/css/admin.css similarity index 99% rename from sportspress-admin.css rename to assets/css/admin.css index 05c084ad..980df0bd 100644 --- a/sportspress-admin.css +++ b/assets/css/admin.css @@ -7,7 +7,7 @@ #adminmenu #menu-posts-sp_list div.wp-menu-image, #adminmenu #menu-posts-sp_tournament div.wp-menu-image, #adminmenu #menu-posts-sp_venue div.wp-menu-image { - background-image: url(images/menu.png); + background-image: url(../images/menu.png); background-repeat: no-repeat; background-position: 1px -33px; } diff --git a/images/menu.png b/assets/images/menu.png similarity index 100% rename from images/menu.png rename to assets/images/menu.png diff --git a/sportspress-admin.js b/assets/js/admin.js similarity index 87% rename from sportspress-admin.js rename to assets/js/admin.js index b5b076ec..33704992 100644 --- a/sportspress-admin.js +++ b/assets/js/admin.js @@ -63,4 +63,13 @@ jQuery(document).ready(function($){ }); } + // Equation selector + $('.sp-equation-selector select').change(function() { + if($(this).val() != '') { + $(this).before($(this).clone().val($(this).val())).val('').siblings().change(function() { + if($(this).val() == '') $(this).remove(); + }).find('option:first').text($(this).attr('data-remove-text')); + } + }); + }); \ No newline at end of file diff --git a/classes/shortcodes/table.php b/classes/shortcodes/table.php new file mode 100644 index 00000000..e817eb6d --- /dev/null +++ b/classes/shortcodes/table.php @@ -0,0 +1,63 @@ + 0, + 'div' => 0 + ), $atts ) ); + + // Get all teams in the division + $args = array( + 'post_type' => 'sp_team', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'tax_query' => array() + ); + if ( $div ) { + $args['tax_query'][] = array( + 'taxonomy' => 'sp_div', + 'terms' => $div, + 'field' => 'term_id' + ); + } + $teams = get_posts( $args ); + + // Check if there are any teams + $size = sizeof( $teams ); + if ( $size == 0 ) + return false; + + // Generate table + $output = ' + + + '; + foreach( $stats as $stat ) { + $output .= ''; + } + $output .= + ' + + '; + // insert rows + $rownum = 0; + foreach ( $teams as $club ) { + $rownum ++; + $club_stats = $club->tb_stats; + $output .= + ''; + $output .= ''; + foreach( $stats as $stat ) { + $output .= ''; + } + } + $output.= + ' +
' . __( 'Position', 'sportspress' ) . '' . $sp_table_stats_labels[$stat] . '
' . $club->place . ' ' . ( $club_links ? '' : '' ) . get_the_post_thumbnail( $club->ID, 'crest-small', array( 'title' => $club->post_title, 'class' => 'crest' ) ) . ' ' . $club->post_title . ( $club_links ? '' : '' ) . '' . $club_stats[$stat] . '
'; + if ( isset( $linkpage ) ) + $output .= '' . $linktext . ''; + $output .= ''; + return $output; +} +?> \ No newline at end of file diff --git a/scripts.php b/scripts.php deleted file mode 100644 index b7869b63..00000000 --- a/scripts.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/actions.php b/sportspress-actions.php similarity index 91% rename from actions.php rename to sportspress-actions.php index cb1a7c11..5c7d8f54 100644 --- a/actions.php +++ b/sportspress-actions.php @@ -31,6 +31,9 @@ function sp_manage_posts_custom_column( $column, $post_id ) { $result = get_post_meta( $post_id, 'sp_result', false ); echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '
', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—'; break; + case 'sp_sport': + echo get_the_terms ( $post_id, 'sp_sport' ) ? preg_replace('#.*?#i', '', sp_the_plain_terms( $post_id, 'sp_sport' ) ) : '—'; + break; case 'sp_player': echo sp_the_posts( $post_id, 'sp_player' ); break; @@ -64,7 +67,7 @@ function sp_restrict_manage_posts() { 'name' => 'sp_team', 'selected' => $selected ); - wp_dropdown_pages( $args ); + // wp_dropdown_pages( $args ); endif; if ( in_array( $typenow, array( 'sp_player', 'sp_staff' ) ) ): $selected = isset( $_REQUEST['sp_pos'] ) ? $_REQUEST['sp_pos'] : null; @@ -86,6 +89,16 @@ function sp_restrict_manage_posts() { ); sp_dropdown_taxonomies( $args ); endif; + if ( in_array( $typenow, array( 'sp_stat', 'sp_metric' ) ) ): + $selected = isset( $_REQUEST['sp_sport'] ) ? $_REQUEST['sp_sport'] : null; + $args = array( + 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Sports', 'sportspress' ) ), + 'taxonomy' => 'sp_sport', + 'name' => 'sp_sport', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + endif; } add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' ); @@ -149,26 +162,6 @@ function sp_save_post( $post_id ) { sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) ); break; endswitch; - - /* - - foreach ( $sportspress as $key => $value ): - delete_post_meta( $post_id, $key ); - if ( is_array( $value ) ): - if ( sp_get_array_depth( $value ) >= 3 ): - add_post_meta( $post_id, $key, $value, false ); - else: - $values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) ); - foreach ( $values as $value ): - add_post_meta( $post_id, $key, $value, false ); - endforeach; - endif; - else: - update_post_meta( $post_id, $key, $value ); - endif; - endforeach; - - */ } add_action( 'save_post', 'sp_save_post' ); ?> \ No newline at end of file diff --git a/filters.php b/sportspress-filters.php similarity index 83% rename from filters.php rename to sportspress-filters.php index 4566cf0d..9f06c331 100644 --- a/filters.php +++ b/sportspress-filters.php @@ -33,4 +33,13 @@ function sp_admin_post_thumbnail_html( $translated_text, $post_id ) { return $translated_text; } add_filter( 'admin_post_thumbnail_html', 'sp_admin_post_thumbnail_html', 10, 2 ); + +function sportspress_the_content( $content ) { + if ( is_singular( 'sp_team' ) && in_the_loop() ) { + // change stuff + $content .= '

' . do_shortcode('[sp_table]') . '

'; + } + return $content; +} +add_filter('the_content', 'sportspress_the_content'); ?> \ No newline at end of file diff --git a/globals.php b/sportspress-globals.php similarity index 100% rename from globals.php rename to sportspress-globals.php diff --git a/helpers.php b/sportspress-helpers.php similarity index 94% rename from helpers.php rename to sportspress-helpers.php index f13060a0..55e03c3a 100644 --- a/helpers.php +++ b/sportspress-helpers.php @@ -70,7 +70,7 @@ if ( !function_exists( 'sp_cpt_labels' ) ) { $labels = array( 'name' => $name, 'singular_name' => $singular_name, - 'all_items' => $is_submenu ? $name : sprintf( __( 'All %s', 'sportspress' ), $name ), + 'all_items' => $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 ), @@ -141,7 +141,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) { printf( '', $args['show_option_none'] ); } foreach ( $terms as $term ) { - printf( '', $term->term_id, selected( true, $args['selected'] == $term->term_id, false ), $term->name ); + printf( '', $term->slug, selected( true, $args['selected'] == $term->slug, false ), $term->name ); } print( '' ); } @@ -193,6 +193,17 @@ if ( !function_exists( 'sp_the_posts' ) ) { } } +if ( !function_exists( 'sp_the_plain_terms' ) ) { + function sp_the_plain_terms( $id, $taxonomy ) { + $terms = get_the_terms( $id, $taxonomy ); + $arr = array(); + foreach( $terms as $term ): + $arr[] = $term->name; + endforeach; + echo implode( ', ', $arr ); + } +} + if ( !function_exists( 'sp_post_checklist' ) ) { function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) { if ( ! isset( $post_id ) ) @@ -249,7 +260,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) { if ( !function_exists( 'sp_get_eos_rows' ) ) { function sp_get_eos_rows( $raw ) { $raw = str_replace( array( "\r\n", ' ' ), array( "\n", '' ), $raw ); - $output = explode( "\r\n", $raw ); + $output = explode( "\n", $raw ); return $output; } } @@ -257,7 +268,7 @@ if ( !function_exists( 'sp_get_eos_rows' ) ) { if ( !function_exists( 'sp_get_eos_keys' ) ) { function sp_get_eos_keys( $raw ) { $raw = str_replace( array( "\r\n", ' :' ), array( "\n", ':' ), $raw ); - $arr = explode( "\r\n", $raw ); + $arr = explode( "\n", $raw ); $output = array(); foreach ( $arr as $value ): $output[] = substr( $value, 0, strpos( $value, ':') ); @@ -288,7 +299,7 @@ if ( !function_exists( 'sp_get_stats_row' ) ) { case 'sp_team': // Get stats settings columns - $columns = sp_get_eos_rows( $stats_settings['event'] ); + $columns = sp_get_eos_rows( get_option( 'sp_event_stats_columns' ) ); // Setup variables $results = array(); @@ -334,14 +345,14 @@ if ( !function_exists( 'sp_get_stats_row' ) ) { $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'] ); + $rows = sp_get_eos_rows( get_option( 'sp_team_stats_columns' ) ); break; case 'sp_player': // Get stats settings keys - $keys = sp_get_eos_keys( $stats_settings['player'] ); + $keys = sp_get_eos_keys( get_option( 'sp_player_stats_columns' ) ); // Add object properties needed for retreiving event stats foreach( $posts as $post ): @@ -548,6 +559,16 @@ if ( !function_exists( 'sportspress_render_option_field' ) ) { case 'checkbox': echo ''; break; + case 'sport': + $terms = get_terms( 'sp_sport' ); + if ( $terms ) { + printf( '' ); + } + break; default: echo ''; break; diff --git a/hooks.php b/sportspress-hooks.php similarity index 100% rename from hooks.php rename to sportspress-hooks.php diff --git a/settings.php b/sportspress-settings.php similarity index 88% rename from settings.php rename to sportspress-settings.php index 62a04e73..47f462a3 100644 --- a/settings.php +++ b/sportspress-settings.php @@ -1,9 +1,10 @@ \ No newline at end of file diff --git a/styles.php b/styles.php deleted file mode 100644 index c5a00fa9..00000000 --- a/styles.php +++ /dev/null @@ -1,21 +0,0 @@ - \ No newline at end of file