+ -
当前位置:首页 → 问答吧 → PHPBB3的百度sitemap生成器

PHPBB3的百度sitemap生成器

时间:2009-12-13

来源:互联网

PHPBB是一个在国外非常流行的论坛系统,但是对SEO的支持不太好。
PHPBB没有对百度支持的sitemap,只好自己写了一个。
<?php error_reporting(0); define('IN_PHPBB', true); $phpbb_root_path = './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'config.' . $phpEx); include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false); if(PHP_VERSION < '4.1.0') { $_GET = &$HTTP_GET_VARS; $_SERVER = &$HTTP_SERVER_VARS; } $maxitemnum = 500; $timestamp = time(); $PHP_SELF = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $boardurl = 'http://'.$_SERVER['HTTP_HOST'].substr($PHP_SELF, 0, strrpos($PHP_SELF, '/') + 1); $sitemapfile = $phpbb_root_path.'./cache/baidu_sitemap.xml'; echo $xmlfiletime = @filemtime($sitemapfile); header("Content-type: application/xml"); $xmlcontent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". "<document xmlns:bbs=\"http://www.baidu.com/search/bbs_sitemap.xsd\">\n"; if($timestamp - $xmlfiletime >= 8 * 3600) { $xmlfiletime = $timestamp - 8 * 3600; $sql = 'SELECT * FROM '.$table_prefix.'topics WHERE topic_time > '.$xmlfiletime.' LIMIT '.$maxitemnum; $result = $db->sql_query($sql); $xmlcontent .= " <webSite>$boardurl</webSite>\n". " <webMaster>[email][email protected][/email]</webMaster>\n". " <updatePeri>8</updatePeri>\n". " <updatetime>".gmdate('Y-m-d H:i:s', $timestamp + 8 * 3600)."</updatetime>\n". " <version>PHPrimer v0.1</version>\n"; while ($data=$db->sql_fetchrow($result)) { print_r($data); $xmlcontent .= " <item>\n". " <link>{$boardurl}viewforum.php?f={$data['forum_id']}&t={$data['topic_id']}</link>\n". " <title>".htmlspecialchars($data['topic_title'])."</title>\n". " <pubDate>".gmdate('Y-m-d H:i:s', $data['topic_time'] + 8 * 3600)."</pubDate>\n". " <bbs:lastDate>".gmdate('Y-m-d H:i:s', $data['topic_last_post_time'] + 8 * 3600)."</bbs:lastDate>\n". " <bbs:reply>$data[topic_replies]</bbs:reply>\n". " <bbs:hit>$data[topic_views]</bbs:hit>\n". " <bbs:boardid>$data[forum_id]</bbs:boardid>\n". " <bbs:pick>".(intval($data['topic_type']) ? 1 : 0)."</bbs:pick>\n". " </item>\n"; } $xmlcontent .= "</document>"; if($fp = @fopen($sitemapfile, 'w')) { fwrite($fp, $xmlcontent); flock($fp, 2); fclose($fp); } echo $xmlcontent; } else { @readfile($sitemapfile); }

作者: neaton   发布时间: 2009-12-13

ji.qing.pian,

作者: dianying   发布时间: 2010-02-28

热门下载

更多