Created
September 11, 2019 07:57
-
-
Save IgorMiroshin/2ab846cb47e8b64e8bb26ec4505d5bdd to your computer and use it in GitHub Desktop.
Автогенерация HTML-карты сайта на основе sitemap.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php"); | |
$APPLICATION->SetTitle("Карта сайта"); | |
require($_SERVER["DOCUMENT_ROOT"] . "/local/include/page_header.php"); | |
?> | |
<h1 class="pile-content-title">Карта сайта</h1> | |
<ul> | |
<?php | |
$host = $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_HOST'] . '/'; | |
$siteMap = simplexml_load_file("../sitemap.xml"); | |
$siteMapArray = []; | |
foreach ($siteMap->url as $url) { | |
$link = $url->loc; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $link); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 15); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
preg_match('#<h1.*?>(.*)<\/h1>#', $result, $m); | |
$explodeLink = explode('/', str_replace($host, '', $link)); | |
$explodeLink = array_filter($explodeLink); | |
if (count($explodeLink) < 2) { | |
$siteMapArray[$explodeLink[0]] = [ | |
'link' => $link, | |
'name' => $m[1], | |
]; | |
?> | |
<li> | |
<a href="<?= $siteMapArray[$explodeLink[0]]['link'] ?>"> | |
<? if ($link == $host) { | |
echo 'Главная'; | |
} else { | |
echo $m[1]; | |
} | |
?> | |
</a> | |
</li> | |
<? | |
} else { | |
$siteMapArray[$explodeLink[1]] = [ | |
'link' => $link, | |
'name' => $m[1], | |
'parent' => $siteMapArray[$explodeLink[0]] | |
]; | |
?> | |
<ul> | |
<li> | |
<a href="<?= $link ?>"> | |
<? echo $m[1]; ?> | |
</a> | |
</li> | |
</ul> | |
<!--<li> | |
<a href="<?/*= $siteMapArray[$explodeLink[1]]['parent']['link'] */?>"> | |
<?/* echo $siteMapArray[$explodeLink[1]]['parent']['name']; */?> | |
</a> | |
<ul> | |
<li> | |
<a href="<?/*= $siteMapArray[$explodeLink[1]]['link'] */?>"> | |
<?/* echo $siteMapArray[$explodeLink[1]]['name']; */?> | |
</a> | |
</li> | |
</ul> | |
</li>--> | |
<? | |
} | |
} | |
?> | |
</ul> | |
<? | |
require($_SERVER["DOCUMENT_ROOT"] . "/local/include/page_footer.php"); | |
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment