Code Duplication    Length = 60-60 lines in 2 locations

geodirectory-admin/admin_functions.php 2 locations

@@ 3892-3951 (lines=60) @@
3889
            }
3890
        }
3891
        break;
3892
        case 'export_locations': {
3893
            $file_url_base = geodir_path_import_export() . '/';
3894
            $file_name = 'gd_locations_' . date( 'dmyHi' );
3895
            $file_url = $file_url_base . $file_name . '.csv';
3896
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
3897
            $file_path_temp = $csv_file_dir . '/gd_locations_' . $nonce . '.csv';
3898
            
3899
            $items_count = (int)geodir_location_imex_count_locations();
3900
            
3901
            if ( isset( $_REQUEST['_st'] ) ) {
3902
                $line_count = (int)geodir_import_export_line_count( $file_path_temp );
3903
                $percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
3904
                $percentage = min( $percentage, 100 );
3905
                
3906
                $json['percentage'] = $percentage;
3907
                wp_send_json( $json );
3908
            } else {
3909
                $chunk_file_paths = array();
3910
                
3911
                if ( !$items_count > 0 ) {
3912
                    $json['error'] = __( 'No records to export.', 'geodirectory' );
3913
                } else {
3914
                    $chunk_per_page = min( $chunk_per_page, $items_count );
3915
                    $chunk_total_pages = ceil( $items_count / $chunk_per_page );
3916
                    
3917
                    $j = $chunk_page_no;
3918
                    $chunk_save_items = geodir_location_imex_locations_data( $chunk_per_page, $j );
3919
                    
3920
                    $per_page = 500;
3921
                    $per_page = min( $per_page, $chunk_per_page );
3922
                    $total_pages = ceil( $chunk_per_page / $per_page );
3923
                    
3924
                    for ( $i = 0; $i <= $total_pages; $i++ ) {
3925
                        $save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
3926
                        
3927
                        $clear = $i == 0 ? true : false;
3928
                        geodir_save_csv_data( $file_path_temp, $save_items, $clear );
3929
                    }
3930
                    
3931
                    if ( $wp_filesystem->exists( $file_path_temp ) ) {
3932
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
3933
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
3934
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
3935
                        $wp_filesystem->move( $file_path_temp, $file_path, true );
3936
                        
3937
                        $file_url = $file_url_base . $chunk_file_name;
3938
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
3939
                    }
3940
                    
3941
                    if ( !empty($chunk_file_paths) ) {
3942
                        $json['total'] = $items_count;
3943
                        $json['files'] = $chunk_file_paths;
3944
                    } else {
3945
                        $json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
3946
                    }
3947
                }
3948
                wp_send_json( $json );
3949
            }
3950
        }
3951
        break;
3952
        case 'export_hoods': {
3953
            $file_url_base = geodir_path_import_export() . '/';
3954
            $file_name = 'gd_neighbourhoods_' . date( 'dmyHi' );
@@ 3952-4011 (lines=60) @@
3949
            }
3950
        }
3951
        break;
3952
        case 'export_hoods': {
3953
            $file_url_base = geodir_path_import_export() . '/';
3954
            $file_name = 'gd_neighbourhoods_' . date( 'dmyHi' );
3955
            $file_url = $file_url_base . $file_name . '.csv';
3956
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
3957
            $file_path_temp = $csv_file_dir . '/gd_neighbourhoods_' . $nonce . '.csv';
3958
            
3959
            $items_count = (int)geodir_location_imex_count_neighbourhoods();
3960
            
3961
            if ( isset( $_REQUEST['_st'] ) ) {
3962
                $line_count = (int)geodir_import_export_line_count( $file_path_temp );
3963
                $percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
3964
                $percentage = min( $percentage, 100 );
3965
                
3966
                $json['percentage'] = $percentage;
3967
                wp_send_json( $json );
3968
            } else {
3969
                $chunk_file_paths = array();
3970
                
3971
                if ( !$items_count > 0 ) {
3972
                    $json['error'] = __( 'No records to export.', 'geodirectory' );
3973
                } else {
3974
                    $chunk_per_page = min( $chunk_per_page, $items_count );
3975
                    $chunk_total_pages = ceil( $items_count / $chunk_per_page );
3976
                    
3977
                    $j = $chunk_page_no;
3978
                    $chunk_save_items = geodir_location_imex_neighbourhoods_data( $chunk_per_page, $j );
3979
                    
3980
                    $per_page = 500;
3981
                    $per_page = min( $per_page, $chunk_per_page );
3982
                    $total_pages = ceil( $chunk_per_page / $per_page );
3983
                    
3984
                    for ( $i = 0; $i <= $total_pages; $i++ ) {
3985
                        $save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
3986
                        
3987
                        $clear = $i == 0 ? true : false;
3988
                        geodir_save_csv_data( $file_path_temp, $save_items, $clear );
3989
                    }
3990
                    
3991
                    if ( $wp_filesystem->exists( $file_path_temp ) ) {
3992
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
3993
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
3994
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
3995
                        $wp_filesystem->move( $file_path_temp, $file_path, true );
3996
                        
3997
                        $file_url = $file_url_base . $chunk_file_name;
3998
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
3999
                    }
4000
                    
4001
                    if ( !empty($chunk_file_paths) ) {
4002
                        $json['total'] = $items_count;
4003
                        $json['files'] = $chunk_file_paths;
4004
                    } else {
4005
                        $json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
4006
                    }
4007
                }
4008
                wp_send_json( $json );
4009
            }
4010
        }
4011
        break;
4012
        case 'prepare_import':
4013
        case 'import_cat':
4014
        case 'import_post':