$name,
'type' => $type,
'tmp_name' => $tmp_name,
'error' => 0,
'size' => $size
);
//the actual image processing, that is, move to upload directory, generate thumbnails and image sizes and writing into the database happens here
$mhs = media_handle_sideload($array, $id);
// store thr processing result/details into an array
$results = array('file' => $array, 'id' => $mhs);
@unlink($tmp_name);
return $results;
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* Variables
* ----------------------------------------------------------------------------------------------------------------------
*/
$MLSID = 0;
$mlsid_listing = array();
$property_id = 0;
$error = 0;
$wp_plugin_aem_params = wp_plugin_aem_params();
/**
* ----------------------------------------------------------------------------------------------------------------------
* Process >> Get Property
* ----------------------------------------------------------------------------------------------------------------------
*/
// check if
if(isset($_GET['mlsid']) && !empty($_GET['mlsid']) && !isset($_POST['action'])) {
$MLSID = $_GET['mlsid'];
// set & parse the xml
$xml_query_url = "property?mlsid=".$MLSID;
$xml_url = $wp_plugin_aem_params['plugin_aem_option_xml_parser'].urlencode($xml_query_url.'&apikey='.$wp_plugin_aem_params['plugin_aem_option_api_key']);
// open the xml url
if ($f = @fopen($xml_url, 'r')) {
$xml = '';
while (!feof($f)) {
$xml .= fgets($f, 4096);
}
fclose($f);
$arr = xml2array($xml);
//print_r($arr);
if (sizeof($arr) == 1 && $arr["Listing"]){
if (array_key_exists("MLS", $arr["Listing"])) {
$mlsid_listing = $arr["Listing"];
} else {
$mlsid_listing = $arr["Listing"];
}
echo '
';
echo 'Property details successfully retrieved. Click the \'Add Property\' button to save the property details.';
echo '
';
} else {
echo '
';
echo 'Failed retrieving property details. MLSID doesn\'t exists';
echo '
';
}
}
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* Process >> Add Property
* ----------------------------------------------------------------------------------------------------------------------
*/
if($_POST['action'] == 'insert') {
$error = 0;
// check if MLS is set
if(!isset($_POST['Listing']['MLS']['value']) || empty($_POST['Listing']['MLS']['value']) || $_POST['Listing']['MLS']['value'] <= 0) {
//$error++;
}
// check if Address is set
if(!isset($_POST['Listing']['Address']['value']) || empty($_POST['Listing']['Address']['value'])) {
$error++;
}
// check if no duplicate on the database
$add_mlsid_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table." WHERE MLS = '".$_POST['Listing']['MLS']['value']."' AND address = '".$_POST['Listing']['address']['value']."' LIMIT 1", ARRAY_A);
if(count($add_mlsid_listings) > 0) { $error++; }
//check if no error
if(error == 0) {
$_POST_Listing = $_POST['Listing'];
$_POST_Listing['Description']['value'] = $_POST['content'];
$POST_Listing = base64_encode(serialize($_POST_Listing));
#echo "
"; print_r($_POST_Listing); echo "
"; exit(); // for testing
if($POST_Listing == '') {
$error++;
}
if(!isset($_POST['Listing']['Address']['value']) || empty($_POST['Listing']['Address']['value'])) {
$error++;
}
if($error == 0) {
$sql = "INSERT INTO ".AEM_PLUGIN_DB_Table." (
MLS,
Title,
URL,
DefaultImageURL,
DefaultThumbnailURL,
PropertyType,
Address,
Bedrooms,
Bathrooms,
ListingPrice,
ListingDate,
SellingPrice,
SoldDate,
Description,
Status,
ListingAgent,
ListingOffice,
Represented,
Comment,
full_property_details,
date_updated,
date_added
) VALUES(
'".aem_clean($_POST['Listing']['MLS']['value'])."',
'".aem_clean($_POST['Listing']['Title']['value'])."',
'".aem_clean($_POST['Listing']['URL']['value'])."',
'".aem_clean($_POST['Listing']['Photos']['Photo'][0]['URL']['value'])."',
'".aem_clean($_POST['Listing']['Photos']['Photo'][0]['ThumbnailURL']['value'])."',
'".aem_clean($_POST['Listing']['PropertyType']['value'])."',
'".aem_clean($_POST['Listing']['Address']['value'])."',
'".aem_clean($_POST['Listing']['Bedrooms']['value'])."',
'".aem_clean($_POST['Listing']['Bathrooms']['value'])."',
'".aem_clean($_POST['Listing']['ListingPrice']['value'])."',
'".aem_clean($_POST['Listing']['ListingDate']['value'])."',
'".aem_clean($_POST['Listing']['SellingPrice']['value'])."',
'".aem_clean($_POST['Listing']['SoldDate']['value'])."',
'".aem_clean($_POST['content'])."',
'".aem_clean($_POST['Listing']['Status']['value'])."',
'".aem_clean($_POST['Listing']['ListingAgent']['value'])."',
'".aem_clean($_POST['Listing']['ListingOffice']['value'])."',
'".aem_clean($_POST['Listing']['Represented']['value'])."',
'".aem_clean($_POST['Listing']['Comment']['value'])."',
'".$POST_Listing."',
CURDATE(),
CURDATE()
)";
$wpdb->query($sql);
$property_id = $wpdb->insert_id;
if($property_id > 0) {
$photo_updated = 0;
$POST['Listing']['Photos']['Photo'] = array();
if(count($_POST['Listing']['Photos']['Photo']) > 0) {
foreach($_POST['Listing']['Photos']['Photo'] as $key => $val) {
$image = $_POST['Listing']['Photos']['Photo'][$key]['URL']['value'];
if($image != AEM_PLUGIN_URL."/images/no_image_available.jpg") {
if(@fopen($image,'r') !== false) {
// upload into wp media library
$add_to_wpml_result = add_xml_image_to_wp_media_ibrary($image, $id);
#echo '
'; echo '
'; print_r($add_to_wpml_result); echo '
';
// check if added into wp media library
if(is_int($add_to_wpml_result['id'])) {
if($add_to_wpml_result['id'] > 0) {
#echo '
Image added into WP Media Library.
';
// get image
@list( $img_src, $width, $height ) = image_downsize($add_to_wpml_result['id'], 'full');
if(@fopen($img_src,'r') !== false) {
$image = $img_src; // update the value of the image url
$photo_updated++;
#echo '
Image retrived from WP Media Library. ('.$image.')
';
} else {
#echo '
Failed getting Image URL from WP Media Library.
';
}
} else {
#echo '
Failed adding image into WP Media Library.
';
}
} else {
#echo '
Failed adding image into WP Media Library.
';
}
} else {
#echo '
Image doesn\'t exists.
';
}
} else {
//echo '
Image is ignore.
';
}
// update the property photos array ....
$POST['Listing']['Photos']['Photo'][] = array('URL' => array('value' => $image), 'ThumbnailURL' => array('value' => $image));
} // end foreach
} // end if
if($photo_updated > 0) {
#echo '
Updating Property Protos...
';
// update the property db table record ....
$_POST_Listing['Photos']['Photo'] = $POST['Listing']['Photos']['Photo']; // updated property photos
$POST_Listing = base64_encode(serialize($_POST_Listing)); // updated full_property_details
$update = $wpdb->query("UPDATE ".AEM_PLUGIN_DB_Table." SET
DefaultImageURL = '".aem_clean($_POST_Listing['Photos']['Photo'][0]['URL']['value'])."',
DefaultThumbnailURL = '".aem_clean($_POST_Listing['Photos']['Photo'][0]['ThumbnailURL']['value'])."',
full_property_details = '".$POST_Listing."'
WHERE id = '".aem_clean($property_id)."'
LIMIT 1");
#echo '
Property Protos Updated.
';
} else {
#echo '
Property Protos Not Updated.
';
}
} else {
#echo '
Failed Adding Property.
';
}
// for testing/checking only
#echo '
'; print_r($_POST); echo '
';
#echo 'SQL: '.$sql.', MEMBER ID: '.$agents_id;
}
}
if($property_id > 0) {
echo '
';
echo 'Property Successfully Added.';
echo '
';
} else {
$add_mlsid_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table."
WHERE MLS = '".$_POST['Listing']['MLS']['value']."'
AND Address = '".$_POST['Listing']['Address']['value']."'
LIMIT 1", ARRAY_A);
if(count($add_mlsid_listings) > 0) {
echo '
';
}
echo '
';
echo 'Failed Adding Property.';
echo '
';
}
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* Set Form fields & the property details
* ----------------------------------------------------------------------------------------------------------------------
*/
if($mlsid_listing['Represented']['value'] == "") {
$tmp_ml['Represented']['value'] = "Both";
} else {
$tmp_ml['Represented']['value'] = $mlsid_listing['Represented']['value'];
}
$tmp_ml['MLS']['value'] = $mlsid_listing['MLS']['value'];
$tmp_ml['Title']['value'] = $mlsid_listing['Title']['value'];
$tmp_ml['Address']['value'] = $mlsid_listing['Address']['value'];
$tmp_ml['Bedrooms']['value'] = $mlsid_listing['Bedrooms']['value'];
$tmp_ml['Bathrooms']['value'] = $mlsid_listing['Bathrooms']['value'];
$tmp_ml['PropertyType']['value'] = $mlsid_listing['PropertyType']['value'];
$tmp_ml['Neighborhood']['value'] = $mlsid_listing['Neighborhood']['value'];
$tmp_ml['Description']['value'] = $mlsid_listing['Description']['value'];
$tmp_ml['ListingPrice']['value'] = $mlsid_listing['ListingPrice']['value'];
$tmp_ml['SellingPrice']['value'] = $mlsid_listing['SellingPrice']['value'];
$tmp_ml['SoldDate']['value'] = $mlsid_listing['SoldDate']['value'];
$tmp_ml['ListingAgent']['value'] = $mlsid_listing['ListingAgent']['value'];
$tmp_ml['ListingOffice']['value'] = $mlsid_listing['ListingOffice']['value'];
$tmp_ml['Status']['value'] = $mlsid_listing['Status']['value'];
$tmp_ml['PrimaryDetails']['CrossStreet']['value'] = $mlsid_listing['PrimaryDetails']['CrossStreet']['value'];
$tmp_ml['PrimaryDetails']['ApproximateSqFt']['value'] = $mlsid_listing['PrimaryDetails']['ApproximateSqFt']['value'];
$tmp_ml['PrimaryDetails']['PricePerSqFt']['value'] = $mlsid_listing['PrimaryDetails']['PricePerSqFt']['value'];
$tmp_ml['PrimaryDetails']['YearBuilt']['value'] = $mlsid_listing['PrimaryDetails']['YearBuilt']['value'];
$tmp_ml['PrimaryDetails']['TotalRooms']['value'] = $mlsid_listing['PrimaryDetails']['TotalRooms']['value'];
$tmp_ml['PrimaryDetails']['HOADues']['value'] = $mlsid_listing['PrimaryDetails']['HOADues']['value'];
$tmp_ml['AdditionalDetails']['Parking']['value'] = $mlsid_listing['AdditionalDetails']['Parking']['value'];
$tmp_ml['AdditionalDetails']['Type']['value'] = $mlsid_listing['AdditionalDetails']['Type']['value'];
$tmp_ml['AdditionalDetails']['Style']['value'] = $mlsid_listing['AdditionalDetails']['Style']['value'];
$tmp_ml['AdditionalDetails']['Floors']['value'] = $mlsid_listing['AdditionalDetails']['Floors']['value'];
$tmp_ml['AdditionalDetails']['BathTypeIncludes']['value'] = $mlsid_listing['AdditionalDetails']['BathTypeIncludes']['value'];
$tmp_ml['AdditionalDetails']['Kitchen']['value'] = $mlsid_listing['AdditionalDetails']['Kitchen']['value'];
$tmp_ml['AdditionalDetails']['DiningRoom']['value'] = $mlsid_listing['AdditionalDetails']['DiningRoom']['value'];
$tmp_ml['AdditionalDetails']['LivingRoom']['value'] = $mlsid_listing['AdditionalDetails']['LivingRoom']['value'];
$tmp_ml['AdditionalDetails']['HeatingCoolingSystem']['value']= $mlsid_listing['AdditionalDetails']['HeatingCoolingSystem']['value'];
$tmp_ml['AdditionalDetails']['LaundryAppliances']['value'] = $mlsid_listing['AdditionalDetails']['LaundryAppliances']['value'];
$tmp_ml['AdditionalDetails']['SpecialFeatures']['value'] = $mlsid_listing['AdditionalDetails']['SpecialFeatures']['value'];
$tmp_ml['AdditionalDetails']['CommonAreas']['value'] = $mlsid_listing['AdditionalDetails']['CommonAreas']['value'];
$tmp_ml['AdditionalDetails']['Transportation']['value'] = $mlsid_listing['AdditionalDetails']['Transportation']['value'];
$tmp_ml['AdditionalDetails']['Shopping']['value'] = $mlsid_listing['AdditionalDetails']['Shopping']['value'];
$tmp_ml['Comment']['value'] = $mlsid_listing['Comment']['value'];
$tmp_ml['Photos'] = $mlsid_listing['Photos'];
if( ($mlsid_listing['Photos']['Photo'][0]['URL']['value'] == "") || ($mlsid_listing['Photos']['Photo'][0]['URL']['value'] == AEM_PLUGIN_URL."/images/no_image_available.jpg") ) {
$tmp_ml['Photos']['Photo'][0]['URL']['value'] = AEM_PLUGIN_URL."/images/no_image_available.jpg";
}
if( ($mlsid_listing['Photos']['Photo'][0]['ThumbnailURL']['value'] == "") || ($mlsid_listing['Photos']['Photo'][0]['ThumbnailURL']['value'] == AEM_PLUGIN_URL."/images/no_image_available.jpg") ) {
$tmp_ml['Photos']['Photo'][0]['ThumbnailURL']['value'] = AEM_PLUGIN_URL."/images/no_image_available.jpg";
}
$mlsid_listing = array();
$mlsid_listing = $tmp_ml;
?>
0) { /* nothing to do... */ } else { ?>
|
Property Details:
|
|
0 && $property_id <= 0) { ?>
0) { ?>
|