mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
Add support for pinging bing (Fixes #22)
- Fix README install link - Update documentation
This commit is contained in:
parent
31f9182e95
commit
e607ea9fc4
23
README.md
23
README.md
@ -12,23 +12,24 @@
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
> composer require "silverstripe/googlesitemaps"
|
> composer require "wilr/googlesitemaps"
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
SilverStripe provides support for the Google Sitemaps XML system, enabling
|
Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html),
|
||||||
Google and other search engines to see all urls on your site. This helps
|
enabling Google, Bing and other search engines to index the web pages on your
|
||||||
your SilverStripe website rank well in search engines, and to encourage the
|
site. This helps your SilverStripe website rank well in search engines, and to
|
||||||
information on your site to be discovered by Google quickly.
|
encourage the information on your site to be discovered by Google quickly.
|
||||||
|
|
||||||
Therefore, all Silverstripe websites contain a special controller which can
|
Any new pages published or unpublished on your website automatically update the
|
||||||
be visited: http://yoursite.com/sitemap.xml
|
Sitemap.
|
||||||
|
|
||||||
Flush this route to ensure the changes take effect with: http://yoursite.com/sitemap.xml?flush=1
|
The XML Sitemap can be accessed by going to http://yoursite.com/sitemap.xml
|
||||||
|
|
||||||
See http://en.wikipedia.org/wiki/Sitemaps for info on this format.
|
|
||||||
|
|
||||||
## Usage Overview
|
## Usage Overview
|
||||||
|
|
||||||
See docs/en for more information about configuring the module.
|
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)
|
||||||
|
@ -120,10 +120,10 @@ class GoogleSitemap extends Object
|
|||||||
{
|
{
|
||||||
if (!isset(self::$dataobjects[$className])) {
|
if (!isset(self::$dataobjects[$className])) {
|
||||||
$lowerKeys = array_change_key_case(self::$dataobjects);
|
$lowerKeys = array_change_key_case(self::$dataobjects);
|
||||||
|
|
||||||
return isset($lowerKeys[$className]);
|
return isset($lowerKeys[$className]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ class GoogleSitemap extends Object
|
|||||||
* If the site is in development mode no ping will be sent regardless whether
|
* If the site is in development mode no ping will be sent regardless whether
|
||||||
* the Google notification is enabled.
|
* the Google notification is enabled.
|
||||||
*
|
*
|
||||||
* @return string Response text
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function ping()
|
public static function ping()
|
||||||
{
|
{
|
||||||
@ -443,7 +443,7 @@ class GoogleSitemap extends Object
|
|||||||
$active = Config::inst()->get('GoogleSitemap', 'google_notification_enabled');
|
$active = Config::inst()->get('GoogleSitemap', 'google_notification_enabled');
|
||||||
|
|
||||||
if (!$active || Director::isDev()) {
|
if (!$active || Director::isDev()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$location = urlencode(Controller::join_links(
|
$location = urlencode(Controller::join_links(
|
||||||
@ -451,11 +451,20 @@ class GoogleSitemap extends Object
|
|||||||
'sitemap.xml'
|
'sitemap.xml'
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = self::send_ping(
|
$googleResponse = self::send_ping(
|
||||||
"www.google.com", "/webmasters/sitemaps/ping", sprintf("sitemap=%s", $location)
|
"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
|
* @return GoogleSitemap
|
||||||
*/
|
*/
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the page object to provide google sitemaps with
|
* Decorate the page object to provide google sitemaps with
|
||||||
* additionally options and configuration.
|
* additionally options and configuration.
|
||||||
*
|
*
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
*/
|
*/
|
||||||
class GoogleSitemapExtension extends DataExtension
|
class GoogleSitemapExtension extends DataExtension
|
||||||
@ -24,7 +24,7 @@ class GoogleSitemapExtension extends DataExtension
|
|||||||
$can = false;
|
$can = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($can) {
|
if ($can) {
|
||||||
$can = $this->owner->canView();
|
$can = $this->owner->canView();
|
||||||
}
|
}
|
||||||
@ -80,10 +80,10 @@ class GoogleSitemapExtension extends DataExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pages change frequency calculated by pages age and number of
|
* Returns a pages change frequency calculated by pages age and number of
|
||||||
* versions. Google expects always, hourly, daily, weekly, monthly, yearly
|
* versions. Google expects always, hourly, daily, weekly, monthly, yearly
|
||||||
* or never as values.
|
* or never as values.
|
||||||
*
|
*
|
||||||
* @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic
|
* @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic
|
||||||
*
|
*
|
||||||
* @return SS_Datetime
|
* @return SS_Datetime
|
||||||
@ -101,7 +101,7 @@ class GoogleSitemapExtension extends DataExtension
|
|||||||
|
|
||||||
$now = new SS_Datetime();
|
$now = new SS_Datetime();
|
||||||
$now->value = $date;
|
$now->value = $date;
|
||||||
|
|
||||||
$versions = ($this->owner->Version) ? $this->owner->Version : 1;
|
$versions = ($this->owner->Version) ? $this->owner->Version : 1;
|
||||||
$timediff = $now->format('U') - $created->format('U');
|
$timediff = $now->format('U') - $created->format('U');
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wilr/silverstripe-googlesitemaps",
|
"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",
|
"type": "silverstripe-module",
|
||||||
"keywords": ["silverstripe", "googlesitemaps", "seo"],
|
"keywords": ["silverstripe", "googlesitemaps", "seo"],
|
||||||
"homepage": "https://github.com/wilr/silverstripe-googlesitemaps",
|
"homepage": "https://github.com/wilr/silverstripe-googlesitemaps",
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
# Google Sitemaps Module
|
# Google Sitemaps Module
|
||||||
|
|
||||||
SilverStripe provides support for the Google Sitemaps XML system, enabling
|
SilverStripe provides support for the Google Sitemaps XML system, enabling
|
||||||
Google and other search engines to see all pages on your site. This helps
|
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
|
your SilverStripe website rank well in search engines, and to encourage the
|
||||||
information on your site to be discovered by Google quickly.
|
information on your site to be discovered by Google quickly.
|
||||||
|
|
||||||
Therefore, all Silverstripe websites contain a special controller which can be
|
Therefore, all Silverstripe websites contain a special controller which can be
|
||||||
visited: http://yoursite.com/sitemap.xml. This is not a file directly, but
|
visited: http://yoursite.com/sitemap.xml. This is not a file directly, but
|
||||||
rather a custom route which points to the GoogleSitemap controller.
|
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.
|
format.
|
||||||
|
|
||||||
Whenever you publish a new or republish an existing page, SilverStripe can
|
Whenever you publish a new or republish an existing page, SilverStripe can
|
||||||
automatically inform Google of the change, encouraging a Google to take notice.
|
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
|
If you install the SilverStripe Google Analytics module, you can see if Google
|
||||||
has updated your page as a result.
|
has updated your page as a result.
|
||||||
|
|
||||||
By default, SilverStripe informs Google that the importance of a page depends
|
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
|
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,
|
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).
|
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.
|
manually, including requesting to have the page excluded from the sitemap.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
@ -55,52 +55,64 @@ editing the `google_notification_enabled` option to true
|
|||||||
google_notification_enabled: true
|
google_notification_enabled: true
|
||||||
use_show_in_search: 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
|
### 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
|
SiteTree such as comments, forum posts and other pages which are stored in your
|
||||||
database as DataObject subclasses.
|
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:
|
defines two functions:
|
||||||
|
|
||||||
* AbsoluteLink() function which returns the URL for this DataObject
|
* AbsoluteLink() function which returns the URL for this DataObject
|
||||||
* canView() function which returns a boolean value.
|
* canView() function which returns a boolean value.
|
||||||
|
|
||||||
The following is a barebones example of a DataObject called 'MyDataObject'. It
|
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
|
assumes that you have a controller called 'MyController' which has a show method
|
||||||
to show the DataObject by its ID.
|
to show the DataObject by its ID.
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class MyDataObject extends DataObject {
|
class MyDataObject extends DataObject {
|
||||||
|
|
||||||
function canView($member = null) {
|
function canView($member = null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AbsoluteLink() {
|
function AbsoluteLink() {
|
||||||
return Director::absoluteURL($this->Link());
|
return Director::absoluteURL($this->Link());
|
||||||
}
|
}
|
||||||
|
|
||||||
function Link() {
|
function Link() {
|
||||||
return 'MyController/show/'. $this->ID;
|
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
|
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.
|
do that, include the following in your _config.php file.
|
||||||
|
|
||||||
GoogleSitemap::register_dataobject('MyDataObject');
|
GoogleSitemap::register_dataobject('MyDataObject');
|
||||||
|
|
||||||
If you need to change the frequency of the indexing, you can pass the change
|
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
|
frequency (daily, weekly, monthly) as a second parameter to register_dataobject(), So
|
||||||
instead of the previous code you would write:
|
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:
|
See the following blog post for more information:
|
||||||
|
|
||||||
http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/
|
http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/
|
||||||
|
Loading…
Reference in New Issue
Block a user