The auto image renaming system standardizes property image filenames using a consistent pattern based on property address, city, MLS ID, and image index before uploading to AWS S3 storage.
// Bridge API Naming (RETS 1.9+)
if ($is_bridge_api) {
// Street Number combine with Unit Number if exist
$street_number = $this->_data['StreetNumber'];
if (!empty($this->_data['StreetDirPrefix'])) {
$street_number = $street_number . ' ' . $this->_data['StreetDirPrefix'];
}
if (!empty($this->_data['UnitNumber'])) {
$street_number = $this->_data['UnitNumber'] . ' ' . $street_number;
}
// Generate standardized image name
$image_name = sprintf('%s-%s-%s-%s',
$street_number . ' ' . $this->_data['StreetName'] . ' ' . $this->_data['StreetSuffix'],
$this->_data['City'],
$this->_data['ListingId'],
$key // Image index
);
} else {
// Legacy RETS Naming
$image_name = sprintf('%s-%s-%s-%s',
$this->_data['L_Address'],
$this->_data['L_City'],
$this->_data['L_DisplayId'],
$key
);
}
// Sanitize for URL-safe filename
$image_name = sanitize_title($image_name);
function cu_esh_phrets_import_images_by_post_id($post_id) {
// Uses WordPress meta fields for naming
$image_name = sprintf('%s-%s-%s-%s',
get_post_meta($post_id, 'fave_address', true),
houzez_taxonomy_simple_2('property_city', $post_id),
get_post_meta($post_id, 'fave_mls_no', true),
$key
);
$image_name = sanitize_title($image_name);
}
$objects = $esh_rets_connected->GetObject(
$field->resource,
$field->object_type,
$value,
'*',
$use_obj_loc
);
Retrieves property images from RETS server using configured object location settings.
foreach ($objects as $key => $object) {
$objContentType = $object->getContentType();
$objLocation = $object->getLocation();
$objContent = $object->getContent();
// Generate standardized name
$image_name = sprintf(...);
$image_name = sanitize_title($image_name);
}
Creates consistent filename using property data and image index.
// Sanitize URL and validate
$sanitized_url = str_replace("\0", '', $aws_img_content);
if (filter_var($sanitized_url, FILTER_VALIDATE_URL)) {
$image_content = file_get_contents($sanitized_url);
if ($image_content !== false) {
$data_array['Body'] = $image_content;
}
}
Validates image URLs and downloads content for S3 upload.
$data_array = [
'Bucket' => 'property-mls-images',
'Key' => $image_name, // <- Renamed image key
'ContentType' => $objContentType,
'Body' => $image_content,
'ACL' => 'public-read',
];
$result = $s3->putObject($data_array);
$images[] = $result['ObjectURL'];
Uploads to S3 with the generated filename as the object key.
| Component | RETS Fields | Processing |
|---|---|---|
| Address |
UnitNumber StreetNumber StreetDirPrefix StreetName StreetSuffix |
Concatenated with spaces |
| City | City | Direct mapping |
| MLS ID | ListingId | Direct mapping |
| Index | $key (loop counter) | Sequential: 0, 1, 2, ... |
| Component | RETS Fields | Processing |
|---|---|---|
| Address | L_Address | Direct mapping |
| City | L_City | Direct mapping |
| MLS ID | L_DisplayId | Direct mapping |
| Index | $key (loop counter) | Sequential: 0, 1, 2, ... |
Used as S3 object key
Used as S3 object key
// Remove null bytes and validate
$sanitized_url = str_replace("\0", '', $aws_img_content);
if (filter_var($sanitized_url, FILTER_VALIDATE_URL)) {
try {
$image_content = file_get_contents($sanitized_url);
if ($image_content !== false) {
$data_array['Body'] = $image_content;
} else {
// Log failed download
$this->log_debug('Failed to get contents from URL');
$failed_upload++;
continue;
}
} catch (Exception $e) {
// Handle exceptions
$this->log_debug('Exception: ' . $e->getMessage());
$failed_upload++;
continue;
}
}
// Validate image content
$im = imagecreatefromstring($aws_img_content);
if ($im === false) {
// Skip invalid images
continue;
}
// Rate limiting to avoid server issues
sleep(2); // 2 second delay between downloads
// Track failed uploads for retry
if ($failed_upload > 0) {
$this->save_post_failed_upload($post_id, $schedule_id, $mode);
}
function esh_phrets_import_images_from_queue() {
$queue = get_option('es_phrets_image_queue', []);
foreach ($queue as $post_key => $post_id) {
// Apply same naming logic to queued images
$property = esh_get_property($post_id);
// Process with consistent naming
$image_name = sprintf('%s-%s-%s-%s', ...);
$image_name = sanitize_title($image_name);
}
}