<?php
header('Content-Type: application/xml; charset=UTF-8');

require_once('blogData/inc/functions.php');

$order = empty($_GET['s']) ? 'd' : $_GET['s'];

echo '<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sitemap.xsl?s='.$order.'"?>';
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
 <url>
  <loc>http://floern.com/</loc>
  <lastmod><?php echo date('Y-m-d', floor(time()/160000)*160000); ?></lastmod>
  <changefreq>always</changefreq>
  <priority>1.0</priority>
 </url>
<?php
$SHX_BLOG_FILE = 'blogData/content/posts.xml';
$entries = getNewestEntry(999999, $SHX_BLOG_FILE);
$newest = current($entries);
$post = getXMLvalue($SHX_BLOG_FILE, '/blog/post[@id="'.$newest.'"]');
?>
 <url>
  <loc>http://floern.com/blog</loc>
  <lastmod><?php echo date('Y-m-d', (int)$post->stime); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
<?php
natsort($entries);
foreach($entries as $postid){ # Linkliste schreiben
  $post = getXMLvalue($SHX_BLOG_FILE, '/blog/post[@id="'.$postid.'"]');
  echo ' <url>
  <loc>http://floern.com/blog/'.urlencodeutf($postid).'</loc>
  <lastmod>'.date('Y-m-d', (int)$post->stime).'</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
';
}

include_once('inc/xmlDBclass.php');
$imgDB = new xml_db;
$imgDB->open('artworkData/content.xml');
$entries = $imgDB->select(array('id','time'), array(), array('time'=>'DESC'));
reset($entries);
$newest = current($entries);
?>
 <url>
  <loc>http://floern.com/microblog</loc>
  <lastmod><?php echo date('Y-m-d', floor(time()/175000)*175000); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.7</priority>
 </url>
 <url>
  <loc>http://floern.com/artwork</loc>
  <lastmod><?php echo date('Y-m-d', $newest['time']); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
<?php
foreach($entries as $entry){
  echo ' <url>
  <loc>http://floern.com/artwork/'.$entry['id'].'</loc>
  <lastmod>'.date('Y-m-d', $entry['time']).'</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
';
}
?>
<?php
$SHX_BLOG_FILE = 'webscriptingData/content/posts.xml';
$entries = getNewestEntry(999999, $SHX_BLOG_FILE);
$newest = current($entries);
$post = getXMLvalue($SHX_BLOG_FILE, '/blog/post[@id="'.$newest.'"]');
$lmtime = (int)$post->stime;
?>
 <url>
  <loc>http://floern.com/webscripting</loc>
  <lastmod><?php echo date('Y-m-d', $lmtime); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
<?php
natsort($entries);
foreach($entries as $postid){ # Linkliste schreiben
  $post = getXMLvalue($SHX_BLOG_FILE, '/blog/post[@id="'.$postid.'"]');
  $lmtime = (int)$post->stime;
  echo ' <url>
  <loc>http://floern.com/webscripting/'.urlencodeutf($postid).'</loc>
  <lastmod>'.date('Y-m-d', $lmtime).'</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
';
}
?>
 <url>
  <loc>http://floern.com/tools</loc>
  <lastmod><?php echo date('Y-m-d', filemtime('toolsData/index.php')); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
<?php
include('toolsData/entries.php');
ksort($tools_sites);
foreach($tools_sites as $link => $name){
  $filename = 'toolsData/'.$link.'.php';
  echo ' <url>
  <loc>http://floern.com/tools/'.$link.'</loc>
  <lastmod>'.date('Y-m-d', (file_exists($filename))?filemtime($filename):0).'</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
';
}
?>
 <url>
  <loc>http://floern.com/software</loc>
  <lastmod><?php echo date('Y-m-d', filemtime('softwareData/index.php')); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
 </url>
<?php
include('softwareData/entries.php');
ksort($software_sites);
foreach($software_sites as $link => $name){
  $filename = 'softwareData/'.$link.'.php';
  echo ' <url>
  <loc>http://floern.com/software/'.$link.'</loc>
  <lastmod>'.date('Y-m-d', (file_exists($filename))?filemtime($filename):0).'</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
';
}
?>
 <url>
  <loc>http://floern.com/sitemap</loc>
  <lastmod><?php echo date('Y-m-d', floor(time()/250000)*250000); ?></lastmod>
  <changefreq>daily</changefreq>
  <priority>0.5</priority>
 </url>
 <url>
  <loc>http://floern.com/kontakt</loc>
  <lastmod><?php echo date('Y-m-d', filemtime('kontakt.php')); ?></lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
 <url>
  <loc>http://floern.com/lizenz</loc>
  <lastmod><?php echo date('Y-m-d', filemtime('lizenz.php')); ?></lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
 </url>
</urlset>