mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
Compare commits
No commits in common. "main" and "2.1.6" have entirely different histories.
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -1,11 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
name: CI
|
|
||||||
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
|
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/vendor
|
|
||||||
/public
|
|
||||||
/composer.lock
|
|
||||||
|
69
.scrutinizer.yml
Normal file
69
.scrutinizer.yml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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/*]
|
32
.travis.yml
Normal file
32
.travis.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- COMPOSER_ROOT_VERSION=2.x-dev
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: 7.2
|
||||||
|
env: DB=MYSQL PHPUNIT_TEST=1 PHPCS_TEST=1
|
||||||
|
- php: 7.3
|
||||||
|
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# Init PHP
|
||||||
|
- phpenv rehash
|
||||||
|
- phpenv config-rm xdebug.ini
|
||||||
|
- composer validate
|
||||||
|
- composer require silverstripe/recipe-cms 4.5.x-dev --no-update
|
||||||
|
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi
|
||||||
|
- if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
|
||||||
|
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
||||||
|
|
||||||
|
script:
|
||||||
|
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
|
||||||
|
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||||
|
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ ; fi
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
@ -1,2 +0,0 @@
|
|||||||
mappings:
|
|
||||||
GoogleSitemap: Wilr\GoogleSitemaps\GoogleSitemap
|
|
5
CHANGELOG
Normal file
5
CHANGELOG
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
0.1
|
||||||
|
- Initial Build
|
||||||
|
|
||||||
|
0.2
|
||||||
|
- Moved Decorator to a separate file
|
@ -6,16 +6,12 @@
|
|||||||
|
|
||||||
## Maintainer Contact
|
## Maintainer Contact
|
||||||
|
|
||||||
- Will Rossiter (Nickname: wrossiter, willr) <will@fullscreen.io>
|
* Will Rossiter (Nickname: wrossiter, willr) <will@fullscreen.io>
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
> composer require "wilr/silverstripe-googlesitemaps"
|
> 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
|
## Documentation
|
||||||
|
|
||||||
Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html),
|
Provides support for the [Sitemaps XML Protocol](http://www.sitemaps.org/protocol.html),
|
||||||
@ -34,4 +30,4 @@ See docs/en for more information about configuring the module.
|
|||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- Flush this route to ensure the changes take effect (e.g http://yoursite.com/sitemap.xml?flush=1)
|
* Flush this route to ensure the changes take effect (e.g http://yoursite.com/sitemap.xml?flush=1)
|
||||||
|
10
_config.php
10
_config.php
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use SilverStripe\Core\ClassInfo;
|
|
||||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
|
||||||
|
|
||||||
if (0 === strpos(ltrim($_SERVER['REQUEST_URI'], '/'), 'sitemap')) {
|
|
||||||
foreach (ClassInfo::implementorsOf(Sitemapable::class) as $className) {
|
|
||||||
GoogleSitemap::register_dataobject($className);
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,6 +4,7 @@ Name: googlesitemaps
|
|||||||
Wilr\GoogleSitemaps\GoogleSitemap:
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
||||||
enabled: true
|
enabled: true
|
||||||
objects_per_sitemap: 1000
|
objects_per_sitemap: 1000
|
||||||
|
google_notification_enabled: false
|
||||||
use_show_in_search: true
|
use_show_in_search: true
|
||||||
---
|
---
|
||||||
Only:
|
Only:
|
||||||
|
@ -1,34 +1,27 @@
|
|||||||
{
|
{
|
||||||
"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 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-vendormodule",
|
"type": "silverstripe-vendormodule",
|
||||||
"keywords": [
|
"keywords": ["silverstripe", "googlesitemaps", "seo"],
|
||||||
"silverstripe",
|
"homepage": "https://github.com/wilr/silverstripe-googlesitemaps",
|
||||||
"googlesitemaps",
|
"license": "BSD-3-Clause",
|
||||||
"seo"
|
"authors": [{
|
||||||
],
|
"name": "Will Rossiter",
|
||||||
"homepage": "https://github.com/wilr/silverstripe-googlesitemaps",
|
"email": "will@fullscreen.io"
|
||||||
"license": "BSD-3-Clause",
|
}],
|
||||||
"authors": [
|
"require": {
|
||||||
{
|
"silverstripe/framework": "^4"
|
||||||
"name": "Will Rossiter",
|
},
|
||||||
"email": "will@fullscreen.io"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
|
||||||
"php": "^8.1",
|
|
||||||
"silverstripe/framework": "^5"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9.5",
|
"phpunit/phpunit": "^5.7",
|
||||||
"squizlabs/php_codesniffer": "^3"
|
"squizlabs/php_codesniffer": "^3"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"silverstripe/googlesitemaps": "*"
|
"silverstripe/googlesitemaps":"*"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-main": "3.x-dev"
|
"dev-master": "2.x-dev"
|
||||||
},
|
},
|
||||||
"expose": [
|
"expose": [
|
||||||
"images",
|
"images",
|
||||||
@ -42,12 +35,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev"
|
||||||
"config": {
|
|
||||||
"allow-plugins": {
|
|
||||||
"composer/installers": true,
|
|
||||||
"silverstripe/vendor-plugin": true,
|
|
||||||
"silverstripe/recipe-plugin": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
267
css/style.css
267
css/style.css
@ -1,145 +1,144 @@
|
|||||||
:root {
|
*{
|
||||||
--color-black: #292B2E;
|
margin: 0;
|
||||||
--color-blue-bright: #005AE1;
|
padding: 0;
|
||||||
--color-blue-dark: #003E94;
|
|
||||||
--color-blue-light: #E6EDF4;
|
|
||||||
--color-grey-dark: #595D64;
|
|
||||||
--color-grey-light: #f7f8f8;
|
|
||||||
--color-grey-medium: #DCDEE0;
|
|
||||||
--color-white: #fff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
|
||||||
font-size: 10px;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
}
|
|
||||||
|
|
||||||
body, table {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
||||||
font-size: 1.4rem;
|
|
||||||
font-weight: 400;
|
|
||||||
line-height: 1.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: var(--color-white);
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
color: var(--color-grey-dark);
|
font-size: 14px;
|
||||||
|
color: #545353;
|
||||||
|
color: #005A92;
|
||||||
|
background: #B0BEC7;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
#content {
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 1200px;
|
||||||
|
background: #fff;
|
||||||
|
padding: 20px 30px;
|
||||||
|
-webkit-box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.2);
|
||||||
|
box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.2);
|
||||||
|
-webkit-border-radius: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
h1{
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #1556B2;
|
||||||
|
color: #005A92;
|
||||||
|
/* text-shadow: 1px 1px 1px rgba(0,0,0,0.7);
|
||||||
|
filter: dropshadow(color=#000, offx=2, offy=2);*/
|
||||||
|
padding-left: 31px;
|
||||||
|
background: url("../images/logo_small.png") transparent left top no-repeat scroll;
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
h1 a{
|
||||||
|
font: inherit;
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
h1 .ss_link{
|
||||||
|
visibility: hidden;
|
||||||
|
font-size: 9px;
|
||||||
|
display: block;
|
||||||
|
text-align: right;
|
||||||
|
margin-top: -5px;
|
||||||
|
}
|
||||||
|
h1:hover .ss_link{
|
||||||
|
visibility: visible;
|
||||||
|
text-decoration: underline;
|
||||||
|
|
||||||
|
}
|
||||||
|
.expl {
|
||||||
|
margin: 10px 3px;
|
||||||
|
line-height: 1.3em;
|
||||||
|
}
|
||||||
|
.expl a {
|
||||||
|
color: #1556B2;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.expl a:hover{
|
||||||
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table.tablesorter {
|
||||||
border-collapse: collapse;
|
background-color: #CDCDCD;
|
||||||
color: var(--color-black);
|
margin:20px 0pt 15px;
|
||||||
text-align: left;
|
font-size: 8pt;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
border: none;
|
||||||
|
border-collapse: collapse;
|
||||||
|
border-bottom: 1px solid #005A92;
|
||||||
|
}
|
||||||
|
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
|
||||||
|
/*background-color: #e6EEEE;*/
|
||||||
|
background-color: #F5FAFA;
|
||||||
|
font-size: 8pt;
|
||||||
|
padding: 4px 20px 4px 10px;
|
||||||
|
}
|
||||||
|
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
|
||||||
|
background-color: #B0BEC7;
|
||||||
|
background-color: #e6EEEE;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
table.tablesorter thead tr .header {
|
||||||
color: inherit;
|
background-image: url("../images/bg.gif");
|
||||||
text-decoration: none;
|
background-repeat: no-repeat;
|
||||||
|
background-position: center right;
|
||||||
|
cursor: pointer;
|
||||||
|
border-bottom: 1px solid #005A92;
|
||||||
|
}
|
||||||
|
table.tablesorter thead tr .headerSortUp {
|
||||||
|
background-image: url("../images/asc.gif");
|
||||||
|
}
|
||||||
|
table.tablesorter thead tr .headerSortDown {
|
||||||
|
background-image: url("../images/desc.gif");
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
table.tablesorter tbody td {
|
||||||
margin: 0 auto;
|
color: #005A92;
|
||||||
max-width: 122rem;
|
padding: 4px;
|
||||||
padding: 2rem;
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody tr{
|
||||||
|
background-color: #FFF;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody tr.odd {
|
||||||
|
background-color:#EFF2F3;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody tr:hover {
|
||||||
|
background-color: #D8E1E8;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody a{
|
||||||
|
color: #444;color: #005A92;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody a:hover{
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
table.tablesorter tbody tr:hover td,
|
||||||
|
table.tablesorter tbody tr:hover a{
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
table.imagestable,
|
||||||
|
table.imagestable a {
|
||||||
|
font-size: 8pt;
|
||||||
|
}
|
||||||
|
table.imagestable {
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
table.imagestable tr.odd {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
table.imagestable tr.even {
|
||||||
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content__title {
|
#Footer{
|
||||||
align-items: center;
|
margin: 50px 0 10px;
|
||||||
color: var(--color-black);
|
text-align: right;
|
||||||
display: inline-flex;
|
font-size: 0.8em;
|
||||||
font-size: 2rem;
|
|
||||||
font-weight: 600;
|
|
||||||
margin: 0 0 3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content__title::before {
|
|
||||||
content: "";
|
|
||||||
background: url("../images/cms_logo.svg") left center no-repeat;
|
|
||||||
border-right: 0.1rem solid var(--color-grey-medium);
|
|
||||||
display: inline-block;
|
|
||||||
height: 3.2rem;
|
|
||||||
margin-right: 1.5rem;
|
|
||||||
padding-right: 1.5rem;
|
|
||||||
width: 3.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content__text {
|
|
||||||
margin: 1rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content__text a {
|
|
||||||
color: var(--color-blue-bright);
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content__text a:hover {
|
|
||||||
color: var(--color-blue-dark);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-wrapper {
|
|
||||||
border-top: 0.1rem solid var(--color-grey-medium);
|
|
||||||
margin: 3rem 0 5rem;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table__cell {
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table__cell--w-10 {
|
|
||||||
width: 10%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table__cell--w-15 {
|
|
||||||
width: 15%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table__cell--w-65 {
|
|
||||||
width: 65%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table__cell--w-85 {
|
|
||||||
width: 85%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table tbody tr:nth-child(odd) td {
|
|
||||||
background-color: var(--color-grey-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.table tbody tr:hover td {
|
|
||||||
background-color: var(--color-blue-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.table a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.image-table__cell {
|
|
||||||
padding: 1rem 1rem 0 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.image-table__cell--image {
|
|
||||||
width: 6rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.image-table__cell--text {
|
|
||||||
width: calc(100% - 6rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
.image-table__image {
|
|
||||||
height: 4rem;
|
|
||||||
object-fit: cover;
|
|
||||||
width: 6rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.image-table__title {
|
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
|
140
docs/en/index.md
140
docs/en/index.md
@ -1,23 +1,23 @@
|
|||||||
# Google Sitemaps Module
|
# Google Sitemaps Module
|
||||||
|
|
||||||
Silverstripe CMS 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 CMS 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 CMS websites contain a special controller which can
|
Therefore, all Silverstripe websites contain a special controller which can be
|
||||||
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 CMS 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 CMS 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 CMS 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).
|
||||||
@ -27,32 +27,45 @@ manually, including requesting to have the page excluded from the sitemap.
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Most module configuration is done via the Silverstripe CMS Config API. Create a
|
Most module configuration is done via the SilverStripe Config API. Create a new
|
||||||
new config file `mysite/_config/googlesitemaps.yml` with the following outline:
|
config file `mysite/_config/googlesitemaps.yml` with the following outline:
|
||||||
|
|
||||||
```yml
|
---
|
||||||
---
|
Name: customgooglesitemaps
|
||||||
Name: customgooglesitemaps
|
After: googlesitemaps
|
||||||
After: googlesitemaps
|
---
|
||||||
---
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
||||||
Wilr\GoogleSitemaps\GoogleSitemap:
|
enabled: true
|
||||||
enabled: true
|
objects_per_sitemap: 1000
|
||||||
objects_per_sitemap: 1000
|
google_notification_enabled: false
|
||||||
use_show_in_search: true
|
use_show_in_search: true
|
||||||
```
|
|
||||||
|
|
||||||
You can now alter any of those properties to set your needs.
|
You can now alter any of those properties to set your needs. A popular option
|
||||||
|
is to turn on automatic pinging so that Google is notified of any updates to
|
||||||
|
your page. You can set this in the file we created in the last paragraph by
|
||||||
|
editing the `google_notification_enabled` option to true
|
||||||
|
|
||||||
```yml
|
---
|
||||||
---
|
Name: customgooglesitemaps
|
||||||
Name: customgooglesitemaps
|
After: googlesitemaps
|
||||||
After: googlesitemaps
|
---
|
||||||
---
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
||||||
Wilr\GoogleSitemaps\GoogleSitemap:
|
enabled: true
|
||||||
enabled: true
|
objects_per_sitemap: 1000
|
||||||
objects_per_sitemap: 1000
|
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
|
||||||
|
---
|
||||||
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
||||||
|
enabled: true
|
||||||
|
bing_notification_enabled: true
|
||||||
|
|
||||||
### Including DataObjects
|
### Including DataObjects
|
||||||
|
|
||||||
@ -63,40 +76,41 @@ 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
|
||||||
|
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
|
|
||||||
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() {
|
||||||
|
return 'MyController/show/'. $this->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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
|
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.
|
||||||
|
|
||||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||||
|
|
||||||
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
|
||||||
@ -104,7 +118,7 @@ instead of the previous code you would write:
|
|||||||
|
|
||||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
@ -112,33 +126,15 @@ http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/
|
|||||||
|
|
||||||
### Including custom routes
|
### Including custom routes
|
||||||
|
|
||||||
Occasionally you may have a need to include custom URLs in your sitemap for
|
Occasionally you may have a need to include custom url's in your sitemap for
|
||||||
your Controllers and other pages which don't exist in the database. To update
|
your Controllers and other pages which don't exist in the database. To update
|
||||||
the sitemap to include those links call register_routes() with your array of
|
the sitemap to include those links call register_routes() with your array of
|
||||||
URLs to include.
|
urls to include.
|
||||||
|
|
||||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||||
|
|
||||||
GoogleSitemap::register_routes(array(
|
GoogleSitemap::register_routes(array(
|
||||||
'/my-custom-controller/',
|
'/my-custom-controller/',
|
||||||
'/Security/',
|
'/Security/',
|
||||||
'/Security/login/'
|
'/Security/login/'
|
||||||
));
|
));
|
||||||
|
|
||||||
### Sitemapable
|
|
||||||
|
|
||||||
For automatic registration of a DataObject subclass, implement the `Sitemapable`
|
|
||||||
extension.
|
|
||||||
|
|
||||||
```
|
|
||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
class MyDataObject extends DataObject implements Sitemapable
|
|
||||||
{
|
|
||||||
public function AbsoluteLink()
|
|
||||||
{
|
|
||||||
// ..
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
BIN
images/asc.gif
Normal file
BIN
images/asc.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 B |
BIN
images/bg.gif
Normal file
BIN
images/bg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 B |
@ -1,4 +0,0 @@
|
|||||||
<svg width="32" height="19" viewBox="0 0 32 19" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M15.832 1.85439L9.09495 6.56978C8.16307 7.22084 7.93658 8.50206 8.58764 9.43478C9.2387 10.3667 10.5199 10.5931 11.4526 9.94209L18.1897 5.2267C20.9787 3.27352 24.8307 3.95216 26.7772 6.74111C28.7304 9.53005 28.0518 13.3821 25.2628 15.3286L23.145 16.8087C24.8993 19.7899 28.8675 18.5354 30.6702 15.3353C32.5549 11.9905 32.4863 7.72146 30.1428 4.37673C26.8926 -0.263432 20.4714 -1.39422 15.832 1.85439Z" fill="#005AE1"/>
|
|
||||||
<path d="M16.1671 16.6776L22.9042 11.9622C23.836 11.3112 24.0625 10.03 23.4115 9.09724C22.7604 8.16536 21.4792 7.93887 20.5465 8.58993L13.8094 13.3053C11.0204 15.2585 7.1684 14.5799 5.22191 11.7909C3.26873 9.00196 3.94737 5.14992 6.73631 3.20343L8.85414 1.72329C7.1007 -1.25705 3.1325 -0.00256691 1.32975 3.19758C-0.554895 6.54231 -0.486362 10.8114 1.85712 14.1561C5.10574 18.7955 11.5269 19.9338 16.1671 16.6785V16.6776Z" fill="#005AE1"/>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 970 B |
BIN
images/desc.gif
Normal file
BIN
images/desc.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 B |
BIN
images/logo_small.png
Normal file
BIN
images/logo_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
@ -1,9 +0,0 @@
|
|||||||
de:
|
|
||||||
GoogleSitemaps:
|
|
||||||
METANOTEPRIORITY: 'Manuelle Google Sitemaps-Priorität für diese Seite (%s)'
|
|
||||||
METAPAGEPRIO: 'Page Priorität'
|
|
||||||
PRIORITYAUTOSET: 'Automatisch basierend auf Verschachtelung im Seitenbaum'
|
|
||||||
PRIORITYLEASTIMPORTANT: 'Am wenigsten wichtig'
|
|
||||||
PRIORITYMOSTIMPORTANT: 'Am wichtigsten'
|
|
||||||
PRIORITYNOTINDEXED: 'Nicht indexiert'
|
|
||||||
TABGOOGLESITEMAP: 'Google Sitemap'
|
|
@ -1,9 +0,0 @@
|
|||||||
sl:
|
|
||||||
GoogleSitemaps:
|
|
||||||
METANOTEPRIORITY: 'Ročno nastavite (Google Sitemaps priority) pomembnost trenutne strani (%s)'
|
|
||||||
METAPAGEPRIO: 'Pomembnost strani'
|
|
||||||
PRIORITYAUTOSET: 'Samodejno glede na nivo v strukturi'
|
|
||||||
PRIORITYLEASTIMPORTANT: 'Manj pomembna'
|
|
||||||
PRIORITYMOSTIMPORTANT: 'Bolj pomembna'
|
|
||||||
PRIORITYNOTINDEXED: 'Ne indeksiraj'
|
|
||||||
TABGOOGLESITEMAP: 'Google Sitemap'
|
|
@ -1,10 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ruleset name="SilverStripe">
|
<ruleset name="SilverStripe">
|
||||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||||
<file>src</file>
|
|
||||||
<file>tests</file>
|
|
||||||
<!-- base rules are PSR-2 -->
|
<!-- base rules are PSR-2 -->
|
||||||
<rule ref="PSR2">
|
<rule ref="PSR2" >
|
||||||
<!-- Current exclusions -->
|
<!-- Current exclusions -->
|
||||||
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
||||||
</rule>
|
</rule>
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?xml version="1.0"?>
|
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
<testsuite name="Default">
|
||||||
<coverage includeUncoveredFiles="true">
|
<directory>tests</directory>
|
||||||
<include>
|
</testsuite>
|
||||||
<directory suffix=".php">src/</directory>
|
|
||||||
</include>
|
<filter>
|
||||||
<exclude>
|
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||||
<directory suffix=".php">tests/</directory>
|
<directory suffix=".php">src/</directory>
|
||||||
</exclude>
|
<exclude>
|
||||||
</coverage>
|
<directory suffix=".php">tests/</directory>
|
||||||
<testsuite name="Default">
|
</exclude>
|
||||||
<directory>tests</directory>
|
</whitelist>
|
||||||
</testsuite>
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -4,8 +4,9 @@ namespace Wilr\GoogleSitemaps\Control;
|
|||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||||
use Wilr\GoogleSitemaps\GoogleSitemap;
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ class GoogleSitemapController extends Controller
|
|||||||
$this->extend('updateGoogleSitemaps', $sitemaps);
|
$this->extend('updateGoogleSitemaps', $sitemaps);
|
||||||
|
|
||||||
return $this->customise(new ArrayData([
|
return $this->customise(new ArrayData([
|
||||||
'Sitemaps' => $sitemaps,
|
'Sitemaps' => $sitemaps
|
||||||
]))->renderWith(__CLASS__);
|
]))->renderWith(__CLASS__);
|
||||||
} else {
|
} else {
|
||||||
return new HTTPResponse('Page not found', 404);
|
return new HTTPResponse('Page not found', 404);
|
||||||
@ -67,17 +68,11 @@ class GoogleSitemapController extends Controller
|
|||||||
public function sitemap()
|
public function sitemap()
|
||||||
{
|
{
|
||||||
$class = $this->unsanitiseClassName($this->request->param('ID'));
|
$class = $this->unsanitiseClassName($this->request->param('ID'));
|
||||||
$page = intval($this->request->param('OtherID'));
|
$page = $this->request->param('OtherID');
|
||||||
|
|
||||||
if ($page) {
|
|
||||||
if (!is_numeric($page)) {
|
|
||||||
return new HTTPResponse('Page not found', 404);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GoogleSitemap::enabled()
|
if (GoogleSitemap::enabled()
|
||||||
&& $class
|
&& $class
|
||||||
&& ($page > 0)
|
&& $page
|
||||||
&& ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))
|
&& ($class == SiteTree::class || $class == 'GoogleSitemapRoute' || GoogleSitemap::is_registered($class))
|
||||||
) {
|
) {
|
||||||
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
||||||
@ -100,7 +95,7 @@ class GoogleSitemapController extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function unsanitiseClassName($class)
|
protected function unsanitiseClassName($class)
|
||||||
{
|
{
|
||||||
return str_replace('-', '\\', (string) $class);
|
return str_replace('-', '\\', $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,10 +123,4 @@ class GoogleSitemapController extends Controller
|
|||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function AbsoluteLink($action = null)
|
|
||||||
{
|
|
||||||
return rtrim(Controller::join_links(Director::absoluteBaseURL(), 'sitemap.xml', $action), '/');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class GoogleSitemapExtension extends DataExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$objHttp = parse_url($this->owner->AbsoluteLink() ?? '', PHP_URL_HOST);
|
$objHttp = parse_url($this->owner->AbsoluteLink(), PHP_URL_HOST);
|
||||||
|
|
||||||
if ($objHttp != $hostHttp) {
|
if ($objHttp != $hostHttp) {
|
||||||
$can = false;
|
$can = false;
|
||||||
@ -66,13 +66,27 @@ class GoogleSitemapExtension extends DataExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($can) && isset($can[0])) {
|
|
||||||
return $can[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $can;
|
return $can;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onAfterPublish()
|
||||||
|
{
|
||||||
|
GoogleSitemap::ping();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onAfterUnpublish()
|
||||||
|
{
|
||||||
|
GoogleSitemap::ping();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default value of the priority field depends on the depth of the page in
|
* The default value of the priority field depends on the depth of the page in
|
||||||
* the site tree, so it must be calculated dynamically.
|
* the site tree, so it must be calculated dynamically.
|
||||||
|
@ -8,7 +8,6 @@ use SilverStripe\Forms\DropdownField;
|
|||||||
use SilverStripe\Forms\LiteralField;
|
use SilverStripe\Forms\LiteralField;
|
||||||
use SilverStripe\Forms\Tab;
|
use SilverStripe\Forms\Tab;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
||||||
{
|
{
|
||||||
@ -104,10 +103,6 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
$result = parent::canIncludeInGoogleSitemap();
|
$result = parent::canIncludeInGoogleSitemap();
|
||||||
$result = ($this->owner instanceof ErrorPage) ? false : $result;
|
$result = ($this->owner instanceof ErrorPage) ? false : $result;
|
||||||
|
|
||||||
if (is_array($result) && isset($result[0])) {
|
|
||||||
return $result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +116,7 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
|
|
||||||
if (!$priority) {
|
if (!$priority) {
|
||||||
$parentStack = $this->owner->getAncestors();
|
$parentStack = $this->owner->getAncestors();
|
||||||
$numParents = $parentStack->count();
|
$numParents = is_array($parentStack) ? count($parentStack) - 1 : 0;
|
||||||
|
|
||||||
$num = max(0.1, 1.0 - ($numParents / 10));
|
$num = max(0.1, 1.0 - ($numParents / 10));
|
||||||
$result = str_replace(",", ".", $num);
|
$result = str_replace(",", ".", $num);
|
||||||
@ -140,21 +135,13 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
$cachedImages = [];
|
$cachedImages = [];
|
||||||
|
|
||||||
foreach ($this->owner->hasOne() as $field => $type) {
|
foreach ($this->owner->hasOne() as $field => $type) {
|
||||||
if (strpos($type, '.') !== false) {
|
|
||||||
$type = explode('.', $type)[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (singleton($type) instanceof Image) {
|
if (singleton($type) instanceof Image) {
|
||||||
$image = $this->owner->getComponent($field);
|
$image = $this->owner->getComponent($field);
|
||||||
|
|
||||||
try {
|
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
$cachedImages[$image->ID] = true;
|
||||||
$cachedImages[$image->ID] = true;
|
|
||||||
|
|
||||||
$list->push($image);
|
$list->push($image);
|
||||||
}
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,48 +151,10 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
|
|||||||
$images = $this->owner->getComponents($field);
|
$images = $this->owner->getComponents($field);
|
||||||
|
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
try {
|
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
$cachedImages[$image->ID] = true;
|
||||||
$cachedImages[$image->ID] = true;
|
|
||||||
|
|
||||||
$list->push($image);
|
$list->push($image);
|
||||||
}
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->owner->manyMany() as $field => $type) {
|
|
||||||
$image = false;
|
|
||||||
|
|
||||||
if (is_array($type) && isset($type['through'])) {
|
|
||||||
if (singleton($type['through']) instanceof Image) {
|
|
||||||
$image = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (strpos($type, '.') !== false) {
|
|
||||||
$type = explode('.', $type)[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (singleton($type) instanceof Image) {
|
|
||||||
$image = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($image) {
|
|
||||||
$images = $this->owner->$field();
|
|
||||||
|
|
||||||
foreach ($images as $image) {
|
|
||||||
try {
|
|
||||||
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
|
|
||||||
$cachedImages[$image->ID] = true;
|
|
||||||
|
|
||||||
$list->push($image);
|
|
||||||
}
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,17 @@ use ReflectionException;
|
|||||||
* The GoogleSitemap handle requests to 'sitemap.xml' the other two classes are
|
* The GoogleSitemap handle requests to 'sitemap.xml' the other two classes are
|
||||||
* used to render the sitemap.
|
* used to render the sitemap.
|
||||||
*
|
*
|
||||||
* The config file is usually located in the _config folder of your project folder.
|
* You can notify ("ping") Google about a changed sitemap automatically whenever
|
||||||
* e.g. app/_config/googlesitemaps.yml
|
* a new page is published or unpublished.
|
||||||
|
*
|
||||||
|
* By default, Google is not notified, and will pick up your new sitemap
|
||||||
|
* whenever the GoogleBot visits your website.
|
||||||
|
*
|
||||||
|
* To Enable notification of Google after every publish set google_notification_enabled
|
||||||
|
* to true in the googlesitemaps.yml config file.
|
||||||
|
*
|
||||||
|
* This file is usually located in the _config folder of your project folder.
|
||||||
|
* e.g mysite/_config/googlesitemaps.yml
|
||||||
*
|
*
|
||||||
* <example>
|
* <example>
|
||||||
* ---
|
* ---
|
||||||
@ -40,6 +49,7 @@ use ReflectionException;
|
|||||||
* Wilr\GoogleSitemaps\GoogleSitemap:
|
* Wilr\GoogleSitemaps\GoogleSitemap:
|
||||||
* enabled: true
|
* enabled: true
|
||||||
* objects_per_sitemap: 1000
|
* objects_per_sitemap: 1000
|
||||||
|
* google_notification_enabled: true
|
||||||
* use_show_in_search: true
|
* use_show_in_search: true
|
||||||
* </example>
|
* </example>
|
||||||
*
|
*
|
||||||
@ -74,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.
|
||||||
@ -216,8 +236,7 @@ class GoogleSitemap
|
|||||||
*/
|
*/
|
||||||
public function getItems($class, $page = 1)
|
public function getItems($class, $page = 1)
|
||||||
{
|
{
|
||||||
$page = (int) $page;
|
//normalise the class name
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$reflectionClass = new ReflectionClass($class);
|
$reflectionClass = new ReflectionClass($class);
|
||||||
$class = $reflectionClass->getName();
|
$class = $reflectionClass->getName();
|
||||||
@ -227,9 +246,9 @@ class GoogleSitemap
|
|||||||
}
|
}
|
||||||
|
|
||||||
$output = new ArrayList();
|
$output = new ArrayList();
|
||||||
$count = (int) Config::inst()->get(__CLASS__, 'objects_per_sitemap');
|
$count = Config::inst()->get(__CLASS__, 'objects_per_sitemap');
|
||||||
$filter = Config::inst()->get(__CLASS__, 'use_show_in_search');
|
$filter = Config::inst()->get(__CLASS__, 'use_show_in_search');
|
||||||
$redirector = Config::inst()->get(__CLASS__, 'exclude_redirector_pages');
|
$redirector = Config::inst()->get(__CLASS__, 'exclude_redirector_pages');
|
||||||
|
|
||||||
// todo migrate to extension hook or DI point for other modules to
|
// todo migrate to extension hook or DI point for other modules to
|
||||||
// modify state filters
|
// modify state filters
|
||||||
@ -371,7 +390,7 @@ class GoogleSitemap
|
|||||||
for ($i = 1; $i <= $neededForPage; $i++) {
|
for ($i = 1; $i <= $neededForPage; $i++) {
|
||||||
$lastEdited = $instances
|
$lastEdited = $instances
|
||||||
->limit($countPerFile, ($i - 1) * $countPerFile)
|
->limit($countPerFile, ($i - 1) * $countPerFile)
|
||||||
->sort(null)
|
->sort(array())
|
||||||
->max('LastEdited');
|
->max('LastEdited');
|
||||||
|
|
||||||
$lastModified = ($lastEdited) ? date('Y-m-d', strtotime($lastEdited)) : date('Y-m-d');
|
$lastModified = ($lastEdited) ? date('Y-m-d', strtotime($lastEdited)) : date('Y-m-d');
|
||||||
@ -397,7 +416,7 @@ class GoogleSitemap
|
|||||||
->limit($countPerFile, ($i - 1) * $countPerFile)
|
->limit($countPerFile, ($i - 1) * $countPerFile)
|
||||||
->last();
|
->last();
|
||||||
|
|
||||||
$lastModified = ($sliced) ? date('Y-m-d', strtotime($sliced->LastEdited)) : date('Y-m-d');
|
$lastModified = ($sliced) ? date('Y-m-d', strtotime($sliced->LastEdited)): date('Y-m-d');
|
||||||
|
|
||||||
$sitemaps->push(new ArrayData(array(
|
$sitemaps->push(new ArrayData(array(
|
||||||
'ClassName' => $this->sanitiseClassName($class),
|
'ClassName' => $this->sanitiseClassName($class),
|
||||||
@ -433,6 +452,41 @@ class GoogleSitemap
|
|||||||
return static::inst()->getSitemaps();
|
return static::inst()->getSitemaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies search indexes about changes to your sitemap. This behavior is disabled
|
||||||
|
* by default, to enable, read the documentation provided in the docs folder.
|
||||||
|
*
|
||||||
|
* After notifications have been enabled, every publish / unpublish of a page.
|
||||||
|
* will notify enabled search indexes of the update.
|
||||||
|
*
|
||||||
|
* If the site is in development mode no ping will be sent.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function ping()
|
||||||
|
{
|
||||||
|
if (!self::enabled() || Director::isDev()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$location = urlencode(Controller::join_links(
|
||||||
|
Director::absoluteBaseURL(),
|
||||||
|
'sitemap.xml'
|
||||||
|
));
|
||||||
|
|
||||||
|
$response = true;
|
||||||
|
|
||||||
|
foreach (self::config()->search_indexes as $name => $url) {
|
||||||
|
$configName = $name . '_notification_enabled';
|
||||||
|
|
||||||
|
if (self::config()->$configName) {
|
||||||
|
$response = $response && file_get_contents($url . $location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is GoogleSitemap enabled?
|
* Is GoogleSitemap enabled?
|
||||||
*
|
*
|
||||||
@ -461,6 +515,6 @@ class GoogleSitemap
|
|||||||
*/
|
*/
|
||||||
protected function sanitiseClassName($class)
|
protected function sanitiseClassName($class)
|
||||||
{
|
{
|
||||||
return str_replace('\\', '-', (string) $class);
|
return str_replace('\\', '-', $class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
namespace Wilr\GoogleSitemaps;
|
|
||||||
|
|
||||||
interface Sitemapable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return the absolute URL for this object
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function AbsoluteLink();
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<?xml-stylesheet type='text/xsl' href='{$AbsoluteLink('styleSheetIndex')}'?>
|
<?xml-stylesheet type='text/xsl' href='{$BaseHref}sitemap.xml/styleSheetIndex'?>
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %>
|
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %>
|
||||||
<sitemap>
|
<sitemap>
|
||||||
<loc>{$Up.AbsoluteLink('sitemap')}/{$ClassName}/{$Page.xml}</loc>
|
<loc>{$AbsoluteBaseURL}sitemap.xml/sitemap/$ClassName/$Page.xml</loc>
|
||||||
<% if $LastModified %><lastmod>{$LastModified}</lastmod><% end_if %>
|
<% if $LastModified %><lastmod>$LastModified</lastmod><% end_if %>
|
||||||
</sitemap><% end_loop %>
|
</sitemap><% end_loop %>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<?xml-stylesheet type='text/xsl' href='{$AbsoluteLink('styleSheet')}'?>
|
<?xml-stylesheet type='text/xsl' href='{$BaseHref}sitemap.xml/styleSheet'?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
||||||
<% loop $Items %>
|
<% loop $Items %>
|
||||||
<url>
|
<url>
|
||||||
<loc>{$AbsoluteLink}</loc>
|
<loc>$AbsoluteLink</loc>
|
||||||
<% if $LastEdited %><lastmod>{$LastEdited.Rfc3339()}</lastmod><% end_if %>
|
<% if $LastEdited %><lastmod>$LastEdited.Rfc3339()</lastmod><% end_if %>
|
||||||
<% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %>
|
<% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %>
|
||||||
<% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %>
|
<% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %>
|
||||||
<% if $ImagesForSitemap %><% loop $ImagesForSitemap %>
|
<% if $ImagesForSitemap %><% loop $ImagesForSitemap %>
|
||||||
<image:image>
|
<image:image>
|
||||||
<image:loc>{$AbsoluteLink}</image:loc>
|
<image:loc>{$AbsoluteLink}</image:loc>
|
||||||
<image:title>{$Title}</image:title>
|
|
||||||
</image:image>
|
</image:image>
|
||||||
<% end_loop %><% end_if %>
|
<% end_loop %><% end_if %>
|
||||||
</url>
|
</url>
|
||||||
|
@ -9,80 +9,81 @@
|
|||||||
<link rel="stylesheet" href="$resourceURL(wilr/silverstripe-googlesitemaps:css/style.css)" />
|
<link rel="stylesheet" href="$resourceURL(wilr/silverstripe-googlesitemaps:css/style.css)" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div id="content">
|
||||||
<h1 class="content__title">
|
<h1>
|
||||||
<a href="https://www.silverstripe.org" target="_blank" rel="noopener noreferrer">XML Sitemap</a>
|
<a href="http://silverstripe.org" target="_blank">XML Sitemap
|
||||||
|
<span class="ss_link">→ silverstripe.org</span>
|
||||||
|
</a>
|
||||||
</h1>
|
</h1>
|
||||||
<p class="content__text">
|
|
||||||
|
<p class="expl">
|
||||||
This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.
|
This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.
|
||||||
</p>
|
</p>
|
||||||
<div class="table-wrapper">
|
<table id="sitemap" cellpadding="3" class="tablesorter">
|
||||||
<table id="sitemap" class="table">
|
<thead>
|
||||||
<thead>
|
<tr>
|
||||||
|
<th width="76%">URL</th>
|
||||||
|
<th width="7%">Priority</th>
|
||||||
|
<th width="7%">Change Freq.</th>
|
||||||
|
<th width="10%">Last Change</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
||||||
|
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
||||||
|
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="table__cell table__cell--w-65">URL</th>
|
<td>
|
||||||
<th class="table__cell table__cell--w-10">Priority</th>
|
<xsl:variable name="itemURL">
|
||||||
<th class="table__cell table__cell--w-10">Change Freq.</th>
|
<xsl:value-of select="sitemap:loc"/>
|
||||||
<th class="table__cell table__cell--w-15">Last Change</th>
|
</xsl:variable>
|
||||||
</tr>
|
<xsl:variable name="imagesCount" select="count(image:image)"/>
|
||||||
</thead>
|
<a href="{\$itemURL}">
|
||||||
<tbody>
|
<xsl:value-of select="sitemap:loc"/>
|
||||||
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
</a>
|
||||||
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
|
||||||
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
|
||||||
<tr>
|
<xsl:if test="\$imagesCount > 0">
|
||||||
<td class="table__cell">
|
<table class="imagestable" cellpadding="0" cellspacing="0">
|
||||||
<xsl:variable name="itemURL">
|
<tr>
|
||||||
<xsl:value-of select="sitemap:loc"/>
|
<th>Images</th>
|
||||||
</xsl:variable>
|
</tr>
|
||||||
<xsl:variable name="imagesCount" select="count(image:image)"/>
|
<xsl:for-each select="image:image">
|
||||||
<a href="{\$itemURL}">
|
<xsl:variable name="imageURL">
|
||||||
<xsl:value-of select="sitemap:loc"/>
|
<xsl:value-of select="image:loc"/>
|
||||||
</a>
|
</xsl:variable>
|
||||||
<xsl:if test="\$imagesCount > 0">
|
|
||||||
<table class="image-table">
|
|
||||||
<tr>
|
<tr>
|
||||||
<th class="image-table__cell">Images</th>
|
<td>
|
||||||
|
<img src="{\$imageURL}" width="40px"/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{\$imageURL}">
|
||||||
|
<xsl:value-of select="image:loc"/>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<xsl:for-each select="image:image">
|
</xsl:for-each>
|
||||||
<xsl:variable name="imageURL">
|
</table>
|
||||||
<xsl:value-of select="image:loc"/>
|
</xsl:if>
|
||||||
</xsl:variable>
|
|
||||||
<tr>
|
|
||||||
<td class="image-table__cell image-table__cell--image">
|
</td>
|
||||||
<img class="image-table__image" src="{\$imageURL}" width="60" height="40" />
|
<td>
|
||||||
</td>
|
<xsl:value-of select="concat(sitemap:priority*100,'%')"/>
|
||||||
<td class="image-table__cell image-table__cell--text">
|
</td>
|
||||||
<span class="image-table__title"><xsl:value-of select="image:title"/></span>
|
<td>
|
||||||
<a href="{\$imageURL}">
|
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat(\$lower, \$upper),concat(\$upper, \$lower)),substring(sitemap:changefreq, 2))"/>
|
||||||
<xsl:value-of select="image:loc"/>
|
</td>
|
||||||
</a>
|
<td>
|
||||||
</td>
|
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
||||||
</tr>
|
</td>
|
||||||
</xsl:for-each>
|
</tr>
|
||||||
</table>
|
</xsl:for-each>
|
||||||
</xsl:if>
|
</tbody>
|
||||||
</td>
|
</table>
|
||||||
<td class="table__cell">
|
<p id="Footer" class="expl">Generated by the SilverStripe
|
||||||
<xsl:value-of select="concat(sitemap:priority*100,'%')"/>
|
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||||
</td>
|
<br />More information about XML sitemaps on <a href="http://sitemaps.org" target="_blank">sitemaps.org</a>.
|
||||||
<td class="table__cell">
|
|
||||||
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat(\$lower, \$upper),concat(\$upper, \$lower)),substring(sitemap:changefreq, 2))"/>
|
|
||||||
</td>
|
|
||||||
<td class="table__cell">
|
|
||||||
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</xsl:for-each>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<p class="content__text">
|
|
||||||
Generated by the Silverstripe CMS
|
|
||||||
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" rel="noopener noreferrer" title="Silverstripe CMS Google Sitemaps module on Github">Google Sitemaps Module</a>
|
|
||||||
</p>
|
|
||||||
<p class="content__text">
|
|
||||||
More information about XML sitemaps on <a href="https://sitemaps.org" target="_blank" rel="noopener noreferrer">sitemaps.org</a>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -9,48 +9,46 @@
|
|||||||
<link rel="stylesheet" href="$resourceURL(wilr/silverstripe-googlesitemaps:css/style.css)" />
|
<link rel="stylesheet" href="$resourceURL(wilr/silverstripe-googlesitemaps:css/style.css)" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="content">
|
<div id="content">
|
||||||
<h1 class="content__title">
|
<h1>
|
||||||
<a href="https://www.silverstripe.org" target="_blank" rel="noopener noreferrer">XML Sitemap</a>
|
<a href="http://silverstripe.org" target="_blank">XML Sitemap
|
||||||
|
<span class="ss_link">→ silverstripe.org</span>
|
||||||
|
</a>
|
||||||
</h1>
|
</h1>
|
||||||
<p class="content__text">
|
|
||||||
|
<p class="expl">
|
||||||
This sitemap consists of <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/> part(s).
|
This sitemap consists of <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/> part(s).
|
||||||
</p>
|
</p>
|
||||||
<div class="table-wrapper">
|
<table id="sitemapindex" cellpadding="3" class="tablesorter">
|
||||||
<table id="sitemapindex" class="table">
|
<thead>
|
||||||
<thead>
|
<tr>
|
||||||
|
<th width="90%">URL</th>
|
||||||
|
<th width="10%">Last Change</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
||||||
|
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
||||||
|
<xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="table__cell table__cell--w-85">URL</th>
|
<td>
|
||||||
<th class="table__cell table__cell--w-15">Last Change</th>
|
<xsl:variable name="itemURL">
|
||||||
|
<xsl:value-of select="sitemap:loc"/>
|
||||||
|
</xsl:variable>
|
||||||
|
<a href="{\$itemURL}">
|
||||||
|
<xsl:value-of select="sitemap:loc"/>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</xsl:for-each>
|
||||||
<tbody>
|
</tbody>
|
||||||
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
</table>
|
||||||
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
<p id="Footer" class="expl">Generated by the SilverStripe
|
||||||
<xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
|
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
||||||
<tr>
|
<br />More information about XML sitemaps on <a href="http://sitemaps.org" target="_blank">sitemaps.org</a>.
|
||||||
<td class="table__cell">
|
|
||||||
<xsl:variable name="itemURL">
|
|
||||||
<xsl:value-of select="sitemap:loc"/>
|
|
||||||
</xsl:variable>
|
|
||||||
<a href="{\$itemURL}">
|
|
||||||
<xsl:value-of select="sitemap:loc"/>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td class="table__cell">
|
|
||||||
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</xsl:for-each>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<p class="content__text">
|
|
||||||
Generated by the Silverstripe CMS
|
|
||||||
<a href="https://github.com/wilr/silverstripe-googlesitemaps" target="_blank" rel="noopener noreferrer" title="SilverStripe Google Sitemaps module on Github">Google Sitemaps Module</a>
|
|
||||||
</p>
|
|
||||||
<p class="content__text">
|
|
||||||
More information about XML sitemaps on <a href="https://sitemaps.org" target="_blank" rel="noopener noreferrer">sitemaps.org</a>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -4,6 +4,7 @@ namespace Wilr\GoogleSitemaps\Tests;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
@ -19,22 +20,7 @@ use Wilr\GoogleSitemaps\Tests\Model\UnviewableDataObject;
|
|||||||
|
|
||||||
class GoogleSitemapTest extends FunctionalTest
|
class GoogleSitemapTest extends FunctionalTest
|
||||||
{
|
{
|
||||||
protected static $fixture_file = [
|
protected static $fixture_file = 'GoogleSitemapTest.yml';
|
||||||
'GoogleSitemapTest.yml'
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $usesDatabase = true;
|
|
||||||
|
|
||||||
public static function get_fixture_file()
|
|
||||||
{
|
|
||||||
$files = [__DIR__ . '/GoogleSitemapTest.yml'];
|
|
||||||
|
|
||||||
if (class_exists('Page')) {
|
|
||||||
$files[] = __DIR__ . '/GoogleSitemapPageTest.yml';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $files;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static $extra_dataobjects = [
|
protected static $extra_dataobjects = [
|
||||||
TestDataObject::class,
|
TestDataObject::class,
|
||||||
@ -46,15 +32,19 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
GoogleSitemapExtension::class
|
GoogleSitemapExtension::class
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function setUp(): void
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
if (class_exists('Page')) {
|
||||||
|
$this->loadFixture($this->resolveFixturePath('GoogleSitemapPageTest.yml'));
|
||||||
|
}
|
||||||
|
|
||||||
GoogleSitemap::clear_registered_dataobjects();
|
GoogleSitemap::clear_registered_dataobjects();
|
||||||
GoogleSitemap::clear_registered_routes();
|
GoogleSitemap::clear_registered_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
public function tearDown()
|
||||||
{
|
{
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
|
||||||
@ -62,100 +52,117 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
GoogleSitemap::clear_registered_routes();
|
GoogleSitemap::clear_registered_routes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanIncludeInGoogleSitemap(): void
|
public function testCanIncludeInGoogleSitemap()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_dataobject(TestDataObject::class, '');
|
GoogleSitemap::register_dataobject(TestDataObject::class, '');
|
||||||
|
|
||||||
|
$unused = $this->objFromFixture(TestDataObject::class, 'UnindexedDataObject');
|
||||||
|
$this->assertFalse($unused->canIncludeInGoogleSitemap());
|
||||||
|
|
||||||
$used = $this->objFromFixture(TestDataObject::class, 'DataObjectTest2');
|
$used = $this->objFromFixture(TestDataObject::class, 'DataObjectTest2');
|
||||||
|
|
||||||
$this->assertTrue($used->canIncludeInGoogleSitemap());
|
$this->assertTrue($used->canIncludeInGoogleSitemap());
|
||||||
|
|
||||||
$used->setPrivate();
|
|
||||||
|
|
||||||
$this->assertFalse($used->canIncludeInGoogleSitemap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIndexFileWithCustomRoute(): void
|
public function testIndexFileWithCustomRoute()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_route('/test/');
|
GoogleSitemap::register_route('/test/');
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
|
|
||||||
$this->assertXmlStringEqualsXmlFile(
|
$expected = "<loc>". Director::absoluteURL("sitemap.xml/sitemap/GoogleSitemapRoute/1") ."</loc>";
|
||||||
__DIR__ . '/xml/' . __FUNCTION__ . '.xml',
|
$this->assertEquals(1, substr_count($body, $expected), 'A link to the custom routes exists');
|
||||||
$body,
|
|
||||||
'A link to the custom routes exists'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetItems(): void
|
|
||||||
|
public function testGetItems()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_dataobject(TestDataObject::class, '');
|
GoogleSitemap::register_dataobject(TestDataObject::class, '');
|
||||||
$google = new GoogleSitemap();
|
|
||||||
|
|
||||||
$items = $google->getItems(TestDataObject::class, 1);
|
$items = GoogleSitemap::get_items(TestDataObject::class, 1);
|
||||||
|
$this->assertEquals(2, $items->count());
|
||||||
|
|
||||||
$this->assertEquals(3, $items->count());
|
$this->assertDOSEquals(array(
|
||||||
|
array("Priority" => "0.2"),
|
||||||
|
array("Priority" => "0.4")
|
||||||
|
), $items);
|
||||||
|
|
||||||
GoogleSitemap::register_dataobject(OtherDataObject::class);
|
GoogleSitemap::register_dataobject(OtherDataObject::class);
|
||||||
$this->assertEquals(1, $google->getItems(OtherDataObject::class, 1)->count());
|
$this->assertEquals(1, GoogleSitemap::get_items(OtherDataObject::class, 1)->count());
|
||||||
|
|
||||||
GoogleSitemap::register_dataobject(UnviewableDataObject::class);
|
GoogleSitemap::register_dataobject(UnviewableDataObject::class);
|
||||||
$this->assertEquals(0, $google->getItems(UnviewableDataObject::class, 1)->count());
|
$this->assertEquals(0, GoogleSitemap::get_items(UnviewableDataObject::class, 1)->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetItemsWithCustomRoutes(): void
|
public function testGetItemsWithCustomRoutes()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_routes([
|
GoogleSitemap::register_routes(array(
|
||||||
'/test-route/',
|
'/test-route/',
|
||||||
'/someother-route/',
|
'/someother-route/',
|
||||||
'/fake-sitemap-route/'
|
'/fake-sitemap-route/'
|
||||||
]);
|
));
|
||||||
|
|
||||||
$google = new GoogleSitemap();
|
$items = GoogleSitemap::get_items('GoogleSitemapRoute', 1);
|
||||||
$items = $google->getItems('GoogleSitemapRoute', 1);
|
|
||||||
$this->assertEquals(3, $items->count());
|
$this->assertEquals(3, $items->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessingSitemapRootXMLFile(): void
|
public function testAccessingSitemapRootXMLFile()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_dataobject(TestDataObject::class);
|
GoogleSitemap::register_dataobject(TestDataObject::class);
|
||||||
GoogleSitemap::register_dataobject(OtherDataObject::class);
|
GoogleSitemap::register_dataobject(OtherDataObject::class);
|
||||||
|
|
||||||
$obj = $this->objFromFixture(TestDataObject::class, 'DataObjectTest1');
|
|
||||||
$table = $obj->baseTable();
|
|
||||||
|
|
||||||
DB::query("UPDATE \"" . $table . "\" SET \"LastEdited\"='2023-02-13 00:00:00'");
|
|
||||||
|
|
||||||
$obj2 = $this->objFromFixture(OtherDataObject::class, 'OtherDataObjectTest2');
|
|
||||||
$table = $obj2->baseTable();
|
|
||||||
|
|
||||||
DB::query("UPDATE \"" . $table . "\" SET \"LastEdited\"='2023-02-13 00:00:00'");
|
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
|
|
||||||
$this->assertXmlStringEqualsXmlFile(__DIR__ . '/xml/' . __FUNCTION__ . '.xml', $body);
|
// the sitemap should contain <loc> to both those files and not the other
|
||||||
|
// dataobject as it hasn't been registered
|
||||||
|
$expected = "<loc>". Director::absoluteURL(
|
||||||
|
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1"
|
||||||
|
) ."</loc>";
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
substr_count($body, $expected),
|
||||||
|
'A link to GoogleSitemapTest_DataObject exists'
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = "<loc>". Director::absoluteURL(
|
||||||
|
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1"
|
||||||
|
) ."</loc>";
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
substr_count($body, $expected),
|
||||||
|
'A link to GoogleSitemapTest_OtherDataObject exists'
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = "<loc>". Director::absoluteURL(
|
||||||
|
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-UnviewableDataObject/2"
|
||||||
|
) ."</loc>";
|
||||||
|
$this->assertEquals(
|
||||||
|
0,
|
||||||
|
substr_count($body, $expected),
|
||||||
|
'A link to a GoogleSitemapTest_UnviewableDataObject does not exist'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLastModifiedDateOnRootXML(): void
|
public function testLastModifiedDateOnRootXML()
|
||||||
{
|
{
|
||||||
Config::inst()->set(GoogleSitemap::class, 'enabled', true);
|
Config::inst()->update(GoogleSitemap::class, 'enabled', true);
|
||||||
|
|
||||||
if (!class_exists('Page')) {
|
if (!class_exists('Page')) {
|
||||||
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->objFromFixture('Page', 'Page1');
|
$page = $this->objFromFixture('Page', 'Page1');
|
||||||
$page->publishSingle();
|
$page->publish('Stage', 'Live');
|
||||||
$page->flushCache();
|
$page->flushCache();
|
||||||
|
|
||||||
$p2 = $this->objFromFixture('Page', 'Page2');
|
$page2 = $this->objFromFixture('Page', 'Page2');
|
||||||
$p2->publishSingle();
|
$page2->publish('Stage', 'Live');
|
||||||
$p2->flushCache();
|
$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-03-14 00:00:00' WHERE \"ID\"='".$page->ID."'");
|
||||||
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='" . $p2->ID . "'");
|
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='".$page2->ID."'");
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -169,38 +176,43 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIndexFilePaginatedSitemapFiles(): void
|
public function testIndexFilePaginatedSitemapFiles()
|
||||||
{
|
{
|
||||||
$original = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
$original = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
||||||
Config::inst()->set(GoogleSitemap::class, 'objects_per_sitemap', 1);
|
Config::inst()->update(GoogleSitemap::class, 'objects_per_sitemap', 1);
|
||||||
GoogleSitemap::register_dataobject(TestDataObject::class);
|
GoogleSitemap::register_dataobject(TestDataObject::class);
|
||||||
|
|
||||||
|
|
||||||
$obj = $this->objFromFixture(TestDataObject::class, 'DataObjectTest1');
|
|
||||||
$obj1 = $this->objFromFixture(TestDataObject::class, 'DataObjectTest2');
|
|
||||||
$obj2 = $this->objFromFixture(TestDataObject::class, 'UnindexedDataObject');
|
|
||||||
|
|
||||||
$t = $obj->baseTable();
|
|
||||||
DB::query("UPDATE \"" . $t . "\" SET \"LastEdited\"='2023-02-13 00:00:00' WHERE \"ID\"='" . $obj->ID . "'");
|
|
||||||
DB::query("UPDATE \"" . $t . "\" SET \"LastEdited\"='2023-02-13 00:00:00' WHERE \"ID\"='" . $obj1->ID . "'");
|
|
||||||
DB::query("UPDATE \"" . $t . "\" SET \"LastEdited\"='2023-02-13 00:00:00' WHERE \"ID\"='" . $obj2->ID . "'");
|
|
||||||
|
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$this->assertXmlStringEqualsXmlFile(__DIR__ . '/xml/' . __FUNCTION__ . '.xml', $body);
|
$expected = "<loc>". Director::absoluteURL(
|
||||||
|
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1"
|
||||||
|
) ."</loc>";
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
substr_count($body, $expected),
|
||||||
|
'A link to the first page of GoogleSitemapTest_DataObject exists'
|
||||||
|
);
|
||||||
|
|
||||||
Config::inst()->set(GoogleSitemap::class, 'objects_per_sitemap', $original);
|
$expected = "<loc>". Director::absoluteURL(
|
||||||
|
"sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2"
|
||||||
|
) ."</loc>";
|
||||||
|
$this->assertEquals(
|
||||||
|
1,
|
||||||
|
substr_count($body, $expected),
|
||||||
|
'A link to the second page GoogleSitemapTest_DataObject exists'
|
||||||
|
);
|
||||||
|
|
||||||
|
Config::inst()->update(GoogleSitemap::class, 'objects_per_sitemap', $original);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRegisterRoutesIncludesAllRoutes(): void
|
public function testRegisterRoutesIncludesAllRoutes()
|
||||||
{
|
{
|
||||||
GoogleSitemap::register_route('/test/');
|
GoogleSitemap::register_route('/test/');
|
||||||
GoogleSitemap::register_routes([
|
GoogleSitemap::register_routes(array(
|
||||||
'/test/', // duplication should be replaced
|
'/test/', // duplication should be replaced
|
||||||
'/unittests/',
|
'/unittests/',
|
||||||
'/anotherlink/'
|
'/anotherlink/'
|
||||||
], 'weekly');
|
), 'weekly');
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml/sitemap/GoogleSitemapRoute/1');
|
$response = $this->get('sitemap.xml/sitemap/GoogleSitemapRoute/1');
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -209,10 +221,10 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$this->assertEquals(3, substr_count($body, "<loc>"));
|
$this->assertEquals(3, substr_count($body, "<loc>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessingNestedSiteMap(): void
|
public function testAccessingNestedSiteMap()
|
||||||
{
|
{
|
||||||
$original = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
$original = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
||||||
Config::inst()->set(GoogleSitemap::class, 'objects_per_sitemap', 1);
|
Config::inst()->update(GoogleSitemap::class, 'objects_per_sitemap', 1);
|
||||||
GoogleSitemap::register_dataobject(TestDataObject::class);
|
GoogleSitemap::register_dataobject(TestDataObject::class);
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1');
|
$response = $this->get('sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1');
|
||||||
@ -220,43 +232,43 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode(), 'successful loaded nested sitemap');
|
$this->assertEquals(200, $response->getStatusCode(), 'successful loaded nested sitemap');
|
||||||
|
|
||||||
Config::inst()->set(GoogleSitemap::class, 'objects_per_sitemap', $original);
|
Config::inst()->update(GoogleSitemap::class, 'objects_per_sitemap', $original);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetItemsWithPages(): void
|
public function testGetItemsWithPages()
|
||||||
{
|
{
|
||||||
if (!class_exists(SiteTree::class)) {
|
if (!class_exists('Page')) {
|
||||||
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->objFromFixture('Page', 'Page1');
|
$page = $this->objFromFixture('Page', 'Page1');
|
||||||
$page->publishSingle();
|
$page->publish('Stage', 'Live');
|
||||||
$page->flushCache();
|
$page->flushCache();
|
||||||
|
|
||||||
$page2 = $this->objFromFixture('Page', 'Page2');
|
$page2 = $this->objFromFixture('Page', 'Page2');
|
||||||
$page2->publishSingle();
|
$page2->publish('Stage', 'Live');
|
||||||
$page2->flushCache();
|
$page2->flushCache();
|
||||||
|
|
||||||
$this->assertListContains([
|
$this->assertDOSContains(array(
|
||||||
['Title' => 'Testpage1'],
|
array('Title' => 'Testpage1'),
|
||||||
['Title' => 'Testpage2']
|
array('Title' => 'Testpage2')
|
||||||
], GoogleSitemap::inst()->getItems(SiteTree::class), "There should be 2 pages in the sitemap after publishing");
|
), GoogleSitemap::inst()->getItems(SiteTree::class), "There should be 2 pages in the sitemap after publishing");
|
||||||
|
|
||||||
// check if we make a page readonly that it is hidden
|
// check if we make a page readonly that it is hidden
|
||||||
$page2->CanViewType = 'LoggedInUsers';
|
$page2->CanViewType = 'LoggedInUsers';
|
||||||
$page2->write();
|
$page2->write();
|
||||||
$page2->publishSingle();
|
$page2->publish('Stage', 'Live');
|
||||||
|
|
||||||
$this->logOut();
|
$this->logOut();
|
||||||
|
|
||||||
$this->assertListEquals([
|
$this->assertDOSEquals(array(
|
||||||
['Title' => 'Testpage1']
|
array('Title' => 'Testpage1')
|
||||||
], GoogleSitemap::inst()->getItems(SiteTree::class), "There should be only 1 page, other is logged in only");
|
), GoogleSitemap::inst()->getItems(SiteTree::class), "There should be only 1 page, other is logged in only");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccess(): void
|
public function testAccess()
|
||||||
{
|
{
|
||||||
Config::inst()->set(GoogleSitemap::class, 'enabled', true);
|
Config::inst()->update(GoogleSitemap::class, 'enabled', true);
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
|
|
||||||
@ -268,7 +280,7 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$this->assertEquals(200, $response->getStatusCode(), 'Sitemap returns a 200 success when enabled');
|
$this->assertEquals(200, $response->getStatusCode(), 'Sitemap returns a 200 success when enabled');
|
||||||
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));
|
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));
|
||||||
|
|
||||||
Config::inst()->set(GoogleSitemap::class, 'enabled', false);
|
Config::inst()->update(GoogleSitemap::class, 'enabled', false);
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
$this->assertEquals(404, $response->getStatusCode(), 'Sitemap index returns a 404 when disabled');
|
$this->assertEquals(404, $response->getStatusCode(), 'Sitemap index returns a 404 when disabled');
|
||||||
@ -277,7 +289,7 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$this->assertEquals(404, $response->getStatusCode(), 'Sitemap file returns a 404 when disabled');
|
$this->assertEquals(404, $response->getStatusCode(), 'Sitemap file returns a 404 when disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDecoratorAddsFields(): void
|
public function testDecoratorAddsFields()
|
||||||
{
|
{
|
||||||
if (!class_exists("Page")) {
|
if (!class_exists("Page")) {
|
||||||
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
@ -293,7 +305,7 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$this->assertInstanceOf(LiteralField::class, $tab->fieldByName('GoogleSitemapIntro'));
|
$this->assertInstanceOf(LiteralField::class, $tab->fieldByName('GoogleSitemapIntro'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPriority(): void
|
public function testGetPriority()
|
||||||
{
|
{
|
||||||
if (!class_exists("Page")) {
|
if (!class_exists("Page")) {
|
||||||
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
@ -314,7 +326,7 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$this->assertFalse($page->getGooglePriority());
|
$this->assertFalse($page->getGooglePriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnpublishedPage(): void
|
public function testUnpublishedPage()
|
||||||
{
|
{
|
||||||
if (!class_exists('SilverStripe\CMS\Model\SiteTree')) {
|
if (!class_exists('SilverStripe\CMS\Model\SiteTree')) {
|
||||||
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
|
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
|
||||||
@ -323,12 +335,12 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
$orphanedPage = new \SilverStripe\CMS\Model\SiteTree();
|
$orphanedPage = new \SilverStripe\CMS\Model\SiteTree();
|
||||||
$orphanedPage->ParentID = 999999; // missing parent id
|
$orphanedPage->ParentID = 999999; // missing parent id
|
||||||
$orphanedPage->write();
|
$orphanedPage->write();
|
||||||
$orphanedPage->publishSingle();
|
$orphanedPage->publish("Stage", "Live");
|
||||||
|
|
||||||
$rootPage = new \SilverStripe\CMS\Model\SiteTree();
|
$rootPage = new \SilverStripe\CMS\Model\SiteTree();
|
||||||
$rootPage->ParentID = 0;
|
$rootPage->ParentID = 0;
|
||||||
$rootPage->write();
|
$rootPage->write();
|
||||||
$rootPage->publishSingle();
|
$rootPage->publish("Stage", "Live");
|
||||||
|
|
||||||
$oldMode = Versioned::get_reading_mode();
|
$oldMode = Versioned::get_reading_mode();
|
||||||
Versioned::set_reading_mode('Live');
|
Versioned::set_reading_mode('Live');
|
||||||
@ -342,7 +354,7 @@ class GoogleSitemapTest extends FunctionalTest
|
|||||||
Versioned::set_reading_mode($oldMode);
|
Versioned::set_reading_mode($oldMode);
|
||||||
throw $ex;
|
throw $ex;
|
||||||
} // finally {
|
} // finally {
|
||||||
Versioned::set_reading_mode($oldMode);
|
Versioned::set_reading_mode($oldMode);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
Wilr\GoogleSitemaps\Tests\Model\TestDataObject:
|
Wilr\GoogleSitemaps\Tests\Model\TestDataObject:
|
||||||
DataObjectTest1:
|
DataObjectTest1:
|
||||||
Priority: 0.4
|
Priority: 0.4
|
||||||
DataObjectTest2:
|
DataObjectTest2:
|
||||||
Priority: 0.2
|
Priority: 0.2
|
||||||
UnindexedDataObject:
|
UnindexedDataObject:
|
||||||
Priority: -1
|
Priority: -1
|
||||||
|
|
||||||
Wilr\GoogleSitemaps\Tests\Model\OtherDataObject:
|
Wilr\GoogleSitemaps\Tests\Model\OtherDataObject:
|
||||||
OtherDataObjectTest2:
|
OtherDataObjectTest2:
|
||||||
Priority: 0.3
|
Priority: 0.3
|
||||||
|
|
||||||
Wilr\GoogleSitemaps\Tests\Model\UnviewableDataObject:
|
Wilr\GoogleSitemaps\Tests\Model\UnviewableDataObject:
|
||||||
Unviewable1:
|
Unviewable1:
|
||||||
Priority: 0.4
|
Priority: 0.4
|
||||||
|
@ -8,7 +8,6 @@ use SilverStripe\Control\Director;
|
|||||||
|
|
||||||
class TestDataObject extends DataObject implements TestOnly
|
class TestDataObject extends DataObject implements TestOnly
|
||||||
{
|
{
|
||||||
protected $private = false;
|
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'Priority' => 'Varchar(10)'
|
'Priority' => 'Varchar(10)'
|
||||||
@ -16,19 +15,9 @@ class TestDataObject extends DataObject implements TestOnly
|
|||||||
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
if ($this->private) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setPrivate()
|
|
||||||
{
|
|
||||||
$this->private = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function AbsoluteLink()
|
public function AbsoluteLink()
|
||||||
{
|
{
|
||||||
return Director::absoluteBaseURL();
|
return Director::absoluteBaseURL();
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc>
|
|
||||||
<lastmod>2023-02-13</lastmod>
|
|
||||||
</sitemap>
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-OtherDataObject/1</loc>
|
|
||||||
<lastmod>2023-02-13</lastmod>
|
|
||||||
</sitemap>
|
|
||||||
</sitemapindex>
|
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/1</loc>
|
|
||||||
<lastmod>2023-02-13</lastmod>
|
|
||||||
</sitemap>
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/2</loc>
|
|
||||||
<lastmod>2023-02-13</lastmod>
|
|
||||||
</sitemap>
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/Wilr-GoogleSitemaps-Tests-Model-TestDataObject/3</loc>
|
|
||||||
<lastmod>2023-02-13</lastmod>
|
|
||||||
</sitemap>
|
|
||||||
</sitemapindex>
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<?xml-stylesheet type='text/xsl' href='http://localhost/sitemap.xml/styleSheetIndex'?>
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<sitemap>
|
|
||||||
<loc>http://localhost/sitemap.xml/sitemap/GoogleSitemapRoute/1</loc>
|
|
||||||
</sitemap>
|
|
||||||
</sitemapindex>
|
|
Loading…
Reference in New Issue
Block a user