Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
simple_sitemap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
simple_sitemap
Commits
708561fc
Commit
708561fc
authored
Aug 25, 2016
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fallback to regular sitemap if only one language is enabled
parent
7a09742c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
src/Form/SimplesitemapCustomLinksForm.php
src/Form/SimplesitemapCustomLinksForm.php
+1
-1
src/SitemapGenerator.php
src/SitemapGenerator.php
+21
-12
No files found.
src/Form/SimplesitemapCustomLinksForm.php
View file @
708561fc
...
...
@@ -94,7 +94,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
private
function
getCustomLinks
(
$custom_links_string
)
{
// Unify newline characters and explode into array.
$custom_links_string_lines
=
explode
(
"
\n
"
,
str_replace
(
"
\r\n
"
,
"
\n
"
,
$custom_links_string
));
// Remove
whitespace from array values
.
// Remove
empty values and whitespaces from array
.
$custom_links_string_lines
=
array_filter
(
array_map
(
'trim'
,
$custom_links_string_lines
));
$custom_links
=
[];
foreach
(
$custom_links_string_lines
as
$i
=>
&
$line
)
{
...
...
src/SitemapGenerator.php
View file @
708561fc
...
...
@@ -20,11 +20,13 @@ class SitemapGenerator {
private
$moduleHandler
;
private
$defaultLanguageId
;
private
$generateFrom
=
'form'
;
private
$isHreflangSitemap
;
public
function
__construct
(
$generator
,
$database
,
$language_manager
,
$module_handler
)
{
$this
->
generator
=
$generator
;
$this
->
db
=
$database
;
$this
->
defaultLanguageId
=
$language_manager
->
getDefaultLanguage
()
->
getId
();
$this
->
isHreflangSitemap
=
count
(
$language_manager
->
getLanguages
())
>
1
;
$this
->
moduleHandler
=
$module_handler
;
}
...
...
@@ -171,26 +173,34 @@ class SitemapGenerator {
$writer
->
writeComment
(
self
::
GENERATED_BY
);
$writer
->
startElement
(
'urlset'
);
$writer
->
writeAttribute
(
'xmlns'
,
self
::
XMLNS
);
$writer
->
writeAttribute
(
'xmlns:xhtml'
,
self
::
XMLNS_XHTML
);
if
(
$this
->
isHreflangSitemap
)
{
$writer
->
writeAttribute
(
'xmlns:xhtml'
,
self
::
XMLNS_XHTML
);
}
foreach
(
$links
as
$link
)
{
// Add each translation variant URL to the sitemap.
// Add each translation variant URL
as location
to the sitemap.
$writer
->
startElement
(
'url'
);
$writer
->
writeElement
(
'loc'
,
$link
[
'url'
]);
// Add all alternate URLs to this translation variant.
foreach
(
$link
[
'alternate_urls'
]
as
$language_id
=>
$alternate_url
)
{
$writer
->
startElement
(
'xhtml:link'
);
$writer
->
writeAttribute
(
'rel'
,
'alternate'
);
$writer
->
writeAttribute
(
'hreflang'
,
$language_id
);
$writer
->
writeAttribute
(
'href'
,
$alternate_url
);
$writer
->
endElement
();
// If more than one language is enabled, add all translation variant URLs
// as alternate links to this location turning the sitemap into a hreflang
// sitemap.
if
(
$this
->
isHreflangSitemap
)
{
foreach
(
$link
[
'alternate_urls'
]
as
$language_id
=>
$alternate_url
)
{
$writer
->
startElement
(
'xhtml:link'
);
$writer
->
writeAttribute
(
'rel'
,
'alternate'
);
$writer
->
writeAttribute
(
'hreflang'
,
$language_id
);
$writer
->
writeAttribute
(
'href'
,
$alternate_url
);
$writer
->
endElement
();
}
}
if
(
isset
(
$link
[
'priority'
]))
{
// Add priority if any.
// Add priority if any.
if
(
isset
(
$link
[
'priority'
]))
{
$writer
->
writeElement
(
'priority'
,
$link
[
'priority'
]);
}
if
(
isset
(
$link
[
'lastmod'
]))
{
// Add lastmod if any.
// Add lastmod if any.
if
(
isset
(
$link
[
'lastmod'
]))
{
$writer
->
writeElement
(
'lastmod'
,
$link
[
'lastmod'
]);
}
$writer
->
endElement
();
...
...
@@ -200,4 +210,3 @@ class SitemapGenerator {
return
$writer
->
outputMemory
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment