<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
if ($userdata['user_level'] != ADMIN)
{
message_die(GENERAL_MESSAGE, 'nur für Admins');
exit;
}
//$cache_data_file = $phpbb_root_path."sitemap.xml";
$cache_data_file = $phpbb_root_path."sitemap.xml.gz";
if (@is_file($cache_data_file))
{
$valid = (date('YzH',time()) - date('YzH',@filemtime($cache_data_file))<23) ? true : false;
} else
{
$valid = false;
}
if ($valid )
{
message_die(GENERAL_MESSAGE, 'noch aktuell');
exit;
} else
{
// erzeugen Daten
$sitemap = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap .= "<urlset xmlns=\"
http://www.google.com/schemas/sitemap/0.84\"\n";
$sitemap .= "xmlns:xsi=\"
http://www.w3.org/2001/XMLSchema-instance\"\n";
$sitemap .= "xsi:schemaLocation=\"
http://www.google.com/schemas/sitemap/0.84\n";
$sitemap .= "
http://www.google.com/schemas/sitemap/0 ... p.xsd\">\n";
$sql = "SELECT MAX(topic_views) as maxviews FROM " . TOPICS_TABLE;
if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not obtain sitemap information', '', __LINE__, __FILE__, $sql);
$row = $db->sql_fetchrow($result);
$maxviews = $row['maxviews'];
$sql = "SELECT t.topic_id, t.topic_time, t.topic_views, t.topic_replies, p.post_time
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " AS p
WHERE f.forum_id = t.forum_id
AND f.auth_view = " . AUTH_ALL . "
AND p.post_id = t.topic_last_post_id
ORDER BY t.topic_last_post_id DESC
LIMIT 50000";
if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not obtain sitemap information', '', __LINE__, __FILE__, $sql);
while ($row = $db->sql_fetchrow($result))
{
// Ausrechnen der avg. Aktualisierungszeit
//"always", "hourly", "daily", "weekly", "monthly", ("yearly" and "never")
$avgtime = ((time()-$row['topic_time'])/($row['topic_replies']+1))/3600;
if ($avgtime < 1) $changefreq = "always";
else if ($avgtime < 24) $changefreq = "hourly";
else if ($avgtime < 168) $changefreq = "daily";
else if ($avgtime < 5040) $changefreq = "weekly";
else $changefreq = "monthly";
//Priorität bezogen auf die Views (quadratisch)
$priority = round( sqrt($row['topic_views']/$maxviews), 1);
if ($priority >= 1) $priority = "1.0";
else if ($priority <= 0) $priority = "0.0";
//Zeit des letzten Beitrags
$iso8601_time = date('Y-m-d\TH:i:s', $row['post_time']) . substr(chunk_split(date('O',$row['post_time']), 3, ':'),0,6);
// Ausgabe der einzelnen Seiten
for($post=0; $post<=$row['topic_replies']; $post+=$board_config['posts_per_page'])
{
$add = ($post>0) ? "&start=".$post : "";
$sitemap .= "<url>\n";
$sitemap .= "<loc>http://".$board_config['server_name'].$board_config['script_path']."viewtopic.php?t=".$row['topic_id'].$add."</loc>\n";
$sitemap .= "<lastmod>".$iso8601_time."</lastmod>\n";
$sitemap .= "<changefreq>".$changefreq."</changefreq>\n";
$sitemap .= "<priority>".$priority."</priority>\n";
$sitemap .= "</url>\n";
}
}
$sitemap .= "</urlset>";
// Schreibe File
/* $fileName = fopen ($cache_data_file, 'w');
fputs ($fileName, $sitemap);
fclose ($fileName); */
$fileName = gzopen($cache_data_file, "w9");
gzwrite($fileName, $sitemap);
gzclose($fileName);
}
message_die(GENERAL_MESSAGE, 'Fertig');
?>