Clean up spaces, tabs, indentation, and bracket formatting
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Event importer - import events into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Event_Importer extends SP_Importer {
|
||||
@@ -20,20 +22,21 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_event_csv';
|
||||
$this->import_page = 'sp_event_csv';
|
||||
$this->import_label = __( 'Import Events', 'sportspress' );
|
||||
$this->columns = array(
|
||||
'post_date' => __( 'Date', 'sportspress' ),
|
||||
'post_time' => __( 'Time', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
$this->columns = array(
|
||||
'post_date' => __( 'Date', 'sportspress' ),
|
||||
'post_time' => __( 'Time', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_results' => __( 'Results', 'sportspress' ),
|
||||
'sp_outcome' => __( 'Outcome', 'sportspress' ),
|
||||
'sp_player' => __( 'Players', 'sportspress' ),
|
||||
'sp_player' => __( 'Players', 'sportspress' ),
|
||||
);
|
||||
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
||||
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) )
|
||||
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
|
||||
$this->columns = array_merge( $this->columns, $performance_labels );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +50,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
@@ -56,29 +59,31 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Get event format, league, and season from post vars
|
||||
$event_format = ( empty( $_POST['sp_format'] ) ? false : sanitize_text_field( $_POST['sp_format'] ) );
|
||||
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) );
|
||||
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) );
|
||||
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
|
||||
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) );
|
||||
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) );
|
||||
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
|
||||
|
||||
// Get labels from result and performance post types
|
||||
$result_labels = sp_get_var_labels( 'sp_result' );
|
||||
$result_labels = sp_get_var_labels( 'sp_result' );
|
||||
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
// Slice array into event, team, and player
|
||||
$event = array_slice( $row, 0, 3 );
|
||||
$team = array_slice( $row, 3, 3 );
|
||||
$event = array_slice( $row, 0, 3 );
|
||||
$team = array_slice( $row, 3, 3 );
|
||||
$player = array_slice( $row, 6 );
|
||||
|
||||
// Get event details
|
||||
@@ -105,16 +110,16 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$player = array(
|
||||
sp_array_value( $meta, 'sp_player' ),
|
||||
);
|
||||
unset( $meta['sp_player' ] );
|
||||
foreach ( $performance_labels as $key => $label ):
|
||||
unset( $meta['sp_player'] );
|
||||
foreach ( $performance_labels as $key => $label ) :
|
||||
$player[] = sp_array_value( $meta, $key, '' );
|
||||
endforeach;
|
||||
|
||||
// Add new event if date is given
|
||||
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
|
||||
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
|
||||
|
||||
// Add player performance to last event if available
|
||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
|
||||
update_post_meta( $id, 'sp_players', $players );
|
||||
endif;
|
||||
|
||||
@@ -122,9 +127,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
list( $date, $time, $venue ) = $event;
|
||||
|
||||
// Format date
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date_array = explode( '-', $date );
|
||||
switch ( $date_format ):
|
||||
switch ( $date_format ) :
|
||||
case 'dd/mm/yyyy':
|
||||
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||
@@ -142,12 +147,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endswitch;
|
||||
|
||||
// Add time to date if given
|
||||
if ( ! empty( $time ) ):
|
||||
if ( ! empty( $time ) ) :
|
||||
$date .= ' ' . trim( $time );
|
||||
endif;
|
||||
|
||||
// Define post type args
|
||||
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) );
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
'post_status' => 'publish',
|
||||
'post_date' => $date,
|
||||
'post_title' => __( 'Event', 'sportspress' ),
|
||||
);
|
||||
|
||||
// Insert event
|
||||
$id = wp_insert_post( $args );
|
||||
@@ -159,17 +169,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
update_post_meta( $id, '_sp_import', 1 );
|
||||
|
||||
// Update event format
|
||||
if ( $event_format ):
|
||||
if ( $event_format ) :
|
||||
update_post_meta( $id, 'sp_format', $event_format );
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
if ( $league ) :
|
||||
wp_set_object_terms( $id, $league, 'sp_league', false );
|
||||
endif;
|
||||
|
||||
// Update season
|
||||
if ( $season ):
|
||||
if ( $season ) :
|
||||
wp_set_object_terms( $id, $season, 'sp_season', false );
|
||||
endif;
|
||||
|
||||
@@ -182,7 +192,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Add new team if team name is given
|
||||
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ):
|
||||
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ) :
|
||||
|
||||
// List team columns
|
||||
list( $team_name, $result, $outcome ) = $team;
|
||||
@@ -191,20 +201,31 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
|
||||
|
||||
// Get or insert team
|
||||
if ( $team_object ):
|
||||
if ( $team_object ) :
|
||||
|
||||
// Make sure team is published
|
||||
if ( $team_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $team_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $team_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
|
||||
// Get team ID
|
||||
$team_id = $team_object->ID;
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Insert team
|
||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) );
|
||||
$team_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $team_name ),
|
||||
)
|
||||
);
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $team_id, '_sp_import', 1 );
|
||||
@@ -212,17 +233,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
if ( $league ) :
|
||||
wp_set_object_terms( $team_id, $league, 'sp_league', true );
|
||||
endif;
|
||||
|
||||
// Update season
|
||||
if ( $season ):
|
||||
if ( $season ) :
|
||||
wp_set_object_terms( $team_id, $season, 'sp_season', true );
|
||||
endif;
|
||||
|
||||
// Add to event if exists
|
||||
if ( isset( $id ) ):
|
||||
if ( isset( $id ) ) :
|
||||
|
||||
// Add team to event
|
||||
add_post_meta( $id, 'sp_team', $team_id );
|
||||
@@ -235,21 +256,21 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Create team results array from result keys
|
||||
$team_results = array();
|
||||
if ( sizeof( $result_labels ) > 0 ):
|
||||
foreach( $result_labels as $key => $label ):
|
||||
if ( sizeof( $result_labels ) > 0 ) :
|
||||
foreach ( $result_labels as $key => $label ) :
|
||||
$team_results[ $key ] = trim( array_shift( $results ) );
|
||||
endforeach;
|
||||
$team_results[ 'outcome' ] = array();
|
||||
$team_results['outcome'] = array();
|
||||
endif;
|
||||
|
||||
// Explode outcomes into array
|
||||
$outcomes = explode( '|', $outcome );
|
||||
|
||||
// Add outcome slugs to team outcomes array
|
||||
foreach ( $outcomes as $outcome ):
|
||||
foreach ( $outcomes as $outcome ) :
|
||||
|
||||
// Continue if outcome doesn't exist
|
||||
if ( $outcome == null ):
|
||||
if ( $outcome == null ) :
|
||||
continue;
|
||||
endif;
|
||||
|
||||
@@ -259,24 +280,35 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
// Get or insert outcome
|
||||
$outcome_object = get_page_by_title( stripslashes( $outcome ), OBJECT, 'sp_outcome' );
|
||||
|
||||
if ( $outcome_object ):
|
||||
if ( $outcome_object ) :
|
||||
|
||||
// Make sure outcome is published
|
||||
if ( $outcome_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $outcome_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $outcome_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
|
||||
// Get outcome slug
|
||||
$outcome_slug = $outcome_object->post_name;
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Insert outcome
|
||||
$outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $outcome ) ) );
|
||||
$outcome_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $outcome ),
|
||||
)
|
||||
);
|
||||
|
||||
// Get outcome slug
|
||||
$post_data = get_post( $outcome_id, ARRAY_A );
|
||||
$outcome_slug = $post_data['post_name'];
|
||||
$post_data = get_post( $outcome_id, ARRAY_A );
|
||||
$outcome_slug = $post_data['post_name'];
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $outcome_id, '_sp_import', 1 );
|
||||
@@ -284,7 +316,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Add to team results array
|
||||
$team_results[ 'outcome' ][] = $outcome_slug;
|
||||
$team_results['outcome'][] = $outcome_slug;
|
||||
|
||||
endforeach;
|
||||
|
||||
@@ -292,7 +324,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$event_results = get_post_meta( $id, 'sp_results', true );
|
||||
|
||||
// Create new array if results not exists
|
||||
if ( ! $event_results ):
|
||||
if ( ! $event_results ) :
|
||||
$event_results = array();
|
||||
endif;
|
||||
|
||||
@@ -317,9 +349,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Update event with new name
|
||||
$post = array(
|
||||
'ID' => $id,
|
||||
'ID' => $id,
|
||||
'post_title' => $title,
|
||||
'post_name' => $id,
|
||||
'post_name' => $id,
|
||||
);
|
||||
wp_update_post( $post );
|
||||
|
||||
@@ -328,7 +360,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Add new player if player name is given
|
||||
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ):
|
||||
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ) :
|
||||
|
||||
// Get and unset player name leaving us with the performance
|
||||
$player_name = $player[0];
|
||||
@@ -338,11 +370,16 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
|
||||
|
||||
// Get or insert player
|
||||
if ( $player_object ):
|
||||
if ( $player_object ) :
|
||||
|
||||
// Make sure player is published
|
||||
if ( $player_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $player_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $player_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
|
||||
// Get player ID
|
||||
@@ -351,10 +388,16 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
// Get player number
|
||||
$player_number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Insert player
|
||||
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) );
|
||||
$player_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_player',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $player_name ),
|
||||
)
|
||||
);
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $player_id, '_sp_import', 1 );
|
||||
@@ -368,29 +411,29 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
if ( $league ) :
|
||||
wp_set_object_terms( $player_id, $league, 'sp_league', true );
|
||||
endif;
|
||||
|
||||
// Update season
|
||||
if ( $season ):
|
||||
if ( $season ) :
|
||||
wp_set_object_terms( $player_id, $season, 'sp_season', true );
|
||||
endif;
|
||||
|
||||
// Add to event if exists
|
||||
if ( isset( $id ) ):
|
||||
if ( isset( $id ) ) :
|
||||
|
||||
// Add player to event
|
||||
add_post_meta( $id, 'sp_player', $player_id );
|
||||
|
||||
// Add player performance to array if team is available
|
||||
if ( isset( $team_id ) ):
|
||||
if ( isset( $team_id ) ) :
|
||||
|
||||
// Initialize performance array
|
||||
$performance = array( 'number' => $player_number );
|
||||
|
||||
// Map keys to player performance
|
||||
foreach ( $performance_labels as $key => $label ):
|
||||
foreach ( $performance_labels as $key => $label ) :
|
||||
$performance[ $key ] = array_shift( $player );
|
||||
endforeach;
|
||||
$players[ $team_id ][ $player_id ] = $performance;
|
||||
@@ -398,17 +441,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
// Get player teams
|
||||
$player_teams = get_post_meta( $player_id, 'sp_team', false );
|
||||
$current_team = get_post_meta( $player_id, 'sp_current_team', true );
|
||||
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
|
||||
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
|
||||
|
||||
// Add team if not exists in player
|
||||
if ( ! in_array( $team_id, $player_teams ) ):
|
||||
if ( ! in_array( $team_id, $player_teams ) ) :
|
||||
add_post_meta( $player_id, 'sp_team', $team_id );
|
||||
endif;
|
||||
|
||||
// Add as past team or set current team if not set
|
||||
if ( ! $current_team ):
|
||||
if ( ! $current_team ) :
|
||||
update_post_meta( $player_id, 'sp_current_team', $team_id );
|
||||
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ):
|
||||
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ) :
|
||||
add_post_meta( $player_id, 'sp_past_team', $team_id );
|
||||
endif;
|
||||
|
||||
@@ -421,13 +464,13 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endforeach;
|
||||
|
||||
// Add player performance to last event if available
|
||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
|
||||
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
|
||||
update_post_meta( $id, 'sp_players', $players );
|
||||
endif;
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -437,7 +480,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -450,7 +493,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
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 (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_event_csv&step=1' );
|
||||
@@ -473,11 +516,11 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
<fieldset id="post-formats-select">
|
||||
<ul>
|
||||
<?php
|
||||
foreach( (new SP_Formats)->event as $name => $title ) {
|
||||
?>
|
||||
foreach ( ( new SP_Formats() )->event as $name => $title ) {
|
||||
?>
|
||||
<li><input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" checked="checked"> <label for="post-format-<?php echo esc_attr( $name ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $title ); ?></label></li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</fieldset>
|
||||
@@ -485,56 +528,60 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
|
||||
<td><?php
|
||||
<td>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'values' => 'slug',
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '— Not set —', 'sportspress' ),
|
||||
);
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ) :
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
|
||||
<td><?php
|
||||
<td>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'values' => 'slug',
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '— Not set —', 'sportspress' ),
|
||||
);
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ) :
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" class="titledesc">
|
||||
<?php _e( 'Date Format', 'sportspress' ); ?>
|
||||
</th>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Event Performance importer - import box scores into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Event_Performance_Importer extends SP_Importer {
|
||||
@@ -20,14 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_event_performance_csv';
|
||||
$this->import_page = 'sp_event_performance_csv';
|
||||
$this->import_label = __( 'Import Box Score', 'sportspress' );
|
||||
$this->columns = array(
|
||||
$this->columns = array(
|
||||
'sp_player' => __( 'Player', 'sportspress' ),
|
||||
);
|
||||
$performance_labels = sp_get_var_labels( 'sp_performance' );
|
||||
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) )
|
||||
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
|
||||
$this->columns = array_merge( $this->columns, $performance_labels );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +44,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'sp_player' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
@@ -52,36 +55,44 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$event = ( empty( $_POST['sp_event'] ) ? false : sanitize_text_field( $_POST['sp_event'] ) );
|
||||
$teams = ( empty( $_POST['sp_teams'] ) ? false : sanitize_text_field( $_POST['sp_teams'] ) );
|
||||
$index = ( empty( $_POST['sp_index'] ) ? false : sanitize_text_field( $_POST['sp_index'] ) );
|
||||
$team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) );
|
||||
$team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) );
|
||||
|
||||
$team_players = array( 0 );
|
||||
$team_players = array( 0 );
|
||||
$team_performance = array();
|
||||
$name_index = (int) array_search( 'sp_player', $columns );
|
||||
$name_index = (int) array_search( 'sp_player', $columns );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$player_name = sp_array_value( $row, $name_index );
|
||||
|
||||
if ( ! $player_name ):
|
||||
|
||||
if ( ! $player_name ) :
|
||||
$this->skipped ++;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
|
||||
|
||||
if ( $player_object ):
|
||||
if ( $player_object ) :
|
||||
|
||||
// Get player ID
|
||||
$player_id = $player_object->ID;
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Insert player
|
||||
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) );
|
||||
$player_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_player',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $player_name ),
|
||||
)
|
||||
);
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $player_id, '_sp_import', 1 );
|
||||
@@ -89,10 +100,12 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
$team_players[] = $player_id;
|
||||
$player = array();
|
||||
$player = array();
|
||||
|
||||
foreach ( $columns as $i => $key ):
|
||||
if ( 'sp_player' === $key ) continue;
|
||||
foreach ( $columns as $i => $key ) :
|
||||
if ( 'sp_player' === $key ) {
|
||||
continue;
|
||||
}
|
||||
$player[ $key ] = sp_array_value( $row, $i, '' );
|
||||
endforeach;
|
||||
|
||||
@@ -100,13 +113,13 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
endforeach;
|
||||
|
||||
if ( $event && $team ):
|
||||
if ( $event && $team ) :
|
||||
$the_players = get_post_meta( $event, 'sp_player', false );
|
||||
$players = array();
|
||||
for ( $i = 0; $i < $teams; $i++ ):
|
||||
if ( $index == $i ):
|
||||
$players = array();
|
||||
for ( $i = 0; $i < $teams; $i++ ) :
|
||||
if ( $index == $i ) :
|
||||
array_push( $players, $team_players );
|
||||
else:
|
||||
else :
|
||||
array_push( $players, sp_array_between( $the_players, 0, $i ) );
|
||||
endif;
|
||||
endfor;
|
||||
@@ -114,15 +127,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
$this->imported = sizeof( $team_players ) - 1;
|
||||
|
||||
$performance = (array) get_post_meta( $event, 'sp_players', true );
|
||||
$performance = array_filter( $performance );
|
||||
$performance = (array) get_post_meta( $event, 'sp_players', true );
|
||||
$performance = array_filter( $performance );
|
||||
$performance[ $team ] = $team_performance;
|
||||
update_post_meta( $event, 'sp_players', $performance );
|
||||
endif;
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> rows and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> rows and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end( $event );
|
||||
@@ -132,7 +145,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end( $event = 0 ) {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( add_query_arg( array( 'post' => $event, 'action' => 'edit' ), 'post.php' ) ) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'post' => $event,
|
||||
'action' => 'edit',
|
||||
),
|
||||
'post.php'
|
||||
)
|
||||
) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -149,8 +170,14 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
echo '<div class="narrow">';
|
||||
|
||||
if ( $event ) {
|
||||
$args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) );
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
$args = array_merge(
|
||||
$_REQUEST,
|
||||
array(
|
||||
'import' => 'sp_event_performance_csv',
|
||||
'step' => '1',
|
||||
)
|
||||
);
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Box scores need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( add_query_arg( $args, 'admin.php' ) );
|
||||
} else {
|
||||
@@ -167,10 +194,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
function options() {
|
||||
$event = sp_array_value( $_REQUEST, 'event', 0, 'key' );
|
||||
$teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' );
|
||||
$index = sp_array_value( $_REQUEST, 'index', 0, 'key' );
|
||||
$team = sp_array_value( $_REQUEST, 'team', 0, 'key' );
|
||||
$event = sp_array_value( $_REQUEST, 'event', 0, 'key' );
|
||||
$teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' );
|
||||
$index = sp_array_value( $_REQUEST, 'index', 0, 'key' );
|
||||
$team = sp_array_value( $_REQUEST, 'team', 0, 'key' );
|
||||
$include = get_post_meta( $event, 'sp_team', false );
|
||||
?>
|
||||
<table class="form-table">
|
||||
@@ -192,10 +219,10 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'values' => 'ID',
|
||||
'selected' => $team,
|
||||
'include' => $include,
|
||||
'name' => 'sp_team',
|
||||
'values' => 'ID',
|
||||
'selected' => $team,
|
||||
'include' => $include,
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?>
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Fixture importer - import fixtures into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Fixture_Importer extends SP_Importer {
|
||||
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_fixture_csv';
|
||||
$this->import_page = 'sp_fixture_csv';
|
||||
$this->import_label = __( 'Import Fixtures', 'sportspress' );
|
||||
$this->columns = array(
|
||||
$this->columns = array(
|
||||
'post_date' => __( 'Date', 'sportspress' ),
|
||||
'post_time' => __( 'Time', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_home' => __( 'Home', 'sportspress' ),
|
||||
'sp_away' => __( 'Away', 'sportspress' ),
|
||||
'sp_day' => __( 'Match Day', 'sportspress' ),
|
||||
'sp_venue' => __( 'Venue', 'sportspress' ),
|
||||
'sp_home' => __( 'Home', 'sportspress' ),
|
||||
'sp_away' => __( 'Away', 'sportspress' ),
|
||||
'sp_day' => __( 'Match Day', 'sportspress' ),
|
||||
);
|
||||
$this->optionals = array( 'sp_day' );
|
||||
$this->optionals = array( 'sp_day' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +46,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
@@ -53,19 +55,21 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Get event format, league, and season from post vars
|
||||
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
|
||||
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
|
||||
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
|
||||
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
|
||||
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
|
||||
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
|
||||
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
@@ -83,15 +87,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
);
|
||||
|
||||
// Add new event if date is given
|
||||
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
|
||||
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
|
||||
|
||||
// List event columns
|
||||
list( $date, $time, $venue, $day ) = $event;
|
||||
|
||||
// Format date
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date_array = explode( '-', $date );
|
||||
switch ( $date_format ):
|
||||
switch ( $date_format ) :
|
||||
case 'dd/mm/yyyy':
|
||||
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||
@@ -109,12 +113,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endswitch;
|
||||
|
||||
// Add time to date if given
|
||||
if ( ! empty( $time ) ):
|
||||
if ( ! empty( $time ) ) :
|
||||
$date .= ' ' . trim( $time );
|
||||
endif;
|
||||
|
||||
// Define post type args
|
||||
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) );
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
'post_status' => 'publish',
|
||||
'post_date' => $date,
|
||||
'post_title' => __( 'Event', 'sportspress' ),
|
||||
);
|
||||
|
||||
// Insert event
|
||||
$id = wp_insert_post( $args );
|
||||
@@ -123,25 +132,25 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
update_post_meta( $id, '_sp_import', 1 );
|
||||
|
||||
// Update event format
|
||||
if ( $event_format ):
|
||||
if ( $event_format ) :
|
||||
update_post_meta( $id, 'sp_format', $event_format );
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
if ( $league ) :
|
||||
wp_set_object_terms( $id, $league, 'sp_league', false );
|
||||
endif;
|
||||
|
||||
// Update season
|
||||
if ( $season ):
|
||||
if ( $season ) :
|
||||
wp_set_object_terms( $id, $season, 'sp_season', false );
|
||||
endif;
|
||||
|
||||
// Update venue
|
||||
if ( $venue == '' ) {
|
||||
$team = reset( $teams );
|
||||
$team = reset( $teams );
|
||||
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
|
||||
$venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' );
|
||||
$venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' );
|
||||
}
|
||||
wp_set_object_terms( $id, $venue, 'sp_venue', false );
|
||||
|
||||
@@ -156,30 +165,41 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Add teams to event
|
||||
if ( sizeof( $teams ) > 0 ):
|
||||
if ( sizeof( $teams ) > 0 ) :
|
||||
|
||||
foreach ( $teams as $team_name ):
|
||||
foreach ( $teams as $team_name ) :
|
||||
|
||||
if ( '' !== $team_name ):
|
||||
if ( '' !== $team_name ) :
|
||||
|
||||
// Find out if team exists
|
||||
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
|
||||
|
||||
// Get or insert team
|
||||
if ( $team_object ):
|
||||
if ( $team_object ) :
|
||||
|
||||
// Make sure team is published
|
||||
if ( $team_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $team_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $team_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
|
||||
// Get team ID
|
||||
$team_id = $team_object->ID;
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Insert team
|
||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) );
|
||||
$team_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $team_name ),
|
||||
)
|
||||
);
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $team_id, '_sp_import', 1 );
|
||||
@@ -187,17 +207,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
endif;
|
||||
|
||||
// Update league
|
||||
if ( $league ):
|
||||
if ( $league ) :
|
||||
wp_set_object_terms( $team_id, $league, 'sp_league', true );
|
||||
endif;
|
||||
|
||||
// Update season
|
||||
if ( $season ):
|
||||
if ( $season ) :
|
||||
wp_set_object_terms( $team_id, $season, 'sp_season', true );
|
||||
endif;
|
||||
|
||||
// Add to event if exists
|
||||
if ( isset( $id ) ):
|
||||
if ( isset( $id ) ) :
|
||||
|
||||
// Add team to event
|
||||
add_post_meta( $id, 'sp_team', $team_id );
|
||||
@@ -217,19 +237,19 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Update event with new name
|
||||
$post = array(
|
||||
'ID' => $id,
|
||||
'ID' => $id,
|
||||
'post_title' => $title,
|
||||
'post_name' => $id,
|
||||
'post_name' => $id,
|
||||
);
|
||||
wp_update_post( $post );
|
||||
|
||||
endif;
|
||||
|
||||
else:
|
||||
else :
|
||||
|
||||
// Add empty team to event
|
||||
add_post_meta( $id, 'sp_team', -1 );
|
||||
|
||||
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
@@ -240,7 +260,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -250,7 +270,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -263,7 +283,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Fixtures need to be defined with columns in a specific order (4+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/fixtures-sample.csv' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_fixture_csv&step=1' );
|
||||
@@ -293,56 +313,60 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
|
||||
<td><?php
|
||||
<td>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'values' => 'slug',
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '— Not set —', 'sportspress' ),
|
||||
);
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ) :
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
|
||||
<td><?php
|
||||
<td>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'values' => 'slug',
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'values' => 'slug',
|
||||
'show_option_none' => __( '— Not set —', 'sportspress' ),
|
||||
);
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ):
|
||||
if ( ! sp_dropdown_taxonomies( $args ) ) :
|
||||
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
|
||||
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?></td>
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" class="titledesc">
|
||||
<?php _e( 'Date Format', 'sportspress' ); ?>
|
||||
</th>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* SportsPress Importer
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7.9
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Importer extends WP_Importer {
|
||||
@@ -21,7 +23,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
var $imported;
|
||||
var $skipped;
|
||||
var $import_label;
|
||||
var $columns = array();
|
||||
var $columns = array();
|
||||
var $optionals = array();
|
||||
|
||||
/**
|
||||
@@ -35,7 +37,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Enqueue scripts
|
||||
*/
|
||||
public function admin_scripts() {
|
||||
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true );
|
||||
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,32 +48,36 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function dispatch() {
|
||||
$this->header();
|
||||
|
||||
if ( ! empty( $_POST['delimiter'] ) )
|
||||
if ( ! empty( $_POST['delimiter'] ) ) {
|
||||
$this->delimiter = stripslashes( trim( sanitize_text_field( $_POST['delimiter'] ) ) );
|
||||
}
|
||||
|
||||
if ( ! $this->delimiter )
|
||||
if ( ! $this->delimiter ) {
|
||||
$this->delimiter = ',';
|
||||
}
|
||||
|
||||
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
|
||||
switch ( $step ):
|
||||
switch ( $step ) :
|
||||
case 0:
|
||||
$this->greet();
|
||||
break;
|
||||
case 1:
|
||||
check_admin_referer( 'import-upload' );
|
||||
if ( $this->handle_upload() ):
|
||||
if ( $this->handle_upload() ) :
|
||||
|
||||
if ( $this->id )
|
||||
if ( $this->id ) {
|
||||
$file = get_attached_file( $this->id );
|
||||
else
|
||||
} else {
|
||||
$file = ABSPATH . $this->file_url;
|
||||
}
|
||||
|
||||
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
||||
|
||||
if ( function_exists( 'gc_enable' ) )
|
||||
if ( function_exists( 'gc_enable' ) ) {
|
||||
gc_enable();
|
||||
}
|
||||
|
||||
@set_time_limit(0);
|
||||
@set_time_limit( 0 );
|
||||
@ob_flush();
|
||||
@flush();
|
||||
|
||||
@@ -80,7 +86,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
break;
|
||||
case 2:
|
||||
check_admin_referer( 'import-upload' );
|
||||
if ( isset( $_POST['sp_import'] ) ):
|
||||
if ( isset( $_POST['sp_import'] ) ) :
|
||||
$columns = array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) );
|
||||
$this->import( $_POST['sp_import'], array_values( $columns ) );
|
||||
endif;
|
||||
@@ -100,7 +106,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
?>
|
||||
<select name="sp_columns[]" data-index="<?php echo array_search( $selected, array_keys( $this->columns ) ); ?>">
|
||||
<option value="0">— <?php _e( 'Disable', 'sportspress' ); ?> —</option>
|
||||
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||
<?php foreach ( $this->columns as $key => $label ) : ?>
|
||||
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $selected, $key ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
@@ -119,26 +125,26 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_file($file) ):
|
||||
if ( ! is_file( $file ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
|
||||
ini_set( 'auto_detect_line_endings', '1' );
|
||||
|
||||
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
|
||||
if ( ( $handle = fopen( $file, 'r' ) ) !== false ) :
|
||||
|
||||
$header = fgetcsv( $handle, 0, $this->delimiter );
|
||||
|
||||
if ( sizeof( $header ) >= 1 ):
|
||||
if ( sizeof( $header ) >= 1 ) :
|
||||
$action = 'admin.php?import=' . $this->import_page . '&step=2';
|
||||
?>
|
||||
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
|
||||
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr( wp_nonce_url( $action, 'import-upload' ) ); ?>">
|
||||
<?php $this->options(); ?>
|
||||
<table class="wp-list-table sp-data-table sp-import-table widefat fixed pages">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||
<?php foreach ( $this->columns as $key => $label ) : ?>
|
||||
<th scope="col" class="manage-column">
|
||||
<?php $this->dropdown( $key ); ?>
|
||||
</th>
|
||||
@@ -149,21 +155,35 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ): ?>
|
||||
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== false ) : ?>
|
||||
<tr>
|
||||
<?php $index = 0; foreach ( $this->columns as $key => $label ): $value = sp_array_value( $row, $index ); ?>
|
||||
<?php
|
||||
$index = 0;
|
||||
foreach ( $this->columns as $key => $label ) :
|
||||
$value = sp_array_value( $row, $index );
|
||||
?>
|
||||
<td>
|
||||
<input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"<?php if ( in_array( $key, $this->optionals ) ) { ?> placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>>
|
||||
<input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"
|
||||
<?php
|
||||
if ( in_array( $key, $this->optionals ) ) {
|
||||
?>
|
||||
placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>>
|
||||
</td>
|
||||
<?php $index ++; endforeach; ?>
|
||||
<?php
|
||||
$index ++;
|
||||
endforeach;
|
||||
?>
|
||||
<td class="sp-actions-column">
|
||||
<a href="#" title="<?php _e( 'Delete row', 'sportspress' ); ?>" class="dashicons dashicons-dismiss sp-delete-row"></a>
|
||||
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $this->imported++; endwhile; ?>
|
||||
<?php
|
||||
$this->imported++;
|
||||
endwhile;
|
||||
?>
|
||||
<tr>
|
||||
<?php foreach ( $this->columns as $key => $label ): ?>
|
||||
<?php foreach ( $this->columns as $key => $label ) : ?>
|
||||
<td>
|
||||
<input type="text" class="widefat" name="sp_import[]">
|
||||
</td>
|
||||
@@ -172,17 +192,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="sp-post-count alignright">
|
||||
<?php printf( __( 'Displaying %s–%s of %s', 'sportspress' ), 1, $this->imported+1, $this->imported+1 ); ?>
|
||||
<?php printf( __( 'Displaying %1$s–%2$s of %3$s', 'sportspress' ), 1, $this->imported + 1, $this->imported + 1 ); ?>
|
||||
</p>
|
||||
<p class="submit">
|
||||
<input type="submit" class="button button-primary button-hero" value="<?php echo esc_attr( $this->import_label ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
else:
|
||||
else :
|
||||
|
||||
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
|
||||
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
|
||||
@@ -191,7 +211,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
endif;
|
||||
|
||||
fclose( $handle );
|
||||
fclose( $handle );
|
||||
endif;
|
||||
}
|
||||
|
||||
@@ -199,7 +219,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* format_data_from_csv function.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $data
|
||||
* @param mixed $data
|
||||
* @param string $enc
|
||||
* @return string
|
||||
*/
|
||||
@@ -239,7 +259,6 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -276,6 +295,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
/**
|
||||
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
||||
*
|
||||
* @param int $val
|
||||
* @return int 60
|
||||
*/
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Official importer - import officials into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.1
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.1
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Official_Importer extends SP_Importer {
|
||||
@@ -20,9 +22,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_official_csv';
|
||||
$this->import_page = 'sp_official_csv';
|
||||
$this->import_label = __( 'Import Officials', 'sportspress' );
|
||||
$this->columns = array(
|
||||
$this->columns = array(
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
);
|
||||
parent::__construct();
|
||||
@@ -39,33 +41,39 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
|
||||
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
$name = sp_array_value( $meta, 'post_title' );
|
||||
|
||||
if ( ! $name ):
|
||||
if ( ! $name ) :
|
||||
$this->skipped++;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
$args = array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||
$args = array(
|
||||
'post_type' => 'sp_official',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $name ),
|
||||
);
|
||||
|
||||
$id = wp_insert_post( $args );
|
||||
|
||||
@@ -75,7 +83,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> officials and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> officials and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -85,7 +93,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_official') . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_official' ) . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -108,7 +116,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Officials need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' );
|
||||
echo '</div>';
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Player importer - import players into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Player_Importer extends SP_Importer {
|
||||
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_player_csv';
|
||||
$this->import_page = 'sp_player_csv';
|
||||
$this->import_label = __( 'Import Players', 'sportspress' );
|
||||
$this->columns = array(
|
||||
'sp_number' => __( 'Squad Number', 'sportspress' ),
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
$this->columns = array(
|
||||
'sp_number' => __( 'Squad Number', 'sportspress' ),
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_nationality' => __( 'Nationality', 'sportspress' ),
|
||||
'post_date' => __( 'Date of Birth', 'sportspress' ),
|
||||
'post_date' => __( 'Date of Birth', 'sportspress' ),
|
||||
);
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -46,21 +48,23 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
|
||||
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||
|
||||
|
||||
// Get Date of Birth format from post vars
|
||||
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row, 'strlen' );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
@@ -76,17 +80,17 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
$meta[ $p ] = '';
|
||||
}
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
$name = sp_array_value( $meta, 'post_title' );
|
||||
$date = sp_array_value( $meta, 'post_date' );
|
||||
|
||||
|
||||
// Format date of birth
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date = str_replace( '/', '-', trim( $date ) );
|
||||
$date_array = explode( '-', $date );
|
||||
switch ( $date_format ):
|
||||
switch ( $date_format ) :
|
||||
case 'dd/mm/yyyy':
|
||||
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||
@@ -103,28 +107,37 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
|
||||
endswitch;
|
||||
|
||||
if ( ! $name ):
|
||||
if ( ! $name ) :
|
||||
$this->skipped++;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
// Get or insert player
|
||||
$player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false;
|
||||
if ( $player_object ):
|
||||
if ( $player_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $player_object ) :
|
||||
if ( $player_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $player_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
$id = $player_object->ID;
|
||||
// Handle preservable data.
|
||||
foreach ( $preservable_metas_keys as $p ) {
|
||||
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
|
||||
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
|
||||
$meta[ $p ] .= '|' . implode( '|', $terms );
|
||||
}
|
||||
else:
|
||||
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||
else :
|
||||
$args = array(
|
||||
'post_type' => 'sp_player',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $name ),
|
||||
);
|
||||
// Check if a DoB was set
|
||||
if( '0000-00-00' !== $date ){
|
||||
$args['post_date'] = $date;
|
||||
if ( '0000-00-00' !== $date ) {
|
||||
$args['post_date'] = $date;
|
||||
}
|
||||
$id = wp_insert_post( $args );
|
||||
|
||||
@@ -148,18 +161,29 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
||||
|
||||
// Update teams
|
||||
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||
$i = 0;
|
||||
foreach ( $teams as $team ):
|
||||
$teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||
$i = 0;
|
||||
foreach ( $teams as $team ) :
|
||||
// Get or insert team
|
||||
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
|
||||
if ( $team_object ):
|
||||
if ( $team_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $team_object ) :
|
||||
if ( $team_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $team_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
$team_id = $team_object->ID;
|
||||
else:
|
||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) );
|
||||
else :
|
||||
$team_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $team ),
|
||||
)
|
||||
);
|
||||
// Flag as import
|
||||
update_post_meta( $team_id, '_sp_import', 1 );
|
||||
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
||||
@@ -170,7 +194,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
add_post_meta( $id, 'sp_team', $team_id );
|
||||
|
||||
// Update current team if first in array, otherwise use as past team
|
||||
if ( $i == 0 ):
|
||||
if ( $i == 0 ) :
|
||||
update_post_meta( $id, 'sp_current_team', $team_id );
|
||||
else :
|
||||
add_post_meta( $id, 'sp_past_team', $team_id );
|
||||
@@ -181,7 +205,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Update nationality
|
||||
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
|
||||
if ( $nationality == '*' ) $nationality = '';
|
||||
if ( $nationality == '*' ) {
|
||||
$nationality = '';
|
||||
}
|
||||
update_post_meta( $id, 'sp_nationality', $nationality );
|
||||
|
||||
$this->imported++;
|
||||
@@ -190,7 +216,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> players and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> players and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -200,7 +226,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_player') . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_player' ) . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -223,7 +249,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' );
|
||||
echo '</div>';
|
||||
@@ -243,22 +269,22 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
<th scope="row" class="titledesc">
|
||||
<?php _e( 'Date of Birth Format', 'sportspress' ); ?>
|
||||
</th>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<td class="forminp forminp-radio">
|
||||
<fieldset>
|
||||
<ul>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Staff importer - import staff into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.5
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.5
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Staff_Importer extends SP_Importer {
|
||||
@@ -20,14 +22,14 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_staff_csv';
|
||||
$this->import_page = 'sp_staff_csv';
|
||||
$this->import_label = __( 'Import Staff', 'sportspress' );
|
||||
$this->columns = array(
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_role' => __( 'Jobs', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
$this->columns = array(
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_role' => __( 'Jobs', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_nationality' => __( 'Nationality', 'sportspress' ),
|
||||
);
|
||||
parent::__construct();
|
||||
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
|
||||
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
$name = sp_array_value( $meta, 'post_title' );
|
||||
|
||||
if ( ! $name ):
|
||||
if ( ! $name ) :
|
||||
$this->skipped++;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
// Get or insert staff
|
||||
$staff_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_staff' ) : false;
|
||||
if ( $staff_object ):
|
||||
if ( $staff_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $staff_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $staff_object ) :
|
||||
if ( $staff_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $staff_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
$id = $staff_object->ID;
|
||||
else:
|
||||
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||
$id = wp_insert_post( $args );
|
||||
else :
|
||||
$args = array(
|
||||
'post_type' => 'sp_staff',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $name ),
|
||||
);
|
||||
$id = wp_insert_post( $args );
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $id, '_sp_import', 1 );
|
||||
@@ -98,18 +111,29 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
wp_set_object_terms( $id, $seasons, 'sp_season', false );
|
||||
|
||||
// Update teams
|
||||
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||
$i = 0;
|
||||
foreach ( $teams as $team ):
|
||||
$teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
|
||||
$i = 0;
|
||||
foreach ( $teams as $team ) :
|
||||
// Get or insert team
|
||||
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
|
||||
if ( $team_object ):
|
||||
if ( $team_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $team_object ) :
|
||||
if ( $team_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $team_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
$team_id = $team_object->ID;
|
||||
else:
|
||||
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) );
|
||||
else :
|
||||
$team_id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $team ),
|
||||
)
|
||||
);
|
||||
// Flag as import
|
||||
update_post_meta( $team_id, '_sp_import', 1 );
|
||||
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
|
||||
@@ -120,7 +144,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
add_post_meta( $id, 'sp_team', $team_id );
|
||||
|
||||
// Update current team if first in array
|
||||
if ( $i == 0 ):
|
||||
if ( $i == 0 ) :
|
||||
update_post_meta( $id, 'sp_current_team', $team_id );
|
||||
endif;
|
||||
|
||||
@@ -129,7 +153,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Update nationality
|
||||
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
|
||||
if ( $nationality == '*' ) $nationality = '';
|
||||
if ( $nationality == '*' ) {
|
||||
$nationality = '';
|
||||
}
|
||||
update_post_meta( $id, 'sp_nationality', $nationality );
|
||||
|
||||
$this->imported++;
|
||||
@@ -138,7 +164,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> staff and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> staff and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -148,7 +174,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_staff') . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_staff' ) . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -171,7 +197,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' );
|
||||
echo '</div>';
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
/**
|
||||
* Team importer - import teams into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.5
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 2.5.5
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Team_Importer extends SP_Importer {
|
||||
@@ -20,15 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->import_page = 'sp_team_csv';
|
||||
$this->import_page = 'sp_team_csv';
|
||||
$this->import_label = __( 'Import Teams', 'sportspress' );
|
||||
$this->columns = array(
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_url' => __( 'Site URL', 'sportspress' ),
|
||||
$this->columns = array(
|
||||
'post_title' => __( 'Name', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' ),
|
||||
'sp_season' => __( 'Seasons', 'sportspress' ),
|
||||
'sp_url' => __( 'Site URL', 'sportspress' ),
|
||||
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
|
||||
'sp_venue' => __( 'Home', 'sportspress' ),
|
||||
'sp_venue' => __( 'Home', 'sportspress' ),
|
||||
);
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
function import( $array = array(), $columns = array( 'post_title' ) ) {
|
||||
$this->imported = $this->skipped = 0;
|
||||
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ):
|
||||
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
|
||||
$this->footer();
|
||||
die();
|
||||
endif;
|
||||
|
||||
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||
|
||||
foreach ( $rows as $row ):
|
||||
foreach ( $rows as $row ) :
|
||||
|
||||
$row = array_filter( $row );
|
||||
|
||||
if ( empty( $row ) ) continue;
|
||||
if ( empty( $row ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
|
||||
foreach ( $columns as $index => $key ):
|
||||
foreach ( $columns as $index => $key ) :
|
||||
$meta[ $key ] = sp_array_value( $row, $index );
|
||||
endforeach;
|
||||
|
||||
$name = sp_array_value( $meta, 'post_title' );
|
||||
|
||||
if ( ! $name ):
|
||||
if ( ! $name ) :
|
||||
$this->skipped++;
|
||||
continue;
|
||||
endif;
|
||||
|
||||
// Get or insert team
|
||||
$team_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_team' ) : false;
|
||||
if ( $team_object ):
|
||||
if ( $team_object->post_status != 'publish' ):
|
||||
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||
if ( $team_object ) :
|
||||
if ( $team_object->post_status != 'publish' ) :
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $team_object->ID,
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
endif;
|
||||
$id = $team_object->ID;
|
||||
else:
|
||||
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||
$id = wp_insert_post( $args );
|
||||
else :
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => wp_strip_all_tags( $name ),
|
||||
);
|
||||
$id = wp_insert_post( $args );
|
||||
|
||||
// Flag as import
|
||||
update_post_meta( $id, '_sp_import', 1 );
|
||||
@@ -107,7 +120,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
|
||||
// Show Result
|
||||
echo '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> teams and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> teams and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
@@ -117,7 +130,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_team') . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>';
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_team' ) . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
@@ -130,7 +143,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
|
||||
echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' );
|
||||
echo '</div>';
|
||||
|
||||
Reference in New Issue
Block a user