mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FEATURE Added GoogleSitemap::enable()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62472 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
65e9165905
commit
5524225ead
@ -8,8 +8,22 @@
|
|||||||
* @subpackage misc
|
* @subpackage misc
|
||||||
*/
|
*/
|
||||||
class GoogleSitemap extends Controller {
|
class GoogleSitemap extends Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected static $enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DataObjectSet
|
||||||
|
*/
|
||||||
protected $Pages;
|
protected $Pages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected static $pings = true;
|
||||||
|
|
||||||
public function Items() {
|
public function Items() {
|
||||||
$this->Pages = Versioned::get_by_stage('SiteTree', 'Live');
|
$this->Pages = Versioned::get_by_stage('SiteTree', 'Live');
|
||||||
|
|
||||||
@ -59,7 +73,12 @@ class GoogleSitemap extends Controller {
|
|||||||
return $newPages;
|
return $newPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string Response text
|
||||||
|
*/
|
||||||
static function ping() {
|
static function ping() {
|
||||||
|
if(!self::$enabled) return false;
|
||||||
|
|
||||||
//Don't ping if the site has disabled it, or if the site is in dev mode
|
//Don't ping if the site has disabled it, or if the site is in dev mode
|
||||||
if(!GoogleSitemap::$pings || Director::isDev())
|
if(!GoogleSitemap::$pings || Director::isDev())
|
||||||
return;
|
return;
|
||||||
@ -72,25 +91,37 @@ class GoogleSitemap extends Controller {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static $pings = true;
|
public static function enable_google_notification() {
|
||||||
|
self::$pings = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables pings to google when the sitemap changes
|
* Disables pings to google when the sitemap changes.
|
||||||
* To use this, in your _config.php file simply include the line
|
|
||||||
* GoogleSitemap::DisableGoogleNotification();
|
|
||||||
*/
|
*/
|
||||||
static function DisableGoogleNotification() {
|
public static function disable_google_notification() {
|
||||||
self::$pings = false;
|
self::$pings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function index($url) {
|
function index($url) {
|
||||||
// We need to override the default content-type
|
if(self::$enabled) {
|
||||||
ContentNegotiator::disable();
|
// We need to override the default content-type
|
||||||
header('Content-type: application/xml; charset="utf-8"');
|
ContentNegotiator::disable();
|
||||||
|
header('Content-type: application/xml; charset="utf-8"');
|
||||||
// But we want to still render.
|
|
||||||
return array();
|
// But we want to still render.
|
||||||
|
return array();
|
||||||
|
} else {
|
||||||
|
return new HTTPResponse('Not allowed', 405);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function enable() {
|
||||||
|
self::$enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function disable() {
|
||||||
|
self::$enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user