'B1 Light Industrial',
'b2' => 'B2 Heavy Industrial',
'warehouse' => 'Warehouse & Logistics',
'business_park' => 'Business & Science Park',
'office' => 'Commercial Office',
'commercial' => 'Commercial Office',
'retail' => 'Retail & Mall Shop',
'shophouse' => 'Commercial Shophouse',
'food_factory' => 'NEA Food Factory & Central Kitchen',
'land' => 'Industrial Land & Open Yard',
'landed_industrial' => 'Landed Industrial',
'landed' => 'Commercial Landed',
'medical' => 'Medical Suite & Clinic',
'canteen' => 'Industrial Canteen & F&B',
'data_centre' => 'Data Centre & High-Spec Facility'
];
/**
* Renders a semantic HTML list of property listings for search and AI crawlers (GEO).
*/
function renderGeoListingItems($rows, $categoryLabels) {
if (empty($rows) || !is_array($rows)) {
return '';
}
$out = '
';
foreach ($rows as $r) {
$id = !empty($r['id']) ? trim($r['id']) : (!empty($r['ref_id']) ? trim($r['ref_id']) : '');
if ($id === '') continue;
$url = 'https://wukplace.sg/?propId=' . urlencode($id) . '&mode=guest';
$t = !empty($r['title']) ? trim($r['title']) : (!empty($r['building_name']) ? trim($r['building_name']) : 'Commercial Property');
$bldg = !empty($r['building_name']) ? trim($r['building_name']) : '';
$isRent = !(isset($r['type']) && strtolower(trim($r['type'])) === 'sale');
$price = isset($r['price']) ? (float)$r['price'] : 0;
$priceStr = $price > 0 ? ($isRent ? ('SGD $' . number_format($price) . ' /month') : ('SGD $' . number_format($price))) : 'Price on Application';
$area = isset($r['area_sqft']) ? (int)$r['area_sqft'] : 0;
$psf = isset($r['psf']) ? (float)$r['psf'] : (($price > 0 && $area > 0) ? round($price / $area, 2) : 0);
$psfStr = $psf > 0 ? (' ($' . number_format($psf, 2) . ' psf' . ($isRent ? '/mo' : '') . ')') : '';
$catKey = isset($r['category']) ? strtolower(trim($r['category'])) : 'commercial';
$catLabel = isset($categoryLabels[$catKey]) ? $categoryLabels[$catKey] : strtoupper($catKey);
$dist = !empty($r['district']) ? trim($r['district']) : '';
$addr = !empty($r['address']) ? trim($r['address']) : '';
$postal = !empty($r['postal_code']) ? ('Singapore ' . trim($r['postal_code'])) : '';
$cea = !empty($r['agent_cea']) ? trim($r['agent_cea']) : '';
$desc = !empty($r['description']) ? trim($r['description']) : '';
if ( strlen($desc) > 280 ) {
$desc = substr($desc, 0, 277) . '...';
}
$out .= '
';
$out .= '';
$specs = [];
$specs[] = 'Price: ' . htmlspecialchars($priceStr . $psfStr, ENT_QUOTES, 'UTF-8');
if ($area > 0) $specs[] = 'Floor Area: ' . number_format($area) . ' sqft';
if ($bldg !== '') $specs[] = 'Building: ' . htmlspecialchars($bldg, ENT_QUOTES, 'UTF-8');
if ($addr !== '' || $dist !== '' || $postal !== '') {
$locParts = array_filter([$addr, $dist, $postal]);
$specs[] = 'Location: ' . htmlspecialchars(implode(', ', $locParts), ENT_QUOTES, 'UTF-8');
}
if ($cea !== '') $specs[] = 'CEA Salesperson Reg. No.: ' . htmlspecialchars($cea, ENT_QUOTES, 'UTF-8');
$out .= '' . implode(' · ', $specs) . '
';
if ($desc !== '') {
$out .= '' . htmlspecialchars($desc, ENT_QUOTES, 'UTF-8') . '
';
}
$out .= ' ';
}
$out .= '
';
return $out;
}
// Default fallback meta
$metaTitle = 'wukplace.sg — Singapore Commercial & Industrial Property Marketplace';
$metaDescription = 'Discover verified Singapore B1/B2 industrial spaces, warehouses, offices, and commercial properties. Direct licensed CEA agents.';
$metaKeywords = 'Singapore commercial property, industrial property Singapore, B1 industrial space, B2 heavy industrial, warehouse for rent, commercial office lease, shophouse Singapore, CEA real estate agents';
$metaAuthor = 'wukplace.sg';
$metaPublisher = 'wukplace.sg';
$metaRobots = 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1';
$canonicalUrl = 'https://wukplace.sg/';
$ogTitle = $metaTitle;
$ogDescription = $metaDescription;
$ogImage = 'https://wukplace.sg/assets/images/wukplace-cover-1200x630.jpg';
$ogImageAlt = $metaTitle;
$ogUrl = $canonicalUrl;
$ogType = 'website';
$ogPriceAmount = '';
$ogPriceCurrency = 'SGD';
$productPriceAmount = '';
$productPriceCurrency = 'SGD';
$productAvailability = 'instock';
$ogUpdatedTime = '';
$geoRegion = 'SG';
$geoPlacename = 'Singapore';
$geoPosition = '1.3521;103.8198';
$geoIcbm = '1.3521, 103.8198';
$twitterCard = 'summary_large_image';
$twitterSite = '@wukplacesg';
$twitterTitle = $metaTitle;
$twitterDescription = $metaDescription;
$twitterImage = $ogImage;
$twitterImageAlt = $ogImageAlt;
$twitterLabel1 = '';
$twitterData1 = '';
$twitterLabel2 = '';
$twitterData2 = '';
$jsonLdGraph = null;
// ==============================================================================
// Branch A0: Commercial & Industrial Building Directory Main Guest Hub (?view=directory)
// ==============================================================================
if ($viewParam === 'directory' && empty($bldgParam) && empty($propId)) {
$metaTitle = 'Singapore Commercial & Industrial Building Directory (1,000+ Buildings) | Units for Rent & Sale | wukplace.sg';
$metaDescription = 'Explore Singapore\'s most comprehensive commercial and industrial building directory. Browse 1,000+ verified B1/B2 industrial buildings, warehouses, offices, and food factories with units for rent and for sale, MCST strata details, and verified tenant directories.';
$canonicalUrl = 'https://wukplace.sg/?view=directory&mode=guest';
$ogUrl = $canonicalUrl;
$ogTitle = $metaTitle;
$ogDescription = $metaDescription;
$ogImage = 'https://wukplace.sg/assets/images/wukplace-cover-1200x630.jpg';
$ogImageAlt = 'Singapore Commercial & Industrial Building Directory - wukplace.sg';
$twitterTitle = $metaTitle;
$twitterDescription = $metaDescription;
$twitterImage = $ogImage;
$twitterImageAlt = $ogImageAlt;
$twitterLabel1 = 'Directory Database';
$twitterData1 = '1,000+ Verified Buildings';
$twitterLabel2 = 'Units Available';
$twitterData2 = 'For Rent & For Sale';
$metaKeywords = implode(', ', [
'Singapore commercial building directory',
'industrial buildings Singapore',
'commercial buildings with units for rent',
'industrial buildings with units for sale',
'B1 industrial units for rent',
'B2 industrial factory for sale',
'Singapore warehouse directory',
'food factory for rent Singapore',
'MCST building directory Singapore',
'Singapore commercial real estate'
]);
$geoRegion = 'SG';
$geoPlacename = 'Singapore';
$geoPosition = '1.3521;103.8198';
$geoIcbm = '1.3521, 103.8198';
$jsonLdGraph = [
"@context" => "https://schema.org",
"@graph" => [
[
"@type" => "CollectionPage",
"@id" => $canonicalUrl . "#directory",
"url" => $canonicalUrl,
"name" => "Singapore Commercial & Industrial Building Directory",
"description" => $metaDescription,
"isPartOf" => [
"@type" => "WebSite",
"@id" => "https://wukplace.sg/#website",
"url" => "https://wukplace.sg/",
"name" => "wukplace.sg"
]
],
[
"@type" => "BreadcrumbList",
"itemListElement" => [
[
"@type" => "ListItem",
"position" => 1,
"name" => "Home",
"item" => "https://wukplace.sg/"
],
[
"@type" => "ListItem",
"position" => 2,
"name" => "Building Directory",
"item" => $canonicalUrl
]
]
]
]
];
$ssrResultsHeading = 'SINGAPORE COMMERCIAL & INDUSTRIAL BUILDING & MCST DIRECTORY';
$dirHtml = 'Singapore Commercial & Industrial Building, Street & MCST Directory ';
$dirHtml .= '' . htmlspecialchars($metaDescription, ENT_QUOTES, 'UTF-8') . '
';
$dirCh = curl_init();
curl_setopt_array($dirCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/building_directory?select=slug,building_name,street_name,address,district,district_name,zoning,postal_code,mcst_number,mcst_management_name,mcst_management_contact,nearest_mrt,top_year,tenure&order=district.asc,building_name.asc&limit=1000',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 6,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
'Range: 0-999',
],
]);
$dirRes = curl_exec($dirCh);
curl_close($dirCh);
if (!empty($dirRes)) {
$dirRows = json_decode($dirRes, true);
if (is_array($dirRows) && count($dirRows) > 0) {
$ssrResultsHeading = count($dirRows) . ' VERIFIED COMMERCIAL & INDUSTRIAL BUILDINGS & MCST RECORDS';
$dirHtml .= '';
foreach ($dirRows as $bRow) {
$bSlug = !empty($bRow['slug']) ? trim($bRow['slug']) : '';
$bName = !empty($bRow['building_name']) ? trim($bRow['building_name']) : $bSlug;
if ($bSlug === '' && $bName === '') continue;
$bLink = 'https://wukplace.sg/?building=' . urlencode($bSlug ?: $bName) . '&mode=guest';
$bStreet = !empty($bRow['street_name']) ? trim($bRow['street_name']) : '';
$bAddr = !empty($bRow['address']) ? trim($bRow['address']) : $bStreet;
$bMcst = '';
if (!empty($bRow['mcst_number']) && stripos($bRow['mcst_number'], 'not available') === false) {
$rawM = trim($bRow['mcst_number']);
$bMcst = (stripos($rawM, 'mcst') === 0) ? $rawM : ('MCST ' . $rawM);
if (!empty($bRow['mcst_management_name']) && stripos($bRow['mcst_management_name'], 'not available') === false) {
$bMcst .= ' (' . trim($bRow['mcst_management_name']) . ')';
}
if (!empty($bRow['mcst_management_contact']) && stripos($bRow['mcst_management_contact'], 'not available') === false) {
$bMcst .= ' Tel/Contact: ' . trim($bRow['mcst_management_contact']);
}
}
$bMeta = array_filter([
$bAddr !== '' ? ('Address: ' . $bAddr) : '',
($bStreet !== '' && stripos($bAddr, $bStreet) === false) ? ('Street: ' . $bStreet) : '',
!empty($bRow['postal_code']) ? ('Singapore ' . trim($bRow['postal_code'])) : '',
!empty($bRow['district']) ? (trim($bRow['district']) . (!empty($bRow['district_name']) ? (' ' . trim($bRow['district_name'])) : '')) : '',
!empty($bRow['zoning']) ? strtoupper(trim($bRow['zoning'])) : '',
$bMcst,
!empty($bRow['tenure']) ? trim($bRow['tenure']) : '',
!empty($bRow['top_year']) ? ('TOP ' . trim($bRow['top_year'])) : '',
!empty($bRow['nearest_mrt']) ? ('MRT: ' . trim($bRow['nearest_mrt'])) : ''
]);
$dirHtml .= '' . htmlspecialchars($bName, ENT_QUOTES, 'UTF-8') . ' ' . (!empty($bMeta) ? (' — ' . htmlspecialchars(implode(' · ', $bMeta), ENT_QUOTES, 'UTF-8')) : '') . ' ';
}
$dirHtml .= ' ';
}
}
$dirHtml .= ' ';
$ssrBodyHtml = $dirHtml;
} elseif (($viewParam === 'resources' || $viewParam === 'external-resources') && empty($bldgParam) && empty($propId)) {
// ==============================================================================
// Branch A0b: Singapore Commercial & Industrial Statutory Boards & Agency Resources Hub (?view=resources)
// ==============================================================================
$metaTitle = 'Singapore Statutory Boards & Regulatory Resources (BCA, URA, JTC, SLA, SP Services) | wukplace.sg';
$metaDescription = 'Essential Singapore commercial and industrial government resources, statutory board guidelines, e-services, zoning maps, BCA CORENET, SLA Land Betterment Charge, JTC industrial lease rules, and utility connections.';
$canonicalUrl = 'https://wukplace.sg/?view=resources&mode=guest';
$ogUrl = $canonicalUrl;
$ogTitle = $metaTitle;
$ogDescription = $metaDescription;
$ogImage = 'https://wukplace.sg/assets/images/wukplace-cover-1200x630.jpg';
$ogImageAlt = 'Singapore Statutory Boards & Agency Resources - wukplace.sg';
$twitterTitle = $metaTitle;
$twitterDescription = $metaDescription;
$twitterImage = $ogImage;
$twitterImageAlt = $ogImageAlt;
$twitterLabel1 = 'Government & Statutory Portals';
$twitterData1 = 'BCA, URA, JTC, SLA, NEA, SCDF, IRAS';
$twitterLabel2 = 'Utilities & Logistics';
$twitterData2 = 'SP Services, SingPost, Land Betterment';
$metaKeywords = implode(', ', [
'Singapore statutory boards',
'BCA CORENET e-submission',
'URA Master Plan zoning Singapore',
'JTC industrial land lease guidelines',
'SLA Land Betterment Charge',
'NEA commercial pollution control',
'SCDF fire safety industrial compliance',
'IRAS property stamp duty buyer',
'SP Services electricity turn-on commercial',
'Singapore commercial property regulations'
]);
$geoRegion = 'SG';
$geoPlacename = 'Singapore';
$geoPosition = '1.3521;103.8198';
$geoIcbm = '1.3521, 103.8198';
$jsonLdGraph = [
"@context" => "https://schema.org",
"@graph" => [
[
"@type" => "CollectionPage",
"@id" => $canonicalUrl . "#resources",
"url" => $canonicalUrl,
"name" => "Singapore Statutory Boards & Regulatory Resources",
"description" => $metaDescription,
"isPartOf" => [
"@type" => "WebSite",
"@id" => "https://wukplace.sg/#website",
"url" => "https://wukplace.sg/",
"name" => "wukplace.sg"
]
],
[
"@type" => "BreadcrumbList",
"itemListElement" => [
[
"@type" => "ListItem",
"position" => 1,
"name" => "Home",
"item" => "https://wukplace.sg/"
],
[
"@type" => "ListItem",
"position" => 2,
"name" => "External Resources",
"item" => $canonicalUrl
]
]
]
]
];
$ssrResultsHeading = 'SINGAPORE STATUTORY BOARDS & REGULATORY RESOURCES';
$ssrBodyHtml = ''
. 'Singapore Commercial & Industrial Statutory Boards & Regulatory Guide '
. '' . htmlspecialchars($metaDescription, ENT_QUOTES, 'UTF-8') . '
'
. ''
. 'Urban Redevelopment Authority (URA): Master Plan zoning (B1, B2, Business Park, Commercial), Change of Use approvals, and 60:40 industrial ancillary quantum rules. '
. 'JTC Corporation (JTC): Industrial land and factory allocation, subletting and assignment guidelines, and anchor tenant criteria. '
. 'Building and Construction Authority (BCA): Structural plans, CORENET e-Submission, Temporary Occupation Permit (TOP), and Certificate of Statutory Completion (CSC). '
. 'Singapore Land Authority (SLA): State land leases, Land Betterment Charge (LBC), and strata title registry (INLIS). '
. 'National Environment Agency (NEA): Industrial siting consultation, pollution control, and central kitchen / food processing licensing. '
. 'Singapore Civil Defence Force (SCDF): Fire Safety Certificate (FSC), Fire Hazard Permit, and industrial storage regulations. '
. 'Inland Revenue Authority of Singapore (IRAS): Buyer\'s Stamp Duty (BSD), Seller\'s Stamp Duty (SSD) for industrial property, GST on commercial leases, and property tax. '
. 'Council for Estate Agencies (CEA): Public Register of licensed real estate agencies and salespersons in Singapore. '
. 'SP Services: Commercial and high-tension industrial electricity and water account activation. '
. ' ';
} elseif (!empty($catParam) && empty($bldgParam) && empty($propId)) {
// ==============================================================================
// Branch A0c: Programmatic Category Hub (?category=b1, b2, office, shophouse, etc.)
// ==============================================================================
$catDisplay = isset($categoryLabels[$catParam]) ? $categoryLabels[$catParam] : strtoupper($catParam);
$canonicalUrl = 'https://wukplace.sg/?category=' . urlencode($catParam) . '&mode=guest';
$ogUrl = $canonicalUrl;
$catFilterMap = [
'b1' => 'category=eq.b1',
'b2' => 'category=eq.b2',
'warehouse' => 'category=in.(warehouse,b1,b2)',
'business_park' => 'category=eq.business_park',
'office' => 'category=in.(office,commercial)',
'commercial' => 'category=in.(office,commercial)',
'retail' => 'category=in.(retail,shophouse)',
'shophouse' => 'category=eq.shophouse',
'food_factory' => 'category=eq.food_factory',
'land' => 'category=in.(land,landed_industrial,landed)',
];
$catFilter = isset($catFilterMap[$catParam]) ? $catFilterMap[$catParam] : ('category=eq.' . urlencode($catParam));
$catListings = [];
$catCh = curl_init();
curl_setopt_array($catCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/property_listings?status=eq.active&' . $catFilter . '&select=id,ref_id,title,building_name,category,type,price,psf,area_sqft,district,address,postal_code,agent_cea,description,updated_at&order=updated_at.desc&limit=50',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 4,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$catRes = curl_exec($catCh);
curl_close($catCh);
if (!empty($catRes)) {
$decodedCat = json_decode($catRes, true);
if (is_array($decodedCat)) {
$catListings = $decodedCat;
}
}
$catCount = count($catListings);
$countPhrase = $catCount > 0 ? " ({$catCount} Active Listings)" : '';
$metaTitle = $catDisplay . ' Properties for Rent & Sale in Singapore' . $countPhrase . ' | wukplace.sg';
$metaDescription = 'Browse verified ' . $catDisplay . ' spaces for rent and for sale in Singapore on wukplace.sg. Compare monthly rents, sale prices, floor areas (sqft), psf rates, building specs, and direct CEA licensed agents.';
$ogTitle = $metaTitle;
$ogDescription = $metaDescription;
$twitterTitle = $metaTitle;
$twitterDescription = $metaDescription;
$twitterLabel1 = 'Category';
$twitterData1 = $catDisplay;
$twitterLabel2 = 'Active Listings';
$twitterData2 = $catCount > 0 ? ($catCount . ' Verified Units') : 'For Rent & Sale';
$itemListElements = [];
foreach ($catListings as $idx => $cRow) {
$cId = !empty($cRow['id']) ? $cRow['id'] : (!empty($cRow['ref_id']) ? $cRow['ref_id'] : '');
if ($cId === '') continue;
$itemListElements[] = [
"@type" => "ListItem",
"position" => $idx + 1,
"name" => !empty($cRow['title']) ? $cRow['title'] : $catDisplay,
"url" => 'https://wukplace.sg/?propId=' . urlencode($cId) . '&mode=guest'
];
}
$jsonLdGraph = [
"@context" => "https://schema.org",
"@graph" => [
[
"@type" => "CollectionPage",
"@id" => $canonicalUrl . "#category",
"url" => $canonicalUrl,
"name" => $catDisplay . " Properties for Rent & Sale in Singapore",
"description" => $metaDescription,
"mainEntity" => [
"@type" => "ItemList",
"numberOfItems" => $catCount,
"itemListElement" => $itemListElements
]
],
[
"@type" => "BreadcrumbList",
"itemListElement" => [
[
"@type" => "ListItem",
"position" => 1,
"name" => "Home",
"item" => "https://wukplace.sg/"
],
[
"@type" => "ListItem",
"position" => 2,
"name" => $catDisplay,
"item" => $canonicalUrl
]
]
]
]
];
$ssrResultsHeading = ($catCount > 0 ? $catCount : 'ACTIVE') . ' ' . strtoupper($catDisplay) . ' LISTINGS';
$ssrBodyHtml = ''
. '' . htmlspecialchars($catDisplay . ' Properties for Rent & Sale in Singapore', ENT_QUOTES, 'UTF-8') . ' '
. '' . htmlspecialchars($metaDescription, ENT_QUOTES, 'UTF-8') . '
'
. renderGeoListingItems($catListings, $categoryLabels)
. ' ';
} elseif (!empty($bldgParam) && empty($propId)) {
// ==============================================================================
// Branch A: Individual Building Directory SEO Hub Request (?building=slug)
// ==============================================================================
$apiUrl = SUPABASE_URL . '/rest/v1/building_directory'
. '?or=(slug.eq.' . urlencode($bldgParam)
. ',building_name.ilike.' . urlencode($bldgParam)
. ',mcst_number.ilike.' . urlencode('%' . $bldgParam . '%')
. ',street_name.ilike.' . urlencode('%' . $bldgParam . '%')
. ',postal_code.eq.' . urlencode($bldgParam) . ')'
. '&select=*'
. '&limit=1';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$bldgName = ucwords(str_replace(['-', '_'], ' ', $bldgParam));
$bldgSlug = $bldgParam;
$bldgDistrict = 'Singapore Commercial & Industrial Sector';
$bldgPostal = '';
$bldgLat = 1.3521;
$bldgLng = 103.8198;
$bldgStreet = '';
$bldgStreetName = '';
$bldgAddress = '';
if ($httpCode === 200 && !empty($response)) {
$data = json_decode($response, true);
if (is_array($data) && count($data) > 0) {
$bldg = $data[0];
$bldgName = !empty($bldg['building_name']) ? $bldg['building_name'] : $bldgName;
$bldgSlug = !empty($bldg['slug']) ? $bldg['slug'] : $bldgSlug;
$bldgDistrict = !empty($bldg['district']) ? ($bldg['district'] . ' (' . (!empty($bldg['district_name']) ? $bldg['district_name'] : 'Commercial') . ')') : $bldgDistrict;
$bldgPostal = !empty($bldg['postal_code']) ? $bldg['postal_code'] : '';
$bldgStreetName = !empty($bldg['street_name']) ? trim($bldg['street_name']) : (!empty($bldg['street']) ? trim($bldg['street']) : '');
$bldgAddress = !empty($bldg['address']) ? trim($bldg['address']) : $bldgStreetName;
$bldgStreet = $bldgAddress !== '' ? $bldgAddress : $bldgStreetName;
if (!empty($bldg['lat']) && !empty($bldg['lng'])) {
$bldgLat = (float)$bldg['lat'];
$bldgLng = (float)$bldg['lng'];
}
if (!empty($bldg['cover_image_url'])) {
$ogImage = $bldg['cover_image_url'];
}
}
}
$specItems = [];
$zoningLabel = 'Commercial/Industrial';
if (!empty($bldg['zoning'])) {
$rawZ = strtolower(trim($bldg['zoning']));
if (strpos($rawZ, 'food') !== false || strpos($rawZ, 'kitchen') !== false) {
$zoningLabel = 'Food Factory';
} elseif (strpos($rawZ, 'park') !== false || strpos($rawZ, 'bp') !== false) {
$zoningLabel = 'Business Park';
} elseif (strpos($rawZ, 'retail') !== false || strpos($rawZ, 'mall') !== false) {
$zoningLabel = 'Mall Shop';
} elseif (strpos($rawZ, 'shophouse') !== false || strpos($rawZ, 'shop') !== false) {
$zoningLabel = 'Shophouse';
} elseif (strpos($rawZ, 'comm') !== false || strpos($rawZ, 'office') !== false) {
$zoningLabel = 'Office';
} elseif (strpos($rawZ, 'b2') !== false) {
$zoningLabel = 'B2 Heavy Industrial';
} elseif (strpos($rawZ, 'b1') !== false) {
$zoningLabel = 'B1 Light Industrial';
} else {
$zoningLabel = strtoupper(trim($bldg['zoning']));
}
$specItems[] = $zoningLabel;
}
if (!empty($bldg['top_year']) && stripos($bldg['top_year'], 'completed') === false && is_numeric(trim($bldg['top_year']))) {
$specItems[] = 'TOP: ' . trim($bldg['top_year']);
}
if (!empty($bldg['nearest_mrt']) && stripos($bldg['nearest_mrt'], 'public transport') === false) {
$specItems[] = 'MRT: ' . trim($bldg['nearest_mrt']);
}
$mcstNum = '';
$mcstMgmtName = '';
$mcstMgmtContact = '';
if (!empty($bldg['mcst_number']) && stripos($bldg['mcst_number'], 'not available') === false) {
$mcstNum = (stripos($bldg['mcst_number'], 'mcst') === 0) ? trim($bldg['mcst_number']) : ('MCST ' . trim($bldg['mcst_number']));
$mcstStr = $mcstNum;
if (!empty($bldg['mcst_management_name']) && stripos($bldg['mcst_management_name'], 'not available') === false) {
$mcstMgmtName = trim($bldg['mcst_management_name']);
$mcstStr .= ' (' . $mcstMgmtName . ')';
}
if (!empty($bldg['mcst_management_contact']) && stripos($bldg['mcst_management_contact'], 'not available') === false) {
$mcstMgmtContact = trim($bldg['mcst_management_contact']);
$mcstStr .= ' Contact: ' . $mcstMgmtContact;
}
$specItems[] = $mcstStr;
}
$specLine = !empty($specItems) ? (implode(' • ', $specItems) . '. ') : '';
$compCount = 0;
if (isset($bldg['verified_companies_count'])) {
$compCount = (int)$bldg['verified_companies_count'];
} elseif (isset($bldg['verified_companies']) && is_array($bldg['verified_companies'])) {
$compCount = count($bldg['verified_companies']);
}
$compText = $compCount > 0 ? ($compCount . ' verified in-building businesses') : 'Verified in-building businesses';
// Query active listing availability (Units for Rent & Units for Sale) for this building
$rentUnits = 0;
$saleUnits = 0;
$bListRows = [];
$bListingsQuery = SUPABASE_URL . '/rest/v1/property_listings'
. '?status=eq.active'
. '&select=id,ref_id,title,building_name,category,type,price,psf,area_sqft,district,address,postal_code,agent_cea,description'
. '&or=(building_name.ilike.' . urlencode('%' . $bldgName . '%') . (!empty($bldgPostal) ? (',postal_code.eq.' . urlencode($bldgPostal)) : '') . ')'
. '&limit=50';
$bListingsCh = curl_init();
curl_setopt_array($bListingsCh, [
CURLOPT_URL => $bListingsQuery,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$bListingsRes = curl_exec($bListingsCh);
curl_close($bListingsCh);
if (!empty($bListingsRes)) {
$bListData = json_decode($bListingsRes, true);
if (is_array($bListData)) {
$bListRows = $bListData;
foreach ($bListData as $row) {
$t = isset($row['type']) ? strtolower(trim($row['type'])) : 'rent';
if ($t === 'sale') {
$saleUnits++;
} else {
$rentUnits++;
}
}
}
}
$totalBldgUnits = $rentUnits + $saleUnits;
if ($totalBldgUnits > 0) {
if ($rentUnits > 0 && $saleUnits > 0) {
$unitTitlePhrase = "Units for Sale & Rent ({$totalBldgUnits} Available)";
$unitDescPhrase = "Featuring {$totalBldgUnits} verified units available for rent ({$rentUnits}) and for sale ({$saleUnits}).";
$twitterData1 = "{$rentUnits} for Rent, {$saleUnits} for Sale";
} elseif ($rentUnits > 0) {
$unitTitlePhrase = "Units for Rent ({$rentUnits} Available)";
$unitDescPhrase = "Featuring {$rentUnits} verified units available for rent.";
$twitterData1 = "{$rentUnits} Available for Rent";
} elseif ($saleUnits > 0) {
$unitTitlePhrase = "Units for Sale ({$saleUnits} Available)";
$unitDescPhrase = "Featuring {$saleUnits} verified units available for sale.";
$twitterData1 = "{$saleUnits} Available for Sale";
}
} else {
$unitTitlePhrase = "Units for Sale & Rent";
$unitDescPhrase = "Verified commercial & industrial units for rent and for sale.";
$twitterData1 = "Units for Rent & Sale Available";
}
$mcstTitlePart = $mcstNum !== '' ? (' (' . $mcstNum . ')') : '';
$streetDescPart = $bldgStreet !== '' ? (' at ' . $bldgStreet . ($bldgPostal !== '' ? (' Singapore ' . $bldgPostal) : '')) : '';
$metaTitle = $bldgName . $mcstTitlePart . ' - ' . $unitTitlePhrase . ', MCST & Building Directory | wukplace.sg';
$metaDescription = 'Explore ' . $bldgName . $streetDescPart . ' in ' . $bldgDistrict . '. ' . $unitDescPhrase . ' ' . $specLine . $compText . ', MCST management contact & strata details, and authentic available listings on wukplace.sg.';
$canonicalUrl = 'https://wukplace.sg/?building=' . urlencode($bldgSlug) . '&mode=guest';
$ogUrl = $canonicalUrl;
$ogTitle = $metaTitle;
$ogDescription = $metaDescription;
$ogImageAlt = $bldgName . $mcstTitlePart . ' - Units for Sale & Rent, MCST & Directory';
$twitterTitle = $metaTitle;
$twitterDescription = $metaDescription;
$twitterImage = $ogImage;
$twitterImageAlt = $ogImageAlt;
$twitterLabel1 = 'Available Units';
$twitterLabel2 = 'Property Type';
$twitterData2 = $zoningLabel . ($mcstNum !== '' ? (' · ' . $mcstNum) : (!empty($bldg['top_year']) ? (' · TOP ' . trim($bldg['top_year'])) : ''));
$metaKeywords = implode(', ', array_filter(array_unique([
$bldgName,
$bldgName . ' units for rent',
$bldgName . ' units for sale',
$bldgName . ' for rent',
$bldgName . ' for sale',
'rent unit at ' . $bldgName,
'buy unit at ' . $bldgName,
$bldgName . ' commercial space',
$bldgName . ' warehouse for rent',
$bldgName . ' industrial factory for sale',
$zoningLabel . ' for rent ' . $bldgName,
$zoningLabel . ' for sale ' . $bldgName,
$bldgName . ' Singapore',
$bldgDistrict . ' industrial property',
$bldgDistrict . ' commercial units for rent',
$bldgDistrict . ' commercial units for sale',
$bldgStreetName !== '' ? $bldgStreetName : '',
$bldgStreetName !== '' ? ($bldgStreetName . ' commercial building') : '',
$bldgStreetName !== '' ? ($bldgStreetName . ' industrial building') : '',
!empty($bldgStreet) ? ($bldgStreet . ' units for rent') : '',
!empty($bldgStreet) ? ($bldgStreet . ' units for sale') : '',
!empty($bldgPostal) ? ('Singapore ' . $bldgPostal) : '',
'Singapore building directory',
'commercial real estate Singapore',
$bldgName . ' MCST',
$mcstNum,
$mcstNum !== '' ? ($mcstNum . ' Singapore') : '',
$mcstNum !== '' ? ($mcstNum . ' contact') : '',
$mcstMgmtName,
'MCST management Singapore'
])));
$geoPlacename = $bldgDistrict . ', Singapore';
$geoPosition = $bldgLat . ';' . $bldgLng;
$geoIcbm = $bldgLat . ', ' . $bldgLng;
$bldgAmenityFeatures = [];
if ($mcstNum !== '') {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "MCST Number", "value" => $mcstNum];
}
if ($mcstMgmtName !== '') {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "MCST Management Corporation / Managing Agent", "value" => $mcstMgmtName];
}
if ($mcstMgmtContact !== '') {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "MCST Management Contact", "value" => $mcstMgmtContact];
}
if (!empty($bldg['tenure'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "Land Tenure", "value" => (string)$bldg['tenure']];
}
if (!empty($bldg['top_year'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "TOP / Completion Year", "value" => (string)$bldg['top_year']];
}
if (!empty($bldg['floor_loading'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "Floor Loading", "value" => (string)$bldg['floor_loading']];
}
if (!empty($bldg['ceiling_height'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "Ceiling Height", "value" => (string)$bldg['ceiling_height']];
}
if (!empty($bldg['power_supply'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "Power Supply", "value" => (string)$bldg['power_supply']];
}
if (!empty($bldg['nearest_mrt'])) {
$bldgAmenityFeatures[] = ["@type" => "LocationFeatureSpecification", "name" => "Nearest MRT", "value" => (string)$bldg['nearest_mrt']];
}
// Building Hub Schema.org JSON-LD
$jsonLdGraph = [
"@context" => "https://schema.org",
"@graph" => [
[
"@type" => ["Place", "CommercialBuilding"],
"@id" => $canonicalUrl . "#building",
"url" => $canonicalUrl,
"name" => $bldgName,
"identifier" => $mcstNum !== '' ? $mcstNum : $bldgSlug,
"description" => $metaDescription,
"image" => $ogImage,
"address" => [
"@type" => "PostalAddress",
"streetAddress" => !empty($bldgStreet) ? $bldgStreet : $bldgName,
"postalCode" => $bldgPostal,
"addressLocality" => "Singapore",
"addressCountry" => "SG",
"addressRegion" => $bldgDistrict
],
"geo" => [
"@type" => "GeoCoordinates",
"latitude" => $bldgLat,
"longitude" => $bldgLng
],
"amenityFeature" => $bldgAmenityFeatures,
"hasOfferCatalog" => [
"@type" => "OfferCatalog",
"name" => $bldgName . " Commercial & Industrial Units",
"itemListElement" => [
[
"@type" => "Offer",
"itemOffered" => [
"@type" => "CommercialProperty",
"name" => $bldgName . " Units for Rent"
],
"businessFunction" => "https://schema.org/LeaseOut"
],
[
"@type" => "Offer",
"itemOffered" => [
"@type" => "CommercialProperty",
"name" => $bldgName . " Units for Sale"
],
"businessFunction" => "https://schema.org/Sell"
]
]
]
],
[
"@type" => "BreadcrumbList",
"itemListElement" => [
[
"@type" => "ListItem",
"position" => 1,
"name" => "Home",
"item" => "https://wukplace.sg/"
],
[
"@type" => "ListItem",
"position" => 2,
"name" => "Building Directory",
"item" => "https://wukplace.sg/?view=directory&mode=guest"
],
[
"@type" => "ListItem",
"position" => 3,
"name" => $bldgName,
"item" => $canonicalUrl
]
]
]
]
];
$ssrResultsHeading = strtoupper($bldgName) . ($mcstNum !== '' ? (' (' . strtoupper($mcstNum) . ')') : '') . ' — ' . ($totalBldgUnits > 0 ? ($totalBldgUnits . ' AVAILABLE UNITS') : 'BUILDING & MCST SPECIFICATIONS');
$bSpecHtml = '';
$bSpecHtml .= '' . htmlspecialchars($bldgName . ($mcstNum !== '' ? (' (' . $mcstNum . ')') : '') . ' — ' . $unitTitlePhrase, ENT_QUOTES, 'UTF-8') . ' ';
$bSpecHtml .= '' . htmlspecialchars($metaDescription, ENT_QUOTES, 'UTF-8') . '
';
$bSpecHtml .= '';
$bSpecHtml .= 'Building Name: ' . htmlspecialchars($bldgName, ENT_QUOTES, 'UTF-8') . ' ';
if ($bldgStreetName !== '') $bSpecHtml .= 'Street Name: ' . htmlspecialchars($bldgStreetName, ENT_QUOTES, 'UTF-8') . ' ';
if ($bldgAddress !== '') $bSpecHtml .= 'Full Street Address: ' . htmlspecialchars($bldgAddress, ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldgPostal)) $bSpecHtml .= 'Postal Code: Singapore ' . htmlspecialchars($bldgPostal, ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['additional_postal_codes']) && is_array($bldg['additional_postal_codes'])) {
$bSpecHtml .= 'Additional Postal Codes: ' . htmlspecialchars(implode(', ', $bldg['additional_postal_codes']), ENT_QUOTES, 'UTF-8') . ' ';
}
if (!empty($bldg['area_streets']) && is_array($bldg['area_streets'])) {
$bSpecHtml .= 'Surrounding Streets: ' . htmlspecialchars(implode(', ', $bldg['area_streets']), ENT_QUOTES, 'UTF-8') . ' ';
}
if (!empty($bldgDistrict)) $bSpecHtml .= 'District: ' . htmlspecialchars($bldgDistrict, ENT_QUOTES, 'UTF-8') . ' ';
$bSpecHtml .= 'Zoning / Property Type: ' . htmlspecialchars($zoningLabel, ENT_QUOTES, 'UTF-8') . ' ';
if ($mcstNum !== '') $bSpecHtml .= 'MCST Number: ' . htmlspecialchars($mcstNum, ENT_QUOTES, 'UTF-8') . ' ';
if ($mcstMgmtName !== '') $bSpecHtml .= 'MCST Management Corporation / Managing Agent: ' . htmlspecialchars($mcstMgmtName, ENT_QUOTES, 'UTF-8') . ' ';
if ($mcstMgmtContact !== '') $bSpecHtml .= 'MCST Management Office Contact: ' . htmlspecialchars($mcstMgmtContact, ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['developer'])) $bSpecHtml .= 'Developer: ' . htmlspecialchars($bldg['developer'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['tenure'])) $bSpecHtml .= 'Land Tenure: ' . htmlspecialchars($bldg['tenure'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['top_year'])) $bSpecHtml .= 'TOP / Completion Year: ' . htmlspecialchars($bldg['top_year'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['floor_loading'])) $bSpecHtml .= 'Floor Loading: ' . htmlspecialchars($bldg['floor_loading'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['ceiling_height'])) $bSpecHtml .= 'Ceiling Height: ' . htmlspecialchars($bldg['ceiling_height'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['power_supply'])) $bSpecHtml .= 'Power Supply: ' . htmlspecialchars($bldg['power_supply'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['cargo_lifts'])) $bSpecHtml .= 'Cargo Lifts: ' . htmlspecialchars($bldg['cargo_lifts'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['passenger_lifts'])) $bSpecHtml .= 'Passenger Lifts: ' . htmlspecialchars($bldg['passenger_lifts'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['loading_bays'])) $bSpecHtml .= 'Loading Bays: ' . htmlspecialchars($bldg['loading_bays'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldg['nearest_mrt'])) $bSpecHtml .= 'Nearest MRT: ' . htmlspecialchars($bldg['nearest_mrt'], ENT_QUOTES, 'UTF-8') . ' ';
$bSpecHtml .= ' ';
if (!empty($bListRows)) {
$bSpecHtml .= 'Available Units for Rent & Sale at ' . htmlspecialchars($bldgName, ENT_QUOTES, 'UTF-8') . ' ';
$bSpecHtml .= renderGeoListingItems($bListRows, $categoryLabels);
}
$bSpecHtml .= ' ';
$ssrBodyHtml = $bSpecHtml;
} elseif (!empty($propId)) {
// ==============================================================================
// Branch B: Property Listing Request (?propId=uuid or ?property=refId)
// ==============================================================================
$canonicalUrl = 'https://wukplace.sg/?propId=' . urlencode($propId) . '&mode=guest';
$ogUrl = $canonicalUrl;
// Fetch complete property specifications from Supabase REST API
$apiUrl = SUPABASE_URL . '/rest/v1/property_listings'
. '?or=(id.eq.' . urlencode($propId) . ',ref_id.eq.' . urlencode($propId) . ')'
. '&select=*'
. '&limit=1';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $apiUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200 && !empty($response)) {
$data = json_decode($response, true);
if (is_array($data) && count($data) > 0) {
$prop = $data[0];
$canonicalId = !empty($prop['id']) ? $prop['id'] : $propId;
$canonicalUrl = 'https://wukplace.sg/?propId=' . urlencode($canonicalId) . '&mode=guest';
$ogUrl = $canonicalUrl;
$title = !empty($prop['title']) ? trim($prop['title']) : (!empty($prop['building_name']) ? trim($prop['building_name']) : 'Commercial Property');
$bldgName = !empty($prop['building_name']) ? trim($prop['building_name']) : '';
// Intent / Type & Pricing
$isRent = !(isset($prop['type']) && strtolower(trim($prop['type'])) === 'sale');
$price = isset($prop['price']) ? (float)$prop['price'] : 0;
$priceDisplay = $price > 0 ? ($isRent ? ('$' . number_format($price) . ' /mo') : ('$' . number_format($price))) : 'Price on Application';
$areaSqft = isset($prop['area_sqft']) ? (int)$prop['area_sqft'] : (isset($prop['floor_area']) ? (int)$prop['floor_area'] : 0);
$areaText = $areaSqft > 0 ? (' • ' . number_format($areaSqft) . ' sqft') : '';
$psf = isset($prop['psf']) ? (float)$prop['psf'] : 0;
if ($psf <= 0 && $price > 0 && $areaSqft > 0) {
$psf = round($price / $areaSqft, 2);
}
$psfText = $psf > 0 ? (' ($' . number_format($psf, 2) . ' psf' . ($isRent ? '/mo' : '') . ')') : '';
// Category & Zoning Normalization
$categoryMap = [
'b1' => 'B1 Industrial',
'b2' => 'B2 Heavy Industrial',
'warehouse' => 'Warehouse',
'office' => 'Commercial Office',
'retail' => 'Commercial Retail',
'shophouse' => 'Commercial Shophouse',
'medical' => 'Medical Suite',
'landed_industrial' => 'Landed Industrial',
'landed' => 'Commercial Landed',
'canteen' => 'F&B / Canteen',
'data_centre' => 'Data Centre'
];
$rawCat = isset($prop['category']) ? strtolower(trim($prop['category'])) : 'commercial';
$categoryDisplay = isset($categoryMap[$rawCat]) ? $categoryMap[$rawCat] : strtoupper($rawCat);
// Geographic location
$address = !empty($prop['address']) ? trim($prop['address']) : (!empty($prop['street']) ? trim($prop['street']) : 'Singapore');
$district = !empty($prop['district']) ? trim($prop['district']) : '';
$postalCode = !empty($prop['postal_code']) ? trim($prop['postal_code']) : '';
$streetName = !empty($prop['street']) ? trim($prop['street']) : $address;
$lat = !empty($prop['lat']) ? (float)$prop['lat'] : 1.3284;
$lng = !empty($prop['lng']) ? (float)$prop['lng'] : 103.8966;
$geoRegion = 'SG';
$geoPlacename = ($district ? $district : $address) . ', Singapore';
$geoPosition = $lat . ';' . $lng;
$geoIcbm = $lat . ', ' . $lng;
// Resolve Agent Details from Supabase profiles (publicly readable columns)
$agentName = 'Licensed CEA Real Estate Salesperson';
$agentCea = !empty($prop['agent_cea']) ? trim($prop['agent_cea']) : '';
$agencyName = '';
$agencyLicense = '';
$agentLookupId = !empty($prop['agent_id']) ? $prop['agent_id'] : null;
if ($agentLookupId || $agentCea) {
$agentQuery = $agentLookupId
? ('id=eq.' . urlencode($agentLookupId))
: ('cea_number=eq.' . urlencode($agentCea));
$agentCh = curl_init();
curl_setopt_array($agentCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/profiles?' . $agentQuery . '&select=full_name,cea_number,agency_name,agency_license&limit=1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$agentRes = curl_exec($agentCh);
$agentHttp = curl_getinfo($agentCh, CURLINFO_HTTP_CODE);
curl_close($agentCh);
if ($agentHttp === 200 && !empty($agentRes)) {
$agentData = json_decode($agentRes, true);
if (is_array($agentData) && count($agentData) > 0) {
$ag = $agentData[0];
if (!empty($ag['full_name']) && !preg_match('/^(res agent|registered res)/i', $ag['full_name'])) {
$agentName = trim($ag['full_name']);
}
if (!empty($ag['cea_number'])) $agentCea = trim($ag['cea_number']);
if (!empty($ag['agency_name'])) $agencyName = trim($ag['agency_name']);
if (!empty($ag['agency_license'])) $agencyLicense = trim($ag['agency_license']);
}
}
}
$agentBrokerDisplay = $agentName . ($agentCea ? ' (' . $agentCea . ')' : '') . ($agencyName ? ' · ' . $agencyName : '');
$metaAuthor = $agentName . ($agencyName ? ', ' . $agencyName : '');
// Technical Specs for description and schema
$specItems = [];
if (!empty($prop['floor_loading'])) {
$specItems[] = 'Floor Loading: ' . $prop['floor_loading'] . ' kN/m²';
}
if (!empty($prop['ceiling_height'])) {
$specItems[] = 'Ceiling Height: ' . $prop['ceiling_height'] . 'm';
}
if (!empty($prop['power_supply'])) {
$specItems[] = 'Power: ' . $prop['power_supply'];
}
if (!empty($prop['tenure'])) {
$specItems[] = 'Tenure: ' . $prop['tenure'];
}
$specSummary = !empty($specItems) ? (implode(' • ', $specItems) . '. ') : '';
// Fetch high-resolution property gallery photos for Schema.org and OpenGraph
$photoUrls = [];
$photosCh = curl_init();
curl_setopt_array($photosCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/listing_photos?listing_id=eq.' . urlencode($canonicalId) . '&select=photo_url,display_order&order=display_order.asc&limit=10',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$photosRes = curl_exec($photosCh);
curl_close($photosCh);
if (!empty($photosRes)) {
$photosData = json_decode($photosRes, true);
if (is_array($photosData)) {
foreach ($photosData as $pRow) {
if (!empty($pRow['photo_url'])) {
$photoUrls[] = $pRow['photo_url'];
}
}
}
}
// Cover photo URL — always serves a direct JPEG optimized for WhatsApp & social link cards
$ogImage = 'https://wukplace.sg/covers/' . urlencode($canonicalId) . '.jpg';
if (empty($photoUrls)) {
$photoUrls[] = $ogImage;
} else {
array_unshift($photoUrls, $ogImage);
$photoUrls = array_values(array_unique($photoUrls));
}
$ogImageAlt = $title . ' - Cover Photo';
// Lookup Building Directory record (MCST number, management contact, street name) if matched
$propMcstNum = '';
$propMcstMgmt = '';
$propMcstContact = '';
$propBldgSlug = !empty($bldgName) ? strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $bldgName), '-')) : '';
if (!empty($bldgName) || !empty($postalCode)) {
$bOrParts = [];
if (!empty($bldgName)) {
$bOrParts[] = 'building_name.ilike.' . urlencode($bldgName);
}
if (!empty($postalCode)) {
$bOrParts[] = 'postal_code.eq.' . urlencode($postalCode);
}
$bLookupCh = curl_init();
curl_setopt_array($bLookupCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/building_directory?or=(' . implode(',', $bOrParts) . ')&select=slug,building_name,street_name,address,mcst_number,mcst_management_name,mcst_management_contact&limit=1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$bLookupRes = curl_exec($bLookupCh);
curl_close($bLookupCh);
if (!empty($bLookupRes)) {
$bLookupData = json_decode($bLookupRes, true);
if (is_array($bLookupData) && count($bLookupData) > 0) {
$bRec = $bLookupData[0];
if (!empty($bRec['slug'])) $propBldgSlug = trim($bRec['slug']);
if (empty($bldgName) && !empty($bRec['building_name'])) $bldgName = trim($bRec['building_name']);
if (!empty($bRec['street_name']) && (empty($streetName) || $streetName === 'Singapore')) {
$streetName = trim($bRec['street_name']);
}
if (!empty($bRec['mcst_number']) && stripos($bRec['mcst_number'], 'not available') === false) {
$rawPm = trim($bRec['mcst_number']);
$propMcstNum = (stripos($rawPm, 'mcst') === 0) ? $rawPm : ('MCST ' . $rawPm);
}
if (!empty($bRec['mcst_management_name']) && stripos($bRec['mcst_management_name'], 'not available') === false) {
$propMcstMgmt = trim($bRec['mcst_management_name']);
}
if (!empty($bRec['mcst_management_contact']) && stripos($bRec['mcst_management_contact'], 'not available') === false) {
$propMcstContact = trim($bRec['mcst_management_contact']);
}
}
}
}
if ($propMcstNum !== '') {
$specItems[] = $propMcstNum . ($propMcstMgmt !== '' ? (' (' . $propMcstMgmt . ')') : '');
$specSummary = implode(' • ', $specItems) . '. ';
}
// High-CTR, Intent-Focused Page Title
$districtPart = $district ? (' | ' . $district) : '';
$metaTitle = $title . ' | ' . $categoryDisplay . ' for ' . ($isRent ? 'Rent' : 'Sale') . $districtPart . ' | ' . $priceDisplay . ' | wukplace.sg';
$ogTitle = $metaTitle;
$twitterTitle = $metaTitle;
// Search-intent rich Meta Description
$locationPart = $address . ($district && stripos($address, $district) === false ? ' (' . $district . ')' : '');
$metaDescription = $locationPart . '. ' . $categoryDisplay . ' for ' . ($isRent ? 'Rent' : 'Sale') . $areaText . ' available at ' . $priceDisplay . $psfText . '. ' . $specSummary . 'Direct CEA Agent: ' . $agentBrokerDisplay . '. View verified details, photos & specifications on wukplace.sg.';
$ogDescription = $metaDescription;
$twitterDescription = $metaDescription;
// High-Intent Targeted Keywords
$keywordsList = [
$title,
!empty($bldgName) ? $bldgName : '',
!empty($bldgName) && $propMcstNum !== '' ? ($bldgName . ' ' . $propMcstNum) : '',
$propMcstNum,
$propMcstMgmt,
$categoryDisplay . ' Singapore',
$categoryDisplay . ($isRent ? ' for Rent' : ' for Sale'),
$district ? ($district . ' commercial property') : '',
$streetName ? $streetName : '',
$streetName ? ($streetName . ' property') : '',
$postalCode ? ('Singapore ' . $postalCode) : '',
$areaSqft > 0 ? ($areaSqft . ' sqft ' . strtolower($categoryDisplay)) : '',
'Singapore commercial real estate',
'industrial property Singapore',
'warehouse for rent Singapore',
'CEA licensed agent',
$agentName,
!empty($agencyName) ? $agencyName : ''
];
$metaKeywords = implode(', ', array_filter(array_unique(array_map('trim', $keywordsList))));
// Commerce / Product Meta Tags
$ogType = 'article';
$ogPriceAmount = $price > 0 ? (string)$price : '';
$ogPriceCurrency = 'SGD';
$productPriceAmount = $ogPriceAmount;
$productPriceCurrency = 'SGD';
$productAvailability = 'instock';
$ogUpdatedTime = !empty($prop['updated_at']) ? $prop['updated_at'] : (!empty($prop['created_at']) ? $prop['created_at'] : date('c'));
// Twitter Card Product Details
$twitterLabel1 = 'Price';
$twitterData1 = $priceDisplay;
$twitterLabel2 = 'Floor Area';
$twitterData2 = $areaSqft > 0 ? (number_format($areaSqft) . ' sqft') : 'Commercial Space';
// Comprehensive Schema.org RealEstateListing + Offer + BreadcrumbList JSON-LD
$amenityFeatures = [];
if ($propMcstNum !== '') {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "MCST Number",
"value" => $propMcstNum . ($propMcstMgmt !== '' ? (' (' . $propMcstMgmt . ')') : '')
];
}
if (!empty($prop['floor_loading'])) {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "Floor Loading",
"value" => $prop['floor_loading'] . " kN/m²"
];
}
if (!empty($prop['ceiling_height'])) {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "Clear Ceiling Height",
"value" => $prop['ceiling_height'] . " m"
];
}
if (!empty($prop['power_supply'])) {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "Electrical Power Supply",
"value" => (string)$prop['power_supply']
];
}
if (!empty($prop['tenure'])) {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "Land Tenure",
"value" => (string)$prop['tenure']
];
}
if (!empty($prop['goods_access']) && is_array($prop['goods_access'])) {
$amenityFeatures[] = [
"@type" => "LocationFeatureSpecification",
"name" => "Goods Access",
"value" => implode(', ', $prop['goods_access'])
];
}
$jsonLdGraph = [
"@context" => "https://schema.org",
"@graph" => [
[
"@type" => "RealEstateListing",
"@id" => $canonicalUrl . "#listing",
"url" => $canonicalUrl,
"name" => $title,
"description" => !empty($prop['description']) ? trim($prop['description']) : $metaDescription,
"datePosted" => !empty($prop['created_at']) ? $prop['created_at'] : date('c'),
"dateModified" => $ogUpdatedTime,
"image" => $photoUrls,
"offers" => [
"@type" => "Offer",
"price" => $price,
"priceCurrency" => "SGD",
"availability" => "https://schema.org/InStock",
"businessFunction" => $isRent ? "https://schema.org/LeaseOut" : "https://schema.org/Sell",
"priceSpecification" => [
"@type" => "UnitPriceSpecification",
"price" => $psf,
"priceCurrency" => "SGD",
"unitText" => $isRent ? "sqft/month" : "sqft"
]
],
"itemOffered" => [
"@type" => ["Place", "Accommodation", "CommercialProperty"],
"name" => !empty($bldgName) ? $bldgName : $title,
"address" => [
"@type" => "PostalAddress",
"streetAddress" => $streetName,
"postalCode" => $postalCode,
"addressLocality" => "Singapore",
"addressCountry" => "SG",
"addressRegion" => $district ? $district : "Singapore"
],
"geo" => [
"@type" => "GeoCoordinates",
"latitude" => $lat,
"longitude" => $lng
],
"floorSize" => [
"@type" => "QuantitativeValue",
"value" => $areaSqft,
"unitCode" => "FTK"
],
"amenityFeature" => $amenityFeatures
],
"broker" => [
"@type" => "RealEstateAgent",
"name" => $agentName,
"identifier" => $agentCea,
"parentOrganization" => [
"@type" => "Organization",
"name" => $agencyName,
"license" => $agencyLicense
]
]
],
[
"@type" => "BreadcrumbList",
"itemListElement" => [
[
"@type" => "ListItem",
"position" => 1,
"name" => "Home",
"item" => "https://wukplace.sg/"
],
[
"@type" => "ListItem",
"position" => 2,
"name" => $categoryDisplay,
"item" => "https://wukplace.sg/?category=" . urlencode($rawCat) . "&mode=guest"
],
[
"@type" => "ListItem",
"position" => 3,
"name" => $title,
"item" => $canonicalUrl
]
]
]
]
];
$ssrResultsHeading = 'VERIFIED LISTING — ' . strtoupper($title);
$pHtml = '';
$pHtml .= '' . htmlspecialchars($title . ' — ' . $categoryDisplay . ' for ' . ($isRent ? 'Rent' : 'Sale'), ENT_QUOTES, 'UTF-8') . ' ';
$pHtml .= ' ';
$pHtml .= '';
$pHtml .= 'Transaction Type: ' . ($isRent ? 'For Rent (Lease)' : 'For Sale') . ' ';
$pHtml .= 'Price: SGD ' . htmlspecialchars($priceDisplay . $psfText, ENT_QUOTES, 'UTF-8') . ' ';
if ($areaSqft > 0) $pHtml .= 'Floor Area: ' . number_format($areaSqft) . ' sqft ';
$pHtml .= 'Property Category: ' . htmlspecialchars($categoryDisplay, ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($bldgName)) {
$pHtml .= 'Building Name: ' . htmlspecialchars($bldgName, ENT_QUOTES, 'UTF-8') . ' ';
}
if (!empty($streetName) && $streetName !== 'Singapore') {
$pHtml .= 'Street Name: ' . htmlspecialchars($streetName, ENT_QUOTES, 'UTF-8') . ' ';
}
$locFull = implode(', ', array_filter([$address, $district, $postalCode ? ('Singapore ' . $postalCode) : '']));
if ($locFull !== '') $pHtml .= 'Address: ' . htmlspecialchars($locFull, ENT_QUOTES, 'UTF-8') . ' ';
if ($propMcstNum !== '') {
$mcstFull = $propMcstNum . ($propMcstMgmt !== '' ? (' — ' . $propMcstMgmt) : '') . ($propMcstContact !== '' ? (' (Contact: ' . $propMcstContact . ')') : '');
$pHtml .= 'MCST Details: ' . htmlspecialchars($mcstFull, ENT_QUOTES, 'UTF-8') . ' ';
}
if (!empty($prop['tenure'])) $pHtml .= 'Tenure: ' . htmlspecialchars($prop['tenure'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($prop['floor_loading'])) $pHtml .= 'Floor Loading: ' . htmlspecialchars($prop['floor_loading'] . ' kN/m²', ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($prop['ceiling_height'])) $pHtml .= 'Clear Ceiling Height: ' . htmlspecialchars($prop['ceiling_height'] . ' m', ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($prop['power_supply'])) $pHtml .= 'Power Supply: ' . htmlspecialchars($prop['power_supply'], ENT_QUOTES, 'UTF-8') . ' ';
if (!empty($prop['goods_access']) && is_array($prop['goods_access'])) {
$pHtml .= 'Goods Access: ' . htmlspecialchars(implode(', ', $prop['goods_access']), ENT_QUOTES, 'UTF-8') . ' ';
}
$pHtml .= 'Listing Reference ID: ' . htmlspecialchars($canonicalId, ENT_QUOTES, 'UTF-8') . ' ';
$pHtml .= 'Listed By (CEA Registered Salesperson): ' . htmlspecialchars($agentName, ENT_QUOTES, 'UTF-8')
. ($agentCea ? (' (CEA Reg. No. ' . htmlspecialchars($agentCea, ENT_QUOTES, 'UTF-8') . ')') : '')
. ($agencyName ? (' — ' . htmlspecialchars($agencyName, ENT_QUOTES, 'UTF-8')) : '')
. ($agencyLicense ? (' (Agency License: ' . htmlspecialchars($agencyLicense, ENT_QUOTES, 'UTF-8') . ')') : '')
. ' ';
$pHtml .= ' ';
if (!empty($prop['description'])) {
$pHtml .= 'Property Description ';
$pHtml .= '' . nl2br(htmlspecialchars(trim($prop['description']), ENT_QUOTES, 'UTF-8')) . '
';
}
$pHtml .= ' ';
$ssrBodyHtml = $pHtml;
}
}
} else {
// ==============================================================================
// Branch C: Default Marketplace Homepage (/ or /?mode=guest) for Search & AI Crawlers
// ==============================================================================
$homeListings = [];
$homeCh = curl_init();
curl_setopt_array($homeCh, [
CURLOPT_URL => SUPABASE_URL . '/rest/v1/property_listings?status=eq.active&select=id,ref_id,title,building_name,category,type,price,psf,area_sqft,district,address,postal_code,agent_cea,description,updated_at&order=updated_at.desc&limit=40',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 4,
CURLOPT_HTTPHEADER => [
'apikey: ' . SUPABASE_ANON_KEY,
'Authorization: Bearer ' . SUPABASE_ANON_KEY,
'Accept: application/json',
],
]);
$homeRes = curl_exec($homeCh);
curl_close($homeCh);
if (!empty($homeRes)) {
$decodedHome = json_decode($homeRes, true);
if (is_array($decodedHome)) {
$homeListings = $decodedHome;
}
}
$homeCount = count($homeListings);
$ssrResultsHeading = ($homeCount > 0 ? $homeCount : 'ACTIVE') . ' LISTINGS FOUND';
$hHtml = '';
$hHtml .= 'Singapore Commercial & Industrial Property Marketplace ';
$hHtml .= 'Browse verified Singapore B1 light industrial, B2 heavy industrial, warehouses, food factories, business parks, commercial offices, retail shops, and shophouses for rent and for sale by licensed CEA real estate salespersons.
';
$hHtml .= ' ';
$hHtml .= renderGeoListingItems($homeListings, $categoryLabels);
$hHtml .= ' ';
$ssrBodyHtml = $hHtml;
}
// ==============================================================================
// Universal Safe Meta Tag & Structured Data Injectors
// ==============================================================================
/**
* Injects or replaces a tag in HTML string.
*/
function injectMetaTag($html, $attrType, $attrName, $content, $id = '') {
$contentEsc = htmlspecialchars($content, ENT_QUOTES, 'UTF-8');
$idAttr = !empty($id) ? (' id="' . htmlspecialchars($id, ENT_QUOTES, 'UTF-8') . '"') : '';
$newTag = ' ';
// Check if tag with id exists
if (!empty($id)) {
$idPattern = '/ ]*?id=["\']' . preg_quote($id, '/') . '["\'][^>]*>/i';
$replaced = false;
$res = preg_replace_callback($idPattern, function() use ($newTag, &$replaced) {
$replaced = true;
return $newTag;
}, $html, 1);
if ($replaced && $res !== null) {
return $res;
}
}
// Check if tag with attrType/attrName exists
$pattern = '/ ]*?' . preg_quote($attrType, '/') . '=["\']' . preg_quote($attrName, '/') . '["\'][^>]*>/i';
$replaced = false;
$res = preg_replace_callback($pattern, function() use ($newTag, &$replaced) {
$replaced = true;
return $newTag;
}, $html, 1);
if ($replaced && $res !== null) {
return $res;
}
// Fallback: inject into
return preg_replace_callback('/<\/head>/i', function() use ($newTag) {
return " " . $newTag . "\n";
}, $html, 1);
}
/**
* Injects or replaces JSON-LD structured data in HTML string.
*/
function injectJsonLd($html, $jsonArray, $id = 'seoStructuredData') {
if (!$jsonArray) return $html;
$jsonEncoded = json_encode($jsonArray, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$scriptTag = '";
$pattern = '/