Add player gallery resolve #11

This commit is contained in:
Brian Miyaji
2014-03-16 16:05:12 +11:00
parent 1780bf4b54
commit 04a1084f2e
3 changed files with 71 additions and 45 deletions

View File

@@ -73,9 +73,6 @@ function sportspress_default_list_content( $content ) {
$id = get_the_ID();
$format = get_post_meta( $id, 'sp_format', true );
switch ( $format ):
case 'roster':
$list = sportspress_player_roster( $id );
break;
case 'gallery':
$list = sportspress_player_gallery( $id );
break;

View File

@@ -6,15 +6,34 @@ if ( !function_exists( 'sportspress_player_gallery' ) ) {
$id = get_the_ID();
$defaults = array(
'statistics' => null,
'orderby' => 'default',
'order' => 'ASC',
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
);
$r = wp_parse_args( $args, $defaults );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-player-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$itemtag = tag_escape( $r['itemtag'] );
$captiontag = tag_escape( $r['captiontag'] );
$icontag = tag_escape( $r['icontag'] );
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) )
$itemtag = 'dl';
if ( ! isset( $valid_tags[ $captiontag ] ) )
$captiontag = 'dd';
if ( ! isset( $valid_tags[ $icontag ] ) )
$icontag = 'dt';
$columns = intval( $r['columns'] );
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$size = $r[ 'size' ];
$float = is_rtl() ? 'right' : 'left';
$selector = 'sp-player-gallery-' . $id;
$data = sportspress_get_player_list_data( $id );
@@ -40,52 +59,62 @@ if ( !function_exists( 'sportspress_player_gallery' ) ) {
uasort( $data, 'sportspress_sort_list_players' );
endif;
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
foreach( $labels as $key => $label ):
if ( ! is_array( $statistics ) || $key == 'name' || in_array( $key, $statistics ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $player_id => $row ):
$gallery_style = $gallery_div = '';
if ( apply_filters( 'use_default_gallery_style', true ) )
$gallery_style = "
<style type='text/css'>
#{$selector} {
margin: auto;
}
#{$selector} .gallery-item {
float: {$float};
margin-top: 10px;
text-align: center;
width: {$itemwidth}%;
}
#{$selector} img {
border: 2px solid #cfcfcf;
}
#{$selector} .gallery-caption {
margin-left: 0;
}
/* see gallery_shortcode() in wp-includes/media.php */
</style>";
$size_class = sanitize_html_class( $size );
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $data as $id => $statistics ):
$caption = get_the_title( $id );
$thumbnail = get_the_post_thumbnail( $id, $size );
if ( $thumbnail ):
$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
<{$icontag} class='gallery-icon portrait'>"
. '<a href="' . get_permalink( $id ) . '">' . $thumbnail . '</a>'
. "</{$icontag}>";
if ( $captiontag && trim($caption) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption'>
" . wptexturize($caption) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= '<br style="clear: both" />';
// Rank or number
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
else:
$number = get_post_meta( $player_id, 'sp_number', true );
$output .= '<td class="data-number">' . ( $number ? $number : '&nbsp;' ) . '</td>';
endif;
// Name as link
$permalink = get_post_permalink( $player_id );
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', '&nbsp;' ) );
$output .= '<td class="data-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $statistics ) || in_array( $key, $statistics ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
$output .= "
<br style='clear: both;' />
</div>\n";
return apply_filters( 'sportspress_player_gallery', $output );

View File

@@ -47,7 +47,7 @@ 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-roster.php';
//require_once dirname( __FILE__ ) . '/admin/templates/player-roster.php';
require_once dirname( __FILE__ ) . '/admin/templates/player-gallery.php';
require_once dirname( __FILE__ ) . '/admin/templates/player-metrics.php';
require_once dirname( __FILE__ ) . '/admin/templates/player-statistics.php';