From e607ea9fc443dfa493106dcf537ed09c13e4e3e3 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 17 Sep 2016 08:27:16 +1200 Subject: [PATCH] Add support for pinging bing (Fixes #22) - Fix README install link - Update documentation --- README.md | 23 ++++---- code/GoogleSitemap.php | 24 +++++--- code/extensions/GoogleSitemapExtension.php | 14 ++--- composer.json | 2 +- docs/en/index.md | 64 +++++++++++++--------- 5 files changed, 75 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 468a1f4..d3db28e 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,24 @@ ## Installation -> composer require "silverstripe/googlesitemaps" +> composer require "wilr/googlesitemaps" ## Documentation -SilverStripe provides support for the Google Sitemaps XML system, enabling -Google and other search engines to see all urls on your site. This helps -your SilverStripe website rank well in search engines, and to encourage the -information on your site to be discovered by Google quickly. +Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html), +enabling Google, Bing and other search engines to index the web pages on your +site. This helps your SilverStripe website rank well in search engines, and to +encourage the information on your site to be discovered by Google quickly. -Therefore, all Silverstripe websites contain a special controller which can -be visited: http://yoursite.com/sitemap.xml +Any new pages published or unpublished on your website automatically update the +Sitemap. -Flush this route to ensure the changes take effect with: http://yoursite.com/sitemap.xml?flush=1 - -See http://en.wikipedia.org/wiki/Sitemaps for info on this format. +The XML Sitemap can be accessed by going to http://yoursite.com/sitemap.xml ## Usage Overview See docs/en for more information about configuring the module. - + +## Troubleshooting + +* Flush this route to ensure the changes take effect (e.g http://yoursite.com/sitemap.xml?flush=1) diff --git a/code/GoogleSitemap.php b/code/GoogleSitemap.php index 025b4ce..fe169b9 100644 --- a/code/GoogleSitemap.php +++ b/code/GoogleSitemap.php @@ -120,10 +120,10 @@ class GoogleSitemap extends Object { if (!isset(self::$dataobjects[$className])) { $lowerKeys = array_change_key_case(self::$dataobjects); - + return isset($lowerKeys[$className]); } - + return true; } @@ -431,7 +431,7 @@ class GoogleSitemap extends Object * If the site is in development mode no ping will be sent regardless whether * the Google notification is enabled. * - * @return string Response text + * @return boolean */ public static function ping() { @@ -443,7 +443,7 @@ class GoogleSitemap extends Object $active = Config::inst()->get('GoogleSitemap', 'google_notification_enabled'); if (!$active || Director::isDev()) { - return; + return false; } $location = urlencode(Controller::join_links( @@ -451,11 +451,20 @@ class GoogleSitemap extends Object 'sitemap.xml' )); - $response = self::send_ping( + $googleResponse = self::send_ping( "www.google.com", "/webmasters/sitemaps/ping", sprintf("sitemap=%s", $location) ); - return $response; + // bing + $bing = Config::inst()->get('GoogleSitemap', 'bing_notification_enabled'); + + if($bing) { + $bingResponse = self::send_ping( + "www.bing.com", "/ping", sprintf("sitemap=%s", $location) + ); + } + + return true; } /** @@ -491,7 +500,8 @@ class GoogleSitemap extends Object /** - * Convenience method for manufacturing an instance for hew instance-level methods (and for easier type definition). + * Convenience method for manufacturing an instance for hew instance-level + * methods (and for easier type definition). * * @return GoogleSitemap */ diff --git a/code/extensions/GoogleSitemapExtension.php b/code/extensions/GoogleSitemapExtension.php index 8e95992..ac5907c 100644 --- a/code/extensions/GoogleSitemapExtension.php +++ b/code/extensions/GoogleSitemapExtension.php @@ -1,9 +1,9 @@ owner->canView(); } @@ -80,10 +80,10 @@ class GoogleSitemapExtension extends DataExtension } /** - * Returns a pages change frequency calculated by pages age and number of - * versions. Google expects always, hourly, daily, weekly, monthly, yearly + * Returns a pages change frequency calculated by pages age and number of + * versions. Google expects always, hourly, daily, weekly, monthly, yearly * or never as values. - * + * * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic * * @return SS_Datetime @@ -101,7 +101,7 @@ class GoogleSitemapExtension extends DataExtension $now = new SS_Datetime(); $now->value = $date; - + $versions = ($this->owner->Version) ? $this->owner->Version : 1; $timediff = $now->format('U') - $created->format('U'); diff --git a/composer.json b/composer.json index 99e997e..980b3ac 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "wilr/silverstripe-googlesitemaps", - "description": "SilverStripe support for the Google Sitemaps XML, enabling Google and other search engines to see all urls on your site. This helps your SilverStripe website rank well in search engines, and to encourage the information on your site to be discovered by Google quickly.", + "description": "SilverStripe support for the Google Sitemaps XML, enabling Google and other search engines to see all urls on your site. This helps your SilverStripe website rank well in search engines, and to encourage the information on your site to be discovered quickly.", "type": "silverstripe-module", "keywords": ["silverstripe", "googlesitemaps", "seo"], "homepage": "https://github.com/wilr/silverstripe-googlesitemaps", diff --git a/docs/en/index.md b/docs/en/index.md index 8d14e27..85a3aa1 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -1,28 +1,28 @@ # Google Sitemaps Module -SilverStripe provides support for the Google Sitemaps XML system, enabling -Google and other search engines to see all pages on your site. This helps -your SilverStripe website rank well in search engines, and to encourage the +SilverStripe provides support for the Google Sitemaps XML system, enabling +Google and other search engines to see all pages on your site. This helps +your SilverStripe website rank well in search engines, and to encourage the information on your site to be discovered by Google quickly. -Therefore, all Silverstripe websites contain a special controller which can be -visited: http://yoursite.com/sitemap.xml. This is not a file directly, but +Therefore, all Silverstripe websites contain a special controller which can be +visited: http://yoursite.com/sitemap.xml. This is not a file directly, but rather a custom route which points to the GoogleSitemap controller. -See http://en.wikipedia.org/wiki/Sitemaps for info on the Google Sitemap +See http://en.wikipedia.org/wiki/Sitemaps for info on the Google Sitemap format. -Whenever you publish a new or republish an existing page, SilverStripe can -automatically inform Google of the change, encouraging a Google to take notice. -If you install the SilverStripe Google Analytics module, you can see if Google +Whenever you publish a new or republish an existing page, SilverStripe can +automatically inform Google of the change, encouraging a Google to take notice. +If you install the SilverStripe Google Analytics module, you can see if Google has updated your page as a result. -By default, SilverStripe informs Google that the importance of a page depends -on its position of in the sitemap. "Top level" pages are most important, and -the deeper a page is nested, the less important it is. (For each level, +By default, SilverStripe informs Google that the importance of a page depends +on its position of in the sitemap. "Top level" pages are most important, and +the deeper a page is nested, the less important it is. (For each level, Importance drops from 1.0, to 0.9, to 0.8, and so on, until 0.1 is reached). -In the CMS, in the Settings tab for each page, you can set the importance +In the CMS, in the Settings tab for each page, you can set the importance manually, including requesting to have the page excluded from the sitemap. ## Configuration @@ -55,52 +55,64 @@ editing the `google_notification_enabled` option to true google_notification_enabled: true use_show_in_search: true +### Bing Ping Support + +To ping Bing whenever your sitemap is updated, set `bing_notification_enabled` + + --- + Name: customgooglesitemaps + After: googlesitemaps + --- + GoogleSitemap: + enabled: true + bing_notification_enabled: true + ### Including DataObjects -The module provides support for including DataObject subclasses as pages in the +The module provides support for including DataObject subclasses as pages in the SiteTree such as comments, forum posts and other pages which are stored in your database as DataObject subclasses. -To include a DataObject instance in the Sitemap it requires that your subclass +To include a DataObject instance in the Sitemap it requires that your subclass defines two functions: * AbsoluteLink() function which returns the URL for this DataObject * canView() function which returns a boolean value. -The following is a barebones example of a DataObject called 'MyDataObject'. It -assumes that you have a controller called 'MyController' which has a show method +The following is a barebones example of a DataObject called 'MyDataObject'. It +assumes that you have a controller called 'MyController' which has a show method to show the DataObject by its ID. Link()); } - + function Link() { return 'MyController/show/'. $this->ID; } } -After those methods have been defined on your DataObject you now need to tell +After those methods have been defined on your DataObject you now need to tell the Google Sitemaps module that it should be listed in the sitemap.xml file. To do that, include the following in your _config.php file. GoogleSitemap::register_dataobject('MyDataObject'); -If you need to change the frequency of the indexing, you can pass the change -frequency (daily, weekly, monthly) as a second parameter to register_dataobject(), So +If you need to change the frequency of the indexing, you can pass the change +frequency (daily, weekly, monthly) as a second parameter to register_dataobject(), So instead of the previous code you would write: - GoogleSitemap::register_dataobject('MyDataObject', 'daily'); - + GoogleSitemap::register_dataobject('MyDataObject', 'daily'); + See the following blog post for more information: http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/