<?php
/**
*
* @package phpBB3
* @version $Id: functions_sitemap_fx.php,v 1.0.5 9467 2009-08-17 20:46:39Z FladeX Exp $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* Generate sitemap
*/
function sitemap_fx_forum($forum_id)
{
global $sitemap_config;
$url = make_url('/');
$sitemap_file = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$sitemap_file .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sql = 'SELECT topic_id, forum_id, topic_last_post_time, topic_type, topic_replies
FROM ' . BB_TOPICS . '
WHERE forum_id = ' . $forum_id;
$result = DB()->sql_query($sql);
while ($row = DB()->sql_fetchrow($result))
{
$lastmod = date($row['topic_last_post_time']);
$pages = $row['topic_replies'] / $sitemap_config['posts_per_page'];
$pages = (int) $pages;
for ($i=0; $i<=$pages; $i++)
{
$sitemap_file .= "<url>\n";
if ($i == 0)
{
$sitemap_file .= "<loc>" . $url . "viewtopic.php?f=" . $row['forum_id'] . "&t=" . $row['topic_id'] . "</loc>\n";
}
else
{
$sitemap_file .= "<loc>" . $url . "viewtopic.php?f=" . $row['forum_id'] . "&t=" . $row['topic_id'] . "&start=" . $i * $sitemap_config['posts_per_page'] . "</loc>\n";
}
$sitemap_file .= "<lastmod>" . $lastmod = Date('Y-m-d') . "</lastmod>\n";
switch ($row['topic_type'])
{
case POST_NORMAL:
$sitemap_file .= "<changefreq>" . $sitemap_config['sitemap_freq_0'] . "</changefreq>\n";
$sitemap_file .= "<priority>" . $sitemap_config['sitemap_priority_0'] . "</priority>\n";
break;
case POST_STICKY:
$sitemap_file .= "<changefreq>" . $sitemap_config['sitemap_freq_1'] . "</changefreq>\n";
$sitemap_file .= "<priority>" . $sitemap_config['sitemap_priority_1'] . "</priority>\n";
break;
case POST_ANNOUNCE:
$sitemap_file .= "<changefreq>" . $sitemap_config['sitemap_freq_2'] . "</changefreq>\n";
$sitemap_file .= "<priority>" . $sitemap_config['sitemap_priority_2'] . "</priority>\n";
break;
default:
$sitemap_file .= "<changefreq>" . $sitemap_config['sitemap_freq_0'] . "</changefreq>\n";
$sitemap_file .= "<priority>" . $sitemap_config['sitemap_priority_0'] . "</priority>\n";
}
$sitemap_file .= "</url>\n";
}
}
DB()->sql_freeresult($result);
$sitemap_file .= "</urlset>\n";
$w=fopen("sitemap/$forum_id.xml",'w');
fwrite($w,$sitemap_file);
fclose($w);
}
function sitemap_fx_global($forum_id)
{
global $sitemap_config;
$url = make_url('/');
$sitemap_file = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$sitemap_file .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sql = 'SELECT topic_id, forum_id, topic_title, topic_last_post_time, topic_type, topic_replies
FROM ' . BB_TOPICS . '
WHERE topic_type = ' . POST_NORMAL;
$result = DB()->sql_query($sql);
if (DB()->sql_fetchrow($result))
{
while ($row = DB()->sql_fetchrow($result))
{
$lastmod = date($row['topic_last_post_time']);
$pages = $row['topic_replies'] / $sitemap_config['posts_per_page'];
$pages = (int) $pages;
for ($i=0; $i<=$pages; $i++)
{
$sitemap_file .= "<url>\n";
if ($i == 0)
{
$sitemap_file .= "<loc>" . $url . "viewtopic.php?f=" . $forum_id . "&t=" . $row['topic_id'] . "</loc>\n";
}
else
{
$sitemap_file .= "<loc>" . $url . "viewtopic.php?f=" . $forum_id . "&t=" . $row['topic_id'] . "&start=" . $i * $sitemap_config['posts_per_page'] . "</loc>\n";
}
$sitemap_file .= "<lastmod>" . $lastmod = Date('Y-m-d') . "</lastmod>\n";
$sitemap_file .= "<changefreq>" . $sitemap_config['sitemap_freq_3'] . "</changefreq>\n";
$sitemap_file .= "<priority>" . $sitemap_config['sitemap_priority_3'] . "</priority>\n";
$sitemap_file .= "</url>\n";
}
}
}
DB()->sql_freeresult($result);
$sql = 'SELECT forum_id
FROM ' . BB_FORUMS;//, forum_type
$result = DB()->sql_query($sql);
if (DB()->sql_fetchrow($result))
{
while ($row = DB()->sql_fetchrow($result))
{
//if ($row['forum_type'] == 1)
//{
$sitemap_file .= "<url>\n";
$sitemap_file .= "<loc>" . $url . "viewforum.php?f=" . $row['forum_id'] . "</loc>\n";
$sitemap_file .= "<lastmod>" . Date('Y-m-d') . "</lastmod>\n";
$sitemap_file .= "<changefreq>daily</changefreq>\n";
$sitemap_file .= "<priority>1</priority>\n";
$sitemap_file .= "</url>\n";
//}
}
}
DB()->sql_freeresult($result);
$sitemap_file .= "</urlset>\n";
$w=fopen("sitemap/0.xml", 'w');
fwrite($w, $sitemap_file);
fclose($w);
}
?>