PHPBB3的百度sitemap生成器代码
<?php
02 error_reporting(0);
03 define('IN_PHPBB', true);
04 $phpbb_root_path = './';
05 $phpEx = substr(strrchr(__FILE__, '.'), 1);
06
07 include($phpbb_root_path . 'config.' . $phpEx);
08 include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
09
10 $db = new $sql_db();
11
12 $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
13
14 if(PHP_VERSION < '4.1.0') {
15 $_GET = &$HTTP_GET_VARS;
16 $_SERVER = &$HTTP_SERVER_VARS;
17 }
18
19
20 $maxitemnum = 500;
21 $timestamp = time();
22 $PHP_SELF = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
23 $boardurl = 'http://'.$_SERVER['HTTP_HOST'].substr($PHP_SELF, 0, strrpos($PHP_SELF, '/') + 1);
24
25 $sitemapfile = $phpbb_root_path.'./cache/baidu_sitemap.<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=xml">xml</SPAN>';
26 echo $xmlfiletime = @filemtime($sitemapfile);
27
28 header("Content-type: application/xml");
29
30 $xmlcontent = "<?xml version="1.0" encoding="utf-8"?>n".
31 "<document xmlns:bbs="n">http://www.baidu.com/search/bbs_sitemap.xsd">n";
32
33 if($timestamp - $xmlfiletime >= 8 * 3600) {
34 $xmlfiletime = $timestamp - 8 * 3600;
35
36 $sql = 'SELECT * FROM '.$table_prefix.'topics WHERE topic_time > '.$xmlfiletime.' LIMIT '.$maxitemnum;
37 $result = $db->sql_query($sql);
38
39 $xmlcontent .= " <webSite>$boardurl</webSite>n".
40 " <webMaster>[email]admin@phprimer.com[/email]</webMaster>n".
41 " <updatePeri>8</updatePeri>n".
42 " <updatetime>".gmdate('Y-m-d H:i:s', $timestamp + 8 * 3600)."</updatetime>n".
43 " <version>PHPrimer v0.1</version>n";
44
45 while ($data=$db->sql_fetchrow($result)) {
46 print_r($data);
47 $xmlcontent .= " <item>n".
48 " <link>{$boardurl}viewforum.php?f={$data['forum_id']}&t={$data['topic_id']}</link>n".
49 " <title>".<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=html">html</SPAN>specialchars($data['topic_title'])."</title>n".
50 " <pubDate>".gmdate('Y-m-d H:i:s', $data['topic_time'] + 8 * 3600)."</pubDate>n".
51 " <bbs:lastDate>".gmdate('Y-m-d H:i:s', $data['topic_last_<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=post">post</SPAN>_time'] + 8 * 3600)."</bbs:lastDate>n".
52 " <bbs:reply>$data[topic_replies]</bbs:reply>n".
53 " <bbs:hit>$data[topic_views]</bbs:hit>n".
54 " <bbs:boardid>$data[forum_id]</bbs:boardid>n".
55 " <bbs:pick>".(intval($data['topic_type']) ? 1 : 0)."</bbs:pick>n".
56 " </item>n";
57 }
58
59 $xmlcontent .= "</document>";
60 if($fp = @fopen($sitemapfile, 'w')) {
61 fwrite($fp, $xmlcontent);
62 flock($fp, 2);
63 fclose($fp);
64 }
65
66 echo $xmlcontent;
67
68 } else {
69
70 @readfile($sitemapfile);
71
72 }