mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
#1784 - Remove external links from sitemap (merged from branches/2.2.0, r44846)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44901 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ce30a13130
commit
f58a5c7992
@ -13,42 +13,50 @@ class Sitemap extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function Items() {
|
public function Items() {
|
||||||
|
$newPages = new DataObjectSet();
|
||||||
|
|
||||||
foreach($this->Pages as $page) {
|
foreach($this->Pages as $page) {
|
||||||
// If the page has been set to 0 priority, we set a flag so it won't be included
|
// Only include pages from this host
|
||||||
if(isset($page->Priority) && $page->Priority <= 0) {
|
if(parse_url($page->AbsoluteLink(), PHP_URL_HOST) == $_SERVER['HTTP_HOST']) {
|
||||||
$page->Include = false;
|
|
||||||
} else {
|
|
||||||
$page->Include = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The one field that isn't easy to deal with in the template is
|
// If the page has been set to 0 priority, we set a flag so it won't be included
|
||||||
// Change frequency, so we set that here.
|
if(isset($page->Priority) && $page->Priority <= 0) {
|
||||||
$properties = $page->toMap();
|
$page->Include = false;
|
||||||
$created = new Datetime($properties['Created']);
|
} else {
|
||||||
$now = new Datetime();
|
$page->Include = true;
|
||||||
$versions = $properties['Version'];
|
}
|
||||||
$timediff = $now->format('U') - $created->format('U');
|
|
||||||
|
|
||||||
// Check how many revisions have been made over the lifetime of the
|
// The one field that isn't easy to deal with in the template is
|
||||||
// Page for a rough estimate of it's changing frequency.
|
// 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');
|
||||||
|
|
||||||
$period = $timediff / ($versions + 1);
|
// Check how many revisions have been made over the lifetime of the
|
||||||
|
// Page for a rough estimate of it's changing frequency.
|
||||||
|
|
||||||
if($period > 60*60*24*365) { // > 1 year
|
$period = $timediff / ($versions + 1);
|
||||||
$page->ChangeFreq='yearly';
|
|
||||||
} else if($period > 60*60*24*30) { // > ~1 month
|
if($period > 60*60*24*365) { // > 1 year
|
||||||
$page->ChangeFreq='monthly';
|
$page->ChangeFreq='yearly';
|
||||||
} else if($period > 60*60*24*7) { // > 1 week
|
} else if($period > 60*60*24*30) { // > ~1 month
|
||||||
$page->ChangeFreq='weekly';
|
$page->ChangeFreq='monthly';
|
||||||
} else if($period > 60*60*24) { // > 1 day
|
} else if($period > 60*60*24*7) { // > 1 week
|
||||||
$page->ChangeFreq='daily';
|
$page->ChangeFreq='weekly';
|
||||||
} else if($period > 60*60) { // > 1 hour
|
} else if($period > 60*60*24) { // > 1 day
|
||||||
$page->ChangeFreq='hourly';
|
$page->ChangeFreq='daily';
|
||||||
} else { // < 1 hour
|
} else if($period > 60*60) { // > 1 hour
|
||||||
$page->ChangeFreq='always';
|
$page->ChangeFreq='hourly';
|
||||||
|
} else { // < 1 hour
|
||||||
|
$page->ChangeFreq='always';
|
||||||
|
}
|
||||||
|
|
||||||
|
$newPages->push($page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->Pages;
|
return $newPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function ping() {
|
static function ping() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user