I would like advice on making my code more elegant and straightforward. The code works great, but it lacks these things.
<?php
if(isset($_POST['retrieve_posts'])) {
$post_ret = $_POST['retrieve_posts'];
}
if(isset($_POST['retrieve_images'])) {
$image_ret = $_POST['retrieve_images'];
} else $image_ret = 0;
require_once('classes.php');
require_once('functions.php');
if($post_ret == 1) {
$obj = new kigo();
$obj->url = "https://app.kigo.net/api/ra/v1/listProperties";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(null);
$list = $obj->curlkigo();
$directory = 'uploads';
$list = $list['API_REPLY'];
$c = count($list);
$kigopropid = array();
for($i=0;$i<$c;$i++) {
$kigopropid[] = $list[$i]['PROP_ID'];
$propname[] = $list[$i]['PROP_NAME'];
}
if(namecheck($kigopropid, $directory)!=null) {
$namecheck = namecheck($kigopropid, $directory);
$tau = 0;
foreach ($namecheck as $key => $prop_id) {
$obj = new kigo();
$obj->url = "https://app.kigo.net/api/ra/v1/readProperty";
$obj->user = "bla";
$obj->pass = "bla";
$obj->data = json_encode(array("PROP_ID" => $prop_id));
$obj->curlkigo();
$data = $obj->curlkigo();
//-----------Prop Name
$title = $propname[$tau].'
';
$tau++;
//-----------Adress informations
$strnr = unarr($data, 'PROP_STREETNO');
$addr1 = unarr($data, 'PROP_ADDR1');
$addr2 = unarr($data, 'PROP_ADDR2');
$addr3 = unarr($data, 'PROP_ADDR3');
$aptno = unarr($data, 'PROP_APTNO');
$prop_postcode = unarr($data, 'PROP_POSTCODE');
$prop_city = unarr($data, 'PROP_CITY');
$prop_region = unarr($data, 'PROP_REGION');
$prop_country = unarr($data, 'PROP_COUNTRY');
$prop_lat = unarr($data, 'PROP_LATITUDE');
$prop_long = unarr($data, 'PROP_LONGITUDE');
$prop_axcode = unarr($data, 'PROP_AXSCODE');
$adress = '
<div class="adress">
<h2>Adress</h2>
<ul>
<li>Primary Adress: '.$addr1.'</li>
<li>Secondary adress: '. $addr2.'</li>
<li>Tertiary adress: '.$addr3.'</li>
<li>Street number: '. $strnr.'</li>
<li>Apartment number: '. $aptno.'</li>
<li>Postcode: '. $prop_postcode.'</li>
<li>City: '. $prop_city.'</li>
<li>Country: '. $prop_country.'</li>
<li>Latitude: '. $prop_lat.'</li>
<li>Longitude: '. $prop_long.'</li>
</ul>
</div>
';
//-----------Property descriptions
$name = unarr($data, 'PROP_NAME');
$instant_book = unarr($data, 'PROP_INSTANT_BOOK');
$metadescription = unarr($data, 'PROP_SHORTDESCRIPTION');
$description = unarr($data, 'PROP_DESCRIPTION');
$areadescription = unarr($data, 'PROP_AREADESCRIPTION');
$properties = '
<div class="content">
<h2>'. $name.'</h2>
<p>'.format($description).'</p>
</div>
';
//-----------Property details
$prop_bedrooms = unarr($data, 'PROP_BEDROOMS');
$prop_beds = unarr($data, 'PROP_BEDS');
$prop_baths = unarr($data, 'PROP_BATHROOMS');
$prop_toilets = unarr($data, 'PROP_TOILETS');
$prop_size = unarr($data, 'PROP_SIZE').strtolower(unarr($data, 'PROP_SIZE_UNIT'))."s";
$prop_floor = unarr($data, 'PROP_FLOOR');
$prop_elevator = unarr($data, 'PROP_ELEVATOR');
$details = '
<div class="propdetails">
<h2>Property details</h2>
<ul>
<li>Bedrooms: '.$prop_bedrooms.'</li>
<li>Beds: '. $prop_beds.'</li>
<li>Baths: '.$prop_baths.'</li>
<li>Toilets: '. $prop_toilets.'</li>
<li>Size: '. $prop_size.'</li>
<li>Floor: '. $prop_floor.'</li>
<li>Elevator: '. $prop_elevator.'</li>
</ul>
</div>
';
//-----------Rates
$nightly_rate_from = unarr($data, 'PROP_RATE_NIGHTLY_FROM');
$nightly_rate_to = unarr($data, 'PROP_RATE_NIGHTLY_TO');
$weekly_rate_from = unarr($data, 'PROP_RATE_WEEKLY_FROM');
$weekly_rate_to = unarr($data, 'PROP_RATE_WEEKLY_TO');
$monthly_rate_from = unarr($data, 'PROP_RATE_MONTHLY_FROM');
$monthly_rate_to = unarr($data, 'PROP_RATE_MONTHLY_TO');
$prop_rate_currency = unarr($data, 'PROP_RATE_CURRENCY');
$rates = '
<div class="rates">
<h2>Rates</h2>
<ul>
<li>Nigtly rate from: '.$nightly_rate_from.'</li>
<li>Nightly rate to: '.$nightly_rate_to.'</li>
<li>Weekly rate from: '.$weekly_rate_from.'</li>
<li>Weekly rate to: '.$weekly_rate_to.'</li>
<li>Montly rate from: '.$monthly_rate_from.'</li>
<li>Montly rate to: '.$monthly_rate_to.'</li>
<li>Rate currency: '.$prop_rate_currency.'</li>
</div>
';
//-----------Contact
$prop_phone = unarr($data, 'PROP_PHONE');
if($prop_phone==null) {$prop_phone = " - ";}
$contact = '
<div class="contact">
<h2>Contact</h2>
<p>'.$prop_phone.'</p>
</div>
';
if($image_ret==2) {
//-----------Property Images
$prop_array_img = unarr($data, 'PROP_PHOTOS');
$img_ct = count($prop_array_img);
$year = date('Y'); $month = date('m');
for($i=0;$i<$img_ct;$i++) {
$photo_id = $prop_array_img[$i]['PHOTO_ID'];
$obj = new kigo();
$obj->url = "https://app.kigo.net/api/ra/v1/readPropertyPhotoFile";
$obj->user = 'bla';
$obj->pass = 'bla';
$obj->data = json_encode(array("PROP_ID" => $prop_id, "PHOTO_ID"=>$photo_id));
$img = $obj->curlkigo();
$img = str_replace(' ', '+', $img['API_REPLY']);
$data = base64_decode($img);
$file ="../../uploads/".$year."/".$month."/".uniqid() . '.jpg';
$success = file_put_contents($file, $data);
}
echo "The Images were automatically added in media files!";
}
$final = $title.$adress.$details.$rates.$properties.$contact;
$create = fopen($directory.'/'.$prop_id.'.txt', 'w+');
$put = file_put_contents($directory.'/'.$prop_id.'.txt', $final);
}//end for
}//end if
$filenames = listfiles($directory);
if (file_exists($directory.'/archive.txt')) {
$filenames = array_values(array_diff($filenames, array('archive.txt')));
}
$pathtozipfiles = array();
foreach ($filenames as $value) {
$pathtozipfiles[] = $directory.'/'.$value;
}
$result = create_zip($pathtozipfiles,'articles.zip');
echo $dir;
}//end post
?>