<?php
include_once('script/constant.php');

$result='<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">';
//MAIN /PHOTOs/ AND /VIDEOs/
$query="SELECT `date` FROM `photos_gallery` WHERE `public`=1 ORDER BY id DESC LIMIT 1";
$link=mysqli_connect(HOST,USER,PASS,DB_NAME);
mysqli_query($link, "SET NAMES utf8");
$sql=mysqli_query($link, $query);
$row=mysqli_fetch_assoc($sql);
$result .= '
<url>
<loc>https://lezbiyanki.net/</loc>
<lastmod>'. gmdate('Y-m-d\TH:i:sP', $row['date']).'</lastmod>
</url>';
//SECTION PHOTOS
$query="SELECT `get_name` FROM `photos_categories`";
$sql=mysqli_query($link, $query);
$row=mysqli_fetch_assoc($sql);
$i=1;
while($row=mysqli_fetch_assoc($sql)){
$getname_photo[$i]=$row['get_name'];
$i++;}
for($i=1;$i<=21;$i++){
$query="SELECT `date` FROM `photos_gallery` WHERE `section_num`=$i and `public`=1 ORDER BY id DESC LIMIT 1";
$sql=mysqli_query($link, $query);
$row=mysqli_fetch_assoc($sql);
$result .= '
<url>
<loc>https://lezbiyanki.net/photos/'.$getname_photo[$i].'/</loc>
<lastmod>'. gmdate('Y-m-d\TH:i:sP', $row['date']).'</lastmod>
</url>';}
//ALL GALLERY PHOTO
$query="SELECT `id`, `get_name`, `section_num`, `number`, `date`, `date_com` FROM `photos_gallery` WHERE `public`=1 ORDER BY id DESC";
$sql=mysqli_query($link, $query);
while($row=mysqli_fetch_assoc($sql)){
if(empty($row['date_com'])){$date=$row['date'];}
else $date=$row['date_com'];

if(empty($row['get_name'])){$path='photos/'.$getname_photo[$row['section_num']].'/'.$row['number'];}
else{$path='gallery/'.$row['id'].'/'.$row['get_name'];}

$result .= '
<url>
<loc>https://lezbiyanki.net/'.$path.'/</loc>
<lastmod>'. gmdate('Y-m-d\TH:i:sP', $date).'</lastmod>
</url>';}

$result .= '
</urlset>';

mysqli_close($link);
header('Content-Type: text/xml; charset=utf-8');
echo $result;
?>