mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
Merge pull request #157 from smindel/issue-156-utilise-stream-context
FIX: enable stream context to pass through CWP egres proxy, fixes #156
This commit is contained in:
commit
473b88ee05
@ -84,6 +84,16 @@ class GoogleSitemap
|
|||||||
*/
|
*/
|
||||||
private static $exclude_redirector_pages = true;
|
private static $exclude_redirector_pages = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @config
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $search_indexes = [
|
||||||
|
'google' => 'http://www.google.com/webmasters/sitemaps/ping?sitemap=',
|
||||||
|
'bing' => 'http://www.bing.com/ping?sitemap=',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorates the given DataObject with {@link GoogleSitemapDecorator}
|
* Decorates the given DataObject with {@link GoogleSitemapDecorator}
|
||||||
* and pushes the class name to the registered DataObjects.
|
* and pushes the class name to the registered DataObjects.
|
||||||
@ -443,27 +453,19 @@ class GoogleSitemap
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies Google about changes to your sitemap. This behavior is disabled
|
* Notifies search indexes about changes to your sitemap. This behavior is disabled
|
||||||
* by default, to enable, read the documentation provided in the docs folder.
|
* by default, to enable, read the documentation provided in the docs folder.
|
||||||
*
|
*
|
||||||
* After notifications have been enabled, every publish / unpublish of a page.
|
* After notifications have been enabled, every publish / unpublish of a page.
|
||||||
* will notify Google of the update.
|
* will notify enabled search indexes of the update.
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
* the Google notification is enabled.
|
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function ping()
|
public static function ping()
|
||||||
{
|
{
|
||||||
if (!self::enabled()) {
|
if (!self::enabled() || Director::isDev()) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't ping if the site has disabled it, or if the site is in dev mode
|
|
||||||
$active = Config::inst()->get(__CLASS__, 'google_notification_enabled');
|
|
||||||
|
|
||||||
if (!$active || Director::isDev()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,44 +474,16 @@ class GoogleSitemap
|
|||||||
'sitemap.xml'
|
'sitemap.xml'
|
||||||
));
|
));
|
||||||
|
|
||||||
$googleResponse = self::send_ping(
|
$response = true;
|
||||||
"www.google.com",
|
|
||||||
"/webmasters/sitemaps/ping",
|
|
||||||
sprintf("sitemap=%s", $location)
|
|
||||||
);
|
|
||||||
|
|
||||||
// bing
|
foreach (self::config()->search_indexes as $name => $url) {
|
||||||
$bing = Config::inst()->get(__CLASS__, 'bing_notification_enabled');
|
$configName = $name . '_notification_enabled';
|
||||||
|
|
||||||
if ($bing) {
|
if (self::config()->$configName) {
|
||||||
$bingResponse = self::send_ping(
|
$response = $response && file_get_contents($url . $location);
|
||||||
"www.bing.com",
|
}
|
||||||
"/ping",
|
|
||||||
sprintf("sitemap=%s", $location)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send an HTTP request to the host.
|
|
||||||
*
|
|
||||||
* @return String Response text
|
|
||||||
*/
|
|
||||||
protected static function send_ping($host, $path, $query)
|
|
||||||
{
|
|
||||||
$socket = fsockopen($host, 80, $errno, $error);
|
|
||||||
if (!$socket) {
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
if ($query) {
|
|
||||||
$query = '?' . $query;
|
|
||||||
}
|
|
||||||
$request = "GET {$path}{$query} HTTP/1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n";
|
|
||||||
fwrite($socket, $request);
|
|
||||||
$response = stream_get_contents($socket);
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user