mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
FEATURE: filter pages which are hidden away from google sitemaps. PATCH via #3709
This commit is contained in:
parent
10bef3a487
commit
d7eeffcb01
@ -35,16 +35,28 @@ class GoogleSitemap extends Controller {
|
||||
*/
|
||||
protected static $google_notification_enabled = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $use_show_in_search = true;
|
||||
|
||||
public function Items() {
|
||||
$this->Pages = Versioned::get_by_stage('SiteTree', 'Live');
|
||||
$filter = '';
|
||||
|
||||
if(self::$use_show_in_search) {
|
||||
$filter = '`ShowInSearch` = 1';
|
||||
}
|
||||
|
||||
$this->Pages = Versioned::get_by_stage('SiteTree', 'Live', $filter);
|
||||
|
||||
$newPages = new DataObjectSet();
|
||||
|
||||
if($this->Pages) {
|
||||
foreach($this->Pages as $page) {
|
||||
// Only include pages from this host and pages which are not an instance of ErrorPage
|
||||
// We prefix $_SERVER['HTTP_HOST'] with 'http://' so that parse_url to help parse_url identify the host name component; we could use another protocol (like
|
||||
// 'ftp://' as the prefix and the code would work the same.
|
||||
if(parse_url($page->AbsoluteLink(), PHP_URL_HOST) == parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST) && !($page instanceof ErrorPage)) {
|
||||
|
||||
// If the page has been set to 0 priority, we set a flag so it won't be included
|
||||
if($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) {
|
||||
// The one field that isn't easy to deal with in the template is
|
||||
@ -82,6 +94,7 @@ class GoogleSitemap extends Controller {
|
||||
}
|
||||
return $newPages;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies Google about changes to your sitemap.
|
||||
|
Loading…
Reference in New Issue
Block a user