<?php
/***************************************************************************
 *             googlesitemapgenerator.php for PunRewrite
 *                            -------------------
 *
 *   Modified by keyes - http://placelibre.ath.cx/keyes/
 *
 *   Based on the script originally by http://www.pentapenguin.com
 *   and modified by Smartys for use with PunBB
 *   Last Modified: 11/27/05
 *
 *   NOTE: Use ONLY if you have installed the PunOOgle PunBB mod!
 *         If you do NOT have this mod installed, please use the Google
 *         Sitemap Generator by Smartys at http://www.punres.org/desc.php?pid=90
 *
 ***************************************************************************/
 
/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('PUN_QUIET_VISIT'1);
define('PUN_ROOT''./');
require 
PUN_ROOT.'include/common.php';

// false = write to file, true = dynamic
$dynamic true;

// This only matters if you're writing to the file
$filename 'sitemap.xml';


// Get the topics
$result $db->query('SELECT t.id as topic_id, subject, last_post, sticky FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL ORDER BY last_post DESC') or error('Unable to fetch topic list'__FILE____LINE__$db->error());

// Get the forums
$result2 $db->query('SELECT f.id as forum_id, forum_name, last_post FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY f.id DESC') or error('Unable to fetch forum list'__FILE____LINE__$db->error());


$output '<' '?xml version="1.0" encoding="UTF-8"?' '>' "\n";
$output .= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' "\n";

// The board itself
$output .= "<url>\n";
$output .= "\t<loc>".$pun_config['o_base_url']."/"  "</loc>\n";
$output .= "\t<lastmod>".gmdate('Y-m-d\TH:i:s+00:00'time())."</lastmod>\n";
$output .= "\t<priority>1.0</priority>\n";
$output .= "</url>\n\n";


// Output the data for the forums
while ($cur_forum $db->fetch_assoc($result2))
{
    
$lastmodified gmdate('Y-m-d\TH:i:s+00:00'$cur_forum['last_post']);
    
$viewforum 'forum-'.$cur_forum['forum_id'].'-'.pun_url($cur_forum['forum_name']);
    
$priority '1.0';
    
    
$output .= "<url>\n";
    
$output .= "\t<loc>".$pun_config['o_base_url']."/$viewforum</loc>\n";
    
$output .= "\t<lastmod>$lastmodified</lastmod>\n";
    
$output .= "\t<priority>$priority</priority>\n";
    
$output .= "</url>\n\n";
}

// Output the data for the topics
while ($cur_topic $db->fetch_assoc($result))
{
    
$lastmodified gmdate('Y-m-d\TH:i:s+00:00'$cur_topic['last_post']);
    
$viewtopic 'sujet-'.$cur_topic['topic_id'].'-'.pun_url($cur_topic['subject']);
    
$priority = ($cur_topic['sticky'] == '1') ? '1.0' '0.5';
    
    
$output .= "<url>\n";
    
$output .= "\t<loc>".$pun_config['o_base_url']."/$viewtopic"  "</loc>\n";
    
$output .= "\t<lastmod>$lastmodified</lastmod>\n";
    
$output .= "\t<priority>$priority</priority>\n";
    
$output .= "</url>\n\n";
}
$output .= "</urlset>\n";

// If we chose dynamic, we output the sitemap
// Otherwise, we write it to the file
if ($dynamic)
{
    
header('Content-type: application/xml');
    echo 
$output;
}
else
{
    
$file fopen($filename"w");
    
fwrite($file$output);
    
fclose($file);
    echo 
"Done";
}
?>