Skip to content

Commit

Permalink
Sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
lincanbin committed Nov 15, 2014
1 parent d12f1ee commit 6d6853e
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ErrorDocument 404 /404.php
RewriteRule ^reply$ reply.php [L]
RewriteRule ^robots.txt$ robots.php [L]
RewriteRule ^settings$ settings.php [L]
RewriteRule ^sitemap-(topics|pages|tags|users|index)(-([0-9]+))?.xml$ sitemap.php?action=$1&page=$3 [L]
RewriteRule ^t/([0-9]+)(-([0-9]*))?$ topic.php?id=$1&page=$3 [L]
RewriteRule ^tag/(.*?)(/page/([0-9]*))?$ tag.php?name=$1&page=$3 [L]
RewriteRule ^tags/following(/page/([0-9]*))?$ favorite_tags.php?page=$2 [L]
Expand Down
1 change: 1 addition & 0 deletions httpd.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RewriteRule ^(.*)/register $1/register.php
RewriteRule ^(.*)/reply $1/reply.php
RewriteRule ^(.*)/robots.txt $1/robots.php
RewriteRule ^(.*)/settings $1/settings.php
RewriteRule ^(.*)/sitemap-(topics|pages|tags|users|index)(-([0-9]+))?.xml $1/sitemap.php\?action=$2&page=$4
RewriteRule ^(.*)/t/([0-9]+)(-([0-9]*))? $1/topic.php\?id=$2&page=$4
RewriteRule ^(.*)/tag/([^/]*)(/page/([0-9]*))? $1/tag.php\?name=$2&page=$4
RewriteRule ^(.*)/tags/following(/page/([0-9]*))? $1/favorite_tags.php\?page=$3
Expand Down
1 change: 1 addition & 0 deletions install/htaccess.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ErrorDocument 404 {{WebSitePath}}404.php
RewriteRule ^reply$ reply.php [L]
RewriteRule ^robots.txt$ robots.php [L]
RewriteRule ^settings$ settings.php [L]
RewriteRule ^sitemap-(topics|pages|tags|users|index)(-([0-9]+))?.xml$ sitemap.php?action=$1&page=$3 [L]
RewriteRule ^t/([0-9]+)(-([0-9]*))?$ topic.php?id=$1&page=$3 [L]
RewriteRule ^tag/(.*?)(/page/([0-9]*))?$ tag.php?name=$1&page=$3 [L]
RewriteRule ^tags/following(/page/([0-9]*))?$ favorite_tags.php?page=$2 [L]
Expand Down
5 changes: 5 additions & 0 deletions robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
//Crawl-delay: 1
$CurHost = 'http://'.$_SERVER['HTTP_HOST'];
$ItemPerSitemap = 30000;
//sitemap 索引
echo 'Sitemap: ',$CurHost,"/sitemap-index.xml\n";
//帖子
for($i = 1; $i <= ceil($Config['NumTopics']/$ItemPerSitemap); $i++)
echo 'Sitemap: ',$CurHost,'/sitemap-topics-',$i,".xml\n";
//帖子页
for($i = 1; $i <= ceil(ceil($Config['NumTopics']/$Config['TopicsPerPage'])/$ItemPerSitemap); $i++)
echo 'Sitemap: ',$CurHost,'/sitemap-pages-',$i,".xml\n";
//话题
for($i = 1; $i <= ceil($Config['NumTags']/$ItemPerSitemap); $i++)
echo 'Sitemap: ',$CurHost,'/sitemap-tags-',$i,".xml\n";
//用户
for($i = 1; $i <= ceil($Config['NumUsers']/$ItemPerSitemap); $i++)
echo 'Sitemap: ',$CurHost,'/sitemap-users-',$i,".xml\n";
?>
108 changes: 108 additions & 0 deletions sitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
include(dirname(__FILE__) . '/common.php');
header("Content-Type: text/xml");
$Action = Request('POST','action',false);
$Page = intval($_GET['page']);
$CurHost = 'http://' . $_SERVER['HTTP_HOST'];
$ItemPerSitemap = 30000;
?><?xml version="1.0" encoding="UTF-8" ?>
<?php
if($_SERVER['HTTP_HOST'] == $Config['MobileDomainName'])
$MobileTag = '<mobile:mobile type="mobile"/>';
else
$MobileTag = '';
switch ($Action) {
case 'topics':
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
<?php if($Page==1){ ?>
<url>
<loc><?php echo $CurHost.'/'; ?></loc>
<?php echo $MobileTag; ?>
<lastmod><?php echo date("Y-m-d", $TimeStamp); ?></lastmod>
<priority>1.0</priority>
</url>
<?php
}
$TopicsArray = $DB->query('SELECT `ID`, `LastTime`, `Replies` FROM '.$Prefix.'topics force index(LastTime) WHERE IsDel=0 ORDER BY LastTime DESC LIMIT '.($Page-1)*$ItemPerSitemap.','.$ItemPerSitemap);
foreach ($TopicsArray as $Topic) {?>
<url>
<loc><?php echo $CurHost.'/t/'.$Topic['ID']; ?></loc>
<?php echo $MobileTag; ?>
<lastmod><?php echo date("Y-m-d", $Topic['LastTime']); ?></lastmod>
<priority>0.<?php echo $Topic['Replies']>=70?'8':ceil(($Topic['Replies']+10)/10); ?></priority>
</url>
<?php } ?>
</urlset><?php
break;


case 'pages':
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
<?php
if(($Page*$ItemPerSitemap) <= ceil($Config['NumTopics']/$Config['TopicsPerPage'])){
for($i = ($Page-1)*$ItemPerSitemap+1; $i <= $Page*$ItemPerSitemap; $i++)
{?>
<url>
<loc><?php echo $CurHost.'/page/'.$i; ?></loc>
<?php echo $MobileTag; ?>
<priority>0.3</priority>
</url>
<?php
}
}
?>
</urlset><?php
break;
case 'tags':
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
<?php
$TagsArray = $DB->query('SELECT `Name`, `MostRecentPostTime`, `TotalPosts` FROM '.$Prefix.'tags force index(PRI) ORDER BY ID DESC LIMIT '.($Page-1)*$ItemPerSitemap.','.$ItemPerSitemap);
foreach ($TagsArray as $Tags) {?>
<url>
<loc><?php echo $CurHost.'/tag/'.urlencode($Tags['Name']); ?></loc>
<?php echo $MobileTag; ?>
<lastmod><?php echo date("Y-m-d", $Tags['MostRecentPostTime']); ?></lastmod>
<priority>0.<?php echo $Tags['TotalPosts']>=50?'6':ceil(($Tags['TotalPosts']+10)/10); ?></priority>
</url>
<?php } ?>
</urlset><?php
break;
case 'users':
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
<?php
$UsersArray = $DB->query('SELECT `UserName`, `Topics`, `Replies`, `LastPostTime` FROM '.$Prefix.'users force index(PRI) WHERE UserAccountStatus=1 ORDER BY ID DESC LIMIT '.($Page-1)*$ItemPerSitemap.','.$ItemPerSitemap);
foreach ($UsersArray as $User) {?>
<url>
<loc><?php echo $CurHost.'/u/'.urlencode($User['UserName']); ?></loc>
<?php echo $MobileTag; ?>
<lastmod><?php echo date("Y-m-d", $User['LastPostTime']); ?></lastmod>
<priority>0.<?php echo $User['Topics']+$User['Replies']>=40?'5':ceil(($User['Topics']+$User['Replies'])/10); ?></priority>
</url>
<?php } ?>
</urlset><?php
break;
default:
?>
<sitemapindex>
<?php
//帖子
for($i = 1; $i <= ceil($Config['NumTopics']/$ItemPerSitemap); $i++)
echo '<sitemap><loc>',$CurHost,'/sitemap-topics-',$i,".xml</loc></sitemap>\n";
//帖子页
for($i = 1; $i <= ceil(ceil($Config['NumTopics']/$Config['TopicsPerPage'])/$ItemPerSitemap); $i++)
echo '<sitemap><loc>',$CurHost,'/sitemap-pages-',$i,".xml</loc></sitemap>\n";
//话题
for($i = 1; $i <= ceil($Config['NumTags']/$ItemPerSitemap); $i++)
echo '<sitemap><loc>',$CurHost,'/sitemap-tags-',$i,".xml</loc></sitemap>\n";
//用户
for($i = 1; $i <= ceil($Config['NumUsers']/$ItemPerSitemap); $i++)
echo '<sitemap><loc>',$CurHost,'/sitemap-users-',$i,".xml</loc></sitemap>\n";
?>
</sitemapindex><?php
break;
}
?>

0 comments on commit 6d6853e

Please sign in to comment.