Site Builder
Editing:
index1.php
writable 0666
<?php /************************************************************************* * /pages/index.php – Lightweight one‑file “shell” that turns the * static module fragments into a mini–single‑page application. * --------------------------------------------------------------------- * ❶ Reads the GLOBAL catalogue ............. pages/modules/modules.json * ❷ Reads the SITE config (order / hidden) pages/config.json * ❸ Filters by tier (free / premium / admin) * ❹ Outputs: • a top hero banner * • a JS‑enhanced tab bar * • a <div id="slot"> where modules are inserted lazily *************************************************************************/ const MOD_ROOT = __DIR__.'/modules'; // /pages/modules const GLOBAL_CFG = MOD_ROOT.'/modules.json'; // global list const SITE_CFG = __DIR__.'/config.json'; // per‑site order / active /* ---------------------------------------------------- helpers -------- */ function read_json(string $f): array { return is_file($f) ? json_decode(file_get_contents($f), true) ?: [] : []; } $catalogue = []; foreach (read_json(GLOBAL_CFG) as $row) $catalogue[$row['name']]=$row; $siteCfg = read_json(SITE_CFG); /* visitor tier check – adjust as required ----------------------------- */ session_start(); $currentTier = 'free'; if (isset($_SESSION['uid'])) { // pseudo‑logic – replace with your own premium test $currentTier = ($_SESSION['uid']??0) === 1 ? 'admin' : 'premium'; } /* ------------------------------------------------ reorder / filter --- */ $order = $siteCfg['order'] ?? array_keys($catalogue); $out = []; foreach ($order as $name) { if (!isset($catalogue[$name])) continue; // removed globally $row = $catalogue[$name]; /* skip if not allowed for this tier */ $tier = $row['tier'] ?? 'free'; if ($tier==='premium' && $currentTier==='free') continue; if ($tier==='admin' && $currentTier!=='admin') continue; /* skip if disabled in site config */ if (isset($siteCfg['disabled']) && in_array($name,$siteCfg['disabled'],true)) continue; $out[] = $row; } /* -------------------------------------------------------------------- */ ?><!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title><?= htmlspecialchars($siteCfg['title'] ?? 'My Mini‑Site') ?></title> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="preconnect" href="https://fonts.gstatic.com"> <style> :root{ --brand:#0066ff;--fg:#111;--bg:#f9fbff; --sel:#003580;--selfg:#fff; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif } *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg)} header{padding:3.2rem 1rem;text-align:center;background:var(--brand);color:#fff} header h1{margin:0;font-size:2rem} nav{display:flex;overflow:auto;background:#fff;box-shadow:0 2px 5px rgb(0 0 0/.07)} nav button{flex:1;min-width:120px;padding:.9rem .6rem;border:none;border-right:1px solid #e4e8f1; background:#fff;color:#333;font-weight:600;cursor:pointer} nav button:last-child{border-right:none} nav button.active{background:var(--sel);color:var(--selfg)} #slot{max-width:1000px;margin:2.2rem auto;padding:0 1rem} .loader{padding:2rem;text-align:center;color:#777} @media(max-width:600px){ header h1{font-size:1.45rem} nav button{min-width:90px;font-size:.9rem} } </style> </head><body> <header><h1><?= htmlspecialchars($siteCfg['hero'] ?? 'Welcome!') ?></h1></header> <?php if ($out): ?> <nav id="tabs"><?php foreach($out as $i=>$m): ?> <button data-mod="<?= htmlspecialchars($m['name']) ?>" <?= $i? '' : 'class="active"' ?>> <?= htmlspecialchars(ucwords(str_replace('-',' ',$m['name']))) ?> </button> <?php endforeach ?></nav> <div id="slot"> <div class="loader">Loading…</div> </div> <?php else: ?> <p style="text-align:center;padding:3rem;font-weight:600"> No active modules for your tier.</p> <?php endif; ?> <script> /* ------------------------------------------------ tabs / lazy‑loader */ const modMap = <?= json_encode(array_column($out,null,'name')) ?>; const slot = document.getElementById('slot'); const tabs = document.getElementById('tabs'); function loadModule(name, first){ /* already loaded? */ if (document.getElementById('mod-'+name)){ show(name); return; } fetch(modMap[name].http_path) /* fetch the PHP fragment */ .then(r=>r.text()) .then(html=>{ const wrap=document.createElement('section'); wrap.id='mod-'+name; wrap.style.display='none'; wrap.innerHTML=html; slot.appendChild(wrap); show(name); if(first) slot.querySelector('.loader')?.remove(); }) .catch(()=>alert('Failed to load module '+name)); } function show(name){ document.querySelectorAll('#slot > section') .forEach(s=>s.style.display = s.id==='mod-'+name ? '' : 'none'); tabs.querySelectorAll('button') .forEach(b=>b.classList.toggle('active', b.dataset.mod===name)); } tabs?.addEventListener('click',e=>{ const b=e.target.closest('button[data-mod]'); if(!b) return; loadModule(b.dataset.mod,false); }); /* initial auto‑load */ if (Object.keys(modMap).length){ loadModule(Object.keys(modMap)[0], true); } </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel