Code Duplication    Length = 60-60 lines in 2 locations

geodirectory-admin/admin_functions.php 2 locations

@@ 3831-3890 (lines=60) @@
3828
            }
3829
        }
3830
        break;
3831
        case 'export_locations': {
3832
            $file_url_base = geodir_path_import_export() . '/';
3833
            $file_name = 'gd_locations_' . date( 'dmyHi' );
3834
            $file_url = $file_url_base . $file_name . '.csv';
3835
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
3836
            $file_path_temp = $csv_file_dir . '/gd_locations_' . $nonce . '.csv';
3837
            
3838
            $items_count = (int)geodir_location_imex_count_locations();
3839
            
3840
            if ( isset( $_REQUEST['_st'] ) ) {
3841
                $line_count = (int)geodir_import_export_line_count( $file_path_temp );
3842
                $percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
3843
                $percentage = min( $percentage, 100 );
3844
                
3845
                $json['percentage'] = $percentage;
3846
                wp_send_json( $json );
3847
            } else {
3848
                $chunk_file_paths = array();
3849
                
3850
                if ( !$items_count > 0 ) {
3851
                    $json['error'] = __( 'No records to export.', 'geodirectory' );
3852
                } else {
3853
                    $chunk_per_page = min( $chunk_per_page, $items_count );
3854
                    $chunk_total_pages = ceil( $items_count / $chunk_per_page );
3855
                    
3856
                    $j = $chunk_page_no;
3857
                    $chunk_save_items = geodir_location_imex_locations_data( $chunk_per_page, $j );
3858
                    
3859
                    $per_page = 500;
3860
                    $per_page = min( $per_page, $chunk_per_page );
3861
                    $total_pages = ceil( $chunk_per_page / $per_page );
3862
                    
3863
                    for ( $i = 0; $i <= $total_pages; $i++ ) {
3864
                        $save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
3865
                        
3866
                        $clear = $i == 0 ? true : false;
3867
                        geodir_save_csv_data( $file_path_temp, $save_items, $clear );
3868
                    }
3869
                    
3870
                    if ( $wp_filesystem->exists( $file_path_temp ) ) {
3871
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
3872
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
3873
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
3874
                        $wp_filesystem->move( $file_path_temp, $file_path, true );
3875
                        
3876
                        $file_url = $file_url_base . $chunk_file_name;
3877
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
3878
                    }
3879
                    
3880
                    if ( !empty($chunk_file_paths) ) {
3881
                        $json['total'] = $items_count;
3882
                        $json['files'] = $chunk_file_paths;
3883
                    } else {
3884
                        $json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
3885
                    }
3886
                }
3887
                wp_send_json( $json );
3888
            }
3889
        }
3890
        break;
3891
        case 'export_hoods': {
3892
            $file_url_base = geodir_path_import_export() . '/';
3893
            $file_name = 'gd_neighbourhoods_' . date( 'dmyHi' );
@@ 3891-3950 (lines=60) @@
3888
            }
3889
        }
3890
        break;
3891
        case 'export_hoods': {
3892
            $file_url_base = geodir_path_import_export() . '/';
3893
            $file_name = 'gd_neighbourhoods_' . date( 'dmyHi' );
3894
            $file_url = $file_url_base . $file_name . '.csv';
3895
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
3896
            $file_path_temp = $csv_file_dir . '/gd_neighbourhoods_' . $nonce . '.csv';
3897
            
3898
            $items_count = (int)geodir_location_imex_count_neighbourhoods();
3899
            
3900
            if ( isset( $_REQUEST['_st'] ) ) {
3901
                $line_count = (int)geodir_import_export_line_count( $file_path_temp );
3902
                $percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
3903
                $percentage = min( $percentage, 100 );
3904
                
3905
                $json['percentage'] = $percentage;
3906
                wp_send_json( $json );
3907
            } else {
3908
                $chunk_file_paths = array();
3909
                
3910
                if ( !$items_count > 0 ) {
3911
                    $json['error'] = __( 'No records to export.', 'geodirectory' );
3912
                } else {
3913
                    $chunk_per_page = min( $chunk_per_page, $items_count );
3914
                    $chunk_total_pages = ceil( $items_count / $chunk_per_page );
3915
                    
3916
                    $j = $chunk_page_no;
3917
                    $chunk_save_items = geodir_location_imex_neighbourhoods_data( $chunk_per_page, $j );
3918
                    
3919
                    $per_page = 500;
3920
                    $per_page = min( $per_page, $chunk_per_page );
3921
                    $total_pages = ceil( $chunk_per_page / $per_page );
3922
                    
3923
                    for ( $i = 0; $i <= $total_pages; $i++ ) {
3924
                        $save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
3925
                        
3926
                        $clear = $i == 0 ? true : false;
3927
                        geodir_save_csv_data( $file_path_temp, $save_items, $clear );
3928
                    }
3929
                    
3930
                    if ( $wp_filesystem->exists( $file_path_temp ) ) {
3931
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
3932
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
3933
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
3934
                        $wp_filesystem->move( $file_path_temp, $file_path, true );
3935
                        
3936
                        $file_url = $file_url_base . $chunk_file_name;
3937
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
3938
                    }
3939
                    
3940
                    if ( !empty($chunk_file_paths) ) {
3941
                        $json['total'] = $items_count;
3942
                        $json['files'] = $chunk_file_paths;
3943
                    } else {
3944
                        $json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
3945
                    }
3946
                }
3947
                wp_send_json( $json );
3948
            }
3949
        }
3950
        break;
3951
        case 'prepare_import':
3952
        case 'import_cat':
3953
        case 'import_post':