PHP中BB生成sitemap地图文件的方法
本文介绍下,在PHPBB论坛中生成sitemap地图文件的实现代码,感兴趣的朋友参考学习下。
将以下PHP文件放到网站的根目录。
加入此sitemap的前提:
必须将PHPBB论坛的默认URL规格改成以下文件里生成的'格式。
具体方法,请参考:
注意:
红色部分的代码,修改成自己网站对应的内容:
复制代码 代码示例:
<?php
// By: Arlinger On 2012-6-4
//
// CUSTOM INSTALLATION VARIABLES:
$subdomain='www.';
$domain=' '; //这里要改成你的网站名
$folder='/forum/'; //这里要改成你把博客所在的文件夹的名字
$urls=50000;
// Change Nothing Below Here:
$domainpath='http://'.$subdomain.$domain.$folder;
// Connect
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);
// Gzip compression
if (@extension_loaded('zlib') && !headers_sent())
{
ob_start('ob_gzhandler');
}
// Send Header
header("Content-Type: text/xml;charset=iso-8859-1");
// Send initial Data
echo '<?xml version="1.0" encoding="UTF-8"?>'."n";
echo '<urlset xmlns="">'."n";
// Send Index
$current_time=time();
echo '<url>
<loc>'.$domainpath.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$current_time).'</lastmod>
</url>';
$urls=$urls-1;
// Send Forums
$sql = 'SELECT forum_id, forum_last_post_time FROM '.$table_prefix.'forums WHERE enable_indexing=1 LIMIT '.$urls;
$result = $db->sql_query($sql);
while ($data=$db->sql_fetchrow($result)) {
// Fix for parents forums showing 1969
if ($data['forum_last_post_time'] == 0) {
$data['forum_last_post_time']=$current_time;}
echo '<url>
<loc>'.$domainpath.'viewforum-'.$data['forum_id'].''.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$data['forum_last_post_time']).'</lastmod>
</url>';
$urls=$urls-1;
}
$db->sql_freeresult($result);
// Send Topics
$sql = 'SELECT * FROM '.$table_prefix.'topics as t, '.$table_prefix.'forums as f WHERE c_approved=1 AND m_id=m_id AND le_indexing=1 ORDER BY c_id DESC LIMIT '.$urls;
$result = $db->sql_query($sql);
while ($data=$db->sql_fetchrow($result)) {
echo '<url>
<loc>'.$domainpath.'viewtopic-'.$data['topic_id'].''.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$data['topic_last_post_time']).'</lastmod>
</url>';
}
$db->sql_freeresult($result);
// Send Closing Tags
echo ' </urlset>';
?>
-
PHP时间和日期函数怎么操作
php函数的多样化和功能相近真是一大特点,同一个应用可以用多种函数实现,这恐怕也是开源的一个弊端了;通过对PHP时间函数的系统学习,充分理解了时间戳和时区的概念(这个真的很重要),有需要的小伙伴可以参考下。PHP中所有函数都是UNIX纪元的,即从1970年1月1日开始的。日...
-
PHP正则匹配中文字母数字正则的表达式
PHP语言是一门实用性很强的语言,下面小编为大家带来了关于PHP正则匹配中文字母数字正则的'表达式,欢迎大家阅读!PHP正则匹配中文字母数字正则的表达式代码如下if(preg_match("/^d*$/","4312")){echo"全数字";}if(preg_match("/^[a-z]*$/i","fdsFDfd")){echo"全...
-
PHP的SPL标准库的用法介绍
本文介绍下,php编程中SPL中的用法,SPL,PHP标准库(StandardPHPLibrary),此从PHP5.0起内置的组件和接口,有需要的朋友参考下。PHPSPL的用法SPL,PHP标准库(StandardPHPLibrary),此从PHP5.0起内置的组件和接口,并且从PHP5.3已逐渐的成熟。SPL其实在所有的PHP5开发环境中被内置,...
-
用PHP遍历目录下的全部文件
项目中有这么一个需求,需要遍历某个文件夹(目录)下的'所有文件。下面是解决这个问题所写的PHP代码,欢迎阅读,更多消息请关注应届毕业生网。第一种实现办法是用dir返回对象,第二种实现办法:用readdir()函数。/**********************一个简单的目录递归函数第一种实...