Add team gallery shortcode to editor button with sorting option

This commit is contained in:
Brian Miyaji
2017-06-06 16:28:24 +10:00
parent a13263ec22
commit c20f8c64a8
3 changed files with 77 additions and 12 deletions

View File

@@ -31,6 +31,7 @@ class SP_AJAX {
'event_list_shortcode' => false,
'event_blocks_shortcode' => false,
'team_standings_shortcode' => false,
'team_gallery_shortcode' => false,
'player_details_shortcode' => false,
'player_statistics_shortcode' => false,
'player_list_shortcode' => false,
@@ -682,6 +683,64 @@ class SP_AJAX {
die();
}
/**
* AJAX team_gallery shortcode
*/
public function team_gallery_shortcode() {
?>
<div class="wrap sp-thickbox-content" id="sp-thickbox-team_gallery">
<p>
<label>
<?php _e( 'Title:', 'sportspress' ); ?>
<input class="regular-text" type="text" name="title">
</label>
</p>
<p>
<label>
<?php printf( __( 'Select %s:', 'sportspress' ), __( 'League Table', 'sportspress' ) ); ?>
<?php
$args = array(
'post_type' => 'sp_table',
'name' => 'id',
'values' => 'ID',
);
sp_dropdown_pages( $args );
?>
</label>
</p>
<p>
<label>
<?php _e( 'Number of teams to show:', 'sportspress' ); ?>
<input type="text" size="3" name="number" id="number" value="5">
</label>
</p>
<p>
<label>
<?php _e( 'Order by', 'sportspress' ); ?>:
<select name="orderby">
<option value="default"><?php _e( 'Rank', 'sportspress' ); ?></option>
<option value="name"><?php _e( 'Alphabetical', 'sportspress' ); ?></option>
<option value="rand"><?php _e( 'Random', 'sportspress' ); ?></option>
</select>
</label>
</p>
<p>
<label>
<input type="checkbox" name="show_full_table_link" id="show_full_table_link">
<?php _e( 'Display link to view full table', 'sportspress' ); ?>
</label>
</p>
<?php do_action( 'sportspress_ajax_shortcode_form', 'league-table' ); ?>
<p class="submit">
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('team_gallery');" />
<a class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'sportspress' ); ?>"><?php _e( 'Cancel', 'sportspress' ); ?></a>
</p>
</div>
<?php
self::scripts();
die();
}
/**
* AJAX player_details shortcode
*/
@@ -977,6 +1036,11 @@ class SP_AJAX {
args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(',');
args.show_team_logo = $div.find('[name=show_team_logo]:checked').length;
args.show_full_table_link = $div.find('[name=show_full_table_link]:checked').length;
} else if ( 'team_gallery' == type ) {
args.title = $div.find('[name=title]').val();
args.number = $div.find('[name=number]').val();
args.orderby = $div.find('[name=orderby]').val();
args.show_full_table_link = $div.find('[name=show_full_table_link]:checked').length;
} else if ( 'player_list' == type ) {
args.title = $div.find('[name=title]').val();
args.number = $div.find('[name=number]').val();

View File

@@ -96,6 +96,17 @@ function sp_sort_random() {
return mt_rand( 0, 1 );
}
/**
* Sort array by name field.
*
* @access public
* @param array $array
* @return bool
*/
function sp_sort_by_name( $a, $b ) {
return strcmp( $a['name'], $b['name'] );
}
/**
* let_to_num function.
*

View File

@@ -15,7 +15,6 @@ $defaults = array(
'title' => false,
'number' => -1,
'orderby' => 'default',
'order' => 'ASC',
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
@@ -57,19 +56,10 @@ $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;
if ( $orderby == 'name' ):
uasort( $data, 'sp_sort_by_name' );
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 )