Site Builder
Editing:
modules-structured.php
writable 0666
<?php /************************************************************************** * STRUCTURED DATA AGGREGATOR (JSON‑LD) – modules-structured.php * ---------------------------------------------------------------------- * • Reads in‑memory objects exposed by the other modules and emits * a single JSON‑LD script block. * • Place inside /pages/modules/structured/ and enable it last. **************************************************************************/ if (!function_exists('get_profile')) return; // must have at minimum $profile = get_profile(); /* -------------------------------------------------- 1. ORGANISATION */ $org = [ '@type' => 'Organization', 'name' => $profile['display_name'] ?? $profile['name'] ?? ($profile['handle'] ?? 'Business'), 'url' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], ]; if (!empty($profile['address'])) { $org['address'] = [ '@type' => 'PostalAddress', 'streetAddress' => $profile['address'] ?? '', 'addressLocality' => $profile['city'] ?? '', 'addressRegion' => $profile['state'] ?? '', 'postalCode' => $profile['zip'] ?? '', 'addressCountry' => 'US' ]; } if (!empty($profile['phone'])) $org['telephone'] = preg_replace('/\D/','', $profile['phone']); if (!empty($profile['website'])) $org['sameAs'][] = $profile['website']; /* -------------------------------------------------- 2. COUPONS → Offer */ $offers = []; if (function_exists('get_coupon') && ($coupons = get_coupon())) { foreach ($coupons as $c) { if (empty($c['title']) || empty($c['link'])) continue; $offers[] = [ '@type' => 'Offer', 'name' => $c['title'], 'url' => $c['link'], 'priceCurrency'=> 'USD', 'price' => '0', // not obligatory, but keeps validator happy 'validThrough' => $c['expiry'] ?: null, 'sku' => $c['code'] ?: null, 'category' => 'Coupons', 'offeredBy' => ['@id' => '#org'] ]; } } /* -------------------------------------------------- 3. LINKS → CreativeWork */ $works = []; if (function_exists('get_links') && ($links = get_links())) { foreach ($links as $l) { if (empty($l['title']) || empty($l['url'])) continue; $works[] = [ '@type' => 'CreativeWork', 'headline' => $l['title'], 'url' => $l['url'], 'abstract' => $l['excerpt'] ?? '', 'isBasedOn' => ['@id' => '#org'] ]; } } /* -------------------------------------------------- 4. RSS cache (if module ran) */ $posts = []; $rssCache = dirname(__DIR__,2).'/rss-cache.html'; if (is_readable($rssCache) && ($html = file_get_contents($rssCache))) { if (preg_match_all('#<a class="rs-title" href="([^"]+)"[^>]*>(.*?)</a>.*?rs-date">(.*?)</#si',$html,$m)){ foreach($m[0] as $i=>$dummy){ $posts[] = [ '@type' => 'BlogPosting', 'headline' => html_entity_decode(strip_tags($m[2][$i])), 'url' => $m[1][$i], 'datePublished' => date('c', strtotime(html_entity_decode(strip_tags($m[3][$i])))), 'author' => ['@id' => '#org'] ]; } } } /* -------------------------------------------------- 5. Assemble graph */ $graph = []; $graph[] = ['@id'=>'#org'] + $org; foreach ([$offers,$works,$posts] as $arr) foreach ($arr as $node) $graph[]=$node; if (count($graph) <= 1) return; // nothing beyond Organisation /* -------------------------------------------------- 6. Emit JSON‑LD */ echo '<script type="application/ld+json">'.PHP_EOL. json_encode(['@context'=>'https://schema.org','@graph'=>$graph], JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT). PHP_EOL.'</script>'.PHP_EOL; /* Optional tiny footer line for debugging – set to TRUE when needed */ $SHOW_NOTE = false; if ($SHOW_NOTE){ echo '<p style="text-align:center;font-size:.8rem;color:#888;margin-top:1rem">' . htmlspecialchars(count($graph)-1).' structured‑data nodes generated ✓</p>'; } ?>
Save changes
Create folder
writable 0777
Create
Cancel