From 5524225ead76aa31260c059f8fdb69b1458cfa38 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 16 Sep 2008 20:38:20 +0000 Subject: [PATCH] FEATURE Added GoogleSitemap::enable() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62472 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- integration/GoogleSitemap.php | 55 +++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/integration/GoogleSitemap.php b/integration/GoogleSitemap.php index fa8be7240..b83b2c115 100755 --- a/integration/GoogleSitemap.php +++ b/integration/GoogleSitemap.php @@ -8,8 +8,22 @@ * @subpackage misc */ class GoogleSitemap extends Controller { + + /** + * @var boolean + */ + protected static $enabled = true; + + /** + * @var DataObjectSet + */ protected $Pages; + /** + * @var boolean + */ + protected static $pings = true; + public function Items() { $this->Pages = Versioned::get_by_stage('SiteTree', 'Live'); @@ -59,7 +73,12 @@ class GoogleSitemap extends Controller { return $newPages; } + /** + * @return string Response text + */ 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 if(!GoogleSitemap::$pings || Director::isDev()) return; @@ -72,25 +91,37 @@ class GoogleSitemap extends Controller { return $response; } - protected static $pings = true; + public static function enable_google_notification() { + self::$pings = true; + } /** - * Disables pings to google when the sitemap changes - * To use this, in your _config.php file simply include the line - * GoogleSitemap::DisableGoogleNotification(); + * Disables pings to google when the sitemap changes. */ - static function DisableGoogleNotification() { + public static function disable_google_notification() { self::$pings = false; } - function index($url) { - // We need to override the default content-type - ContentNegotiator::disable(); - header('Content-type: application/xml; charset="utf-8"'); - - // But we want to still render. - return array(); + if(self::$enabled) { + // We need to override the default content-type + ContentNegotiator::disable(); + header('Content-type: application/xml; charset="utf-8"'); + + // 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; } } ?>