Site Builder
Editing:
new-sitemap1.php
writable 0666
<?php // Where to look for businesses $phDir = $_SERVER['DOCUMENT_ROOT'] . '/../ph/'; if (!is_dir($phDir)) $phDir = $_SERVER['DOCUMENT_ROOT'] . '/ph/'; // Where to save the sitemap $outFile = __DIR__ . '/new-sitemap.xml'; $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $urls = []; foreach (scandir($phDir) as $d) { if (!preg_match('/^\d{10}$/', $d)) continue; $dir = $phDir . $d; if (!is_dir($dir)) continue; if (is_readable("$dir/business.json")) $json = "$dir/business.json"; elseif (is_readable("$dir/new-business.json")) $json = "$dir/new-business.json"; else continue; $mtime = filemtime($json); $urls[] = [ 'loc' => "$baseUrl/ph/$d/", 'lastmod' => date('Y-m-d', $mtime), 'priority' => is_readable("$dir/business.json") ? '0.9' : '0.6' ]; } // Build XML $xml = new DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; $urlset = $xml->createElement('urlset'); $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($urls as $u) { $url = $xml->createElement('url'); $loc = $xml->createElement('loc', $u['loc']); $url->appendChild($loc); $lastmod = $xml->createElement('lastmod', $u['lastmod']); $url->appendChild($lastmod); $priority = $xml->createElement('priority', $u['priority']); $url->appendChild($priority); $urlset->appendChild($url); } $xml->appendChild($urlset); // Save the file file_put_contents($outFile, $xml->saveXML()); // Show result header('Content-Type: text/html; charset=utf-8'); echo "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'><title>Sitemap Generated</title> <style>body{font-family:sans-serif;background:#f9fbff;color:#234;margin:3em;}a{color:#1257c7;}</style> </head><body>"; echo "<h2>✅ Sitemap created!</h2>"; echo "<p><b>File:</b> <a href='new-sitemap.xml' target='_blank'>new-sitemap.xml</a> (" . count($urls) . " URLs)</p>"; if (count($urls)) { echo "<ol>"; foreach (array_slice($urls, 0, 20) as $u) { echo "<li><a href='" . htmlspecialchars($u['loc']) . "' target='_blank'>" . htmlspecialchars($u['loc']) . "</a> <span style='color:#999'>(lastmod: {$u['lastmod']})</span></li>"; } if (count($urls) > 20) echo "<li>...and more</li>"; echo "</ol>"; } echo "<p style='margin-top:2em;'><a href='new-sitemap.xml' target='_blank'>Download new-sitemap.xml</a></p>"; echo "</body></html>"; ?>
Save changes
Create folder
writable 0777
Create
Cancel