<?php
require('includes/cmain.inc.php');
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;

$query = "SELECT * FROM `tbl_blog` order by post_date DESC";
$result = db_query($query);

while ($row = mysqli_fetch_array($result)) {
    echo '<url>' . PHP_EOL;
    echo '<loc>'. SITE_WS_PATH.'/knowledge-base/'. strtolower(str_replace(" ","-",$row["heading"])) .'</loc>' . PHP_EOL;
    /* Convert the date format to W3C Datetime format in UTC*/
    $w3cDatetime = gmdate('c', strtotime($row['post_date']));
    echo '<lastmod>' . $w3cDatetime . '</lastmod>' . PHP_EOL;
    echo '<priority>0.80</priority>' . PHP_EOL;
    echo '</url>' . PHP_EOL;
}

echo '</urlset>' . PHP_EOL;
?>