<?

//http://www.google.com/ping?sitemap=https://example.com/sitemap.xml - сообщить гуглу об обновлениях в сайтмапе, см. //https://support.google.com/webmasters/answer/6065812?hl=ru

include ($_SERVER['DOCUMENT_ROOT']."/i_config.php");

$list = array();

//include ($_SERVER['DOCUMENT_ROOT']."/i_sitemap_static.php"); // перепарсить!

foreach ($folders as $parsedcontentfolder) 
{

$folder=$parsedcontentfolder.'-raw';

include($_SERVER['DOCUMENT_ROOT']."/".$folder.'/scandir.php');



if (!(count($healthfiles)>0))
{
$healthfiles=scandir($_SERVER['DOCUMENT_ROOT']."/".$folder); // массив всех файлов папки
$hf=var_export($healthfiles, TRUE);

file_put_contents($_SERVER['DOCUMENT_ROOT']."/".$folder.'/scandir.php', '<? $healthfiles='.$hf.'; ?>');
}
 

//$healthfiles=scandir ($_SERVER['DOCUMENT_ROOT']."/".$parsedcontentfolder.'-raw');
unset($healthfiles[array_search('replace.php',$healthfiles)]);
unset($healthfiles[array_search('scandir.php',$healthfiles)]);

array_pop($healthfiles); 
unset($healthfiles[0],$healthfiles[1]);

for ($i=0; $i<count($healthfiles); $i++) { $healthfiles[$i] = str_ireplace('-raw','',$folder).'/'.$healthfiles[$i]; }

$list = array_merge($list, $healthfiles);

//print_r ($list); echo "*********************************************";

}

//echo "+++++++++++++++++++++++++++++++++++";
//print_r( $list); exit;

if (count($list)<50000 || isset($_GET['from'])) {  // если менее 50 000 страниц - сайтмап один

echo"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
<url>
            <loc>https://<? echo $_SERVER['HTTP_HOST']."/";?></loc>
            <priority>1</priority>
</url>

<?

$from=isset($_GET['from']) ? $_GET['from'] : 0;
$to=(isset($_GET['to']) && !isset($_GET['last'])) ? $_GET['to'] : count($list);

for ($i = $from; $i <= $to; $i++)

{

$url=$list[$i];

?>



        <url>
            <loc>https://<? echo $_SERVER['HTTP_HOST']."/".$url;?></loc>
            <priority>0.8</priority>
        </url>
<?
}

/*    http://www.example.com/page1.html</loc>
            <lastmod>2005-01-01</lastmod>
            <changefreq>daily</changefreq>
            <priority>0.8</priority>
        </url>
    </urlset>
*/
?>
</urlset>

<?

}
else {

echo"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";


?>


<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<?

for ($j=0; $j<=intdiv(count($list), 49000); $j++) {

?>

   <sitemap>

      <loc>https://<?=$_SERVER['HTTP_HOST'];?>/sitemap.xml?from=<?=$j*49000;?>&amp;to=<?=($j+1)*49000;?>
<? if ($j==intdiv(count($list), 49000)) { echo '&amp;last=1'; } ?>
</loc>

   </sitemap>

<?

}

?>

</sitemapindex>

<?

}

?>