AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.114
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/helpers/JsonTranslator.php
<?php

class JsonTranslator{

    //This one does all the magic
    //returns an array with the default json
    // keys, but with the actual values
    //instead of identifiers;
    private function swapKeys($array){
        $foo = new stdClass();
        foreach($array as $key => $value){
            if(is_array($value)){
                //if value is an array, recursively go throught it
                //to get all values
                $foo->$key = $this->swapKeys($value);
            }else{
                $value = $value === 0 ? null : $value;
                $foo->$key = $value;
            }
        }
        return $foo;
    }

    private function sanitizeMonetaryValue($val){

        //removing everything after a comma
        $pattern = "/(?<=,).*$/";
        $floatToInt = preg_replace($pattern, "", $val);
        //then removing everything that is not a number
        $numsOnly = preg_replace("/\D+/", "", $floatToInt);
        return $numsOnly;
    }

    private function castToInt($val){
        //if intval can do the job
        if(intval($val) != 0){
            return intval($val);
        }
        //pattern matching to make sure it doesn't just return 0 
        //if it comes up with a word or something
        $pattern = "/\D+/";
        $num = preg_replace($pattern, "", $val);
        return intval($num);
    }

    private function formatPrice($value){
        $value = is_array($value) ? $value[0] : $value;
        $value = strval($value);
        $pattern = "/(?<=)\.\d+/";
        return preg_replace($pattern, "", $value);
    }

    private function checkDescForParkingSpaces($desc){
        $pattern = "/\d(?= vagas| vaga| garagem| garagens)/";
        $matches = [];
        preg_match_all($pattern, $desc, $matches);
        if($matches[0]){
            return intval($matches[0][0]);
        }
        return 0;
    }

    private function checkDescForSuites($desc){
        $pattern = "/\d(?= suites| suítes| Suites| Suítes)/";
        $matches = [];
        preg_match_all($pattern, $desc, $matches);
        if($matches[0]){
            return intval($matches[0][0]);
        }
        return 0;
    }

    private function itemsAsArrays($translated){
        $translated->listing->pricingInfos = (array) $translated->listing->pricingInfos;
        $translated->listing->floors = (array) $translated->listing->floors;
        $translated->listing->suites = (array) $translated->listing->suites;
        $translated->listing->bedrooms = (array) $translated->listing->bedrooms;
        $translated->listing->bathrooms = (array) $translated->listing->bathrooms;
        $translated->listing->usableAreas = (array) $translated->listing->usableAreas;
        $translated->listing->parkingSpaces = (array) $translated->listing->parkingSpaces;
        $translated->listing->unitTypes = (array) $translated->listing->unitTypes;
        $translated->listing->amenities = (array) $translated->listing->amenities;
        $translated->listing->unitSubTypes = (array) $translated->listing->unitSubTypes;
        $translated->listing->ceilingHeight = (array) $translated->listing->ceilingHeight;
        $translated->listing->stamps = (array) $translated->listing->stamps;
        $translated->listing->portals = (array) $translated->listing->portals;
        $translated->listing->usageTypes = (array) $translated->listing->usageTypes;
        $translated->listing->address->pois = (array) $translated->listing->address->pois;
        $translated->listing->address->poisList = (array) $translated->listing->address->poisList;
        $translated->listing->address->valuableZones = (array) $translated->listing->address->valuableZones;
        $translated->listing->totalAreas = (array) $translated->listing->totalAreas;
        $translated->listing->capacityLimit = (array) $translated->listing->capacityLimit;
        $translated->listing->advertiserContact->phones = (array) $translated->listing->advertiserContact->phones;
        $translated->medias = (array) $translated->medias;
        // $j = count($translated->medias);
        // for($i = 0; $i < $j; $i++){
        //     $translated->medias[$i] = (array) $translated->medias[$i];
        // }
        return $translated;
    }

    public function from123i($api){
        $perimeter = $api->info->perimeter== null ?"0":(string)$api->info->perimeter;
        if(!$api->info->address->city){
            $api->info->address->city = "Goiânia";
        }
        $mapping = [
            "listing" =>[
                    "displayAddressType" =>null,
                    "amenities" => [],
                    "feedsId" => "",
                    "contractType" =>null,
                    "usableAreas" => [
                        $perimeter
                    ],
                    "constructionStatus" =>null,
                    "videoTourLink" =>null,
                    "listingType" => "USED",
                    "description" =>$api->description,
                    "title" =>$api->title,
                    "createdAt" =>null,
                    "floors" => [],
                    "unitTypes" => [
                    ],
                    "nonActivationReason" =>null,
                    "providerId" =>null,
                    "propertyType" =>null,
                    "unitSubTypes" => [],
                    "ceilingHeight" => [],
                    "unitsOnTheFloor" => null,
                    "legacyId" =>null,
                    "modifiedBy" =>null,
                    "id" => $api->id,
                    "portal" =>null,
                    "unitFloor" => null,
                    "statusEncoded" => null,
                    "stamps" => [],
                    "parkingSpaces" => [
                        $this->castToInt($api->info->garage)
                    ],
                    "updatedAt" =>null,
                    "address" => [
                        "country" =>"BR",
                        "zipCode" =>null,
                        "geoJson" =>null,
                        "city" =>$api->info->address->city,
                        "streetNumber" =>$api->info->address->numaddr,
                        "level" =>null,
                        "precision" =>null,
                        "confidence" =>null,
                        "stateAcronym" =>$api->info->address->uf,
                        "source" =>null,
                        "point" => [
                        ],
                        "ibgeCityId" =>null,
                        "zone" =>null,
                        "street" =>$api->info->address->street,
                        "locationId" =>null,
                        "district" =>null,
                        "name" =>null,
                        "state" =>$api->info->address->uf,
                        "neighborhood" =>$api->info->address->nm_hood,
                        "poisList" => [
                        ],
                        "complement" =>null,
                        "pois" => [],
                        "valuableZones" => []
                    ],
                    "suites" => [
                        $this->castToInt($api->info->bedRoom)
                    ],
                    "portals" => [
                    ],
                    "publicationType" =>null,
                    "externalId" =>null,
                    "bathrooms" => [
                        $this->castToInt($api->info->bathRoom)
                    ],
                    "usageTypes" => [
                    ],
                    "totalAreas" => [],
                    "advertiserId" =>null,
                    "bedrooms" => [
                        $this->castToInt($api->info->room)
                    ],
                    "acceptExchange" => null,
                    "pricingInfos" => [
                        [
                            "price" => $this->sanitizeMonetaryValue($api->info->price),
                            "businessType" => "SALE",
                            "monthlyCondoFee" =>null,
                            "yearlyIptu" =>null
                        ]
                    ],
                    "showPrice" => null,
                    "resale" => null,
                    "buildings" => null,
                    "searchableAmenities" =>null,
                    "capacityLimit" => [],
                    "status" =>null,
                    "advertiserContact" => [
                        "phones" => [
                            $api->relatedCompanies->companies[0]->userTelephone
                        ]
                    ],
                    "whatsappNumber" =>null
                ],
                    "account" => [
                        "id" =>null,
                        "name" =>$api->relatedCompanies->companies[0]->userName,
                        "phones" => [
                            "primary" => $api->relatedCompanies->companies[0]->userTelephone,
                            "mobile" =>null
                        ],
                        "licenseNumber" =>null,
                        "websiteUrl" =>null,
                        "createdDate" =>null,
                        "showAddress" => null,
                        "legacyVivarealId" => null,
                        "legacyZapId" => null
                    ],
                    "medias" => $this->uolImgArray($api->more->images),
                    "accountLink" => [
                        "data" => [],
                        "name" =>$api->relatedCompanies->companies[0]->userName,
                        "href" =>null,
                        "rel" =>null
                    ],
                    "link" => [
                        "data" => [
                            "street" => $api->info->address->street,
                            "streetNumber" => $api->info->address->numaddr,
                            "state" => $api->info->address->uf,
                            "city" => $api->info->address->city,
                            "zone" => null,
                            "neighborhood" => $api->info->address->nm_hood
                        ],
                        "name" =>null,
                        "href" => $api->url,
                        "rel" =>null
                    ]
        ];
        $translated = json_decode(json_encode($mapping));
        // $translated = $this->swapKeys($mapping);

        //items cast as arrays
        $translated = $this->itemsAsArrays($translated);
        return $translated;
    }

    private function uolImgArray($images){
        $bar = [];
        foreach($images as $img){
            $i = new stdClass();
            $i->url = $img->src;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;
    }

    public function fromWebImoveis($api){
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => [],
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $api->mainFeatures->CFT100->value
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>$api->tour->reference,
                "listingType" =>null,
                "description" =>$api->description,
                "title" =>$api->title,
                "createdAt" =>$api->publication->beginDate,
                "floors" => [],
                "unitTypes" => [
                ],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->postingId,
                "portal" =>null,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $api->mainFeatures->CFT7->value
                ],
                "updatedAt" =>null,
                "address" => [
                    "country" => $api->postingLocation->location->parent->parent->parent->name,
                    "zipCode" =>null,
                    "geoJson" =>$api->postingLocation->postingGeolocation,
                    "city" =>$api->postingLocation->location->parent->name,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>null,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$api->postingLocation->address->name,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $api->postingLocation->location->parent->parent->name,
                    "neighborhood" => $api->postingLocation->location->name,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    $api->mainFeatures->CFT4->value
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                    $api->mainFeatures->CFT3->value
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => [
                    $api->mainFeatures->CFT2->value
                ],
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$api->priceOperationTypes->prices->amount,
                        "businessType" =>$api->priceOperationTypes->operationType->name,
                        "monthlyCondoFee" => $api->expenses->amount,
                        "yearlyIptu" => $api->iptu
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                            $api->whatsApp
                    ]
                ],
                "whatsappNumber" => $api->whatsApp
            ],
            "account" => [
                "id" =>null,
                "name" =>$api->publisher->name,
                "phones" => [
                    "primary" =>null,
                    "mobile" => $api->whatsApp
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => [
                $this->uolImgArray($api->visiblePictures->pictures)
            ],
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" =>$this->webImoveisUrl($api->postingId),
                "rel" =>null
            ]
        ];
        return $this->swapKeys($mapping);
    }

    private function webImoveisUrl($url){
        return 'https://www.wimoveis.com.br/propriedades/cod-ap0707-' . $url . '.html';
    }


    public function fromUrbs($api, $businessType){
        
        // Verifico a quantidade de vagas
        $fixed_vagas = $api->vagas;
        if($fixed_vagas == 0){
            $fixed_vagas = $this->checkDescForParkingSpaces($api->descricao);
        }
        
        // Verifico o telefone do captador
        $captador_fone = isset($api->captador_telefone)?preg_replace('/\D/', '', $api->captador_telefone):"62999101075";
        $mapping = [
            "listing" => [
                "imoblesCustomFields" => ["enterpriseName" => $api->condominio],
                "displayAddressType" =>null,
                "amenities" => [],
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $api->area_privativa
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>$api->url_tourvirtual,
                "listingType" =>"USED",
                "description" =>$api->descricao,
                "title" =>$api->nome,
                "createdAt" =>$api->data_criacao,
                "floors" => [],
                "unitTypes" => [],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->objectID,
                "portal" =>"URBS",
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $fixed_vagas
                ],
                "updatedAt" =>$api->data_criacao,
                "address" => [
                    "country" => "BR",
                    "zipCode" =>null,
                    "geoJson" =>null,
                    "city" =>$api->cidade,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>$api->estado,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$api->logradouro,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $api->estado,
                    "neighborhood" => $api->bairro,
                    "poisList" => [
                    ],
                    "complement" =>$api->condominio,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    $api->suites
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [$api->area_total],
                "advertiserId" =>null,
                "bedrooms" => [
                    $api->dormitorios
                ],
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$this->formatPrice($businessType=="SALE"?$api->valor_venda:$api->valor_locacao),
                        "businessType" =>$businessType,
                        "monthlyCondoFee" => $api->valor_condominio_total,
                        "yearlyIptu" => $api->valor_iptu_total
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>"ACTIVE",
                "advertiserContact" => [
                    "phones" => [
                        "62999101075"
                    ]
                ],
                "whatsappNumber" => $captador_fone
            ],
            "account" => [
                "id" =>null,
                "name" =>"URBS",
                "phones" => [
                    "primary" =>$captador_fone,
                    "mobile" => $captador_fone
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => isset($api->fotos)?$this->urbsImgArray($api->fotos):[],
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" => "https://www.urbs.com.br/s/imovel/" . $api->objectID . "?negocio=" . ($businessType=="SALE"?"Comprar":"Alugar"),
                "rel" =>null
            ]
        ];
        $translated = json_decode(json_encode($mapping));
        return $this->itemsAsArrays($translated);
    }

    private function urbsImgArray($images){
        $bar = [];
        foreach($images as $img){
            $i = new stdClass();
            $i->url = $img->url_imagem;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;
    }

    public function fromInGaia($api, $phone, $url) {
        //fix addres to get streetname
        $address_array = $api->full_address ? explode('-',$api->full_address) : [null];
        $street_name = trim($address_array[0]);

        //fix businesstype
        $businessType = $this->fixBusinessType($api->property_purposes);
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => $api->amenities,
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => $api->area,
                "constructionStatus" =>null,
                "videoTourLink" =>null,
                "listingType" =>null,
                "description" =>$api->listing_description,
                "title" =>$api->heading1,
                "createdAt" =>$api->created_at,
                "floors" => [],
                "unitTypes" => [],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->property_full_reference,
                "portal" =>null,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => $api->garages,
                "updatedAt" =>$api->updated_at,
                "address" => [
                    "country" => "BR",
                    "zipCode" =>null,
                    "geoJson" =>null,
                    "city" =>$api->city,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>$api->state,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$street_name,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $api->state,
                    "neighborhood" => $api->neighborhood,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => $api->suites,
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => $api->bathrooms,
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => $api->bedrooms,
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$this->formatPrice($api->sale_price),
                        "businessType" =>$businessType,
                        "monthlyCondoFee" => null,
                        "yearlyIptu" => null
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                        $phone
                    ]
                ],
                "whatsappNumber" => $phone
            ],
            "account" => [
                "id" =>null,
                "name" =>"InGaia",
                "phones" => [
                    "primary" =>$phone,
                    "mobile" =>$phone
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => $this->inGaiaImgArray($api->photos),
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" => $this->sanitizeInGaiaUrl($url) . $api->property_full_reference,
                "rel" =>null
            ]
        ];
        // $translated = $this->swapKeys($mapping);
        $translated = json_decode(json_encode($mapping));
        return $this->itemsAsArrays($translated);
    }

    private function sanitizeInGaiaUrl($url){
        $pattern = "/(?<=)\/api.+/"; //match every char after "/api"
        $url = preg_replace($pattern, "", $url);
        return $url . "/empreendimento/";
    }

    private function fixBusinessType($value){
        $value = is_array($value) ? $value : [$value];
        foreach($value as $v){
            if(strpos($v, "NEW") && strpos($v, "SALE") !== false){
                return "SALE";
            }
        }
        return "RENTAL";
    }

    private function inGaiaImgArray($images){
        $bar = [];
        foreach($images as $img){
            $i = new stdClass();
            $i->url = $img->picture_full;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;
    }


    public function fromProprietarioDireto($api) {
        $suites = $this->checkDescForSuites($api->desc);
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => [],
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $api->area
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>null,
                "listingType" =>null,
                "description" =>$api->desc,
                "title" =>$api->title,
                "createdAt" =>$api->created_at,
                "floors" => [],
                "unitTypes" => [
                ],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->id,
                "portal" =>null,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $api->parking_spaces
                ],
                "updatedAt" =>null,
                "address" => [
                    "country" => $api->country,
                    "zipCode" =>$api->postal_code,
                    "geoJson" =>null,
                    "city" =>$api->neighborhood->locality->name,
                    "streetNumber" =>$api->street_number,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>$api->neighborhood->locality->state->abbr,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$api->route,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $api->neighborhood->locality->state->name,
                    "neighborhood" => $api->neighborhood->name,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    $suites
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                    $api->bath
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => [
                    $api->room
                ],
                "acceptExchange" => null,
                "pricingInfos" => array (
                    [
                        "price" =>$this->formatPrice($api->sale),
                        "businessType" =>null,
                        "monthlyCondoFee" => $this->formatPrice($api->condominium),
                        "yearlyIptu" => $this->formatPrice($api->iptu)
                    ]
                    ),
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                            null
                    ]
                ],
                "whatsappNumber" => null,
            ],
            "account" => [
                "id" =>$api->user->id,
                "name" =>$api->user->first_name . $api->user->last_name,
                "phones" => [
                    "primary" =>null,
                    "mobile" => null
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => $this->proprietarioDiretoImgArray($api->photos),
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" =>$api->url,
                "rel" =>null
            ]
        ];

        $translated = json_decode(json_encode($mapping));
        return $this->itemsAsArrays($translated);
    }

    private function proprietarioDiretoImgArray($images) {
        $bar = [];
        foreach($images as $img){
            $i = new stdClass();
            $i->url = $img->url->original;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;

    }

    public function fromQuintoAndar($api) {
        //all important data is inside a 'source' json obj
        $city="Goiânia";
        $state="GO";
        $api = $api->_source;
        $created_at = $api->firstPublicationDateSale ? $api->firstPublicationDateSale : $api->firstPublicationDateRent;
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => $api->amenities,
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $api->area
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>null,
                "listingType" =>null,
                "description" =>"",
                "title" =>"",
                "createdAt" =>$created_at,
                "floors" => [],
                "unitTypes" => [
                ],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->id,
                "portal" =>null,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $api->parkingSpaces
                ],
                "updatedAt" =>null,
                "address" => [
                    "country" => "BR",
                    "zipCode" =>null,
                    "geoJson" =>null,
                    "city" =>$city,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>$state,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$api->address,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $state,
                    "neighborhood" => $api->neighbourhood,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    $api->suites,
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                    $api->bathrooms
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => [
                    $api->bedrooms
                ],
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$this->formatPrice($api->salePrice),
                        "businessType" =>null,
                        "monthlyCondoFee" => $this->formatPrice($api->condominium),
                        "yearlyIptu" => $this->formatPrice($api->iptu)
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                            null
                    ]
                ],
                "whatsappNumber" => null,
            ],
            "account" => [
                "id" =>null,
                "name" =>"Quinto Andar",
                "phones" => [
                    "primary" =>null,
                    "mobile" => null
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => $this->quintoAndarImgArray($api->imageList),
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" =>"https://www.quintoandar.com.br/imovel/".$api->id,
                "rel" =>null
            ]
        ];

        $translated = $this->swapKeys($mapping);
        return $this->itemsAsArrays($translated);
    }

    private function quintoAndarImgArray($images) {
        $foo = [];
        $bar = [];
        foreach($images as $img){
            $foo['url'] = "https://www.quintoandar.com.br/img/xlg/".$img;
            $foo['type'] = 'IMAGE';
            array_push($bar, $foo);
        }
        return $bar;

    }

    public function fromLoopim($api) {
        //all important data is inside a '_source' json obj
        $id = $api->_id;
        $api = (object) $api->_source;
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => $this->loopimAmenities($api->opcionais),
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $api->area_total
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>null,
                "listingType" => "USED",
                "description" =>$api->descricao,
                "title" =>$api->title,
                "createdAt" =>$api->timestamp,
                "floors" => [],
                "unitTypes" => [
                  $api->tipo_imovel_bruto == 'Apartamento' ? 'APARTMENT' : $api->tipo_imovel_bruto
                ],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$id,
                "portal" => $api->nome_portal,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $api->garagem
                ],
                "updatedAt" =>null,
                "address" => [
                    "country" => "BR",
                    "zipCode" =>null,
                    "geoJson" =>null,
                    "city" =>$api->cidade->short_name,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" => $api->uf,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>$api->endereco,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => null,
                    "neighborhood" => $api->bairro?$api->bairro->nome:$api->bairro_bruto,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    $api->suite,
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                    $api->banheiro
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => [
                    $api->quarto
                ],
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$this->formatPrice($api->valor),
                        "businessType" => $api->tipo_negocio=="Venda"?"SALE":"RENTAL",
                        "monthlyCondoFee" => null,
                        "yearlyIptu" => null
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                            null
                    ]
                ],
                "whatsappNumber" => null,
            ],
            "account" => [
                "id" =>null,
                "name" =>$api->anunciante->nome,
                "phones" => [
                    "primary" => null,
                    "mobile" => null
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>null,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => $this->loopimImgArray($api->lista_fotos),
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" =>$api->url,
                "rel" =>null
            ]
        ];

        $translated = json_decode(json_encode($mapping));
        return $this->itemsAsArrays($translated);
    }

    private function loopimImgArray($images) {
        $bar = [];
        foreach($images as $img){
            $i = new stdClass();
            $i->url = $img;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;
    }

    private function loopimAmenities($opcionais){
        $amenities = [];
        foreach($opcionais as $o){
           array_push($amenities, $o->name);
        }
        return $amenities;
    }

    public function fromMeli($api, $images) {
        $mapping = [
            "listing" => [
                "displayAddressType" =>null,
                "amenities" => null,
                "feedsId" =>null,
                "contractType" =>null,
                "usableAreas" => [
                    $this->findInMeli($api, 'TOTAL_AREA')
                ],
                "constructionStatus" =>null,
                "videoTourLink" =>null,
                "listingType" =>"USED",
                "description" =>null,
                "title" =>$api->title,
                "createdAt" =>null,
                "floors" => [],
                "unitTypes" => [
                  'APARTMENT'
                ],
                "nonActivationReason" =>null,
                "providerId" =>null,
                "propertyType" =>null,
                "unitSubTypes" => [],
                "ceilingHeight" => [],
                "unitsOnTheFloor" => null,
                "legacyId" =>null,
                "modifiedBy" =>null,
                "id" =>$api->id,
                "portal" =>null,
                "unitFloor" => null,
                "statusEncoded" => null,
                "stamps" => [],
                "parkingSpaces" => [
                    $this->findInMeli($api, 'PARKING_LOTS')
                ],
                "updatedAt" =>null,
                "address" => [
                    "country" => "BR",
                    "zipCode" =>null,
                    "geoJson" =>null,
                    "city" =>$api->address->city_name,
                    "streetNumber" =>null,
                    "level" =>null,
                    "precision" =>null,
                    "confidence" =>null,
                    "stateAcronym" =>null,
                    "source" =>null,
                    "point" => [
                    ],
                    "ibgeCityId" =>null,
                    "zone" =>null,
                    "street" =>null,
                    "locationId" =>null,
                    "district" =>null,
                    "name" =>null,
                    "state" => $api->address->state_name,
                    "neighborhood" => $api->location->neighborhood->name,
                    "poisList" => [
                    ],
                    "complement" =>null,
                    "pois" => [],
                    "valuableZones" => []
                ],
                "suites" => [
                    null
                ],
                "portals" => [
                ],
                "publicationType" =>null,
                "externalId" =>null,
                "bathrooms" => [
                    $this->findInMeli($api, 'FULL_BATHROOMS')
                ],
                "usageTypes" => [
                ],
                "totalAreas" => [],
                "advertiserId" =>null,
                "bedrooms" => [
                    $this->findInMeli($api, 'BEDROOMS')
                ],
                "acceptExchange" => null,
                "pricingInfos" => [
                    [
                        "price" =>$this->formatPrice($api->price),
                        "businessType" =>"SALE",
                        "monthlyCondoFee" => null,
                        "yearlyIptu" => null
                    ]
                ],
                "showPrice" => null,
                "resale" => null,
                "buildings" => null,
                "searchableAmenities" =>null,
                "capacityLimit" => [],
                "status" =>null,
                "advertiserContact" => [
                    "phones" => [
                            $api->seller_contact->phone
                    ]
                ],
                "whatsappNumber" => null,
            ],
            "account" => [
                "id" =>null,
                "name" =>'Mercado Livre',
                "phones" => [
                    "primary" =>$api->seller_contact->phone,
                    "mobile" => null
                ],
                "licenseNumber" =>null,
                "websiteUrl" =>$api->seller_contact->webpage,
                "createdDate" =>null,
                "showAddress" => null,
                "legacyVivarealId" => null,
                "legacyZapId" => null
            ],
            "medias" => $this->meliImgArray($images),
            "accountLink" => [
                "data" => [],
                "name" =>null,
                "href" =>null,
                "rel" =>null
            ],
            "link" => [
                "data" => [
                ],
                "name" =>null,
                "href" =>$api->permalink,
                "rel" =>null
            ]
        ];

        $translated = json_decode(json_encode($mapping));
        return $this->itemsAsArrays($translated);
    }

    private function findInMeli($api, $key) {
        foreach($api->attributes as $value) {
            if($value->id == $key) {
                return $value->value_name ? $value->value_name : $value->values->struct->number;
            }
        }
        return null;
    }

    private function meliImgArray($images) {
        $bar = [];
        foreach($images as $img){
            $url = $img->secure_url;
            $url = str_replace('.jpg', '.webp', $url);
            $i = new stdClass();
            $i->url = $url;
            $i->type = 'IMAGE';
            array_push($bar, $i);
        }
        return $bar;
    }

}

Anon7 - 2022
AnonSec Team