SiteโฏBuilder
Editing:
index-new.php
writable 0666
<?php /************************************************************************** * index.php โ Ultraโlight โSmart templateโ for BestDealOn microsites * --------------------------------------------------------------------- * โข Lives in each profile dir (/ph/##########/index.php OR /social/<slug>/index.php) * โข Expects in the same folder * โ config.json (ownerโeditable order, extra toggles) * โ *.json data (profile.json, coupon.json, โฆ) โ consumed by modules themselves * โข Uses global catalogue โฆ/pages/modules/modules.json (curated by modules-admin.php) **************************************************************************/ define('GLOBAL_MOD_JSON', $_SERVER['DOCUMENT_ROOT'].'/pages/modules/modules.json'); /* ---------- load global catalogue ---------- */ $global = json_decode(file_get_contents(GLOBAL_MOD_JSON), true) ?: []; /* ---------- load local config -------------- */ $localCfg = []; if (is_file(__DIR__.'/config.json')) { $localCfg = json_decode(file_get_contents(__DIR__.'/config.json'), true) ?: []; } /* example structure: [ {"name":"hero" ,"active":true}, {"name":"coupon" ,"active":true}, {"name":"links" ,"active":false} ] */ /* helper: find module row by name */ $byName = []; foreach ($global as $g) $byName[$g['name']] = $g; /* ---------- salting: who is looking? ---------- */ $viewerRole = 'free'; // default for public traffic session_start(); if (!empty($_SESSION['uid']) && !empty($_SESSION['role'])) { $viewerRole = ($_SESSION['role']==='admin') ? 'admin' : 'premium'; // loggedโin owner or admin } /* ---------- decide final list (order = local config) ---------- */ $final = []; foreach ($localCfg as $slot) { $n = $slot['name']; if (empty($slot['active'])) continue; // turned off locally if (empty($byName[$n])) continue; // unknown globally $g = $byName[$n]; if (!$g['active']) continue; // disabled by master switch if ($g['tier']==='premium' && $viewerRole==='free') continue; if ($g['tier']==='admin' && $viewerRole!=='admin') continue; $final[] = $g; // ok โ include later } /* ---------- very small helper for pretty section IDs ---------- */ function section_id(string $name): string { return 'mโ'.preg_replace('/[^a-z0-9]/i','', $name); } ?><!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title><?= htmlspecialchars(json_decode(file_get_contents(__DIR__.'/profile.json'),true)['name'] ?? 'BestDealOn')?> โ BestDealOn</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <!-- โธโธ 2025 aesthetic โ feel free to tweak --> <style> :root{ --brand:#0d6efd;--bg:#f9fbff;--fg:#111;--hero:#00143d; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif; scroll-behavior:smooth; } *{box-sizing:border-box} body{margin:0;background:var(--bg);color:var(--fg)} /* ---- hero banner ----*/ .hero{background:var(--hero);color:#fff;padding:5.5rem 1rem 6rem;text-align:center} .hero h1{margin:0;font-size:2.3rem;line-height:1.15} .hero p{opacity:.85;margin:.8rem auto 0;max-width:22rem} /* ---- nav ---- */ nav#jump{position:fixed;top:1rem;right:1rem;z-index:1000} nav select,nav ul{background:#fff;border:1px solid #ccd2e2;border-radius:8px;padding:.55rem .9rem;font:inherit} nav ul{list-style:none;margin:0;padding:.35rem 0;box-shadow:0 4px 16px rgba(0,0,0,.09);display:flex;gap:.6rem} nav a{color:var(--brand);text-decoration:none;font-weight:600;font-size:.9rem} nav a:hover{text-decoration:underline} /* hide desktop nav on narrow screens */ @media(max-width:640px){ nav ul{display:none}} /* hide dropdown on wide screens */ @media(min-width:641px){ nav select{display:none}} /* ---- module sections ---- */ section{padding:3.5rem 1rem;max-width:840px;margin:auto} section + section{border-top:1px solid #edf1ff} </style> </head> <body> <!-- hero block can be its own module too --> <header class="hero" id="top"> <h1><?= htmlspecialchars(json_decode(file_get_contents(__DIR__.'/profile.json'),true)['slogan'] ?? 'Your local expert') ?></h1> <p>Powered by BestDealOn</p> </header> <!-- jump nav built from $final --> <nav id="jump"> <select onchange="location.hash=this.value"> <option value="#top">โ jump to โ</option> <?php foreach($final as $m): ?> <option value="#<?= section_id($m['name']) ?>"><?= ucfirst($m['name']) ?></option> <?php endforeach; ?> </select> <ul> <?php foreach($final as $m): ?> <li><a href="#<?= section_id($m['name']) ?>"><?= ucfirst($m['name']) ?></a></li> <?php endforeach; ?> </ul> </nav> <?php /* ---------- render each module ---------- */ foreach ($final as $m) { echo '<section id="'.section_id($m['name']).'">'; // Every module is responsible for its own <h2> etc. include $_SERVER['DOCUMENT_ROOT'].'/pages/modules/'.$m['relative_path']; echo '</section>'; } ?> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel