[FIX] canINcludeInGoogleSitemap

It was not handling the URLs properly/parsing of the URLs, as well as missing ->owner.

Would really appreciate this being quickly patched as I need it to be working for a project.
This commit is contained in:
Thomas Speak 2013-08-23 15:40:36 +01:00 committed by Tom Speak
parent 7ba2e67a17
commit e1abd27214
2 changed files with 14 additions and 6 deletions

View File

@ -14,23 +14,31 @@ class GoogleSitemapExtension extends DataExtension {
public function canIncludeInGoogleSitemap() { public function canIncludeInGoogleSitemap() {
$can = true; $can = true;
if(method_exists($this, 'AbsoluteLink')) { //if the class we're decorating has an AbsoluteLink method, we'll use
$objHttp = parse_url($this->AbsoluteLink(), PHP_URL_HOST); // it to determine if the page is on this domain - this hadnles
$hostHttp = parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST); // RedirectorPages nicely
if($this->owner->hasMethod('AbsoluteLink')) {
//parse out the hosts and compare them
$objHttp = parse_url($this->owner->AbsoluteLink(), PHP_URL_HOST);
$hostHttp = parse_url(Director::protocolAndHost(), PHP_URL_HOST);
//if they don't match, then we won't add it
if($objHttp != $hostHttp) { if($objHttp != $hostHttp) {
$can = false; $can = false;
} }
} }
if($can) { if($can) {
//check we canView
$can = $this->owner->canView(); $can = $this->owner->canView();
} }
if($can) { if($can) {
//only show priorities over 0%
$can = $this->owner->getGooglePriority(); $can = $this->owner->getGooglePriority();
} }
//allow people to hook into the $can
$this->owner->extend('alterCanIncludeInGoogleSitemap', $can); $this->owner->extend('alterCanIncludeInGoogleSitemap', $can);
return $can; return $can;

View File

@ -249,7 +249,7 @@ class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
} }
public function AbsoluteLink() { public function AbsoluteLink() {
return Director::baseURL(); return Director::absoluteBaseURL();
} }
} }
@ -268,7 +268,7 @@ class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
} }
public function AbsoluteLink() { public function AbsoluteLink() {
return Director::baseURL(); return Director::absoluteBaseURL();
} }
} }
@ -287,6 +287,6 @@ class GoogleSitemapTest_UnviewableDataObject extends DataObject implements TestO
} }
public function AbsoluteLink() { public function AbsoluteLink() {
return Director::baseURL(); return Director::absoluteBaseURL();
} }
} }