Add team gallery template

This commit is contained in:
Brian Miyaji
2017-06-06 15:22:33 +10:00
parent 18a417adf3
commit 2cb7a7528b
15 changed files with 334 additions and 29 deletions

View File

@@ -24,6 +24,10 @@
content: "\f334"; content: "\f334";
} }
.post-state-format.post-format-standings:before, .post-format-icon.post-format-standings:before, a.post-state-format.format-standings:before {
content: "\f185";
}
.post-state-format.post-format-list:before, .post-format-icon.post-format-list:before, a.post-state-format.format-list:before { .post-state-format.post-format-list:before, .post-format-icon.post-format-list:before, a.post-state-format.format-list:before {
content: "\f163"; content: "\f163";
} }

View File

@@ -191,6 +191,11 @@
max-height: 2em; max-height: 2em;
} }
/* Team Gallery */
.sp-template-team-gallery img {
padding: 1em;
}
/* Player List */ /* Player List */
.sp-player-list td { .sp-player-list td {
line-height: 2em; line-height: 2em;

View File

@@ -6,6 +6,7 @@ $options = array(
'event' => array( 'event' => array(
'details', 'results', 'performance' 'details', 'results', 'performance'
), ),
'team' => array(),
'player' => array( 'player' => array(
'details', 'statistics' 'details', 'statistics'
), ),
@@ -14,6 +15,7 @@ $options = array(
$options = apply_filters( 'sportspress_shortcodes', $options ); $options = apply_filters( 'sportspress_shortcodes', $options );
foreach ( $options as $name => $group ) { foreach ( $options as $name => $group ) {
if ( empty( $group ) ) continue;
$shortcodes .= $name . '[' . implode( '|', $group ) . ']'; $shortcodes .= $name . '[' . implode( '|', $group ) . ']';
} }
@@ -30,7 +32,8 @@ $raw = apply_filters( 'sportspress_tinymce_strings', array(
'performance' => __( 'Box Score', 'sportspress' ), 'performance' => __( 'Box Score', 'sportspress' ),
'calendar' => __( 'Calendar', 'sportspress' ), 'calendar' => __( 'Calendar', 'sportspress' ),
'statistics' => __( 'Statistics', 'sportspress' ), 'statistics' => __( 'Statistics', 'sportspress' ),
'table' => __( 'League Table', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ),
'standings' => __( 'League Table', 'sportspress' ),
'player' => __( 'Player', 'sportspress' ), 'player' => __( 'Player', 'sportspress' ),
'list' => __( 'List', 'sportspress' ), 'list' => __( 'List', 'sportspress' ),
'blocks' => __( 'Blocks', 'sportspress' ), 'blocks' => __( 'Blocks', 'sportspress' ),

View File

@@ -0,0 +1,39 @@
<?php
/**
* Table Format
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Table_Format
*/
class SP_Meta_Box_Table_Format {
/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$the_format = get_post_meta( $post->ID, 'sp_format', true );
?>
<div id="post-formats-select">
<?php foreach ( SP()->formats->table as $key => $format ): ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( true, ( $key == 'standings' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $format; ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'standings' ) );
}
}

View File

@@ -19,11 +19,13 @@ class SP_Meta_Box_Table_Shortcode {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'standings';
?> ?>
<p class="howto"> <p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?> <?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p> </p>
<p><input type="text" value="<?php sp_shortcode_template( 'league_table', $post->ID ); ?>" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'team_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

View File

@@ -30,7 +30,7 @@ class SP_AJAX {
'event_calendar_shortcode' => false, 'event_calendar_shortcode' => false,
'event_list_shortcode' => false, 'event_list_shortcode' => false,
'event_blocks_shortcode' => false, 'event_blocks_shortcode' => false,
'table_table_shortcode' => false, 'team_standings_shortcode' => false,
'player_details_shortcode' => false, 'player_details_shortcode' => false,
'player_statistics_shortcode' => false, 'player_statistics_shortcode' => false,
'player_list_shortcode' => false, 'player_list_shortcode' => false,
@@ -610,11 +610,11 @@ class SP_AJAX {
} }
/** /**
* AJAX league_table shortcode * AJAX team_standings shortcode
*/ */
public function table_table_shortcode() { public function team_standings_shortcode() {
?> ?>
<div class="wrap sp-thickbox-content" id="sp-thickbox-league_table"> <div class="wrap sp-thickbox-content" id="sp-thickbox-team_standings">
<p> <p>
<label> <label>
<?php _e( 'Title:', 'sportspress' ); ?> <?php _e( 'Title:', 'sportspress' ); ?>
@@ -673,7 +673,7 @@ class SP_AJAX {
</p> </p>
<?php do_action( 'sportspress_ajax_shortcode_form', 'league-table' ); ?> <?php do_action( 'sportspress_ajax_shortcode_form', 'league-table' ); ?>
<p class="submit"> <p class="submit">
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('league_table');" /> <input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('team_standings');" />
<a class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'sportspress' ); ?>"><?php _e( 'Cancel', 'sportspress' ); ?></a> <a class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'sportspress' ); ?>"><?php _e( 'Cancel', 'sportspress' ); ?></a>
</p> </p>
</div> </div>
@@ -971,7 +971,7 @@ class SP_AJAX {
args.orderby = $div.find('[name=orderby]').val(); args.orderby = $div.find('[name=orderby]').val();
args.order = $div.find('[name=order]').val(); args.order = $div.find('[name=order]').val();
args.show_all_events_link = $div.find('[name=show_all_events_link]:checked').length; args.show_all_events_link = $div.find('[name=show_all_events_link]:checked').length;
} else if ( 'league_table' == type ) { } else if ( 'team_standings' == type ) {
args.title = $div.find('[name=title]').val(); args.title = $div.find('[name=title]').val();
args.number = $div.find('[name=number]').val(); args.number = $div.find('[name=number]').val();
args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(','); args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(',');

View File

@@ -32,6 +32,10 @@ class SP_Formats {
'list' => __( 'List', 'sportspress' ), 'list' => __( 'List', 'sportspress' ),
'blocks' => __( 'Blocks', 'sportspress' ), 'blocks' => __( 'Blocks', 'sportspress' ),
), ),
'table' => array(
'standings' => __( 'Standings', 'sportspress' ),
'gallery' => __( 'Gallery', 'sportspress' ),
),
'list' => array( 'list' => array(
'list' => __( 'List', 'sportspress' ), 'list' => __( 'List', 'sportspress' ),
'gallery' => __( 'Gallery', 'sportspress' ), 'gallery' => __( 'Gallery', 'sportspress' ),

View File

@@ -27,6 +27,8 @@ class SP_Shortcodes {
'event_list' => __CLASS__ . '::event_list', 'event_list' => __CLASS__ . '::event_list',
'event_blocks' => __CLASS__ . '::event_blocks', 'event_blocks' => __CLASS__ . '::event_blocks',
'league_table' => __CLASS__ . '::league_table', 'league_table' => __CLASS__ . '::league_table',
'team_standings' => __CLASS__ . '::league_table',
'team_gallery' => __CLASS__ . '::team_gallery',
'player_list' => __CLASS__ . '::player_list', 'player_list' => __CLASS__ . '::player_list',
'player_gallery' => __CLASS__ . '::player_gallery', 'player_gallery' => __CLASS__ . '::player_gallery',
); );
@@ -144,7 +146,7 @@ class SP_Shortcodes {
} }
/** /**
* League table shortcode. * League table (team standings) shortcode.
* *
* @access public * @access public
* @param mixed $atts * @param mixed $atts
@@ -154,6 +156,17 @@ class SP_Shortcodes {
return self::shortcode_wrapper( array( 'SP_Shortcode_League_Table', 'output' ), $atts ); return self::shortcode_wrapper( array( 'SP_Shortcode_League_Table', 'output' ), $atts );
} }
/**
* Team gallery shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function team_gallery( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Team_Gallery', 'output' ), $atts );
}
/** /**
* Player details shortcode. * Player details shortcode.
* *

View File

@@ -0,0 +1,24 @@
<?php
/**
* Team Gallery Shortcode
*
* @author ThemeBoy
* @category Shortcodes
* @package SportsPress/Shortcodes/Team_Gallery
* @version 2.3.2
*/
class SP_Shortcode_Team_Gallery {
/**
* Output the team gallery shortcode.
*
* @param array $atts
*/
public static function output( $atts ) {
if ( ! isset( $atts['id'] ) && isset( $atts[0] ) && is_numeric( $atts[0] ) )
$atts['id'] = $atts[0];
sp_get_template( 'team-gallery.php', $atts );
}
}

View File

@@ -330,7 +330,12 @@ if ( ! function_exists( 'sportspress_output_league_table' ) ) {
* @return void * @return void
*/ */
function sportspress_output_league_table() { function sportspress_output_league_table() {
sp_get_template( 'league-table.php' ); $id = get_the_ID();
$format = get_post_meta( $id, 'sp_format', true );
if ( array_key_exists( $format, SP()->formats->table ) && 'standings' !== $format )
sp_get_template( 'team-' . $format . '.php', array( 'id' => $id ) );
else
sp_get_template( 'league-table.php', array( 'id' => $id ) );
} }
} }

View File

@@ -185,6 +185,13 @@ class SportsPress_League_Tables {
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'format' => array(
'title' => __( 'Layout', 'sportspress' ),
'save' => 'SP_Meta_Box_Table_Format::save',
'output' => 'SP_Meta_Box_Table_Format::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Table_Details::save', 'save' => 'SP_Meta_Box_Table_Details::save',
@@ -209,7 +216,8 @@ class SportsPress_League_Tables {
* @return array * @return array
*/ */
public function add_shortcodes( $shortcodes ) { public function add_shortcodes( $shortcodes ) {
$shortcodes['table'] = array( 'table' ); $shortcodes['team'][] = 'standings';
$shortcodes['team'][] = 'gallery';
return $shortcodes; return $shortcodes;
} }

View File

@@ -7,12 +7,12 @@
{ "name" : "Finish", "condition" : "else", "description" : "Finished" } { "name" : "Finish", "condition" : "else", "description" : "Finished" }
], ],
"results": [ "results": [
{ "name" : "Score", "equation" : "$strokes", "description" : "Total score" }, { "name" : "Par", "equation" : "$strokes - $par", "description" : "Reported score", "primary" : 1 },
{ "name" : "FH", "description" : "Fairways hit" }, { "name" : "FH", "description" : "Fairways hit" },
{ "name" : "GIR", "description" : "Greens in regulation" }, { "name" : "GIR", "description" : "Greens in regulation" },
{ "name" : "Avg. Drive", "id" : "avgdrive", "description" : "Average drive (yards)" }, { "name" : "Avg. Drive", "id" : "avgdrive", "description" : "Average drive (yards)" },
{ "name" : "Putts", "description" : "Number of putts" }, { "name" : "Putts", "description" : "Number of putts" },
{ "name" : "Par", "equation" : "$strokes - $par", "description" : "Reported score", "primary" : 1 } { "name" : "Score", "equation" : "$strokes", "description" : "Total score" }
], ],
"performance": [ "performance": [
{ "name" : "1", "id" : "one", "description" : "Hole 1" }, { "name" : "1", "id" : "one", "description" : "Hole 1" },

View File

@@ -23,9 +23,6 @@ if ( ! isset( $caption ) ) $caption = __( 'Results', 'sportspress' );
// Get event result data // Get event result data
$data = $event->results(); $data = $event->results();
// Apply filters to results data
$data = apply_filters( 'sportspress_event_results', $data, $id );
// The first row should be column labels // The first row should be column labels
$labels = $data[0]; $labels = $data[0];

View File

@@ -0,0 +1,41 @@
<?php
/**
* Team Gallery Thumbnail
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.3.2
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$defaults = array(
'id' => null,
'icontag' => 'dt',
'captiontag' => 'dd',
'caption' => null,
'size' => 'sportspress-crop-medium',
'link_posts' => get_option( 'sportspress_link_teams', 'yes' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
// Add caption tag if has caption
if ( $captiontag && $caption )
$caption = '<' . $captiontag . ' class="wp-caption-text gallery-caption small-3 columns">' . wptexturize( $caption ) . '</' . $captiontag . '>';
if ( $link_posts )
$caption = '<a href="' . get_permalink( $id ) . '">' . $caption . '</a>';
if ( has_post_thumbnail( $id ) )
$thumbnail = get_the_post_thumbnail( $id, $size );
else
$thumbnail = '<img width="150" height="150" src="http://www.gravatar.com/avatar/?s=150&d=blank&f=y" class="attachment-thumbnail wp-post-image">';
echo "<{$itemtag} class='gallery-item'>";
echo "
<{$icontag} class='gallery-icon portrait'>"
. '<a href="' . get_permalink( $id ) . '">' . $thumbnail . '</a>'
. "</{$icontag}>";
echo $caption;
echo "</{$itemtag}>";

160
templates/team-gallery.php Normal file
View File

@@ -0,0 +1,160 @@
<?php
/**
* Team Gallery
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.3.2
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$html5 = current_theme_supports( 'html5', 'gallery' );
$defaults = array(
'id' => get_the_ID(),
'title' => false,
'number' => -1,
'orderby' => 'default',
'order' => 'ASC',
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'sportspress-crop-medium',
'show_all_teams_link' => false,
'link_posts' => get_option( 'sportspress_link_teams', 'yes' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
// Determine number of teams to display
if ( -1 === $number ):
$number = (int) get_post_meta( $id, 'sp_number', true );
if ( $number <= 0 ) $number = -1;
endif;
$itemtag = tag_escape( $itemtag );
$captiontag = tag_escape( $captiontag );
$icontag = tag_escape( $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( $columns );
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$size = $size;
$float = is_rtl() ? 'right' : 'left';
$selector = 'sp-team-gallery-' . $id;
$table = new SP_League_Table( $id );
$data = $table->data();
// Remove the first row to leave us with the actual data
unset( $data[0] );
if ( $orderby == 'default' ):
$orderby = $table->orderby;
$order = $table->order;
elseif ( $orderby == 'rand' ):
uasort( $data, 'sp_sort_random' );
else:
$table->priorities = array(
array(
'key' => $orderby,
'order' => $order,
),
);
uasort( $data, array( $table, 'sort' ) );
endif;
if ( $title )
echo '<h4 class="sp-table-caption">' . $title . '</h4>';
$gallery_style = $gallery_div = '';
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) )
$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}'>";
echo apply_filters( 'gallery_style', $gallery_style . "\n\t\t" );
?>
<?php echo $gallery_div; ?>
<?php
if ( intval( $number ) > 0 )
$limit = $number;
$i = 0;
$gallery = '';
foreach( $data as $team_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$caption = get_the_title( $team_id );
$caption = trim( $caption );
ob_start();
sp_get_template( 'team-gallery-thumbnail.php', array(
'id' => $team_id,
'itemtag' => $itemtag,
'icontag' => $icontag,
'captiontag' => $captiontag,
'caption' => $caption,
'size' => $size,
'link_posts' => $link_posts,
) );
$gallery .= ob_get_clean();
$i++;
endforeach;
echo '<div class="sp-template sp-template-team-gallery sp-template-gallery">';
echo '<div class="sp-team-gallery-wrapper sp-gallery-wrapper">';
echo $gallery;
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
echo '<br style="clear: both" />';
}
echo '</div>';
if ( $show_all_teams_link ) {
echo '<div class="sp-team-gallery-link sp-gallery-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all teams', 'sportspress' ) . '</a></div>';
}
echo '</div>';
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
echo '<br style="clear: both" />';
}
echo "</div>\n";
?>