BUGFIX #2390: Not indexed pages are removed from sitemap.xml

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62910 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-09-23 03:16:23 +00:00
parent a47f5834a2
commit 2a1d4376e2
3 changed files with 33 additions and 36 deletions

View File

@ -998,13 +998,15 @@ class SiteTree extends DataObject {
* the site tree, so it must be calculated dynamically.
*/
function getPriority() {
if($this->getField('Priority') === null) {
if(!$this->getField('Priority')) {
$parentStack = $this->parentStack();
$numParents = is_array($parentStack) ? count($parentStack) - 1: 0;
return max(0.1, 1.0 - ($numParents / 10));
} else if($this->getField('Priority') == -1) {
return 0;
} else {
return $this->getField('Priority');
}
return $this->getField('Priority');
}
/**
@ -1085,7 +1087,8 @@ class SiteTree extends DataObject {
$pagePriorities = array(
'0.0' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"),
'' => _t('SiteTree.PRIORITYAUTOSET','Auto-set based on page depth'),
'-1' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"), // We set this to -ve one because a blank value implies auto-generation of Priority
'1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"),
'0.9' => '2',
'0.8' => '3',

View File

@ -34,40 +34,36 @@ class GoogleSitemap extends Controller {
if(parse_url($page->AbsoluteLink(), PHP_URL_HOST) == $_SERVER['HTTP_HOST'] && !($page instanceof ErrorPage)) {
// If the page has been set to 0 priority, we set a flag so it won't be included
if(isset($page->Priority) && $page->Priority <= 0) {
$page->Include = false;
} else {
$page->Include = true;
}
if(!isset($page->Priority) || $page->Priority > 0) {
// The one field that isn't easy to deal with in the template is
// Change frequency, so we set that here.
$properties = $page->toMap();
$created = new Datetime($properties['Created']);
$now = new Datetime();
$versions = $properties['Version'];
$timediff = $now->format('U') - $created->format('U');
// The one field that isn't easy to deal with in the template is
// Change frequency, so we set that here.
$properties = $page->toMap();
$created = new Datetime($properties['Created']);
$now = new Datetime();
$versions = $properties['Version'];
$timediff = $now->format('U') - $created->format('U');
// Check how many revisions have been made over the lifetime of the
// Page for a rough estimate of it's changing frequency.
// Check how many revisions have been made over the lifetime of the
// Page for a rough estimate of it's changing frequency.
$period = $timediff / ($versions + 1);
$period = $timediff / ($versions + 1);
if($period > 60*60*24*365) { // > 1 year
$page->ChangeFreq='yearly';
} else if($period > 60*60*24*30) { // > ~1 month
$page->ChangeFreq='monthly';
} else if($period > 60*60*24*7) { // > 1 week
$page->ChangeFreq='weekly';
} else if($period > 60*60*24) { // > 1 day
$page->ChangeFreq='daily';
} else if($period > 60*60) { // > 1 hour
$page->ChangeFreq='hourly';
} else { // < 1 hour
$page->ChangeFreq='always';
}
if($period > 60*60*24*365) { // > 1 year
$page->ChangeFreq='yearly';
} else if($period > 60*60*24*30) { // > ~1 month
$page->ChangeFreq='monthly';
} else if($period > 60*60*24*7) { // > 1 week
$page->ChangeFreq='weekly';
} else if($period > 60*60*24) { // > 1 day
$page->ChangeFreq='daily';
} else if($period > 60*60) { // > 1 hour
$page->ChangeFreq='hourly';
} else { // < 1 hour
$page->ChangeFreq='always';
}
$newPages->push($page);
$newPages->push($page);
}
}
}
return $newPages;

View File

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% control Items %>
<% if Include %>
<url>
<loc>$AbsoluteLink</loc>
<lastmod>$LastEdited.Format(c)</lastmod>
<% if ChangeFreq %><changefreq>$ChangeFreq</changefreq><% end_if %>
<% if Priority %><priority>$Priority</priority><% end_if %>
</url>
<% end_if %>
<% end_control %>
</urlset>