diff --git a/.gitignore b/.gitignore
index e43b0f9..3f5c4fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
.DS_Store
+/vendor
+/public
+/composer.lock
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index d1ebd80..0000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-inherit: true
-
-checks:
- php:
- verify_property_names: true
- verify_argument_usable_as_reference: true
- verify_access_scope_valid: true
- useless_calls: true
- use_statement_alias_conflict: true
- variable_existence: true
- unused_variables: true
- unused_properties: true
- unused_parameters: true
- unused_methods: true
- unreachable_code: true
- too_many_arguments: true
- sql_injection_vulnerabilities: true
- simplify_boolean_return: true
- side_effects_or_types: true
- security_vulnerabilities: true
- return_doc_comments: true
- return_doc_comment_if_not_inferrable: true
- require_scope_for_properties: true
- require_scope_for_methods: true
- require_php_tag_first: true
- psr2_switch_declaration: true
- psr2_class_declaration: true
- property_assignments: true
- prefer_while_loop_over_for_loop: true
- precedence_mistakes: true
- precedence_in_conditions: true
- phpunit_assertions: true
- php5_style_constructor: true
- parse_doc_comments: true
- parameter_non_unique: true
- parameter_doc_comments: true
- param_doc_comment_if_not_inferrable: true
- optional_parameters_at_the_end: true
- one_class_per_file: true
- no_unnecessary_if: true
- no_trailing_whitespace: true
- no_property_on_interface: true
- no_non_implemented_abstract_methods: true
- no_error_suppression: true
- no_duplicate_arguments: true
- no_commented_out_code: true
- newline_at_end_of_file: true
- missing_arguments: true
- method_calls_on_non_object: true
- instanceof_class_exists: true
- foreach_traversable: true
- fix_line_ending: true
- fix_doc_comments: true
- duplication: true
- deprecated_code_usage: true
- deadlock_detection_in_loops: true
- code_rating: true
- closure_use_not_conflicting: true
- catch_class_exists: true
- blank_line_after_namespace_declaration: false
- avoid_multiple_statements_on_same_line: true
- avoid_duplicate_types: true
- avoid_conflicting_incrementers: true
- avoid_closing_tag: true
- assignment_of_null_return: true
- argument_type_checks: true
-
-filter:
- paths: [code/*, tests/*]
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 580c3a4..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,29 +0,0 @@
-# Changelog
-
-This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-
-Older releases can be found on Github.
-
-## 2.1.7
-
-- Adds legacy file for migration from Silverstripe 3
-
-Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.6...2.1.7
-
-## 2.1.6
-
-- Fixes incorrect priority calculations
-
-Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.5...2.1.6
-
-## 2.1.5
-
-- FIX: enable stream context to pass through CWP egres proxy, fixes #156
-
-Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.4...2.1.5
-
-## 2.1.4
-
-- Fixes extending alterSiteMap to support falsey values
-
-Full changelog: https://github.com/wilr/silverstripe-googlesitemaps/compare/2.1.3...2.1.4
diff --git a/README.md b/README.md
index 14a17c2..ecfa11e 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,10 @@
> composer require "wilr/silverstripe-googlesitemaps"
+If you're using Silverstripe 5 then version 3 or `dev-main` will work.
+
+For Silverstripe 4 use the `2.x` branch line.
+
## Documentation
Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html),
diff --git a/src/Control/GoogleSitemapController.php b/src/Control/GoogleSitemapController.php
index 01a75b5..6bbad81 100644
--- a/src/Control/GoogleSitemapController.php
+++ b/src/Control/GoogleSitemapController.php
@@ -4,9 +4,8 @@ namespace Wilr\GoogleSitemaps\Control;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
-use SilverStripe\Core\Config\Config;
+use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
-use SilverStripe\Core\Manifest\ModuleResourceLoader;
use Wilr\GoogleSitemaps\GoogleSitemap;
use SilverStripe\View\ArrayData;
@@ -52,7 +51,7 @@ class GoogleSitemapController extends Controller
$this->extend('updateGoogleSitemaps', $sitemaps);
return $this->customise(new ArrayData([
- 'Sitemaps' => $sitemaps
+ 'Sitemaps' => $sitemaps,
]))->renderWith(__CLASS__);
} else {
return new HTTPResponse('Page not found', 404);
@@ -76,7 +75,8 @@ class GoogleSitemapController extends Controller
}
}
- if (GoogleSitemap::enabled()
+ if (
+ GoogleSitemap::enabled()
&& $class
&& ($page > 0)
&& ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))
@@ -129,4 +129,10 @@ class GoogleSitemapController extends Controller
return $html;
}
+
+
+ public function AbsoluteLink($action = null)
+ {
+ return Controller::join_links(Director::absoluteBaseURL(), 'sitemap.xml', $action);
+ }
}
diff --git a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss
index 1e0852f..ee231ad 100644
--- a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss
+++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss
@@ -1,8 +1,8 @@
-
+
<% loop Sitemaps %>
-
- {$AbsoluteBaseURL}/sitemap.xml/sitemap/$ClassName/$Page.xml
- <% if $LastModified %>$LastModified<% end_if %>
- <% end_loop %>
+
+ {$AbsoluteLink('sitemap')}/{$ClassName}/{$Page.xml}
+ <% if $LastModified %>{$LastModified}<% end_if %>
+ <% end_loop %>
diff --git a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss
index 99aa385..c14e214 100644
--- a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss
+++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss
@@ -1,10 +1,10 @@
-
+
<% loop $Items %>
- $AbsoluteLink
- <% if $LastEdited %>$LastEdited.Rfc3339()<% end_if %>
+ {$AbsoluteLink}
+ <% if $LastEdited %>{$LastEdited.Rfc3339()}<% end_if %>
<% if $ChangeFrequency %>$ChangeFrequency<% end_if %>
<% if $GooglePriority %>$GooglePriority<% end_if %>
<% if $ImagesForSitemap %><% loop $ImagesForSitemap %>
diff --git a/tests/GoogleSitemapTest.php b/tests/GoogleSitemapTest.php
index ff659b5..c493a00 100644
--- a/tests/GoogleSitemapTest.php
+++ b/tests/GoogleSitemapTest.php
@@ -4,7 +4,6 @@ namespace Wilr\GoogleSitemaps\Tests;
use Exception;
use SilverStripe\CMS\Model\SiteTree;
-use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\DropdownField;
@@ -25,6 +24,8 @@ class GoogleSitemapTest extends FunctionalTest
'GoogleSitemapPageTest.yml',
];
+ protected $usesDatabase = true;
+
protected static $extra_dataobjects = [
TestDataObject::class,
OtherDataObject::class,
@@ -131,8 +132,8 @@ class GoogleSitemapTest extends FunctionalTest
$page2->publishSingle();
$page2->flushCache();
- DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-03-14 00:00:00' WHERE \"ID\"='".$page->ID."'");
- DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='".$page2->ID."'");
+ DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-03-14 00:00:00' WHERE \"ID\"='" . $page->ID . "'");
+ DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='" . $page2->ID . "'");
$response = $this->get('sitemap.xml');
$body = $response->getBody();
@@ -309,7 +310,7 @@ class GoogleSitemapTest extends FunctionalTest
Versioned::set_reading_mode($oldMode);
throw $ex;
} // finally {
- Versioned::set_reading_mode($oldMode);
+ Versioned::set_reading_mode($oldMode);
// }
}
}
diff --git a/tests/xml/testAccessingSitemapRootXMLFile.xml b/tests/xml/testAccessingSitemapRootXMLFile.xml
index 81887a8..d6452be 100644
--- a/tests/xml/testAccessingSitemapRootXMLFile.xml
+++ b/tests/xml/testAccessingSitemapRootXMLFile.xml
@@ -1,12 +1,12 @@
-
+
- http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1
+ http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1
2023-02-13
- http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1
+ http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1
2023-02-13
diff --git a/tests/xml/testIndexFilePaginatedSitemapFiles.xml b/tests/xml/testIndexFilePaginatedSitemapFiles.xml
index 24e5635..108caf1 100644
--- a/tests/xml/testIndexFilePaginatedSitemapFiles.xml
+++ b/tests/xml/testIndexFilePaginatedSitemapFiles.xml
@@ -1,16 +1,16 @@
-
+
- http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1
+ http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1
2023-02-13
- http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2
+ http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2
2023-02-13
- http://localhostsitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/3
+ http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/3
2023-02-13
diff --git a/tests/xml/testIndexFileWithCustomRoute.xml b/tests/xml/testIndexFileWithCustomRoute.xml
index 6dc3307..e45e5bb 100644
--- a/tests/xml/testIndexFileWithCustomRoute.xml
+++ b/tests/xml/testIndexFileWithCustomRoute.xml
@@ -1,7 +1,7 @@
-
+
- http://localhostsitemap.xml/sitemap/GoogleSitemapRoute/1
+ http://localhost/sitemap.xml/sitemap/GoogleSitemapRoute/1