diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index aa1e9629c..abc04d525 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -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', diff --git a/integration/GoogleSitemap.php b/integration/GoogleSitemap.php index b83b2c115..2fe8f431b 100755 --- a/integration/GoogleSitemap.php +++ b/integration/GoogleSitemap.php @@ -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; diff --git a/templates/GoogleSitemap.ss b/templates/GoogleSitemap.ss index 73da1b2f1..9272ed44f 100755 --- a/templates/GoogleSitemap.ss +++ b/templates/GoogleSitemap.ss @@ -1,13 +1,11 @@ <% control Items %> - <% if Include %> $AbsoluteLink $LastEdited.Format(c) <% if ChangeFreq %>$ChangeFreq<% end_if %> <% if Priority %>$Priority<% end_if %> - <% end_if %> <% end_control %> \ No newline at end of file