Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions includes/classes/class-listings-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public static function get_prepared_listings_export_file() {
file_put_contents( $file, $file_contents );

$wp_filetype = wp_check_filetype( $file_name, null );
$attachment = [
$attachment = [
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
];

$attach_id = wp_insert_attachment( $attachment, $file );
$attach_id = wp_insert_attachment( $attachment, $file );
$attach_url = wp_get_attachment_url( $attach_id );

update_directorist_option( 'directorist_export_attachent_id', $attach_id );
Expand Down Expand Up @@ -71,7 +71,7 @@ public static function get_listings_data_as_csv_content() {

$row_content__ = str_replace( '"', "'", $row_content__ );
$row_content__ = '"' . $row_content__ . '",';
$row_content .= $row_content__;
$row_content .= $row_content__;
}
$contents .= rtrim( $row_content, ',' ) . "\n";
}
Expand All @@ -95,27 +95,27 @@ public static function get_listings_data() {
);

$field_map = [
'native_field' => [
'native_field' => [
'verify' => 'verifyNativeField',
'update_data' => 'updateNativeFieldData',
],
'taxonomy_field' => [
'taxonomy_field' => [
'verify' => 'verifyTaxonomyField',
'update_data' => 'updateTaxonomyFieldData',
],
'listing_image_module_field' => [
'verify' => 'verifyListingImageModuleField',
'update_data' => 'updateListingImageModuleFieldsData',
],
'price_module_field' => [
'price_module_field' => [
'verify' => 'verifyPriceModuleField',
'update_data' => 'updatePriceModuleFieldData',
],
'map_module_field' => [
'map_module_field' => [
'verify' => 'verifyMapModuleField',
'update_data' => 'updateMapModuleFieldData',
],
'meta_key_field' => [
'meta_key_field' => [
'verify' => 'verifyMetaKeyField',
'update_data' => 'updateMetaKeyFieldData',
],
Expand All @@ -127,8 +127,8 @@ public static function get_listings_data() {
while ( $listings->have_posts() ) {
$listings->the_post();

$row = [];
$row['id'] = get_the_ID();
$row = [];
$row['id'] = get_the_ID();
$row['directory'] = self::get_directory_slug_by_id( get_the_id() );

$directory_type_id = get_post_meta( get_the_ID(), '_directory_type', true );
Expand All @@ -149,9 +149,9 @@ public static function get_listings_data() {
}
}

$row = self::updateListingReviewsData( $row, get_the_ID() );
$row = apply_filters( 'directorist_listings_export_row', $row );
$max_row_length = count( array_keys( $row ) );
$row = self::updateListingReviewsData( $row, get_the_ID() );
$row = apply_filters( 'directorist_listings_export_row', $row );
$max_row_length = count( array_keys( $row ) );
$tr_lengths [] = $max_row_length;
$listings_data[] = $row;
}
Expand All @@ -166,20 +166,40 @@ public static function get_listings_data() {
// justifyDataRow
public static function justifyDataTableRow( $data_table = [], $tr_lengths = [] ) {
if ( empty( $data_table ) ) {
return $data_table; }
return $data_table;
}

if ( ! is_array( $data_table ) ) {
return $data_table; }
return $data_table;
}

$columns = [];
foreach ( $data_table as $row ) {
if ( ! is_array( $row ) ) {
continue;
}

foreach ( $row as $row_key => $row_value ) {
if ( ! array_key_exists( $row_key, $columns ) ) {
$columns[ $row_key ] = '';
}
}
}

$max_tr_val = max( $tr_lengths );
$max_tr_index = array_search( $max_tr_val, $tr_lengths );
$modal_tr = $data_table[ $max_tr_index ];
if ( empty( $columns ) ) {
return $data_table;
}

$justify_table = [];
foreach ( $data_table as $row ) {
if ( ! is_array( $row ) ) {
continue;
}

$tr = [];

foreach ( $modal_tr as $row_key => $row_value ) {
$tr[ $row_key ] = ( isset( $row[ $row_key ] ) ) ? $row[ $row_key ] : '';
foreach ( array_keys( $columns ) as $row_key ) {
$tr[ $row_key ] = array_key_exists( $row_key, $row ) ? $row[ $row_key ] : '';
}

$justify_table[] = $tr;
Expand Down Expand Up @@ -218,7 +238,7 @@ public static function updateNativeFieldData( array $row = [], string $field_key
];

$field_key = $field_args['field_key'];
$content = call_user_func( $field_data_map[ $field_key ] );
$content = call_user_func( $field_data_map[ $field_key ] );
// $content = str_replace( '"', '""', $content );

$row[ $field_key ] = self::escape_data( $content );
Expand Down Expand Up @@ -326,15 +346,15 @@ public static function verifyMetaKeyField( $args = [] ) {

// updateMetaKeyFieldData
public static function updateMetaKeyFieldData( array $row = [], string $field_key = '', array $field_args = [] ) {
$value = get_post_meta( get_the_id(), '_' . $field_args['field_key'], true );
$row[ 'publish_date' ] = get_the_date( 'Y-m-d H:i:s', get_the_ID() );
$value = get_post_meta( get_the_id(), '_' . $field_args['field_key'], true );
$row[ 'publish_date' ] = get_the_date( 'Y-m-d H:i:s', get_the_ID() );
$row[ $field_args['field_key'] ] = self::escape_data( $value );

return $row;
}

public static function updateListingReviewsData( array $row = [], $listing_id = 0 ) {
$reviews = self::get_listing_reviews_data( $listing_id );
$reviews = self::get_listing_reviews_data( $listing_id );
$row['reviews'] = '';

if ( empty( $reviews ) ) {
Expand Down Expand Up @@ -362,8 +382,8 @@ public static function verifyPriceModuleField( $args = [] ) {

// updatePriceModuleFieldData
public static function updatePriceModuleFieldData( array $row = [], string $field_key = '', array $field_args = [] ) {
$row[ 'price' ] = self::escape_data( get_post_meta( get_the_id(), '_price', true ) );
$row[ 'price_range' ] = self::escape_data( get_post_meta( get_the_id(), '_price_range', true ) );
$row[ 'price' ] = self::escape_data( get_post_meta( get_the_id(), '_price', true ) );
$row[ 'price_range' ] = self::escape_data( get_post_meta( get_the_id(), '_price_range', true ) );
$row[ 'atbd_listing_pricing' ] = self::escape_data( get_post_meta( get_the_id(), '_atbd_listing_pricing', true ) );

return $row;
Expand All @@ -385,7 +405,7 @@ public static function verifyMapModuleField( $args = [] ) {

// updateMapModuleFieldData
public static function updateMapModuleFieldData( array $row = [], string $field_key = '', array $field_args = [] ) {
$row[ 'hide_map' ] = get_post_meta( get_the_id(), '_hide_map', true );
$row[ 'hide_map' ] = get_post_meta( get_the_id(), '_hide_map', true );
$row[ 'manual_lat' ] = self::escape_data( get_post_meta( get_the_id(), '_manual_lat', true ) );
$row[ 'manual_lng' ] = self::escape_data( get_post_meta( get_the_id(), '_manual_lng', true ) );

Expand Down
Loading