Adjustments to event importer
This commit is contained in:
14
admin/globals/formats.php
Normal file
14
admin/globals/formats.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
function sportspress_define_formats_global() {
|
||||
global $sportspress_formats;
|
||||
|
||||
$sportspress_formats = array( 'event' => array(), 'list' => array() );
|
||||
|
||||
$sportspress_formats['event']['league'] = __( 'League', 'sportspress' );
|
||||
$sportspress_formats['event']['friendly'] = __( 'Friendly', 'sportspress' );
|
||||
|
||||
$sportspress_formats['list']['list'] = __( 'List', 'sportspress' );
|
||||
$sportspress_formats['list']['roster'] = __( 'Roster', 'sportspress' );
|
||||
$sportspress_formats['list']['gallery'] = __( 'Gallery', 'sportspress' );
|
||||
}
|
||||
add_action( 'init', 'sportspress_define_formats_global', 10 );
|
||||
@@ -7,7 +7,6 @@ function sportspress_admin_init() {
|
||||
'sp_player',
|
||||
'sp_list',
|
||||
'sp_staff',
|
||||
'sp_sponsor',
|
||||
'sp_config',
|
||||
);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
global $typenow;
|
||||
|
||||
if ( is_admin() ):
|
||||
if ( in_array( $typenow, array( 'sp_team', 'sp_sponsor' ) ) ):
|
||||
if ( in_array( $typenow, array( 'sp_team' ) ) ):
|
||||
switch ( $untranslated_text ):
|
||||
case 'Set featured image':
|
||||
$translated_text = __( 'Select Logo', 'sportspress' );
|
||||
@@ -42,14 +42,6 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
break;
|
||||
endswitch;
|
||||
endif;
|
||||
|
||||
if ( in_array( $typenow, array( 'sp_sponsor' ) ) ):
|
||||
switch ( $untranslated_text ):
|
||||
case 'Enter title here':
|
||||
$translated_text = __( 'Sponsor', 'sportspress' );
|
||||
break;
|
||||
endswitch;
|
||||
endif;
|
||||
|
||||
if ( in_array( $typenow, array( 'sp_player', 'sp_staff' ) ) ):
|
||||
switch ( $untranslated_text ):
|
||||
|
||||
@@ -108,9 +108,6 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
case 'sp_venue':
|
||||
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '—';
|
||||
break;
|
||||
case 'sp_sponsor':
|
||||
echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—';
|
||||
break;
|
||||
case 'sp_time':
|
||||
echo get_post_time( 'H:i', false, $post );
|
||||
break;
|
||||
|
||||
@@ -75,17 +75,6 @@ function sportspress_activation_hook() {
|
||||
'delete_private_sp_tables' => true,
|
||||
'delete_published_sp_tables' => true,
|
||||
|
||||
'edit_sp_sponsor' => true,
|
||||
'edit_sp_sponsors' => true,
|
||||
'edit_private_sp_sponsors' => true,
|
||||
'edit_published_sp_sponsors' => true,
|
||||
'read_sp_sponsors' => true,
|
||||
'read_private_sp_sponsors' => true,
|
||||
'publish_sp_sponsors' => true,
|
||||
'delete_sp_sponsors' => true,
|
||||
'delete_private_sp_sponsors' => true,
|
||||
'delete_published_sp_sponsors' => true,
|
||||
|
||||
'view_sportspress_reports' => true,
|
||||
)
|
||||
);
|
||||
|
||||
@@ -45,9 +45,6 @@ function sportspress_save_post( $post_id ) {
|
||||
// Update season taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
|
||||
// Update tournament taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_tournament', 0 ), 'sp_tournament' );
|
||||
|
||||
// Update venue taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
|
||||
|
||||
|
||||
@@ -61,13 +61,13 @@ function sportspress_event_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_event_format_meta( $post ) {
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
global $sportspress_formats;
|
||||
$the_format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<input type="radio" name="sp_format" class="post-format" id="post-format-league" value="league" <?php checked( true, ! $format || $format == 'league' ); ?>> <label for="post-format-league" class="post-format-icon post-format-league">League</label>
|
||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-tournament" value="tournament" <?php checked( 'tournament', $format ); ?>> <label for="post-format-tournament" class="post-format-icon post-format-tournament">Tournament</label>
|
||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-friendly" value="friendly" <?php checked( 'friendly', $format ); ?>> <label for="post-format-friendly" class="post-format-icon post-format-friendly">Friendly</label>
|
||||
<br>
|
||||
<?php foreach ( $sportspress_formats['event'] 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 == 'league' && ! $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
|
||||
}
|
||||
@@ -76,11 +76,10 @@ function sportspress_event_details_meta( $post ) {
|
||||
$type = sportspress_get_the_term_id( $post->ID, 'sp_type', null );
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$tournament_id = sportspress_get_the_term_id( $post->ID, 'sp_tournament', 0 );
|
||||
$venue_id = sportspress_get_the_term_id( $post->ID, 'sp_venue', 0 );
|
||||
?>
|
||||
<div>
|
||||
<fieldset class="sp-event-format-field sp-league-event-field sp-league-event-field">
|
||||
<fieldset class="sp-event-format-field sp-league-event-field sp-friendly-event-field">
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
@@ -112,23 +111,6 @@ function sportspress_event_details_meta( $post ) {
|
||||
?>
|
||||
</p>
|
||||
</fieldset>
|
||||
<fieldset class="sp-event-format-field sp-tournament-event-field">
|
||||
<p><strong><?php _e( 'Tournament', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_tournament',
|
||||
'name' => 'sp_tournament',
|
||||
'selected' => $tournament_id,
|
||||
'values' => 'term_id',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
sportspress_taxonomy_adder( 'sp_tournament', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
</fieldset>
|
||||
<p><strong><?php _e( 'Venue', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
|
||||
@@ -58,13 +58,13 @@ function sportspress_list_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sportspress_list_format_meta( $post ) {
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
global $sportspress_formats;
|
||||
$the_format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<input type="radio" name="sp_format" class="post-format" id="post-format-list" value="list" <?php checked( true, ! $format || $format == 'list' ); ?>> <label for="post-format-list" class="post-format-icon post-format-list"><?php _e( 'List', 'sportspress' ); ?></label>
|
||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-roster" value="roster" <?php checked( 'roster', $format ); ?>> <label for="post-format-roster" class="post-format-icon post-format-roster"><?php _e( 'Roster', 'sportspress' ); ?></label>
|
||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-gallery" value="gallery" <?php checked( 'gallery', $format ); ?>> <label for="post-format-gallery" class="post-format-icon post-format-gallery"><?php _e( 'Gallery', 'sportspress' ); ?></label>
|
||||
<br>
|
||||
<?php foreach ( $sportspress_formats['list'] 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 == 'list' && ! $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
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
function sportspress_sponsor_post_init() {
|
||||
$labels = array(
|
||||
'name' => __( 'Sponsors', 'sportspress' ),
|
||||
'singular_name' => __( 'Sponsor', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New Sponsor', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Sponsor', 'sportspress' ),
|
||||
'new_item' => __( 'New', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
|
||||
);
|
||||
$args = array(
|
||||
'label' => __( 'Sponsors', 'sportspress' ),
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
|
||||
'register_meta_box_cb' => 'sportspress_sponsor_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_sponsor_slug', 'sponsor' ) ),
|
||||
'menu_icon' => 'dashicons-portfolio',
|
||||
'capability_type' => 'sp_sponsor'
|
||||
);
|
||||
register_post_type( 'sp_sponsor', $args );
|
||||
}
|
||||
add_action( 'init', 'sportspress_sponsor_post_init' );
|
||||
|
||||
function sportspress_sponsor_meta_init() {
|
||||
}
|
||||
|
||||
function sportspress_sponsor_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'sp_icon' => ' ',
|
||||
'title' => __( 'Name', 'sportspress' ),
|
||||
'sp_views' => __( 'Views', 'sportspress' ),
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_sponsor_columns', 'sportspress_sponsor_edit_columns' );
|
||||
@@ -21,7 +21,6 @@ function sportspress_staff_post_init() {
|
||||
'register_meta_box_cb' => 'sportspress_staff_meta_init',
|
||||
'rewrite' => array( 'slug' => get_option( 'sp_staff_slug', 'staff' ) ),
|
||||
'show_in_menu' => 'edit.php?post_type=sp_player',
|
||||
'menu_icon' => 'dashicons-businessman',
|
||||
'capability_type' => 'sp_staff'
|
||||
);
|
||||
register_post_type( 'sp_staff', $args );
|
||||
|
||||
@@ -4,7 +4,7 @@ function sportspress_league_term_init() {
|
||||
'name' => __( 'Leagues', 'sportspress' ),
|
||||
'singular_name' => __( 'League', 'sportspress' ),
|
||||
'all_items' => __( 'All', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit League', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'update_item' => __( 'Update', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New', 'sportspress' ),
|
||||
|
||||
@@ -4,7 +4,7 @@ function sportspress_position_term_init() {
|
||||
'name' => __( 'Positions', 'sportspress' ),
|
||||
'singular_name' => __( 'Position', 'sportspress' ),
|
||||
'all_items' => __( 'All', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Position', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'update_item' => __( 'Update', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New', 'sportspress' ),
|
||||
|
||||
@@ -4,7 +4,7 @@ function sportspress_season_term_init() {
|
||||
'name' => __( 'Seasons', 'sportspress' ),
|
||||
'singular_name' => __( 'Season', 'sportspress' ),
|
||||
'all_items' => __( 'All', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Season', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'update_item' => __( 'Update', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New', 'sportspress' ),
|
||||
|
||||
@@ -4,7 +4,7 @@ function sportspress_venue_term_init() {
|
||||
'name' => __( 'Venues', 'sportspress' ),
|
||||
'singular_name' => __( 'Venue', 'sportspress' ),
|
||||
'all_items' => __( 'All', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit', 'sportspress' ),
|
||||
'edit_item' => __( 'Edit Venue', 'sportspress' ),
|
||||
'view_item' => __( 'View', 'sportspress' ),
|
||||
'update_item' => __( 'Update', 'sportspress' ),
|
||||
'add_new_item' => __( 'Add New', 'sportspress' ),
|
||||
|
||||
@@ -110,10 +110,13 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
||||
|
||||
if ( sizeof( $header ) >= 4 ):
|
||||
if ( sizeof( $header ) >= 3 ):
|
||||
|
||||
$loop = 0;
|
||||
|
||||
// Get event format
|
||||
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
|
||||
|
||||
// Get league
|
||||
$league = ( empty( $_POST['sp_league'] ) ? false : $_POST['sp_league'] );
|
||||
|
||||
@@ -128,7 +131,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ):
|
||||
|
||||
$date = str_replace( '/', '-', $row[0] );
|
||||
$date = str_replace( '/', '-', trim( $row[0] ) );
|
||||
unset( $row[0] );
|
||||
|
||||
if ( ! empty( $date ) ):
|
||||
@@ -145,10 +148,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Add time to date
|
||||
$date .= ' ' . $row[1];
|
||||
$date .= ' ' . trim( $row[1] );
|
||||
unset( $row[1] );
|
||||
|
||||
$venue = $row[2];
|
||||
$venue = trim( $row[2] );
|
||||
unset( $row[2] );
|
||||
|
||||
// Initialize arrays
|
||||
@@ -161,14 +164,14 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
$teamdata = explode( '|', $team );
|
||||
|
||||
$name = $teamdata[0];
|
||||
$name = trim( $teamdata[0] );
|
||||
unset( $teamdata[0] );
|
||||
|
||||
$team_results = array();
|
||||
|
||||
if ( sizeof( $result_labels ) > 0 ):
|
||||
foreach( $result_labels as $key => $label ):
|
||||
$team_results[ $key ] = array_shift( $teamdata );
|
||||
$team_results[ $key ] = trim( array_shift( $teamdata ) );
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
@@ -176,6 +179,8 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
foreach ( $teamdata as $outcome ):
|
||||
|
||||
$outcome = trim( $outcome );
|
||||
|
||||
// Get or insert outcome
|
||||
$outcome_object = get_page_by_path( $outcome, OBJECT, 'sp_outcome' );
|
||||
if ( $outcome_object ):
|
||||
@@ -208,6 +213,11 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
// Flag as import
|
||||
update_post_meta( $id, '_sp_import', 1 );
|
||||
|
||||
// Update event format
|
||||
if ( $event_format ):
|
||||
update_post_meta( $id, 'sp_format', $event_format );
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
wp_set_object_terms( $id, $league, 'sp_league', false );
|
||||
@@ -271,7 +281,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$team_name = $team_names[ $ti ];
|
||||
$statistics = explode( '|', $player );
|
||||
|
||||
$name = $statistics[0];
|
||||
$name = trim( $statistics[0] );
|
||||
unset( $statistics[0] );
|
||||
|
||||
$player_statistics = array();
|
||||
@@ -442,7 +452,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
|
||||
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (4+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), SPORTSPRESS_PLUGIN_URL . 'dummy-data/events-sample.csv' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), SPORTSPRESS_PLUGIN_URL . 'dummy-data/events-sample.csv' ) . '</p>';
|
||||
|
||||
$action = 'admin.php?import=sportspress_event_csv&step=1';
|
||||
|
||||
@@ -480,6 +490,16 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
<th><label><?php _e( 'Delimiter', 'sportspress' ); ?></label><br/></th>
|
||||
<td><input type="text" name="delimiter" placeholder="," size="2" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label><?php _e( 'Format', 'sportspress' ); ?></label><br/></th>
|
||||
<td id="sp_formatdiv">
|
||||
<div id="post-formats-select">
|
||||
<input type="radio" name="sp_format" class="post-format" id="post-format-league" value="league" checked="checked"> <label for="post-format-league" class="post-format-icon post-format-league">League</label>
|
||||
<br><input type="radio" name="sp_format" class="post-format" id="post-format-friendly" value="friendly"> <label for="post-format-friendly" class="post-format-icon post-format-friendly">Friendly</label>
|
||||
<br>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
|
||||
<td><?php
|
||||
@@ -489,7 +509,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sportspress_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -501,7 +524,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '-- Not set --', 'sportspress' ),
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
if ( ! sportspress_dropdown_taxonomies( $args ) ):
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sportspress_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user