Site Builder
Editing:
modules-performance.php
writable 0666
<?php /************************************************************************** * PAGE PERFORMANCE MODULE (v1.1 – gold card, no external fetch) * – Fixes double‑https bug by sending plain URLs to PSI **************************************************************************/ /* 1. Get $profile if the parent page hasn’t already */ if (!isset($profile) && function_exists('get_profile')) { $profile = get_profile(); } /* 2. Helper: normalise user‑typed domains --------------------------------*/ function normalise(string $url): string { $url = trim($url); if ($url === '') return ''; /* prepend https:// if missing */ if (!preg_match('#^https?://#i', $url)) { $url = 'https://' . $url; } /* collapse repeated protocol tokens */ $url = preg_replace('#^(https?://)+#i', 'https://', $url); /* strip stray whitespace / zero‑width chars */ $url = preg_replace('/[^\S\r\n]+/', '', $url); return rtrim($url, '/'); } /* 3. Build target URLs & score ------------------------------------------ */ $pageURL = 'https://' . $_SERVER['HTTP_HOST'] . strtok($_SERVER['REQUEST_URI'], '?'); // current page $siteURL = normalise($profile['website'] ?? ''); // business website $score = (int)($profile['pagespeed_score'] ?? 100); $score = max(0, min(100, $score)); // 0‑100 clamp if (!$pageURL && !$siteURL) return; // nothing to test /* Google PSI endpoint */ $psi = 'https://pagespeed.web.dev/report?url='; ?> <!-- ===== PAGE PERFORMANCE ===== --> <section class="pp-shell"> <div class="pp-card"> <h2>📈 Page Performance</h2> <!-- score gauge --> <div class="pp-gauge"> <svg width="120" height="120" viewBox="0 0 42 42"> <circle cx="21" cy="21" r="18" fill="none" stroke="#e5effb" stroke-width="4"/> <circle cx="21" cy="21" r="18" fill="none" stroke="#1ec57d" stroke-width="4" stroke-dasharray="<?= $score * 1.13 ?> 113" stroke-linecap="round" transform="rotate(-90 21 21)"/> <text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-size="11" font-weight="700" fill="#0e4b24"><?= $score ?></text> </svg> <div class="label">Performance</div> </div> <!-- action buttons --> <div class="pp-actions"> <?php if ($pageURL): ?> <button data-url="<?= $psi . $pageURL ?>"> Test This Page </button> <?php endif; ?> <?php if ($siteURL): ?> <button data-url="<?= $psi . $siteURL ?>"> Test Website </button> <?php endif; ?> </div> </div> </section> <style> /* same “gold‑card” styling used across modules */ .pp-shell{margin:2.6rem auto;max-width:clamp(480px,70vw,720px);width:100%; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif} .pp-card {background:#fff;padding:1.8rem 1.6rem;border:3.5px solid #ffb63b; border-radius:27px;box-shadow:0 8px 26px rgba(0,0,0,.06);text-align:center} .pp-card h2{margin:0 0 1.2rem;font-size:1.35rem;font-weight:700;color:#102a66} .pp-gauge{display:inline-flex;flex-direction:column;align-items:center;margin-bottom:1.2rem} .pp-gauge .label{margin-top:.4rem;font-size:.95rem;color:#0e4b24;font-weight:600} .pp-actions{display:flex;gap:1rem;justify-content:center;flex-wrap:wrap} .pp-actions button{ background:#ffb63b;border:none;border-radius:9px;padding:.65em 1.6em; font-weight:700;font-size:1rem;color:#000;cursor:pointer; box-shadow:0 2px 6px rgba(0,0,0,.08);transition:background .15s} .pp-actions button:hover{background:#ffa726} @media(max-width:500px){.pp-actions button{flex:1 1 100%}} </style> <script> /* open PSI report in a new tab */ document.querySelectorAll('.pp-actions button') .forEach(btn=>btn.onclick=()=>window.open(btn.dataset.url,'_blank')); </script>
Save changes
Create folder
writable 0777
Create
Cancel