Uname: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
Software: Apache
PHP version: 5.6.40 [ PHP INFO ] PHP os: Linux
Server Ip: 217.160.0.194
Your Ip: 216.73.216.203
User: u72294154 (9179942) | Group: ftpusers (600)
Safe Mode: OFF
Disable Function:
NONE

name : xml-nuroa.php
<?
/* XML PARA TROVIT */

ini_set("memory_limit","256M");
ini_set("max_execution_time",0);


function url($datos,$base=null){
	
	if($base != null)
		$url = "/$base/";
	else
		$url = '/';
		
	$temp = array();
	
	if($datos['localidad'])
		$temp[] = format_url($datos['localidad']);
	if($datos['tipologia'])
		$temp[] = format_url($datos['tipologia']);
	if($datos['zona'])
		$temp[] = format_url("zona-".$datos['zona']);
	if($datos['habitaciones'])
		$temp[] = format_url($datos['habitaciones']."-habitaciones");
	if($datos['referencia'] && $datos['id'])
		$temp[] = format_url($datos['referencia']."_".$datos['id']);

	$url .= implode('/',$temp);
	
	return $url;
}

require_once $_SERVER['DOCUMENT_ROOT'].'/requires/sources/__requires.php';



$xml = new DOMDocument('1.0','UTF-8');

	$inmuebles = $xml->createElement('nuroa');
	
 
	$SQL = "SELECT 
					i.*, 
					l.nombre AS localidad, 
					p.nombre AS provincia, 
					z.nombre AS zona,
					t.nombre AS tipologia,
					tv.nombre AS tipo_via
			FROM 
					inmuebles i
			LEFT JOIN 
					poblaciones l ON l.id = i.id_poblacion
			LEFT JOIN 
					provincias p ON p.id = i.id_provincia
			LEFT JOIN 
					zonas z ON z.id = i.id_zona
			LEFT JOIN 
					tipos_inmueble t ON t.id = i.id_tipo_inmueble
			LEFT JOIN 
					tipos_de_via tv ON tv.id = i.id_tipo_via
			LEFT JOIN
					inmuebles_galeria ig ON ig.id_inmueble = i.id
			WHERE
				i.activa = '1' AND i.estado = 'inmueble' AND ig.principal = '1'
				and  i.banco='0'
			";

	$consulta = @mysql_query($SQL);

	 //echo $SQL;
	 //die;
	
	if(mysql_error())
		// echo $SQL;
		echo "Se ha producido un error";

	if(mysql_num_rows($consulta)){

		while($resultado = mysql_fetch_assoc($consulta)){
			$inmueble = $xml->createElement('property');
			
			$id = $xml->createElement('id');
			$id->appendChild($xml->createCDATASection($resultado['referencia'].'_'.$resultado['id']));
			$inmueble->appendChild($id);
			
			$url = $xml->createElement('link');
			$url->appendChild($xml->createCDATASection("http://www.altamira21.com".url($resultado)));
			$inmueble->appendChild($url);


			$pictures = $xml->createElement('pictures');
			$SQLfotos = "
						 SELECT 
							* 
						 FROM 
							inmuebles_galeria
						 WHERE
							id_inmueble = '{$resultado['id']}'
						 AND 
							tipo = 'imagen'
						ORDER BY
							principal DESC, orden ASC
						 ";
						 
			$consulta2 = @mysql_query($SQLfotos);
			
			if(mysql_error()){
				// echo $SQL;
				echo "Se ha producido un error";
				die;
			}
			if(mysql_num_rows($consulta2)){
			
				while($resultado2 = mysql_fetch_assoc($consulta2)){
						$picture = $xml->createElement('picture');
							$picture_url = $xml->createElement('picture_url');
							$picture_url->appendChild($xml->createCDATASection($resultado2['url']));
							$picture->appendChild($picture_url);
							
							$picture_title = $xml->createElement('picture_title');
							$picture_title->appendChild($xml->createCDATASection($resultado2['descripcion']));
							$picture->appendChild($picture_title);
						$pictures->appendChild($picture);
				}
			}
			$inmueble->appendChild($pictures);


			$agency = $xml->createElement('agency');
			$agency->appendChild($xml->createCDATASection('altamira21'));
			$inmueble->appendChild($agency);


			$agency_address = $xml->createElement('agency_address');
			$agency_address->appendChild($xml->createCDATASection(' C/ Julián Ceballos 15 entlo. 6 - 39300 Torrelavega (Cantabria)'));
			$inmueble->appendChild($agency_address);


			$type = $xml->createElement('ad_type');
			if(strpos('Alquiler',$resultado['gestion']) !== FALSE)
				$type->appendChild($xml->createCDATASection("For Rent"));
			elseif($resultado['gestion'] == 'Traspaso')
					$type->appendChild($xml->createCDATASection("Transfer Local"));
				else
					$type->appendChild($xml->createCDATASection("For Sale"));
			
			$inmueble->appendChild($type);


			if($resultado['gestion'] != 'Traspaso'){
				$type = $xml->createElement('category');
				$type->appendChild($xml->createCDATASection($resultado['tipologia']));
				$inmueble->appendChild($type);
			}


			$title = $xml->createElement('title');
			$title->appendChild($xml->createCDATASection("{$resultado['tipologia']} en {$resultado['localidad']}"));
			$inmueble->appendChild($title);
			
			
			
			$descripcion = $xml->createElement('description');
			
			$content = strip_tags(trim($resultado['descripcion']));
			
			$content = str_replace( array('vacacional','VACACIONAL','Vacacional'),array('en vacaciones','EN VACACIONES','Vacaciones'),$content);
			$content = str_replace( array('naves industriales','NAVES INDUSTRIALES', 'Naves industriales'),array('naves','NAVES', 'Naves'),$content);
			
			$content = str_replace( array('se vende','SE VENDE'),array('',''),$content);
			$content = str_replace( array('naves en alquiler','NAVES EN ALQUILER','Naves en alquiler'),array('naves','NAVES','Naves'),$content);
			$content = str_replace( array('negocio rentable','NEGOCIO RENTABLE', 'Negocio rentable'),array('negocio','NEGOCIO','Negocio'),$content);

			
			$palabrasCadena = explode(" ",$content); // Separamos la cadena por los espacios

			$contenido="";
			foreach($palabrasCadena as $valor){

				if(strlen($valor)<42){
					$contenido.=" ";
					$contenido.=$valor;	
				}
			}
			
			if($contenido != ''){
				if(strlen($contenido) < 30 )
					$descripcion->appendChild($xml->createCDATASection("$contenido. {$resultado['tipologia']} en {$resultado['localidad']} de {$resultado['superficie_construida']} m2, {$resultado['habitaciones']} habitacion/es, {$resultado['banos']} baño/s."));
				else
				$descripcion->appendChild($xml->createCDATASection($contenido));
			}
			else
				$descripcion->appendChild($xml->createCDATASection("{$resultado['tipologia']} en {$resultado['localidad']} de {$resultado['superficie_construida']} m2, {$resultado['habitaciones']} habitacion/es, {$resultado['banos']} baño/s."));
			
			$inmueble->appendChild($descripcion);


			if($resultado['habitaciones'] > 0){
				$rooms = $xml->createElement('rooms');
				$rooms->appendChild($xml->createCDATASection($resultado['habitaciones']));
				$inmueble->appendChild($rooms);
			}

			if($resultado['banos'] > 0 && $resultado['banos'] <= 20){
				$bathrooms = $xml->createElement('bathrooms');
				$bathrooms->appendChild($xml->createCDATASection($resultado['banos']));
				$inmueble->appendChild($bathrooms);
			}


			if($resultado['superficie_construida'] >=  15 && $resultado['superficie_construida'] <=  50000){
				$floor_number = $xml->createElement('floor_number');
				$floor_number->appendChild($xml->createCDATASection($resultado['superficie_construida']));
				$inmueble->appendChild($floor_number)->setAttribute("unit", "meters");
			}
			


			
			if($resultado['precio_venta'] >=  10000 && $resultado['precio_venta'] <=  100000000){
				
				$price = $xml->createElement('price');
				$price->appendChild($xml->createCDATASection($resultado['precio_venta']));
				
				if($resultado['gestion'] == 'Alquiler')
					$inmueble->appendChild($price)->setAttribute("period", "monthly");
				else
					$inmueble->appendChild($price);
			
			}
			
			
			$localidad = $xml->createElement('city');
			$localidad->appendChild($xml->createCDATASection($resultado['localidad']));
			$inmueble->appendChild($localidad);
			

			$country = $xml->createElement('country');
			$country->appendChild($xml->createCDATASection("España"));
			$inmueble->appendChild($country);


			$area = $xml->createElement('location');
			$area->appendChild($xml->createCDATASection($resultado['zona']));
			$inmueble->appendChild($area);
			

			
			if(strlen($resultado['cp'])==5){
				$postcode = $xml->createElement('postcode');
				$postcode->appendChild($xml->createCDATASection($resultado['cp']));
				$inmueble->appendChild($postcode);
			}
				
			
			
			
			if($resultado['latitud'] >= -90 && $resultado['latitud'] <= 90 && $resultado['longitud'] >= -180 && $resultado['longitud'] <= 180){
			
				$latitude = $xml->createElement('latitude');
				$latitude->appendChild($xml->createCDATASection($resultado['latitud']));
				$inmueble->appendChild($latitude);
				
				$longitude = $xml->createElement('longitude');
				$longitude->appendChild($xml->createCDATASection($resultado['longitud']));
				$inmueble->appendChild($longitude);
			}
			
			$date = $xml->createElement('insertion_date');
			$date->appendChild($xml->createCDATASection($resultado['fecha_captacion']));
			$inmueble->appendChild($date);
			
			
			
			$inmuebles->appendChild($inmueble);
		}

	}
	
	$xml->appendChild($inmuebles);




$xml->save('nuroa-altamira21.xml');
//formatXml('nuroa-altamira21.xml');

function formatXml($archivoXml) {
    $doc = new DOMDocument();
    $doc->preserveWhiteSpace = false;
    $doc->formatOutput = true;
    $doc->load($archivoXml);
    $doc->save($archivoXml);
}
?>
© 2026 GrazzMean