Remove redirector pages (Fixes #43)

This commit is contained in:
Will Rossiter 2016-03-04 16:40:30 +13:00
parent 9f461b8d7c
commit 356350ede5
1 changed files with 42 additions and 27 deletions

View File

@ -56,6 +56,13 @@ class GoogleSitemap extends Object
*/
private static $routes = array();
/**
* @config
*
* @var boolean
*/
private static $exclude_redirector_pages = true;
/**
* Decorates the given DataObject with {@link GoogleSitemapDecorator}
* and pushes the class name to the registered DataObjects.
@ -204,6 +211,7 @@ class GoogleSitemap extends Object
$output = new ArrayList();
$count = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
$filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search');
$redirector = Config::inst()->get('GoogleSitemap', 'exclude_redirector_pages');
// todo migrate to extension hook or DI point for other modules to
// modify state filters
@ -212,8 +220,15 @@ class GoogleSitemap extends Object
}
if ($class == "SiteTree") {
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
$instances = Versioned::get_by_stage('SiteTree', 'Live', $filter);
$instances = Versioned::get_by_stage('SiteTree', 'Live');
if($filter) {
$instances = $instances->filter('ShowInSearch', 1);
}
if($redirector) {
$instances = $instances->exclude('ClassName', 'RedirectorPage');
}
} elseif ($class == "GoogleSitemapRoute") {
$instances = array_slice(self::$routes, ($page - 1) * $count, $count);
$output = new ArrayList();