Clean up spaces, tabs, indentation, and bracket formatting

This commit is contained in:
Brian Miyaji
2021-11-10 15:41:40 +09:00
parent e58beb1201
commit 3dff686a00
285 changed files with 29638 additions and 24147 deletions

View File

@@ -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 );
?>