Clean up spaces, tabs, indentation, and bracket formatting
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user