Add support for pinging bing (Fixes #22)

- Fix README install link
- Update documentation
This commit is contained in:
Will Rossiter 2016-09-17 08:27:16 +12:00
parent 31f9182e95
commit e607ea9fc4
5 changed files with 75 additions and 52 deletions

View File

@ -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)

View File

@ -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
*/

View File

@ -1,9 +1,9 @@
<?php
/**
* Decorate the page object to provide google sitemaps with
* Decorate the page object to provide google sitemaps with
* additionally options and configuration.
*
*
* @package googlesitemaps
*/
class GoogleSitemapExtension extends DataExtension
@ -24,7 +24,7 @@ class GoogleSitemapExtension extends DataExtension
$can = false;
}
}
if ($can) {
$can = $this->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');

View File

@ -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",

View File

@ -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.
<?php
class MyDataObject extends DataObject {
function canView($member = null) {
return true;
}
function AbsoluteLink() {
return Director::absoluteURL($this->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/