Plugin Directory

Changeset 3228040


Ignore:
Timestamp:
01/24/2025 01:00:15 PM (14 months ago)
Author:
respacio
Message:

updated functionality and admin dashboard

Location:
houzez-respacio-import
Files:
2736 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • houzez-respacio-import/trunk/includes/admin-page.php

    r2731772 r3228040  
    11<?php
    2     define("RHIMO_PLUGIN_NAME", "Respacio Houzez Import");
    3     define("RHIMO_THEME_TYPE", "1");
    4    
    5     function respacio_add_options_link(){
    6 
    7         add_menu_page(__(RHIMO_PLUGIN_NAME), __(RHIMO_PLUGIN_NAME), 'manage_options', 'respacio_houzez_import', 'respacio_import', '', 6);
    8         add_submenu_page('respacio_houzez_import','Import','Import','manage_options', 'respacio_houzez_import', 'respacio_import');
    9         add_submenu_page('respacio_houzez_import','Export','Export','manage_options', 'respacio_houzez_export', 'respacio_export');
    10     }
    11 
    12     add_action('admin_menu', 'respacio_add_options_link');
    13     add_action('admin_enqueue_scripts', 'respacio_enqueue_styles' );
    14     function respacio_enqueue_styles(){
    15         wp_enqueue_style( 'custom-style', plugins_url( '/css/style.css', __FILE__ ) );
    16         wp_enqueue_script('my-script', plugins_url('/js/my-script.js',__FILE__ ));
    17     }
    18 
    19     // Live
    20     define('RHIMO_API_BASE_URL',"https://crm.respacio.com/ws/properties");
    21     define('RHIMO_FEED_URL',"https://crm.respacio.com/ws/properties/sync_properties_json");
    22     define('RHIMO_PROPERTY_WEB_URL',"https://crm.respacio.com/ws/properties/sync_property_web_url");
    23 
    24     function respacio_import(){
    25         if(empty($_POST)){
    26             $error = '';
    27             $sa_apikey_verify = get_option( 'verify_api');
    28             if($sa_apikey_verify){
    29                 $message = "Your license key is verified successfully. Your properties will start to import in batches.";
    30             }
    31         }
    32         else if(!empty($_POST["property_verification_api"])){
    33 
    34             $api_key = sanitize_text_field($_POST["property_verification_api"]);
    35 
    36             $propData = wp_remote_post(RHIMO_API_BASE_URL, array(
    37                 'method'      => 'POST',
    38                 'timeout'     => 45,
    39                 'redirection' => 5,
    40                 'httpversion' => '1.0',
    41                 'blocking'    => true,
    42                 'headers'     => array(
    43                         "authorization"=> "Basic YWRtaW46MTIzNA==",
    44                         "x-api-key"=>$api_key,
    45                         "Content-Type"=>"application/x-www-form-urlencoded"
    46                 ),
    47                 'cookies' => array()
    48             ));
    49 
    50             $response = $propData["body"];
    51             $response = json_decode($response,true);
    52             if($response["status"] == "success"){
    53                 delete_option( 'property_verification_api' );
    54                 delete_option( 'verify_api' );
    55                 add_option('property_verification_api',$api_key,'','yes');
    56                 add_option('verify_api',true,'','yes');
    57                 delete_option('sync_type');
    58                 add_option('sync_type',1,'','yes');
    59                
    60                 $message = "Your license key is verified successfully. Your properties will start to import in batches.";
    61             }
    62             else{
    63                 $error = "Your license key is not valid, please check and try again.";
    64                 delete_option( 'property_verification_api' );
    65                 delete_option( 'verify_api' );
    66             }
    67         } else if($_POST["remove_licence_key"]){
    68             delete_option( 'property_verification_api' );
    69             delete_option( 'verify_api' );
    70             $message = "Your license key is removed successfully.";
    71         } else if($_POST["save_changes"]){
    72             delete_option('sync_type');
    73             add_option('sync_type',sanitize_text_field($_POST["sync_type"]),'','yes');
    74         }
    75         $template_path = plugin_dir_path( __FILE__ ) . "template/api-varification.php";
    76         require_once ($template_path);
    77     }
    78 
    79     /**
    80     Author : Peter
    81     Description : This function is execute cron at every 3 or mints of interval and auto download properties and images.
    82     **/
    83     add_filter( 'cron_schedules', 'respacio_isa_add_cron_recurrence_interval' );
    84     function respacio_isa_add_cron_recurrence_interval( $schedules ) {
    85 
    86         $schedules['every_three_minutes'] = array(
    87             'interval'  => 180,
    88             'display'   => __( 'Every 3 Minutes', 'respacio-admin' )
    89         );
    90         $schedules['every_five_minutes'] = array(
    91             'interval'  => 300,
    92             'display'   => __( 'Every 5 Minutes', 'respacio-admin' )
    93         );
    94         $schedules['every_seven_minutes'] = array(
    95             'interval'  => 420,
    96             'display'   => __( 'Every 7 Minutes', 'respacio-admin' )
    97         );
    98         $schedules['every_eleven_minutes'] = array(
    99             'interval'  => 660,
    100             'display'   => __( 'Every 11 Minutes', 'respacio-admin' )
    101         );
    102         $schedules['every_thirteen_minutes'] = array(
    103             'interval'  => 780,
    104             'display'   => __( 'Every 13 Minutes', 'respacio-admin' )
    105         );
    106         $schedules['every_fifteen_minutes'] = array(
    107             'interval'  => 900,
    108             'display'   => __( 'Every 15 Minutes', 'respacio-admin' )
    109         );
    110         $schedules['every_seventeen_minutes'] = array(
    111             'interval'  => 1020,
    112             'display'   => __( 'Every 17 Minutes', 'respacio-admin' )
    113         );
    114         $schedules['every_ninteen_minutes'] = array(
    115             'interval'  => 1140,
    116             'display'   => __( 'Every 19 Minutes', 'respacio-admin' )
    117         );
    118         $schedules['every_thirty_minutes'] = array(
    119             'interval'  => 1800,
    120             'display'   => __( 'Every 30 Minutes', 'respacio-admin' )
    121         );
    122         $schedules['every_sixty_minutes'] = array(
    123             'interval'  => 3600,
    124             'display'   => __( 'Every 60 Minutes', 'respacio-admin' )
    125         );
    126         return $schedules;
    127     }
    128 
    129     if (! wp_next_scheduled ('add_daily_properties')) {
    130         wp_schedule_event(time(),'every_eleven_minutes','add_daily_properties');
    131     }
    132 
    133     add_action('add_daily_properties', 'respacio_sync_properties');
    134    
    135     function respacio_sync_properties(){
    136        
    137         $sa_apikey_verify = get_option( 'verify_api');
    138         include(ABSPATH . "wp-includes/pluggable.php");
    139         if($sa_apikey_verify){
    140             $api_key = get_option( 'property_verification_api');
    141             $sync_type = get_option( 'sync_type');
    142             $posted_properties = 10;
    143             global $wpdb;
    144        
    145             $table_name = $wpdb->prefix . "postmeta";
    146             $post_img = $wpdb->get_results("SELECT * FROM $table_name WHERE meta_key = 'is_from_crm' and meta_value = 1");
    147             $posted_properties =  count($post_img);
    148             $url = RHIMO_FEED_URL;
    149    
    150             $data = array(
    151                 "theme_type"=>RHIMO_THEME_TYPE
    152             );
    153    
    154             $propData = wp_remote_post($url, array(
    155                 'method'      => 'GET',
    156                 'timeout'     => 60,
    157                 'redirection' => 5,
    158                 'httpversion' => '1.0',
    159                 'blocking'    => true,
    160                 'body'    => $data,
    161                 'headers'     => array(
    162                         "authorization"=> "Basic YWRtaW46MTIzNA==",
    163                         "x-api-key"=>$api_key,
    164                         "Content-Type"=>"application/x-www-form-urlencoded"
    165                 ),
    166                 'cookies' => array()
    167             ));
    168    
    169             if(!empty($propData)){
    170                
    171                 $propDataJsonDcod = json_decode($propData['body'],TRUE);
    172                 if(isset($propDataJsonDcod) && !empty($propDataJsonDcod)){
    173    
    174                     if(!empty($propDataJsonDcod) && !empty($propDataJsonDcod["data"]["inactive_properties"])){
    175                         $inactive_properties = $propDataJsonDcod["data"]["inactive_properties"];
    176                        
    177                         if(!empty($inactive_properties)){
    178                             foreach($inactive_properties as $pdata){
    179                                 $propFavId = isset($pdata['reference_no']) ? $pdata['reference_no'] : '';
    180                                
    181                                 $args = array (
    182                                     'post_type'              => array('property'),
    183                                     'post_status'            => array( 'publish' ),
    184                                     'meta_query'             => array(
    185                                         array(
    186                                             'key'       => 'fave_property_id',
    187                                             'value'     => $propFavId,
    188                                         ),
    189                                     ),
    190                                 );
    191                                 // The Query
    192                                 $query = new WP_Query($args);
    193                                 // The Loop
    194                                 if ( $query->have_posts() ) {
    195 
    196                                     $query_data = json_decode(json_encode($query),true);
    197                                     $postData = array(
    198                                         'ID' => $query_data['posts'][0]['ID'],
    199                                         'post_date' => date('Y-m-d h:i:s'),
    200                                         'post_date_gmt' => date('Y-m-d h:i:s'),
    201                                         'post_content' => $propContent,
    202                                         'post_title' => $propTitle,
    203                                         'post_excerpt' => $propExcerpt,
    204                                         'post_status'=>'trash',
    205                                         'post_type'=>'property',
    206                                     );
    207                                     $postId = wp_update_post( $postData );
    208                                     update_post_meta($postId,'fave_property_id',$propFavId);
    209                                 }
    210                             }
    211                         }
    212                     }
    213    
    214                     if(!empty($propDataJsonDcod) && !empty($propDataJsonDcod["data"]["properties"])){
    215                         $propDataJsonDcod = $propDataJsonDcod["data"]["properties"];
    216                         $charset_collate = $wpdb->get_charset_collate();
    217    
    218                         //CREATE TABLE FOR PROPERTY IMAGES AND DOCUMENTS
    219                         $table_name = $wpdb->prefix . "property_images";
    220                         $sql = "CREATE TABLE $table_name (
    221                             id mediumint(9) NOT NULL AUTO_INCREMENT,
    222                             post_id int(11),
    223                             image_url varchar(255),
    224                             image_id int(11),
    225                             type tinyint(1),
    226                             is_download tinyint(1) default '0',
    227                             PRIMARY KEY  (id)
    228                         ) $charset_collate;";
    229    
    230                         require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    231                         dbDelta( $sql );
    232                        
    233                         foreach($propDataJsonDcod as $pData){
    234                             // Description
    235                             $propTitle = isset($pData['post_title'])  ? $pData['post_title'] : '';
    236                             $propContent = isset($pData['post_content'])  ? $pData['post_content'] : '';
    237    
    238                             //Details >> Rooms & Sizez
    239                             $propBedrooms = isset($pData['fave_property_bedrooms']) ? $pData['fave_property_bedrooms'] : '';
    240                             $propBathrooms = isset($pData['fave_property_bathrooms']) ? $pData['fave_property_bathrooms'] : '';
    241                             $propGarage = isset($pData['fave_property_garage']) ? $pData['fave_property_garage'] : '';
    242                             $propGarageSize = isset($pData['fave_property_garage_size']) ? $pData['fave_property_garage_size'] : '';
    243                             $propYear = isset($pData['fave_property_year']) ? $pData['fave_property_year'] : '';
    244                             $propFavId = isset($pData['fave_property_id']) ? $pData['fave_property_id'] : '';
    245                             $propDefPrice = isset($pData['fave_property_price']) ? $pData['fave_property_price'] : '';
    246                             $propSize = isset($pData['fave_property_size']) ? $pData['fave_property_size'] : '';
    247                             $propLand = isset($pData['fave_property_land']) ? $pData['fave_property_land'] : '';
    248                             $fave_property_size_prefix = isset($pData['fave_property_size_prefix']) ? $pData['fave_property_size_prefix'] : '';
    249    
    250                             //Address
    251                             $propAdd = isset($pData['fave_property_address']) ? $pData['fave_property_address'] : '';
    252                             $prop_street_address = isset($pData['fave_property_street_address']) ? $pData['fave_property_street_address'] : '';
    253                             $propLocation = isset($pData['fave_property_location']) ? $pData['fave_property_location'] : '';
    254                             $propCountry = isset($pData['fave_property_country']) ? $pData['fave_property_country'] : '';
    255                             $propLat = isset($pData['houzez_geolocation_lat']) ? $pData['houzez_geolocation_lat'] : '';
    256                             $propLong = isset($pData['houzez_geolocation_long']) ? $pData['houzez_geolocation_long'] : '';
    257                             $propZip = isset($pData['fave_property_zip']) ? $pData['fave_property_zip'] : '';
    258    
    259                             //Details
    260                             $propAgent = isset($pData['fave_agents']) ? $pData['fave_agents'] : '';
    261    
    262                             // Misc >> Customfields
    263                             $propIsAtt = isset($pData['fave_additional_features_enable']) ? $pData['fave_additional_features_enable'] : '';
    264                             $propIsFloorPlan = isset($pData['fave_floor_plans_enable']) ? $pData['fave_floor_plans_enable'] : '';
    265                             $propIsFeatured = isset($pData['fave_featured']) ? $pData['fave_featured'] : '';
    266                             $propTerSize = isset($pData['fave_single_top_area']) ? $pData['fave_single_top_area'] : '';
    267                             $fave_single_content_area = isset($pData['fave_single_content_area']) ? $pData['fave_single_content_area'] : '';
    268                             $propExcerpt = isset($pData['post_excerpt']) ? trim($pData['post_excerpt']) : '';
    269                             $propMapSView = isset($pData['fave_property_map_street_view']) ? $pData['fave_property_map_street_view'] : '';
    270                             $propMUnitPlan = isset($pData['fave_multiunit_plans_enable']) ? $pData['fave_multiunit_plans_enable'] : '';
    271                             $fave_property_sec_price = isset($pData['fave_property_sec_price']) ? $pData['fave_property_sec_price'] : '';
    272                             $fave_energy_global_index = isset($pData['fave_energy_global_index']) ? $pData['fave_energy_global_index'] : '';
    273                             $_houzez_expiration_date = $houzez_manual_expire = '';
    274                             if(isset($pData['_houzez_expiration_date']) && !empty($pData['_houzez_expiration_date'])){
    275                                 $_houzez_expiration_date = strtotime($pData['_houzez_expiration_date']) ;
    276                                 $houzez_manual_expire = 'checked' ;
    277                             }
    278                             $fave_prop_homeslider = trim(strtolower($pData['fave_prop_homeslider']));
    279                             $fave_property_price_prefix = isset($pData['fave_property_price_prefix']) ? $pData['fave_property_price_prefix'] : '';
    280                             $fave_property_price_postfix = isset($pData['fave_property_price_postfix']) ? $pData['fave_property_price_postfix'] : '';
    281    
    282                             // Attachments
    283                             $propImages = isset($pData['images']) ? $pData['images'] : '';
    284                             $propAttachment = isset($pData['fave_attachments']) ? $pData['fave_attachments'] : '';
    285                             $propVTour = isset($pData['fave_virtual_tour']) ? $pData['fave_virtual_tour'] : '';
    286    
    287                             // Details >> Notes
    288                             $propPNote = isset($pData['fave_private_note']) ? $pData['fave_private_note'] : '';
    289    
    290                             // Misc >> Energy Performance
    291                             $fave_energy_class = isset($pData['fave_energy_class']) ? trim(strtoupper($pData['fave_energy_class'])) : '';
    292                             $fave_renewable_energy_global_index = isset($pData['fave_renewable_energy_global_index']) ? $pData['fave_renewable_energy_global_index'] : '';
    293                             $fave_energy_performance = isset($pData['fave_energy_performance']) ? $pData['fave_energy_performance'] : '';
    294    
    295                             $post_status = isset($pData['post_status']) ? $pData['post_status'] : '';
    296                             if($post_status == 'Active'){
    297                                 $post_status = 'publish' ;
    298                             } else {
    299                                 $post_status = 'draft' ;
    300                             }
    301                             $fave_property_land_postfix =   $fave_property_size_prefix ;
    302                            
    303                             // INSERT FLOOR PLAN START
    304                             // Attachments
    305                             $floorPlanData = array();
    306                             $propFloorPlan = array();
    307                             if(!empty($pData['floorplans'])){
    308                                 $floor_plan = explode(",",$pData['floorplans']);
    309                                     if(!empty($floor_plan)){
    310                                             foreach($floor_plan as $fplan){
    311                                                     $propFloorPlan = ($fplan);
    312                                                     $floorPlanData[] = array(
    313                                                             'fave_plan_title'=>'',
    314                                                             'fave_plan_rooms'=>'',
    315                                                             'fave_plan_bathrooms'=>'',
    316                                                             'fave_plan_price'=>'',
    317                                                             'fave_plan_size' =>'',
    318                                                             'fave_plan_image'=>$propFloorPlan,
    319                                                             'fave_plan_description'=>''
    320                                                     );
    321                                             }
    322                                             $propFloorPlan = serialize($floorPlanData);
    323                                         }
    324                             }
    325                             // INSERT FLOOR PLAN END
    326                             // INSERT AGENT DATA IN WP POSTS START
    327                             // Details
    328                             if(isset($propAgent) && !empty($propAgent)){
    329    
    330                                 $propAgent = explode('|',$propAgent);
    331                                 $agentData = array();
    332                                 $agentData = array(
    333                                     'post_author'=>1,
    334                                     'post_date' => date('Y-m-d h:i:s'),
    335                                     'post_date_gmt' => date('Y-m-d h:i:s'),
    336                                     'post_title' => $propAgent[0],
    337                                     'post_type'=>'houzez_agent'
    338                                 );
    339                                 $agentId = post_exists($propAgent,'','','') ;
    340    
    341                                 if($agentId > 0){
    342                                     $agentData['ID'] = $agentId ;
    343                                 }
    344                                 $agent_id = wp_insert_post($agentData);
    345    
    346                                 respacio_update_property_postmeta($agent_id,'fave_agent_email',$propAgent[1]);
    347                                 respacio_update_property_postmeta($agent_id,'fave_agent_mobile',$propAgent[2]);
    348    
    349                             }
    350                             // INSERT AGENT DATA IN WP POSTS END
    351                            
    352                             $postData = array() ;
    353                             //$check_title=get_page_by_title($propTitle, 'OBJECT', 'property');
    354                             //$favrt_id_check = get_post_meta( $check_title->ID, 'fave_property_id', true );
    355                             // CHECK POST EXISTS
    356                             //if(empty($favrt_id_check)){
    357                             $args = array (
    358                                 'post_type'              => array( 'property' ),
    359                                 'post_status'            => array( 'publish' ),
    360                                 'meta_query'             => array(
    361                                     array(
    362                                         'key'       => 'fave_property_id',
    363                                         'value'     => $propFavId,
    364                                     ),
    365                                 ),
    366                             );
    367                             // The Query
    368                             $query = new WP_Query($args);
    369                             // The Loop
    370                             if ( $query->have_posts() ) {
    371 
    372                                 $query_data = json_decode(json_encode($query),true);
    373                                 $postData = array(
    374                                     'ID' => $query_data['posts'][0]['ID'],
    375                                     'post_date' => date('Y-m-d h:i:s'),
    376                                     'post_date_gmt' => date('Y-m-d h:i:s'),
    377                                     'post_content' => $propContent,
    378                                     'post_title' => $propTitle,
    379                                     'post_excerpt' => $propExcerpt,
    380                                     'post_status'=>$post_status,
    381                                     'post_type'=>'property',
    382                                     'post_name' =>  sanitize_title_with_dashes(remove_accents(wp_strip_all_tags($propTitle)),'','save'),
    383                                 );
    384                                 $postId = wp_update_post( $postData );
    385                                 update_post_meta($postId,'fave_property_id',$propFavId);
    386                             }
    387                             else{
    388                                
    389                                 $postData = array(
    390                                     'post_author'   => 1,
    391                                     'post_date' => date('Y-m-d h:i:s'),
    392                                     'post_date_gmt' => date('Y-m-d h:i:s'),
    393                                     'post_content' => !empty(trim($propContent)) ? trim($propContent) : '',
    394                                     'post_title' => wp_strip_all_tags($propTitle),
    395                                     'post_excerpt' => $propExcerpt,
    396                                     'post_status'=>$post_status,
    397                                     'post_name' =>  sanitize_title_with_dashes(remove_accents(wp_strip_all_tags($propTitle)),'','save'),
    398                                     'post_modified_gmt'=>date("Y-m-d H:i:s"),
    399                                     'post_type'=>'property'
    400                                 );
    401                                 $postId = wp_insert_post($postData);
    402                             }
    403                             // CHECK POST EXISTS
    404                             // $table_name = $wpdb->prefix . "postmeta";
    405                             // $post_img = $wpdb->get_results("SELECT post_id FROM $table_name WHERE meta_key = 'fave_property_id' and meta_value = '".$propFavId."'");
    406    
    407                             // if(!empty($post_img) && !empty($post_img[0]->post_id)){
    408                             //  $postData['ID'] = $post_img[0]->post_id;
    409                             // }
    410                             // $postId = wp_insert_post($postData);
    411    
    412                             // PROPERTY VIDEO URL & IMAGE START
    413                             $propVideoImage = '';
    414                             if(isset($pData['fave_video_url']) && !empty($pData['fave_video_url'])){
    415                                 $propVideoLink = ($pData['fave_video_url']);
    416                                 $propVideoUrl = $propVideoLink[0]['inspiry_video_group_url'] ;
    417    
    418                                 $propVideoImage = $propVideoLink[0]['inspiry_video_group_image'] ;
    419    
    420                                 $table_name1 = $wpdb->prefix . "property_images";
    421                                 $post_attch = $wpdb->get_results("SELECT id,image_url,image_id FROM $table_name1 WHERE type = 3 AND post_id = ".$postId);
    422                                 $vImg_array = array();
    423    
    424                                 if(!empty($post_attch)) {
    425                                     $post_attch = json_decode(json_encode($post_attch), true);
    426                                     $vImg_array = array_column($post_attch,"image_url");
    427                                     $vImg_ids = array_column($post_attch,"image_id");
    428                                 }
    429    
    430                                 $propVideoImage = explode('?image_id=',$propVideoImage);
    431                                 if(isset($propVideoImage[1]) && !empty($propVideoImage[1])){
    432                                     $inspiry_video_group_image_id = $propVideoImage[1] ;
    433                                     respacio_update_property_postmeta($postId,'fave_video_image',$inspiry_video_group_image_id);
    434                                 } else {
    435    
    436                                     $inspiry_video_group_image_id = $propVideoImage[0];
    437    
    438                                     //INSERT IMAGE URL IN PROPERTY IMAGES TABLE TO DOWNLOAD START
    439                                     if(!in_array($inspiry_video_group_image_id,$vImg_array)){
    440                                         $videoImage_array = array(
    441                                             "post_id"       =>  $postId,
    442                                             "image_url"     =>  $inspiry_video_group_image_id,
    443                                             "type"          =>  3, //FOR VIDEO IMAGE
    444                                             "is_download"   =>  0,
    445                                         );
    446                                         $wpdb->insert($table_name1,$videoImage_array);
    447                                     } else if (($key = array_search($inspiry_video_group_image_id,$vImg_array)) !== false) {
    448    
    449                                         $inspiry_video_group_image_id = $vImg_ids[$key];
    450                                         respacio_update_property_postmeta($postId,'fave_video_image',$inspiry_video_group_image_id);
    451                                     }
    452                                     //INSERT IMAGE URL IN PROPERTY IMAGES TABLE TO DOWNLOAD END
    453    
    454                                 }
    455                             }
    456                             // PROPERTY VIDEO URL & IMAGE END
    457    
    458                             //PROPERTY METAS UPDATE START
    459                             respacio_update_property_postmeta($postId,'_edit_last','2');
    460                             respacio_update_property_postmeta($postId,'_edit_lock',strtotime(date("Y-m-d H:i:s")).":".'2');
    461                             respacio_update_property_postmeta($postId,'_houzez_expiration_date_status','saved');
    462                             respacio_update_property_postmeta($postId,'fave_currency_info',"&nbsp;");
    463                             respacio_update_property_postmeta($postId,'slide_template','default');
    464                             respacio_update_property_postmeta($postId,'_vc_post_settings','');
    465                             respacio_update_property_postmeta($postId,'fave_property_size_prefix',$fave_property_size_prefix);
    466                             respacio_update_property_postmeta($postId,'fave_property_map',1);
    467                             respacio_update_property_postmeta($postId,'is_from_crm',1);
    468                             respacio_update_property_postmeta($postId,'fave_property_size',$propSize);
    469                             respacio_update_property_postmeta($postId,'_houzez_expiration_date',$_houzez_expiration_date);
    470                             respacio_update_property_postmeta($postId,'houzez_manual_expire',$houzez_manual_expire);
    471                             respacio_update_property_postmeta($postId,'fave_property_bedrooms',$propBedrooms);
    472                             respacio_update_property_postmeta($postId,'fave_property_bathrooms',$propBathrooms);
    473                             respacio_update_property_postmeta($postId,'fave_property_garage',$propGarage);
    474                             respacio_update_property_postmeta($postId,'fave_property_garage_size',$propGarageSize);
    475                             respacio_update_property_postmeta($postId,'fave_property_year',$propYear);
    476                             respacio_update_property_postmeta($postId,'fave_property_id',$propFavId);
    477                             respacio_update_property_postmeta($postId,'fave_property_price',$propDefPrice);
    478                             respacio_update_property_postmeta($postId,'fave_property_location',$propLocation);
    479                             respacio_update_property_postmeta($postId,'fave_agents',$agent_id);
    480                             respacio_update_property_postmeta($postId,'fave_floor_plans_enable',$propIsFloorPlan);
    481                             respacio_update_property_postmeta($postId,'floor_plans',$propFloorPlan);//serialize data
    482                             respacio_update_property_postmeta($postId,'fave_featured',$propIsFeatured);
    483                             respacio_update_property_postmeta($postId,'fave_property_map_address',$propAdd);
    484                             respacio_update_property_postmeta($postId,'fave_property_address',$prop_street_address);
    485                             //respacio_update_property_postmeta($postId,'fave_property_address',$propAdd);
    486                             respacio_update_property_postmeta($postId,'fave_video_url',$propVideoUrl);
    487                             respacio_update_property_postmeta($postId,'_dp_original','');
    488                             respacio_update_property_postmeta($postId,'houzez_geolocation_lat',$propLat);
    489                             respacio_update_property_postmeta($postId,'houzez_geolocation_long',$propLong);
    490                             respacio_update_property_postmeta($postId,'fave_single_top_area',$propTerSize);
    491                             respacio_update_property_postmeta($postId,'fave_property_zip',$propZip);
    492                             respacio_update_property_postmeta($postId,'fave_property_land',$propLand);
    493                             respacio_update_property_postmeta($postId,'fave_virtual_tour',$propVTour);
    494                             respacio_update_property_postmeta($postId,'fave_private_note',$propPNote);
    495                             respacio_update_property_postmeta($postId,'fave_property_map_street_view',$propMapSView);
    496                             respacio_update_property_postmeta($postId,'fave_multiunit_plans_enable',$propMUnitPlan);
    497                             respacio_update_property_postmeta($postId,'fave_property_sec_price',$fave_property_sec_price);
    498                             respacio_update_property_postmeta($postId,'fave_energy_global_index',$fave_energy_global_index);
    499                             respacio_update_property_postmeta($postId,'fave_energy_class',$fave_energy_class);
    500                             respacio_update_property_postmeta($postId,'fave_prop_homeslider',$fave_prop_homeslider);
    501                             respacio_update_property_postmeta($postId,'fave_property_price_postfix',$fave_property_price_postfix);
    502                             respacio_update_property_postmeta($postId,'fave_renewable_energy_global_index',$fave_renewable_energy_global_index);
    503                             respacio_update_property_postmeta($postId,'fave_energy_performance',$fave_energy_performance);
    504                             respacio_update_property_postmeta($postId,'fave_property_land_postfix',$fave_property_land_postfix);
    505                             respacio_update_property_postmeta($postId,'fave_single_content_area',$fave_single_content_area);
    506                             //PROPERTY METAS UPDATE END
    507                            
    508                             //PROPERTY IMAGE START //
    509                             $table_name = $wpdb->prefix . "property_images";
    510                             $post_img = $wpdb->get_results("SELECT id,image_url,image_id FROM $table_name WHERE type = 1 AND image_url != '' AND post_id = ".$postId);
    511                             $img_array = array();
    512                             if(!empty($post_img)){
    513                                 $post_img = json_decode(json_encode($post_img), true);
    514                                 $img_array = array_column($post_img,"image_url");
    515                                 $img_ids = array_column($post_img,"image_id");
    516                             }
    517    
    518                             if(!empty($propImages)){
    519                                 $propImages = explode(",",$propImages);
    520                                 foreach($propImages as $key => $img){
    521    
    522                                     $img = explode("?image_id=",$img);
    523    
    524                                     if(!in_array($img[0],$img_array)){
    525    
    526                                         $is_download = (isset($img[1]) &&  $img[1] > 0) ? 1 : 0 ;
    527                                         $image_id = (isset($img[1]) &&  $img[1] > 0) ? $img[1] : '' ;
    528                                             $images_array = array(
    529                                             "post_id"       =>  $postId,
    530                                             "image_url"     =>  $img[0],
    531                                             "type"          =>  1,
    532                                             "image_id"          =>  $image_id,
    533                                             "is_download"   =>  $is_download
    534                                         );
    535                                         $table_name = $wpdb->prefix . "property_images";
    536                                         $wpdb->insert($table_name,$images_array);
    537                                     }
    538                                     else if (($key = array_search($img[0], $img_array)) !== false) {
    539    
    540                                             $image_id = $img_ids[$key];
    541                                             if(!empty($image_id)){
    542                                                 $table_name = $wpdb->prefix . "postmeta";
    543                                                 $sql = "delete FROM ".$table_name." WHERE post_id = ".$postId." and meta_value = ".$image_id;
    544    
    545                                                 $wpdb->get_results($sql);
    546    
    547                                                 $meta_key = "fave_property_images";
    548                                                 if($key == 0){
    549                                                     //$meta_key = "_thumbnail_id";
    550                                                    
    551                                                     $add_same_image = array(
    552                                                         "post_id"   =>  $postId,
    553                                                         "meta_key"  =>  "_thumbnail_id",
    554                                                         "meta_value"    =>  $image_id
    555                                                     );
    556                                                     $table_name = $wpdb->prefix . "postmeta";
    557                                                     $wpdb->insert($table_name,$add_same_image);
    558                                                 }
    559    
    560                                                 $add_same_image = array(
    561                                                     "post_id"   =>  $postId,
    562                                                     "meta_key"  =>  $meta_key,
    563                                                     "meta_value"    =>  $image_id
    564                                                 );
    565                                                 $table_name = $wpdb->prefix . "postmeta";
    566                                                 $wpdb->insert($table_name,$add_same_image);
    567                                                 unset($img_array[$key]);
    568                                             }
    569                                     }
    570                                 }
    571                             }
    572    
    573                             $post_id = array();
    574                             if(!empty($img_array)){
    575                                     if(!empty($post_img)){
    576                                             foreach($post_img as $img_str){
    577    
    578                                                     $img_val = $img_str["image_url"];
    579                                                     if(in_array($img_val,$img_array)){
    580                                                         $post_id[] = $img_str["image_id"];
    581                                                     }
    582                                             }
    583                                     }
    584                             }
    585    
    586                             if(!empty($post_id)){
    587                                         foreach($post_id as $ids){
    588                                             $table = $wpdb->prefix . "posts";
    589                                             $wpdb->delete($table, array('ID'=>$ids));
    590    
    591                                             $table = $wpdb->prefix . "postmeta";
    592                                             $wpdb->delete($table, array('post_id'=>$postId,"meta_value"=>$ids));
    593                                         }
    594                                 }
    595                             //PROPERTY IMAGE END //
    596    
    597                             //PROPERTY ATTACHMENT DOCUMENT START //
    598                             $table_name = $wpdb->prefix . "property_images";
    599                             $sql = "SELECT id,image_url,image_id FROM $table_name WHERE type = 2 and post_id = ".$postId;
    600                             $post_attch = $wpdb->get_results($sql);
    601                             $img_array = array();
    602                             if(!empty($post_attch))
    603                             {
    604                                     $post_attch = json_decode(json_encode($post_attch), true);
    605                                     $img_array = array_column($post_attch,"image_url");
    606                             }
    607    
    608                             if(!empty($propAttachment)){
    609                                 $propAttachment = explode(",",$propAttachment);
    610    
    611                                 foreach($propAttachment as $img){
    612    
    613                                     $img = explode("?image_id=",$img);
    614                                     if(!in_array($img[0],$img_array)){
    615    
    616                                         $is_download = (isset($img[1]) &&  $img[1] > 0) ? 1 : 0 ;
    617                                         $image_id = (isset($img[1]) &&  $img[1] > 0) ? $img[1] : '' ;
    618                                         $images_array = array(
    619                                             "post_id"       =>  $postId,
    620                                             "image_url"     =>  $img[0],
    621                                             "type"          =>  2,
    622                                             "image_id"          =>  $image_id,
    623                                             "is_download"   =>  $is_download,
    624                                         );
    625                                         $table_name = $wpdb->prefix . "property_images";
    626                                         $wpdb->insert($table_name,$images_array);
    627    
    628                                     } else if (($key = array_search($img[0], $img_array)) !== false) {
    629    
    630                                         unset($img_array[$key]);
    631    
    632                                     }
    633                                 }
    634                             }
    635    
    636                             if(!empty($img_array)){
    637                                     $post_id = array();
    638    
    639                                     if(!empty($post_attch)){
    640                                             foreach($post_attch as $img_str){
    641    
    642                                                     $img_val = $img_str["image_url"];
    643                                                     if(in_array($img_val,$img_array)){
    644                                                             $post_id[] = $img_str["image_id"];
    645                                                     }
    646                                             }
    647                                     }
    648                             }
    649    
    650                             if(!empty($post_id)){
    651                                         foreach($post_id as $ids){
    652    
    653                                                 $table = $wpdb->prefix . "posts";
    654                                                 $wpdb->delete($table, array('ID'=>$ids));
    655    
    656                                                 $table = $wpdb->prefix . "postmeta";
    657                                                 $wpdb->delete($table, array('post_id'=>$postId,"meta_value"=>$ids));
    658                                         }
    659                                 }
    660                                 //PROPERTY ATTACHMENT DOCUMENT END //
    661    
    662                             // INSERT PROPERTY FEATURE START
    663                             //Details >> Features
    664                             respacio_update_features($postId,$pData['property_feature'],'property_feature');
    665                             // INSERT PROPERTY FEATURE END
    666    
    667                             //INSERT PROPERTY TYPE START
    668                             //Details
    669                             respacio_update_features($postId,$pData['property_type'],'property_type');
    670                             //INSERT PROPERTY TYPE END
    671    
    672                             // INSERT PROPERTY STATUS START
    673                             respacio_update_features($postId,$pData['property_status'],'property_status');
    674                             //INSERT PROPERTY STATUS END
    675    
    676                             // INSERT PROPERTY CITY START
    677                             respacio_update_features($postId,$pData['property_city'],'property_city');
    678                             // INSERT PROPERTY CITY END
    679    
    680                             // INSERT PROPERTY LABEL START
    681                             respacio_update_features($postId,$pData['property_label'],'property_label');
    682                             // INSERT PROPERTY LABEL END
    683    
    684                             //INSERT PROPERTY STATE START
    685                             respacio_update_features($postId,$pData['fave_property_country'],'property_country');
    686                            
    687                             //INSERT PROPERTY STATE START
    688                             respacio_update_features($postId,$pData['property_state'],'property_state');
    689                             // INSERT PROPERTY STATE END
    690    
    691                             // INSERT PROPERTY AREA START
    692                             respacio_update_features($postId,$pData['property_area'],'property_area');
    693                             // INSERT PROPERTY AREA END
    694                         }
    695                     }
    696                 }
    697             }   
    698         }
    699     }
    700    
    701     if($_GET["flag"] == 1){
    702         copy_thumb_image_to_gallary();
    703     }
    704    
    705     function copy_thumb_image_to_gallary(){
    706         global $wpdb;
    707        
    708         $table_name = $wpdb->prefix."posts";
    709         $sql = "SELECT ID FROM ".$table_name." WHERE post_type = 'property'";       
    710         $all_properties = $wpdb->get_results($sql);
    711        
    712         $postmeta = $wpdb->prefix."postmeta";
    713         if(!empty($all_properties)){
    714             foreach($all_properties as $p){
    715                 $post_id = $p->ID;
    716                
    717                 $sql = "SELECT meta_id,post_id,meta_key,meta_value FROM ".$postmeta." WHERE post_id = ".$post_id." and meta_key = '_thumbnail_id'";
    718                 $get_thumb = $wpdb->get_results($sql);
    719                
    720                 if(!empty($get_thumb)){
    721                    
    722                     $sql = "SELECT meta_id,post_id,meta_key,meta_value FROM ".$postmeta." WHERE post_id = ".$post_id." and meta_key = 'fave_property_images' and meta_value = ".$get_thumb[0]->meta_value;
    723                     $check = $wpdb->get_results($sql);
    724                    
    725                     if(empty($check)){
    726                        
    727                         //$sql = "SELECT meta_id,post_id,meta_key,meta_value FROM ".$postmeta." WHERE post_id = ".$post_id." and meta_key = 'fave_property_images'";
    728                         //$check = $wpdb->get_results($sql);
    729                        
    730                         $post_images = $wpdb->prefix."property_images";
    731                         $sql = "SELECT image_id FROM ".$post_images." WHERE post_id = ".$post_id." and type = 1";
    732                         $property_images = $wpdb->get_results($sql);
    733                        
    734                         $sql = "delete FROM ".$postmeta." WHERE post_id = ".$post_id." and meta_key = 'fave_property_images'";
    735                         $wpdb->get_results($sql);
    736                        
    737                         if(!empty($property_images)){
    738                             foreach($property_images as $pi){
    739                                
    740                                 $add_same_image = array(
    741                                     "post_id"   =>  $post_id,
    742                                     "meta_key"  =>  "fave_property_images",
    743                                     "meta_value"    =>  $pi->image_id
    744                                 );
    745                                
    746                                 $wpdb->insert($postmeta,$add_same_image);
    747                             }
    748                         }
    749                     }
    750                 }
    751             }
    752         }
    753     }
    754 
    755     function respacio_update_features($postId,$customTaxo,$type){
     2/*
     3 * unable to find the usage
     4 */
     5if(!function_exists('respacio_add_term_relationship')){
     6    function respacio_add_term_relationship($post_id,$term_id,$type){
    7567
    7578        global $wpdb;
    758         if(isset($customTaxo) && !empty($customTaxo)){
     9        $table_name = $wpdb->prefix . 'term_taxonomy';
     10        $check = $wpdb->get_results( $wpdb->prepare( "SELECT term_taxonomy_id FROM %s WHERE (term_id = %d )",$table_name, $term_id )  );
     11        $table_name = $wpdb->prefix . 'term_relationships';
     12        if(!empty($check)){
     13            $add_relationship = [
     14                'object_id'        =>     $post_id,
     15                'term_taxonomy_id' =>  $check[0]->term_taxonomy_id,
     16            ];
    75917
    760             $delete_feature = '' ;
    761 
    762             $propAtt = ($customTaxo);
    763             $table_name = $wpdb->prefix."term_relationships";
    764 
    765             $term_taxonomy = get_the_terms($postId, $type );
    766 
    767             $exist_array = array();
    768             if(!empty($term_taxonomy)){
    769                 $term_taxonomy = json_decode(json_encode($term_taxonomy), true);
    770                 $exist_array = array_column($term_taxonomy,"term_id");
    771             }
    772 
    773             $came_taxonomy = array();
    774             if(isset($propAtt) && !empty($propAtt)){
    775                 $propAtt = explode('|',$propAtt);
    776                 foreach($propAtt as $pAtt){
    777 
    778                     $propFeatureTermId = '';
    779                     $propFeatureTermId = term_exists($pAtt,$type);
    780                     if(!isset($propFeatureTermId) || empty($propFeatureTermId)){
    781                         $propFeatureTermId = wp_insert_term($pAtt,$type);
    782                     }
    783 
    784                     if(is_array($propFeatureTermId)){
    785                         $taxonomy = $propFeatureTermId["term_taxonomy_id"];
    786                     }
    787                     else{
    788                         $taxonomy = $propFeatureTermId;
    789                     }
    790 
    791                     $came_taxonomy[] =  $taxonomy;
    792                     try{
    793                         $table_name = $wpdb->prefix."term_relationships";
    794 
    795                         $sql = "SELECT object_id,term_taxonomy_id FROM ".$table_name." WHERE object_id = ".$postId." and term_taxonomy_id = ".$taxonomy;
    796                        
    797                         $check = $wpdb->get_results($sql);
    798 
    799                         if(empty($check)){
    800 
    801                             $term_relationship = array(
    802                                 "object_id" =>  $postId,
    803                                 "term_taxonomy_id"  =>  $taxonomy
    804                             );
    805 
    806                             $wpdb->insert($table_name,$term_relationship);
    807                         }
    808 
    809                     }
    810                     catch(Exception $e) {
    811 
    812                     }
    813 
    814                 }
    815             }
    816 
    817             $delete_feature = array_diff($exist_array,$came_taxonomy);
    818 
    819             if(!empty($delete_feature)){
    820                 $table_name = $wpdb->prefix."term_relationships";
    821                 $sql = "delete FROM ".$table_name." WHERE object_id = ".$postId." and term_taxonomy_id in (".implode(',',$delete_feature).")";
    822                 $wpdb->get_results($sql);
    823             }
     18            $wpdb->insert($table_name,$add_relationship);
    82419        }
    825     }
    826 
    827     function respacio_add_term_relationship($post_id,$term_id,$type){
    828 
    829         global $wpdb;
    830         $table_name = $wpdb->prefix . "term_taxonomy";
    831         $check = $wpdb->get_results("SELECT term_taxonomy_id FROM $table_name WHERE (term_id = ".$term_id.")");
    832         $table_name = $wpdb->prefix . "term_relationships";
    833         if(!empty($check)){
    834             $add_relationship = array(
    835                 "object_id" =>     $post_id,
    836                 "term_taxonomy_id"  =>  $check[0]->term_taxonomy_id,
    837             );
    838 
    839             $wpdb->insert($table_name,$add_relationship);
    840         }
    84120
    84221
    84322    }
    844 
    845     function respacio_update_property_postmeta($postId,$meta_key,$meta_value){
    846         global $wpdb;
    847 
    848         if(!empty($meta_value)){
    849             $table_name = $wpdb->prefix . "postmeta";
    850             $post_img = $wpdb->get_results("SELECT meta_id FROM $table_name WHERE (post_id = ".$postId." AND meta_key = '".$meta_key."')");
     23}
    85124
    85225
    853             if(!empty($post_img)){
     26/*
     27 * unable to find the usage
     28 */
     29if(!function_exists('respacio_pr')){
     30    function respacio_pr($arr){
     31        echo '<pre>';
     32        //print_r($arr);
     33    }
     34}
    85435
    855                 if($meta_key != "fave_video_image"){
    856                     $table_name = $wpdb->prefix . "postmeta";
    857                     $wpdb->update($table_name, array("meta_value"=>$meta_value),array('meta_id'=>$post_img[0]->meta_id));
    858                 }
    859             }
    860             else{
    861 
    862                 if($meta_key == "fave_video_image"){
    863                     $url = $meta_value;
    864                     $image_sizes = array(
    865                         array("width"   =>  150,"height"    =>  150,"type"  =>  "thumbnail"),
    866                         array("width"   =>  300,"height"    =>  227,"type"  =>  "medium"),
    867                         array("width"   =>  150,"height"    =>  114,"type"  =>  "post-thumbnail"),
    868                         array("width"   =>  385,"height"    =>  258,"type"  =>  "houzez-property-thumb-image"),
    869                         array("width"   =>  380,"height"    =>  280,"type"  =>  "houzez-property-thumb-image-v2"),
    870                         array("width"   =>  570,"height"    =>  340,"type"  =>  "houzez-image570_340"),
    871                         array("width"   =>  810,"height"    =>  430,"type"  =>  "houzez-property-detail-gallery"),
    872                         array("width"   =>  350,"height"    =>  350,"type"  =>  "houzez-image350_350"),
    873                         array("width"   =>  150,"height"    =>  110,"type"  =>  "thumbnail"),
    874                         array("width"   =>  350,"height"    =>  9999,"type" =>  "houzez-widget-prop"),
    875                         array("width"   =>  0,"height"  =>  480,"type"  =>  "houzez-image_masonry"),
    876                     );
    877 
    878 
    879                     $meta_value = respacio_add_postmetadata($postId,$url,$image_sizes,0);
    880 
    881                 }
    882 
    883                 $meta_add = array(
    884                     "post_id"   =>  $postId,
    885                     "meta_key"  =>  $meta_key,
    886                     "meta_value"    =>  $meta_value
    887                 );
    888 
    889                 $wpdb->insert($table_name,$meta_add);
    890             }
    891         }
    892     }
    893 
    894     function respacio_cron_log($log_type=''){
    895         global $wpdb;
    896         $charset_collate = $wpdb->get_charset_collate();
    897         if(!empty($log_type)){
    898             $table_name = $wpdb->prefix . "cron_log";
    899             $sql = "CREATE TABLE $table_name (
    900                id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    901                log_type varchar(255),
    902                logtime DATETIME,
    903                PRIMARY KEY (id)
    904             ) $charset_collate;";
    905 
    906             require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    907             dbDelta( $sql );
    908 
    909             $table_name = $wpdb->prefix . "cron_log";
    910             $insert_thumb = array(
    911                 "log_type"  =>  $log_type,
    912                 "logtime"   =>  date("Y-m-d H:i:s")
    913             );
    914 
    915             $wpdb->insert($table_name,$insert_thumb);
    916         }
    917     }
    918 
    919     if(!wp_next_scheduled ('import_images_trigger')){
    920         wp_schedule_event(time(),'every_five_minutes','import_images_trigger');
    921     }
    922 
    923     add_action('import_images_trigger', 'respacio_add_property_image_hourly');
    924    
    925     function respacio_add_property_image_hourly() {
    926         // do something every hour
    927         $sa_apikey_verify = get_option( 'verify_api');
    928         if($sa_apikey_verify){
    929             global $wpdb;
    930             $table_name = $wpdb->prefix . "property_images";
    931             $post_img = $wpdb->get_results("SELECT * FROM $table_name WHERE image_url != '' AND is_download = 0 AND type = 1 order by id asc limit 10");
    932             $image_sizes = respacio_get_image_sizes();
    933            
    934             if(!empty($post_img)){
    935                 foreach($post_img as $key => $val){
    936                     $url = $val->image_url;
    937                     $postId = $val->post_id;
    938                     $id = $val->id;
    939                     respacio_add_postmetadata($postId,$url,$image_sizes,$id);
    940                 }
    941             }   
    942         }
    943     }
    944 
    945     function respacio_pr($arr){
    946         echo "<pre>";
    947         print_r($arr);
    948     }
    949 
    950     function respacio_get_image_sizes(){
    951         $image_sizes = array(
    952             array("width"   =>  300,"height"    =>  200,"type"  =>  "medium"),
    953             array("width"   =>  1024,"height"   =>  683,"type"  =>  "large"),
    954             array("width"   =>  150,"height"    =>  150,"type"  =>  "thumbnail"),
    955             array("width"   =>  768,"height"    =>  512,"type"  =>  "medium_large"),
    956             array("width"   =>  1536,"height"   =>  1024,"type" =>  "1536x1536"),
    957             array("width"   =>  2048,"height"   =>  1366,"type" =>  "2048x2048"),
    958             array("width"   =>  1170,"height"   =>  785,"type"  =>  "houzez-gallery"),
    959             array("width"   =>  592,"height"    =>  444,"type"  =>  "houzez-item-image-1"),
    960             array("width"   =>  758,"height"    =>  564,"type"  =>  "houzez-item-image-4"),
    961             array("width"   =>  584,"height"    =>  438,"type"  =>  "houzez-item-image-6"),
    962             array("width"   =>  900,"height"    =>  600,"type"  =>  "houzez-variable-gallery"),
    963             array("width"   =>  120,"height"    =>  90,"type"   =>  "houzez-map-info"),
    964             array("width"   =>  496,"height"    =>  331,"type"  =>  "houzez-image_masonry"),
    965         );
    966 
    967         return $image_sizes;
    968     }
    969 
    970     function respacio_add_postmetadata($postId,$url,$image_sizes,$id){
    971 
    972         global $wpdb;
    973        
    974         if(!function_exists('wp_get_current_user')) {
    975             include(ABSPATH . "wp-includes/pluggable.php");
    976         }
    977        
    978         if(!empty($url)){
    979             $headers = get_headers($url);
    980             $attachment_id = '';
    981             if(!empty($headers) && $headers[0] == "HTTP/1.1 200 OK"){
    982                
    983                 $request = wp_remote_get($url, array( 'timeout' => 7200000, 'httpversion' => '1.1' ) );
    984                 $file_content = wp_remote_retrieve_body( $request );
    985                 $res = wp_upload_dir();
    986                
    987                 $file_obj = explode("/",$url);
    988                 $full_file_name = $file_obj[count($file_obj)-1];
    989                 list($file_name,$extention) = explode(".",$full_file_name);
    990                 $upload_dir = $res["path"].'/'.$file_name.'.'.$extention;
    991                 $uploaded_url = $res["url"];
    992                 $subdir = $res['subdir'];
    993                 file_put_contents($upload_dir,$file_content);
    994                
    995                 $attachment_id = respacio_insert_post_data($postId,$uploaded_url,$file_name,$id,$extention);
    996                 $serialize_array = array(
    997                     "width" =>  110,
    998                     "height"    =>  200,
    999                     "file"  =>  $subdir.'/'.$file_name.'.'.$extention
    1000                 );
    1001                 foreach($image_sizes as $ims){
    1002 
    1003                     $width = $ims["width"];
    1004                     $height = $ims["height"];
    1005                     $new_file_name = $file_name.'-'.$width.'x'.$height.'.'.$extention;
    1006                     $upload_dir = $res["path"].'/'.$new_file_name;
    1007                     $img_url = $uploaded_url.'/'.$new_file_name;
    1008                     file_put_contents($upload_dir,$file_content);
    1009                    
    1010                     $image = wp_get_image_editor($upload_dir,array());
    1011                     if ( ! is_wp_error( $image ) ) {
    1012                         $image->resize( $width, $height, true );
    1013                         $image->save($upload_dir);
    1014                     }
    1015                    
    1016                     $serialize_array["sizes"][$ims["type"]] = array(
    1017                         "file"  =>  $new_file_name,
    1018                         "width" =>  $width,
    1019                         "height"    =>  $height,
    1020                     );
    1021                 }
    1022 
    1023                 respacio_add_post_metadata($attachment_id,$subdir,$file_name,$serialize_array,$extention);
    1024                 if(!empty($id)){
    1025                     $table_name = $wpdb->prefix . "property_images";
    1026                     $wpdb->update($table_name, array('is_download'=>1,"image_id"=>$attachment_id), array('id'=>$id));
    1027                 }
    1028             }
    1029 
    1030             return $attachment_id;
    1031         }
    1032     }
    1033 
    1034     function respacio_insert_post_data($postId,$uploaded_url,$file_name,$flag,$extention){
    1035 
    1036         global $wpdb;
    1037         $post_array = array(
    1038             "post_author"   =>  1,
    1039             "post_date"     =>  date("Y-m-d H:i:s"),
    1040             "post_date_gmt" =>  date("Y-m-d H:i:s"),
    1041             "post_status"   =>  'inherit',
    1042             "comment_status"=>  "closed",
    1043             "ping_status"   =>  "closed",
    1044             "post_name"     =>  $file_name,
    1045             "post_parent"   =>  $postId,
    1046             "guid"          =>  $uploaded_url.'/'.$file_name.'.'.$extention,
    1047             "post_type"     =>  "attachment",
    1048             "post_mime_type"=>  "image/jpg",
    1049         );
    1050 
    1051         $post_attachment_id = wp_insert_post($post_array);
    1052         /*
    1053         $table_name = $wpdb->prefix . "postmeta";
    1054         $insert_thumb = array(
    1055             "post_id"   =>  $postId,
    1056             "meta_key"  =>  "_thumbnail_id",
    1057             "meta_value"    =>  $post_attachment_id
    1058         );
    1059 
    1060         $wpdb->insert($table_name,$insert_thumb);
    1061         */
    1062         $table_name = $wpdb->prefix . "postmeta";
    1063         $post_img = $wpdb->get_results("SELECT meta_id,meta_value FROM $table_name WHERE (post_id = ".$postId." AND meta_key = '_thumbnail_id')");
    1064 
    1065         if(!empty($post_attachment_id)){
    1066             if(empty($post_img)){
    1067 
    1068                 if(!empty($flag)){
    1069                     $insert_thumb = array(
    1070                         "post_id"   =>  $postId,
    1071                         "meta_key"  =>  "_thumbnail_id",
    1072                         "meta_value"    =>  $post_attachment_id
    1073                     );
    1074 
    1075                     $wpdb->insert($table_name,$insert_thumb);
    1076 
    1077                     $insert_thumb = array(
    1078                         "post_id"   =>  $postId,
    1079                         "meta_key"  =>  "fave_property_images",
    1080                         "meta_value"    =>  $post_attachment_id
    1081                     );
    1082 
    1083                     $wpdb->insert($table_name,$insert_thumb);
    1084                 }
    1085             }
    1086             else if(!empty($post_img) && empty($post_img[0]->meta_value)){
    1087                 $table_name = $wpdb->prefix . "postmeta";
    1088                 $wpdb->update($table_name, array("meta_value"   =>  $post_attachment_id), array('meta_id'=>$post_img[0]->meta_id));
    1089             }
    1090             else
    1091             {
    1092                 if(!empty($flag)){
    1093                     $insert_thumb = array(
    1094                         "post_id"   =>  $postId,
    1095                         "meta_key"  =>  "fave_property_images",
    1096                         "meta_value"    =>  $post_attachment_id
    1097                     );
    1098 
    1099                     $wpdb->insert($table_name,$insert_thumb);
    1100                 }
    1101             }
    1102         }
    1103         return $post_attachment_id;
    1104     }
    1105 
    1106 
    1107     function respacio_add_post_metadata($attachment_id,$subdir,$file_name,$serialize_array,$extention){
    1108         global $wpdb;
    1109         $post_meta = array(
    1110             "post_id"   =>  $attachment_id,
    1111             "meta_key"  =>  '_wp_attached_file',
    1112             'meta_value'    =>  $subdir.'/'.$file_name.'.'.$extention,
    1113         );
    1114        
    1115         $table_name = $wpdb->prefix . "postmeta";
    1116         $wpdb->insert($table_name,$post_meta);
    1117 
    1118         $post_meta = array(
    1119             "post_id"   =>  $attachment_id,
    1120             "meta_key"  =>  '_wp_attachment_metadata',
    1121             'meta_value'    =>  serialize($serialize_array),
    1122         );
    1123 
    1124         $table_name = $wpdb->prefix . "postmeta";
    1125         $wpdb->insert($table_name,$post_meta);
    1126     }
    1127 
    1128 
    1129     function respacio_add_property_documents(){
    1130 
    1131         global $wpdb;
    1132 
    1133         //GET DOCUMENTS FROM TABLES
    1134         $table_name = $wpdb->prefix . "property_images";
    1135         $post_docs = $wpdb->get_results("SELECT * FROM $table_name WHERE is_download = 0 AND type = 2 order by id asc limit 300");
    1136 
    1137         $attachment_id = '' ;
    1138         if(!empty($post_docs)){
    1139             foreach($post_docs as $dKey => $dVal){
    1140                 $docUrl = $dVal->image_url;
    1141                 $docPostId = $dVal->post_id;
    1142                 $docId = $dVal->id;
    1143 
    1144                 $attachment_id = respacio_add_property_docdata($docId,$docPostId,$docUrl);
    1145 
    1146                 if(!empty($attachment_id)){
    1147                     $table_name = $wpdb->prefix . "property_images";
    1148                     $wpdb->update($table_name, array('is_download'=>1,"image_id"=>$attachment_id), array('id'=>$docId));
    1149                 }
    1150             }
    1151         }
    1152     }
    1153 
    1154     function respacio_add_property_docdata($docId,$docPostId,$docUrl){
    1155 
    1156         global $wpdb;
    1157 
    1158         if(!empty($docUrl)){
    1159             $docHeaders = get_headers($docUrl);
    1160 
    1161             $docAttachmentId = '';
    1162             if(!empty($docHeaders) && $docHeaders[0] == "HTTP/1.1 200 OK"){
    1163 
    1164                     $request = wp_remote_get($docUrl, array( 'timeout' => 7200000, 'httpversion' => '1.1' ) );
    1165                     $doc_content = wp_remote_retrieve_body( $request );
    1166 
    1167                     $res = wp_upload_dir();
    1168                 $file_obj = explode("/",$docUrl);
    1169                     $full_file_name = $file_obj[count($file_obj)-1];
    1170                     list($file_name,$extention) = explode(".",$full_file_name);
    1171                 $upload_dir = $res["path"].'/'.$file_name.'.'.$extention;
    1172                 $uploaded_url = $res["url"];
    1173                 $subdir = $res['subdir'];
    1174                 file_put_contents($upload_dir,$doc_content);
    1175 
    1176                 // GET MIME TYPE OF FILE
    1177                 //$mimeType = mime_content_type($upload_dir);
    1178                 $mimeType = 'application/pdf';
    1179                 //INSERT INTO POST TABLE START
    1180                 $post_array = array(
    1181                     "post_author"   =>  1,
    1182                     "post_date"     =>  date("Y-m-d H:i:s"),
    1183                     "post_date_gmt" =>  date("Y-m-d H:i:s"),
    1184                     "post_title"    =>  $file_name,
    1185                     "post_status"   =>  'inherit',
    1186                     "comment_status"=>  "closed",
    1187                     "ping_status"   =>  "closed",
    1188                     "post_name"     =>  $file_name,
    1189                     "post_parent"   =>  $docPostId,
    1190                     "guid"          =>  $uploaded_url.'/'.$file_name.'.'.$extention,
    1191                     "post_type"     =>  "attachment",
    1192                     "post_mime_type"=>  $mimeType
    1193                 );
    1194 
    1195                 $post_attachment_id = wp_insert_post($post_array);
    1196                 //INSERT INTO POST TABLE END
    1197 
    1198                 //INSERT INTO POST META TABLE START
    1199 
    1200                 $post_meta = array(
    1201                     "post_id"   =>  $post_attachment_id,
    1202                     "meta_key"  =>  '_wp_attached_file',
    1203                     'meta_value'    =>  $subdir.'/'.$file_name.'.'.$extention
    1204                 );
    1205 
    1206                 $table_name = $wpdb->prefix . "postmeta";
    1207                 $wpdb->insert($table_name,$post_meta);
    1208 
    1209                 $post_meta = array(
    1210                     "post_id"   =>  $docPostId,
    1211                     "meta_key"  =>  'fave_attachments',
    1212                     'meta_value'    =>  $post_attachment_id
    1213                 );
    1214 
    1215                 $table_name = $wpdb->prefix . "postmeta";
    1216                 $wpdb->insert($table_name,$post_meta);
    1217 
    1218                 // INSERT INTO POST META TABLE END
    1219 
    1220                 return $post_attachment_id ;
    1221             }
    1222         }
    1223     }
    1224 
    1225 
    1226     if (! wp_next_scheduled ('property_attachment_download')) {
    1227         wp_schedule_event(time(),'every_sixty_minutes','property_attachment_download');
    1228     }
    1229 
    1230     add_action('property_attachment_download', 'respacio_add_property_documents');
    1231 
    1232 
    1233     /* VIDEO IMAGE DOWNLOAD START */
    1234     function respacio_download_video_image(){
    1235 
    1236         global $wpdb;
    1237 
    1238         $table_name = $wpdb->prefix . "property_images";
    1239         $post_img = $wpdb->get_results("SELECT * FROM $table_name WHERE image_url != '' AND is_download = 0 AND type = 3 order by id asc limit 300");
    1240 
    1241         $image_sizes = respacio_get_image_sizes();
    1242 
    1243         if(!empty($post_img)){
    1244             foreach($post_img as $key => $val){
    1245 
    1246                 $url = $val->image_url;
    1247                 $postId = $val->post_id;
    1248                 $id = $val->id;
    1249                 respacio_add_imagepostmetadata($postId,$url,$image_sizes,$id);
    1250             }
    1251         }
    1252     }
    1253 
    1254     function respacio_add_imagepostmetadata($postId,$url,$image_sizes,$id){
    1255 
    1256         //echo "<br> post id : ".$postId;
    1257         global $wpdb;
    1258         if(!empty($url)){
    1259             $headers = get_headers($url);
    1260 
    1261             $attachment_id = '';
    1262             if(!empty($headers) && $headers[0] == "HTTP/1.1 200 OK"){
    1263                     $request = wp_remote_get($url, array( 'timeout' => 7200000, 'httpversion' => '1.1' ) );
    1264                     $file_content = wp_remote_retrieve_body( $request );
    1265 
    1266                 $res = wp_upload_dir();
    1267 
    1268                 $file_obj = explode("/",$url);
    1269                 $full_file_name = $file_obj[count($file_obj)-1];
    1270                 list($file_name,$extention) = explode(".",$full_file_name);
    1271                 $upload_dir = $res["path"].'/'.$file_name.'.'.$extention;
    1272                 $uploaded_url = $res["url"];
    1273                 $subdir = $res['subdir'];
    1274                 file_put_contents($upload_dir,$file_content);
    1275 
    1276                 //INSERT INTO POST TABLE START //
    1277 
    1278                 $post_array = array(
    1279                     "post_author"   =>  1,
    1280                     "post_date"     =>  date("Y-m-d H:i:s"),
    1281                     "post_date_gmt" =>  date("Y-m-d H:i:s"),
    1282                     "post_status"   =>  'inherit',
    1283                     "comment_status"=>  "closed",
    1284                     "ping_status"   =>  "closed",
    1285                     "post_name"     =>  $file_name,
    1286                     "post_parent"   =>  $postId,
    1287                     "guid"          =>  $uploaded_url.'/'.$file_name.'.'.$extention,
    1288                     "post_type"     =>  "attachment",
    1289                     "post_mime_type"=>  "image/jpg",
    1290                 );
    1291 
    1292                 $attachment_id = wp_insert_post($post_array);
    1293                 // INSERT INTO POST TABLE END
    1294 
    1295                 //respacio_update_property_postmeta($postId,'fave_video_image',$attachment_id);
    1296                 add_post_meta($postId,'fave_video_image',$attachment_id, true );
    1297 
    1298                 foreach($image_sizes as $ims){
    1299 
    1300                     $width = $ims["width"];
    1301                     $height = $ims["height"];
    1302                     $new_file_name = $file_name.'-'.$width.'x'.$height.'.'.$extention;
    1303                     $upload_dir = $res["path"].'/'.$new_file_name;
    1304                     file_put_contents($upload_dir,$file_content);
    1305 
    1306                     $image = wp_get_image_editor($upload_dir);
    1307                     if ( ! is_wp_error( $image ) ) {
    1308                         $image->resize( $width, $height, true );
    1309                         $image->save($upload_dir);
    1310                     }
    1311 
    1312                     $serialize_array["sizes"][$ims["type"]] = array(
    1313                         "file"  =>  $new_file_name,
    1314                         "width" =>  $width,
    1315                         "height"    =>  $height,
    1316                     );
    1317                 }
    1318 
    1319                 if(isset($attachment_id) && !empty($attachment_id)){
    1320                    
    1321                     respacio_add_post_metadata($attachment_id,$subdir,$file_name,$serialize_array,$extention);
    1322 
    1323                 }
    1324 
    1325                 if(!empty($id)){
    1326                     $table_name = $wpdb->prefix . "property_images";
    1327                     $wpdb->update($table_name, array('is_download'=>1,"image_id"=>$attachment_id), array('id'=>$id));
    1328                 }
    1329 
    1330             }
    1331 
    1332             return $attachment_id;
    1333         }
    1334     }
    1335     /* VIDEO IMAGE DOWNLOAD END */
    1336 
    1337     if (! wp_next_scheduled ('add_hourly_properties_url')) {
    1338         wp_schedule_event(time(),'every_sixty_minutes','add_hourly_properties_url');
    1339     }
    1340 
    1341     add_action('add_hourly_properties_url', 'respacio_update_property_link');
    1342 
    1343     function respacio_update_property_link(){
    1344         global $wpdb;
    1345        
    1346         $table_name = $wpdb->prefix . "posts as p";
    1347         $join = $wpdb->prefix . "postmeta as pm";
    1348         $post_img = $wpdb->get_results("SELECT p.ID,p.guid,pm.meta_value,p.post_name FROM $table_name left join $join on pm.post_id = p.ID WHERE p.post_type = 'property' and pm.meta_key = 'fave_property_id'");
    1349        
    1350         $api_key = get_option( 'property_verification_api');
    1351         $data = array("property_friendly_url"   =>  json_encode($post_img));
    1352         $propData = wp_remote_post(RHIMO_PROPERTY_WEB_URL, array(
    1353             'method'      => 'POST',
    1354             'timeout'     => 60,
    1355             'redirection' => 5,
    1356             'httpversion' => '1.0',
    1357             'blocking'    => true,
    1358             'body'    => $data,
    1359             'headers'     => array(
    1360                     "authorization"=> "Basic YWRtaW46MTIzNA==",
    1361                     "x-api-key"=>$api_key,
    1362                     "Content-Type"=>"application/x-www-form-urlencoded"
    1363             ),
    1364             'cookies' => array()
    1365         ));
    1366     }
    1367 
    1368     if (! wp_next_scheduled ('add_video_images')) {
    1369         wp_schedule_event(time(),'every_ninteen_minutes','add_video_images');
    1370     }
    1371 
    1372     add_action('add_video_images', 'respacio_download_video_image');
    1373 
    1374     function respacio_export(){
    1375 
    1376         $template_path = plugin_dir_path( __FILE__ ) . "template/export.php";
    1377         require_once ($template_path);
    1378     }
    1379 
    1380     function respacio_export_XML($finalFilePath,$finalFileSrc){
    1381 
    1382         global $wpdb;
    1383 
    1384         /* GET PROPERTIES FROM wp_posts TABLE START */
    1385         $args = array(
    1386             'post_type'   => 'property',
    1387             'numberposts' => -1,
    1388             'post_status' => 'any'
    1389         );
    1390 
    1391         $properties = get_posts( $args );
    1392         //echo '<pre> ';  print_r($properties); die;
    1393         if(isset($properties) && !empty($properties)){
    1394 
    1395             $doc = new DOMDocument();
    1396             $doc->formatOutput = true;
    1397 
    1398             $mainTag = $doc->createElement("data");
    1399             $doc->appendChild( $mainTag );
    1400 
    1401             // APPEND PROPERTY DATA TO XML START //
    1402             foreach($properties as $property){
    1403 
    1404                 //echo '<pre> ';  print_r($property); die;
    1405                 $favPropImgs = $favAttachments = array();
    1406 
    1407                 $property_id = $property->ID ;
    1408                 $propertyMetaDatas = get_post_meta($property_id,false,false);
    1409                 //echo '<pre> ';  print_r($propertyMetaDatas); die;
    1410 
    1411                 $propTag = $doc->createElement("Property");
    1412 
    1413                 $post_id = $doc->createElement("post_id");
    1414                 $post_id->appendChild($doc->createTextNode($property_id));
    1415                 $propTag->appendChild( $post_id );
    1416 
    1417                 $property_title = $doc->createElement("post_title");
    1418                 $property_title->appendChild($doc->createTextNode($property->post_title));
    1419                 $propTag->appendChild( $property_title );
    1420 
    1421                 $property_content = $doc->createElement("post_content");
    1422                 $property_content->appendChild($doc->createTextNode($property->post_content));
    1423                 $propTag->appendChild( $property_content );
    1424                
    1425                 $post_name = $doc->createElement("post_name");
    1426                 $post_name->appendChild($doc->createTextNode($property->post_name));
    1427                 $propTag->appendChild( $post_name );
    1428 
    1429                 $property_modified = $doc->createElement("post_modified");
    1430                 $property_modified->appendChild($doc->createTextNode($property->post_modified));
    1431                 $propTag->appendChild( $property_modified );
    1432 
    1433                 $property_excerpt = $doc->createElement("post_excerpt");
    1434                 $property_excerpt->appendChild($doc->createTextNode($property->post_excerpt));
    1435                 $propTag->appendChild( $property_excerpt );
    1436                 $is_private = 0;
    1437                 $post_status = $doc->createElement("post_status");
    1438                 $post_status1 = $property->post_status ;
    1439                 if($post_status1 == 'publish'){
    1440                     $post_status1 = 'Active' ;
    1441                 }
    1442                 else if($post_status1 == 'private'){
    1443                     $is_private = 1;
    1444                     $post_status1 = 'Active' ;
    1445                 }
    1446                 else {
    1447                     $post_status1 = 'Inactive' ;
    1448                 }
    1449                 $post_status->appendChild($doc->createTextNode($post_status1));
    1450                 $propTag->appendChild( $post_status );
    1451 
    1452                 $property_private = $doc->createElement("is_private");
    1453                 $property_private->appendChild($doc->createTextNode($is_private));
    1454                 $propTag->appendChild( $property_private );
    1455 
    1456                 //GET META DATA START
    1457                 if(isset($propertyMetaDatas) && !empty($propertyMetaDatas)){
    1458                     foreach($propertyMetaDatas as $propertyMetaKey=>$propertyMetaVal){
    1459 
    1460                         if($propertyMetaKey != 'fave_attachments' && $propertyMetaKey != 'fave_currency_info' && $propertyMetaKey != 'floor_plans' && $propertyMetaKey != 'fave_property_images' && !empty($propertyMetaVal)){
    1461                             $$propertyMetaKey = $doc->createElement($propertyMetaKey);
    1462                         }
    1463 
    1464                         if($propertyMetaKey == '_thumbnail_id' || $propertyMetaKey == 'fave_video_image' || $propertyMetaKey == 'fave_prop_slider_image'){
    1465 
    1466                             $postMetaVal = get_the_guid($propertyMetaVal[0]) ;
    1467                             if(isset($postMetaVal) && !empty($postMetaVal)){
    1468                                 $postMetaVal .= '?image_id='.$propertyMetaVal[0] ;
    1469                             }
    1470                         } elseif($propertyMetaKey == 'fave_agents'){
    1471 
    1472                             $postMetaVal = '' ;
    1473                             $agnetId = $propertyMetaVal[0] ;
    1474 
    1475                             if(isset($agnetId) && !empty($agnetId)){
    1476 
    1477                                 //GET AGENT NAME
    1478                                 $postMetaVal .= get_the_title($agnetId);
    1479 
    1480                                 // GET AGENT EMAIL ID
    1481                                 $agentEmail = get_post_meta($agnetId,'fave_agent_email',true);
    1482                                 if(isset($agentEmail) && !empty($agentEmail)){
    1483                                     $postMetaVal .= " | ".$agentEmail;
    1484                                 }
    1485 
    1486                                 // GET AGENT WORK NUMBER
    1487                                 $agentOfcNo = get_post_meta($agnetId,'fave_agent_office_num',true);
    1488                                 if(isset($agentOfcNo) && !empty($agentOfcNo)){
    1489                                     $postMetaVal .= " | ".$agentOfcNo;
    1490                                 }
    1491 
    1492                                 // GET IMAGE URL
    1493                                 $agentThumbId = get_post_meta($agnetId,'_thumbnail_id',true);
    1494                                 if(isset($agentThumbId) && !empty($agentThumbId)){
    1495                                     $postMetaVal .= " | ".get_the_guid($agentThumbId) ;
    1496                                 }
    1497 
    1498                             }
    1499 
    1500                         } else if($propertyMetaKey == 'fave_property_images'){
    1501 
    1502                             $favPropImgs = $propertyMetaVal ;
    1503 
    1504                         } else if($propertyMetaKey == 'houzez_views_by_date'){
    1505 
    1506                             if(!empty($propertyMetaVal[0])){
    1507 
    1508                                 $unSerializeData = array_keys(unserialize($propertyMetaVal[0]));
    1509                                 if(isset($unSerializeData) && !empty($unSerializeData)){
    1510 
    1511                                     $propertyCreateDate = $doc->createElement('property_create_date');
    1512                                     $propertyCreateDate->appendChild($doc->createTextNode($unSerializeData[0]));
    1513                                     $propTag->appendChild( $propertyCreateDate );
    1514 
    1515                                     if(!empty($unSerializeData[1])){
    1516                                         $propertyModifiedDate = $doc->createElement('property_modified_date');
    1517                                         $propertyModifiedDate->appendChild($doc->createTextNode($unSerializeData[1]));
    1518                                         $propTag->appendChild($propertyModifiedDate);
    1519                                     }
    1520                                 }
    1521                             }
    1522 
    1523                         }else if($propertyMetaKey == 'floor_plans'){
    1524 
    1525                             $floorPlanData = unserialize($propertyMetaVal[0]);
    1526                             //if($property_id == '8408'){ echo '<pre>' ; print_r($floorPlanData) ;  die; }
    1527                             if(isset($floorPlanData) && !empty($floorPlanData)){
    1528 
    1529                                 $floorPlanWrapTag = $doc->createElement("floorplans");
    1530                                 foreach($floorPlanData as $fpData){
    1531 
    1532                                     if(isset($fpData['fave_plan_image']) && !empty($fpData['fave_plan_image'])){
    1533                                         $fpDataImgId = $fpData['fave_plan_image'] ;
    1534                                         $floorPlanID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", $fpDataImgId ) );
    1535                                         if(isset($floorPlanID) && !empty($floorPlanID)){
    1536                                             $fpDataImgId .= '?image_id='.$floorPlanID ;
    1537                                         }
    1538 
    1539                                         $fpData1 = $doc->createElement("image");
    1540                                         $fpData1->appendChild($doc->createTextNode($fpDataImgId));
    1541                                         $floorPlanWrapTag->appendChild($fpData1);
    1542                                     }
    1543 
    1544                                 }
    1545                                 $propTag->appendChild( $floorPlanWrapTag );
    1546                             }
    1547 
    1548                         } else if($propertyMetaKey == 'additional_features'){
    1549 
    1550                             $addiFeaturesData = unserialize($propertyMetaVal[0]);
    1551                             //echo '<pre>' ; print_r($addiFeaturesData); die;
    1552                             if(isset($addiFeaturesData) && !empty($addiFeaturesData)){
    1553                                 $postMetaVal = '' ;
    1554                                 foreach($addiFeaturesData as $addFeaData){
    1555                                     if(!empty($postMetaVal)){
    1556                                         $postMetaVal .= " | ";
    1557                                     }
    1558                                     $postMetaVal .= $addFeaData['fave_additional_feature_title']." : ".$addFeaData['fave_additional_feature_value'] ;
    1559 
    1560                                 }
    1561                             }
    1562 
    1563                         } else if($propertyMetaKey == 'fave_attachments'){
    1564 
    1565                             $favAttachments = $propertyMetaVal ;
    1566 
    1567                         } else if( $propertyMetaKey == '_houzez_expiration_date'){
    1568 
    1569                             $postMetaVal = date('d-m-Y h:i:s',$propertyMetaVal[0]);
    1570 
    1571                         } else if($propertyMetaKey == 'fave_virtual_tour'){
    1572 
    1573                             $virtualTour = $propertyMetaVal[0];
    1574                             if(isset($virtualTour) && !empty($virtualTour)){
    1575                                 preg_match('@src="([^"]+)"@' ,$virtualTour,$match);
    1576                                 if(isset($match[1])){
    1577                                     $postMetaVal = $match[1] ;
    1578                                 } else {
    1579                                     $postMetaVal = $virtualTour ;
    1580                                 }
    1581                             }
    1582                         } else {
    1583 
    1584                             $postMetaVal = $propertyMetaVal[0];
    1585 
    1586                         }
    1587 
    1588                         if($propertyMetaKey != 'fave_attachments' && $propertyMetaKey != 'fave_currency_info' && $propertyMetaKey != 'floor_plans' && $propertyMetaKey != 'fave_property_images' && !empty($propertyMetaVal)){
    1589                             $$propertyMetaKey->appendChild($doc->createTextNode($postMetaVal));
    1590                             $propTag->appendChild( $$propertyMetaKey );
    1591                         }
    1592 
    1593                         $$propertyMetaKey = $postMetaVal = '' ;
    1594                     }
    1595                 }
    1596                 // GET META DATA END
    1597 
    1598                     //echo '<pre>'; print_r($favAttachments); die;
    1599                 // PROPERTY IMAGE START
    1600                 if(isset($favPropImgs) && !empty($favPropImgs)){
    1601 
    1602                     $imageWrapTag = $doc->createElement("images");
    1603                     foreach($favPropImgs as $favPropImg){
    1604 
    1605                         $imgUrl = get_the_guid($favPropImg);
    1606                         $imgUrl .= '?image_id='.$favPropImg ;
    1607 
    1608                         $favPropImg1 = $doc->createElement("image");
    1609                         $favPropImg1->appendChild($doc->createTextNode($imgUrl));
    1610                         $imageWrapTag->appendChild( $favPropImg1 );
    1611 
    1612                     }
    1613                     $propTag->appendChild( $imageWrapTag );
    1614 
    1615                 }
    1616                 // PROPERTY IMAGE END
    1617 
    1618                 // PROPERTY ATTACHMENT START
    1619                 if(isset($favAttachments) && !empty($favAttachments)){
    1620 
    1621                     $attachWrapTag = $doc->createElement("fave_attachments");
    1622                     foreach($favAttachments as $favAttachment){
    1623 
    1624                         $attchUrl = get_the_guid($favAttachment);
    1625                         $attchUrl .= '?image_id='.$favAttachment ;
    1626 
    1627                         $favAttachment1 = $doc->createElement("image");
    1628                         $favAttachment1->appendChild($doc->createTextNode($attchUrl));
    1629                         $attachWrapTag->appendChild( $favAttachment1 );
    1630 
    1631                     }
    1632                     $propTag->appendChild( $attachWrapTag );
    1633 
    1634                 }
    1635                 // PROPERTY ATTACHMENT END
    1636 
    1637                 $property_type = wp_get_post_terms( $property_id, 'property_type');
    1638                 if(isset($property_type) && !empty($property_type)){
    1639 
    1640                     $property_type_names = implode('| ',wp_list_pluck($property_type,'name'));
    1641                     $propertyType = $doc->createElement("property_type");
    1642                     $propertyType->appendChild($doc->createTextNode($property_type_names));
    1643                     $propTag->appendChild($propertyType);
    1644 
    1645                 }
    1646 
    1647                 $property_status = wp_get_post_terms( $property_id, 'property_status');
    1648                 if(isset($property_status) && !empty($property_status)){
    1649 
    1650                     $property_status_names = implode('| ',wp_list_pluck($property_status,'name'));
    1651                     $propertyStatus = $doc->createElement("property_status");
    1652                     $propertyStatus->appendChild($doc->createTextNode($property_status_names));
    1653                     $propTag->appendChild($propertyStatus);
    1654 
    1655                 }
    1656 
    1657                 $property_features = wp_get_post_terms( $property_id, 'property_feature');
    1658                 if(isset($property_features) && !empty($property_features)){
    1659 
    1660                     $property_features_names = implode('| ',wp_list_pluck($property_features,'name'));
    1661                     $propertyFeature = $doc->createElement("property_feature");
    1662                     $propertyFeature->appendChild($doc->createTextNode($property_features_names));
    1663                     $propTag->appendChild( $propertyFeature );
    1664 
    1665                 }
    1666 
    1667                 $property_labels = wp_get_post_terms( $property_id, 'property_label');
    1668                 if(isset($property_labels) && !empty($property_labels)){
    1669 
    1670                     $property_label_names = implode('| ',wp_list_pluck($property_labels,'name'));
    1671                     $propertyLabel = $doc->createElement("property_label");
    1672                     $propertyLabel->appendChild($doc->createTextNode($property_label_names));
    1673                     $propTag->appendChild( $propertyLabel );
    1674 
    1675                 }
    1676 
    1677                 $property_city = wp_get_post_terms( $property_id, 'property_city');
    1678                 if(isset($property_city) && !empty($property_city)){
    1679 
    1680                     $property_city_names = implode('| ',wp_list_pluck($property_city,'name'));
    1681                     $propertyCity = $doc->createElement("property_city");
    1682                     $propertyCity->appendChild($doc->createTextNode($property_city_names));
    1683                     $propTag->appendChild( $propertyCity );
    1684 
    1685                 }
    1686 
    1687                 $property_state = wp_get_post_terms( $property_id, 'property_state');
    1688                 if(isset($property_state) && !empty($property_state)){
    1689 
    1690                     $property_state_names = implode('| ',wp_list_pluck($property_state,'name'));
    1691                     $propertyState = $doc->createElement("property_state");
    1692                     $propertyState->appendChild($doc->createTextNode($property_state_names));
    1693                     $propTag->appendChild( $propertyState );
    1694 
    1695                 }
    1696 
    1697                 $property_area = wp_get_post_terms( $property_id, 'property_area');
    1698                 if(isset($property_area) && !empty($property_area)){
    1699 
    1700                     $property_area_names = implode('| ',wp_list_pluck($property_area,'name'));
    1701                     $propertyArea = $doc->createElement("property_area");
    1702                     $propertyArea->appendChild($doc->createTextNode($property_area_names));
    1703                     $propTag->appendChild( $propertyArea );
    1704 
    1705                 }
    1706 
    1707                 $currencyInfo = $doc->createElement("fave_currency_info");
    1708                 $currencyInfo->appendChild($doc->createTextNode("€"));
    1709                 $propTag->appendChild( $currencyInfo );
    1710 
    1711                 $mainTag->appendChild( $propTag );
    1712 
    1713             }
    1714             // APPEND PROPERTY DATA TO XML END //
    1715 
    1716             // SAVE XML
    1717             $doc->saveXML();
    1718             $xml = $doc->save($finalFilePath);
    1719 
    1720 
    1721             if($xml !== false){
    1722             ?>
    1723                 <script>respacio_showModal('<?php echo $finalFileSrc;?>');</script>
    1724             <?php
    1725             } else {
    1726                 echo $xml ;
    1727             }
    1728         }
    1729         /* GET PROPERTIES FROM wp_posts TABLE END */
    1730 
    1731     }
    1732 
    1733 
    1734     function respacio_export_XLS($finalFilePath,$finalFileSrc){
    1735 
    1736         $args = array(
    1737             'post_type'   => 'property',
    1738             'numberposts' => -1,
    1739             'post_status' => 'any'
    1740         );
    1741 
    1742         $properties = get_posts( $args );
    1743 
    1744         header("Content-Disposition: attachment; filename=\"$finalFilePath\"");
    1745         header("Content-Type: application/vnd.ms-excel");
    1746         header("Pragma: no-cache");
    1747         header("Expires: 0");
    1748 
    1749         $finalData = array();
    1750         $headings[] = array("post_id","post_title","post_content","post_modified","slide_template","_thumbnail_id","fave_property_size","fave_property_size_prefix","fave_property_bedrooms","fave_property_bathrooms","fave_property_garage","fave_property_garage_size","fave_property_year","fave_property_id","fave_property_price","fave_property_price_postfix","fave_property_map","fave_property_map_address","fave_property_location","fave_property_country","fave_agents","fave_additional_features_enable","additional_features","fave_floor_plans_enable","floor_plans","fave_featured","fave_property_address","fave_property_zip","fave_video_url","fave_payment_status","fave_property_map_street_view","_dp_original","fave_property_sec_price","houzez_total_property_views","fave_multiunit_plans_enable","property_create_date","property_modified_date","houzez_recently_viewed","houzez_geolocation_lat","houzez_geolocation_long","fave_virtual_tour","fave_single_top_area","fave_single_content_area","fave_agent_display_option","fave_property_agency","_edit_lock","_edit_last","fave_currency_info","houzez_manual_expire","_houzez_expiration_date_status","fave_video_image","fave_attachments","images","property_type","property_status","property_feature","property_label","property_city","property_state","post_status");
    1751 
    1752         $out = fopen($finalFilePath, 'w');
    1753 
    1754         foreach($headings as $heading) {
    1755 
    1756             fputcsv($out, $heading,"\t");
    1757 
    1758         }
    1759         foreach($properties as $property) {
    1760 
    1761             $propertyId = $property->ID;
    1762             $propertyMetaDatas = get_post_meta($propertyId,false,false);
    1763 
    1764             $favPropImgs = $favAttachments = array();
    1765 
    1766             $propertyTitle = $propertyContent = $propertyModified = $slide_template = $_thumbnail_id = $fave_property_size = $fave_property_size_prefix = $fave_property_bedrooms = $fave_property_bathrooms = $fave_property_garage = $fave_property_garage_size = $fave_property_year = $fave_property_id = $fave_property_price = $fave_property_price_postfix = $fave_property_map = $fave_property_map_address = $fave_property_location = $fave_property_country = $fave_agents = $fave_additional_features_enable = $additional_features = $fave_floor_plans_enable = $floor_plans = $fave_featured = $fave_property_address = $fave_property_zip = $fave_video_url = $fave_payment_status = $fave_property_map_street_view = $_dp_original = $fave_property_sec_price = $houzez_total_property_views = $fave_multiunit_plans_enable = $propertyCreateDate = $propertyModifiedDate = $houzez_recently_viewed = $houzez_geolocation_lat = $houzez_geolocation_long = $fave_virtual_tour = $fave_single_top_area = $fave_single_content_area = $fave_agent_display_option = $fave_property_agency = $_edit_lock = $_edit_last = $fave_currency_info = $houzez_manual_expire = $_houzez_expiration_date_status = $fave_property_images = $fave_video_image = $favAtta = $images = $property_type = $property_status = $property_feature = $property_label = $property_city = $property_state = $post_status = '' ;
    1767 
    1768             $propertyTitle = $property->post_title;
    1769             $propertyContent = $property->post_content;
    1770             $propertyModified = $property->post_modified;
    1771             $fave_currency_info = "€" ;
    1772             $post_status = $property->post_status ;
    1773             if($post_status == 'publish'){
    1774                 $post_status = 'Active' ;
    1775             } else {
    1776                 $post_status = 'Inactive' ;
    1777             }
    1778 
    1779             if(isset($propertyMetaDatas) && !empty($propertyMetaDatas)){
    1780                 foreach($propertyMetaDatas as $propertyMetaKey=>$propertyMetaVal){
    1781 
    1782                     if($propertyMetaKey == '_thumbnail_id' || $propertyMetaKey == 'fave_video_image'){
    1783 
    1784                         $$propertyMetaKey = get_the_guid($propertyMetaVal[0]) ;
    1785                         if(isset($propertyMetaKey) && !empty($propertyMetaKey)){
    1786                             $$propertyMetaKey .= '?image_id='.$propertyMetaVal[0] ;
    1787                         }
    1788 
    1789                     } elseif($propertyMetaKey == 'fave_agents'){
    1790 
    1791                         $$propertyMetaKey = '' ;
    1792                         $agnetId = $propertyMetaVal[0] ;
    1793 
    1794                         if(isset($agnetId) && !empty($agnetId)){
    1795 
    1796                             //GET AGENT NAME
    1797                             $$propertyMetaKey .= get_the_title($agnetId);
    1798 
    1799                             // GET AGENT EMAIL ID
    1800                             $agentEmail = get_post_meta($agnetId,'fave_agent_email',true);
    1801                             if(isset($agentEmail) && !empty($agentEmail)){
    1802                                 $$propertyMetaKey .= " | ".$agentEmail;
    1803                             }
    1804 
    1805                             // GET AGENT WORK NUMBER
    1806                             $agentOfcNo = get_post_meta($agnetId,'fave_agent_office_num',true);
    1807                             if(isset($agentOfcNo) && !empty($agentOfcNo)){
    1808                                 $$propertyMetaKey .= " | ".$agentOfcNo;
    1809                             }
    1810 
    1811                             // GET IMAGE URL
    1812                             $agentThumbId = get_post_meta($agnetId,'_thumbnail_id',true);
    1813                             if(isset($agentThumbId) && !empty($agentThumbId)){
    1814                                 $$propertyMetaKey .= " | ".get_the_guid($agentThumbId) ;
    1815                             }
    1816 
    1817                         }
    1818 
    1819                     } else if($propertyMetaKey == 'fave_property_images'){
    1820 
    1821                         $favPropImgs = $propertyMetaVal ;
    1822                         //array_push($favPropImgs,$propertyMetaVal[0]);
    1823 
    1824                     } else if($propertyMetaKey == 'houzez_views_by_date'){
    1825 
    1826                         if(!empty($propertyMetaVal[0])){
    1827 
    1828                             $unSerializeData = array_keys(unserialize($propertyMetaVal[0]));
    1829                             if(isset($unSerializeData) && !empty($unSerializeData)){
    1830                                 $propertyCreateDate = $unSerializeData[0];
    1831                                 $propertyModifiedDate = $unSerializeData[1];
    1832                             }
    1833                         }
    1834 
    1835                     } else if($propertyMetaKey == 'floor_plans'){
    1836 
    1837                         $floorPlanData = unserialize($propertyMetaVal[0]);
    1838 
    1839                         if(isset($floorPlanData) && !empty($floorPlanData)){
    1840                             $fpData1 = '' ;
    1841                             foreach($floorPlanData as $fpData){
    1842                                 if(isset($fpData1) && !empty($fpData1)){ $fpData1 .= " | "; }
    1843                                 $fpData1 .= $fpData['fave_plan_image'] ;
    1844                             }
    1845                         }
    1846 
    1847                     }   else if($propertyMetaKey == 'additional_features'){
    1848 
    1849                             $addiFeaturesData = unserialize($propertyMetaVal[0]);
    1850                             if(isset($addiFeaturesData) && !empty($addiFeaturesData)){
    1851                                 $addiFeatureData = '' ;
    1852                                 foreach($addiFeaturesData as $addFeaData){
    1853                                     if(!empty($addiFeatureData)){
    1854                                         $addiFeatureData .= " | ";
    1855                                     }
    1856                                     $addiFeatureData .= $addFeaData['fave_additional_feature_title']." : ".$addFeaData['fave_additional_feature_value'] ;
    1857                                 }
    1858                             }
    1859 
    1860                     }   else if($propertyMetaKey == 'fave_currency_info'){
    1861 
    1862                         $$propertyMetaKey = "€" ;
    1863 
    1864                     }   else if($propertyMetaKey == 'fave_attachments'){
    1865 
    1866                             $favAttachments = $propertyMetaVal ;
    1867 
    1868                     }   else {
    1869 
    1870                         $$propertyMetaKey = $propertyMetaVal[0];
    1871 
    1872                     }
    1873 
    1874                 }
    1875             }
    1876 
    1877             if(isset($favPropImgs) && !empty($favPropImgs)){
    1878 
    1879                 $images = $imgUrl = '' ;
    1880                 foreach($favPropImgs as $favPropImg){
    1881 
    1882                     $imgUrl = '' ;
    1883                     $imgUrl = get_the_guid($favPropImg);
    1884                     if(isset($imgUrl) && !empty($imgUrl)){ $imgUrl .= '?image_id='.$favPropImg ; }
    1885                     if(isset($images) && !empty($images)){ $images .= ' | ' ;}
    1886                     $images .= $imgUrl ;
    1887 
    1888                 }
    1889             }
    1890 
    1891 
    1892             // PROPERTY ATTACHMENT START
    1893             if(isset($favAttachments) && !empty($favAttachments)){
    1894 
    1895                 $favAtta = $attchUrl = '' ;
    1896                 foreach($favAttachments as $favAttachment){
    1897 
    1898                     $attchUrl = '' ;
    1899                     $attchUrl = get_the_guid($favAttachment);
    1900                     if(isset($attchUrl) && !empty($attchUrl)){ $attchUrl .= '?image_id='.$favAttachment ; }
    1901                     if(isset($favAtta) && !empty($favAtta)){ $favAtta .= ' | ' ;}
    1902                     $favAtta .= $attchUrl ;
    1903 
    1904                 }
    1905             }
    1906 
    1907             // PROPERTY ATTACHMENT END
    1908 
    1909             $property_type1 = wp_get_post_terms( $propertyId, 'property_type');
    1910             if(isset($property_type1) && !empty($property_type1)){
    1911                 $property_type = implode(' | ',wp_list_pluck($property_type1,'name'));
    1912             }
    1913 
    1914             $property_status1 = wp_get_post_terms( $propertyId, 'property_status');
    1915             if(isset($property_status1) && !empty($property_status1)){
    1916 
    1917                 $property_status = implode(' | ',wp_list_pluck($property_status1,'name'));
    1918 
    1919             }
    1920 
    1921             $property_features1 = wp_get_post_terms( $propertyId, 'property_feature');
    1922             if(isset($property_features1) && !empty($property_features1)){
    1923 
    1924                 $property_feature = implode(' | ',wp_list_pluck($property_features1,'name'));
    1925 
    1926             }
    1927 
    1928             $property_labels1 = wp_get_post_terms( $propertyId, 'property_label');
    1929 
    1930             if(isset($property_labels1) && !empty($property_labels1)){
    1931 
    1932                 $property_label = implode(' | ',wp_list_pluck($property_labels1,'name'));
    1933 
    1934             }
    1935 
    1936             $property_city1 = wp_get_post_terms( $propertyId, 'property_city');
    1937             if(isset($property_city1) && !empty($property_city1)){
    1938 
    1939                 $property_city = implode(' | ',wp_list_pluck($property_city1,'name'));
    1940 
    1941             }
    1942 
    1943             $property_state1 = wp_get_post_terms( $propertyId, 'property_state');
    1944             if(isset($property_state1) && !empty($property_state1)){
    1945 
    1946                 $property_state = implode(' | ',wp_list_pluck($property_state1,'name'));
    1947 
    1948             }
    1949 
    1950             $row = array($propertyId,$propertyTitle,$propertyContent,$propertyModified,$slide_template,$_thumbnail_id,$fave_property_size,$fave_property_size_prefix,$fave_property_bedrooms,$fave_property_bathrooms,$fave_property_garage,$fave_property_garage_size,$fave_property_year,$fave_property_id,$fave_property_price,$fave_property_price_postfix,$fave_property_map,$fave_property_map_address,$fave_property_location,$fave_property_country,$fave_agents,$fave_additional_features_enable,$addiFeatureData,$fave_floor_plans_enable,$fpData1,$fave_featured,$fave_property_address,$fave_property_zip,$fave_video_url,$fave_payment_status,$fave_property_map_street_view,$_dp_original,$fave_property_sec_price,$houzez_total_property_views,$fave_multiunit_plans_enable,$propertyCreateDate,$propertyModifiedDate,$houzez_recently_viewed,$houzez_geolocation_lat,$houzez_geolocation_long,$fave_virtual_tour,$fave_single_top_area,$fave_single_content_area,$fave_agent_display_option,$fave_property_agency,$_edit_lock,$_edit_last,$fave_currency_info,$houzez_manual_expire,$_houzez_expiration_date_status,$fave_video_image,$favAtta,$images,$property_type,$property_status,$property_feature,$property_label,$property_city,$property_state,$post_status);
    1951 
    1952             fputcsv($out, $row,"\t");
    1953         }
    1954 
    1955         fclose($out);
    1956         if($out){
    1957         ?>
    1958             <script>respacio_showModal('<?php echo $finalFileSrc;?>');</script>
    1959         <?php
    1960         } else {
    1961             echo $out ;
    1962         }
    1963     }
    1964     ?>
     36?>
  • houzez-respacio-import/trunk/includes/css/style.css

    r2263105 r3228040  
    44    overflow: auto;
    55    margin: 16px 0;
    6     padding: 5px 30px 5px 30px;
     6    padding: 30px;
    77    border: 1px solid #e5e5e5;
    88    box-shadow: 0 1px 1px rgba(0,0,0,.04);
     
    1111    line-height: 2.1em;
    1212    width:94%;
     13    border-radius: 12px;
    1314}
    1415#respacio_verification_key{
     
    2627    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
    2728    box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
     29    margin-right: 12px;
    2830}
    2931.verify_button, .btn-submit{
     
    5153.respacio-notice p{font-size:16px;}
    5254.res-success-msg{font-size:16px; color:#3A5F0B;font-weight:bold;}
    53 .res-error-msg{font-size:16px; color:#ff0000;font-weight:bold;}
    54 
    55 
     55.res-error-msg{font-size: 16px;
     56    color: #ff0000;
     57
     58    background: rgb(255 0 0 / 13%);
     59    display: inline-block;
     60    padding: 15px;
     61    margin-top: 10px;
     62    border-radius: 6px;}
     63
     64.res-error-msg:empty{
     65    display: none;
     66}
    5667/* The container */
    5768.container {
     
    175186    box-shadow: none;
    176187}
     188.respacio-notice:empty{
     189    display: none;
     190
     191}
    177192.copyClip{
    178193    background: #006799 !important;
     
    182197    float:right;
    183198}
     199.flex{
     200    display:flex;
     201}
     202.flex-row{
     203    flex-direction: row;
     204}
     205.justify-center{
     206    justify-content: center;
     207}
     208.justify-end{
     209    justify-content: end;
     210}
     211.items-center{
     212    align-items: center;
     213}
     214.items-end{
     215    align-items: end;
     216}
     217.my-button{
     218    padding: 11px 20px;
     219    height: auto;
     220    border: 0 !important;
     221    line-height: initial;
     222    box-shadow: none;
     223}
     224.m-0{
     225    margin:0;
     226}
     227.p-0{
     228    padding:0;
     229}
  • houzez-respacio-import/trunk/includes/template/api-varification.php

    r2263105 r3228040  
    22/* Property API key Verifications */
    33$property_export = get_option( 'property_export');
    4 $property_verification_api = !empty(sanitize_text_field($_POST['property_verification_api'])) ? sanitize_text_field($_POST['property_verification_api']) : "";
    5 $message_btn = "";
    6 if(!isset($error)){
    7     $error = "";
     4
     5$property_verification_api = '';
     6
     7if(array_key_exists('property_verification_api',$_POST) && $_POST['property_verification_api'] != ''){
     8    if ( ! isset( $_POST['api_field'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['api_field'] ) ), 'property_api' ) )
     9    $property_verification_api = sanitize_text_field( wp_unslash( $_POST['property_verification_api'] ) );
    810}
    9 if(!isset($message)){
    10     $message = "";
    11 }
     11
     12$message_btn = '';
     13if(!isset($error)) $error = '';
     14if(!isset($message)) $message = '';
    1215
    1316global $wpdb, $prop_web_name,$prop_options, $prop_messages;
     
    1518$sa_apikey = get_option( 'property_verification_api');
    1619$sync_type = get_option( 'sync_type');
    17 $message1 = "";
    18 if(sanitize_text_field($_POST['property_sync_property'])){
     20$message1 = '';
     21
     22if(array_key_exists('property_sync_property',$_POST) && sanitize_text_field( wp_unslash( $_POST['property_sync_property'] ) ) ){
    1923    $method = 'POST';
    20     $data['lang_code'] = "en";
     24    $data['lang_code'] = 'en';
     25    //TODO: where is the defination ? remove it ?
    2126    $property_sync = property_syncing_cb();
     27
    2228    $property_sync_json = json_decode($property_sync,true);
    2329    if($property_sync_json['is_record'] != 0){
     
    2632        $result = sa_verify_api_curl($ws_name,$data,$method);
    2733        $finalres = json_decode($result);
    28         if(!empty($finalres) && $finalres->status == "success"){
     34        if(!empty($finalres) && $finalres->status == 'success' ){
    2935            $wpdb->update('properties',
    3036            array(
    3137                'property_export_success' => 1,
    32                 'property_export_date' => date('Y-m-d H:i:s')
     38                'property_export_date' => gmdate('Y-m-d H:i:s')
    3339            ),
    3440            array('property_export_success' => 0) );
     
    4753    <div class="respacio-notice">
    4854        <form action="" method="post">
    49             <h2 class="activation_title">Activate Respacio</h2>
     55
     56            <h2 class="activation_title m-0">Activate Respacio</h2>
    5057            <p>Enter your website API key from your Respacio CRM. </p>
    51            
     58            <div class="flex flex-row items-end">
    5259            <?php if(!empty($sa_apikey_verify) && !empty($sa_apikey)) { ?>
    53                
     60
    5461                <div id="title-wrap" class="input-text-wrap">
    5562                    <label id="api_key_prompt_text" class="prompt" for="api_key"></label>
    5663                   
    57                     <input type="text" disabled='' name="remove_api" value="<?php echo get_option( 'property_verification_api'); ?>" id="respacio_verification_key" spellcheck="true" autocomplete="on">
     64                    <input type="text" disabled='' name="remove_api" value="<?php echo esc_attr( get_option( 'property_verification_api') ); ?>" id="respacio_verification_key" spellcheck="true" autocomplete="on">
    5865                </div>             
    59                 <input type="submit" name="remove_licence_key" value="Remove license key" id="verify_button" class="btn btn-submit verify_button"/>
     66                <input type="submit" name="remove_licence_key" value="Remove license key" id="verify_button" class="btn btn-submit verify_button my-button"/>
    6067               
    6168            <?php } else { ?>
     
    6370            <div id="title-wrap" class="input-text-wrap">
    6471                <label id="api_key_prompt_text" class="prompt" for="api_key"> Enter your purchase key </label>
    65                 <input type="text" name="property_verification_api" size="30" autocomplete="off" value="<?php echo get_option( 'property_verification_api'); ?>" id="respacio_verification_key" spellcheck="true" autocomplete="on" placeholder="Enter your API key">
     72                <input type="text" name="property_verification_api" size="30" autocomplete="off" value="<?php echo esc_attr( get_option( 'property_verification_api') ); ?>" id="respacio_verification_key" spellcheck="true" autocomplete="on" placeholder="Enter your API key">
    6673            </div>
    67            
    68             <input type="submit" name="property_verification_submit" value="Verify" href="#" id="verify_button" class="btn btn-submit verify_button"/>
     74            <?php wp_nonce_field( 'property_api', 'api_field' ) ?>
     75            <input type="submit" name="property_verification_submit" value="Verify" href="#" id="verify_button" class="btn btn-submit verify_button my-button"/>
    6976        <?php } ?>
     77            </div>
    7078        </form>
    7179       
     
    7482            <div class="sa-groupset-heading"></div>
    7583            <div class="sa-single-option">
    76                 <div class="register-product__message res-success-msg"><?php echo $message; ?></div>
    77                 <div class="register-product__message res-error-msg"><?php echo $error; ?></div>
     84                <div class="register-product__message res-success-msg"><?php echo esc_attr( $message ); ?></div>
     85                <div class="register-product__message res-error-msg"><?php echo esc_attr( $error ); ?></div>
    7886            </div>
    7987        </div>
  • houzez-respacio-import/trunk/readme.txt

    r2578739 r3228040  
    11=== Respacio Houzez Import ===
    2 Contributors: Respacio
     2Contributors: Respacio, 1aamir, samkitrespacio
    33Donate link: https://respacio.com
    44Tags: import, export
    55Requires at least: 4.6
    6 Tested up to: 5.8
    7 Stable tag: 4.3
     6Tested up to: 6.7.1
     7Stable tag: 1.2.0
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
     
    1616Manage all your property listings and contacts from Respacio to take your real estate sales and marketing to the next level. From multinational franchises to sole traders, the Respacio CRM is used by successful real estate agents and developers all over the world to sell and rent properties.
    1717
    18 This plugin is designed to import your properties into the Respacio CRM and then feed them back to your Houzez website, allowing you to manage your properties from within the Respacio CRM. The plugin makes changes to the content of data tables in your Wordpress installation. It does not affect the Houzez theme design, functionality, CSS or any other element of your site. 
     18This plugin is designed to import your properties into the Respacio CRM and then feed them back to your Houzez website, allowing you to manage your properties from within the Respacio CRM. The plugin makes changes to the content of data tables in your Wordpress installation. It does not affect the Houzez theme design, functionality, CSS or any other element of your site.
    1919
    20 Not only can you sync properties to your Houzez website, but with Respacio you can connect multiple websites in any languages and currencies, each with its own Top Level Domain (TLD eg .com, .es, .pt, .fr) allowing you build the perfect SEO structure.
     20Forms will also connect to the Respacio API so when someone enquires their details will be sent to the CRM immediately which can generate an immediate auto response by email and WhatsApp.
    2121
    22 Respacio will also feed properties out to property portals such as Rightmove, Zoopla, Kyero or systems like Facebook to create a property catalogue... using the Feedbuilder module you can connect synchronise XML and JSON feeds to almost anywhere. This means you can also feed in properties directly from partner agents, MLS systems etc and then feed these properties out to your websites. You can also apply feeds to contacts.
     22Not only can you sync properties and contacts to your Houzez website, but with Respacio you can connect multiple websites in any languages and currencies, each with its own Top Level Domain (TLD eg .com, .es, .pt, .fr) allowing you build the perfect SEO structure.
    2323
    24 New enquiries from websites, property portals and other online sources enter your Respacio system automatically, no typing using the API, Plugins or automated inbuilt email reader. Respacio comes with hundreds of possible automations to speed up your business flow.
     24Respacio will also feed properties out to property portals such as Rightmove, Zoopla, Idealista, Realtor.CA or systems like Facebook to create a property catalogue... using the Feedbuilder module you can connect synchronise XML and JSON feeds to almost anywhere. This means you can also feed in properties directly from partner agents, MLS systems etc and then feed these properties out to your websites. You can also apply feeds to contacts.
     25
     26New enquiries from websites, property portals and other online sources enter your Respacio system automatically, no typing using the API, Plugins or automated inbuilt email reader. Respacio comes with hundreds of possible automations to speed up your business flow. Immediately send automated WhatsApp replies and boost your retention rates.
    2527
    2628Team management, pipelines, deals, GSuite integration, emails, calendars, newsletters, reports: Respacio allows real estate businesses to take control, measure and refine their digital marketing and sales processes.
     
    5254== Screenshots ==
    5355
    54 1. This screen for import export data or API
    55 2. This screen for enter API key for import data
    56 3. Screen for export properties
     561. Status and list of properties.
     57
     582. Export data tab to export properties in XML and excel format.
     59
     603. Settings tab for entering API from to sync properties.
     61
     624. Connect tab is for new registration in CRM.
     63
     645. Forms tab for custom forms sync settings on click.
     65
     666. Knowledge base of CRM.
     67
     687. Support page for CRM.
    5769
    5870== Upgrade Notice ==
     
    6476
    6577= 1.0 =
     78
     79= [1.2.0] 23-01-2025 =
     80
     81Added: New admin dashboard with more functionality in admin page.
     82Added: Functionality for properties status and view on click.
     83Added: Functionality to register to our CRM from dashboard.
     84Added: Custom form integration to send contacts to Respacio CRM on completion of forms.
     85Added: Auto WPML detection for Houzez theme site to add properties to CRM in multiple languages.
     86Added: Knowledge base link about CRM in admin dashboard.
     87Added: Support services mail and whatsapp in admin dashboard.
     88Added: Screenshots about plugin dashboard.
     89Added: POT file for translation.
     90Added: Translation for French, Spanish, German, Portugese and Italian.
Note: See TracChangeset for help on using the changeset viewer.