Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
X
xmlsitemap
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
xmlsitemap
Commits
79cfd857
Unverified
Commit
79cfd857
authored
Oct 29, 2018
by
Dave Reid
Committed by
Dave Reid
Oct 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3007089
by Dave Reid: Use headers to output debugging data,
parent
b8e9ed2a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
78 deletions
+48
-78
src/Controller/XmlSitemapController.php
src/Controller/XmlSitemapController.php
+33
-31
templates/sitemap-developer-mode.html.twig
templates/sitemap-developer-mode.html.twig
+0
-43
xmlsitemap.module
xmlsitemap.module
+15
-4
No files found.
src/Controller/XmlSitemapController.php
View file @
79cfd857
...
...
@@ -2,13 +2,14 @@
namespace
Drupal\xmlsitemap\Controller
;
use
Drupal\Component\Serialization\Json
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\State\StateInterface
;
use
Drupal\Core\Template\TwigEnvironmen
t
;
use
Symfony\Component\HttpFoundation\Reques
t
;
/**
* Class for Xml Sitemap Controller.
...
...
@@ -25,24 +26,14 @@ class XmlSitemapController extends ControllerBase {
*/
protected
$state
;
/**
* The twig loader object.
*
* @var \Drupal\Core\Template\TwigEnvironment
*/
protected
$twig
;
/**
* Constructs a new XmlSitemapController object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param Drupal\Core\Template\TwigEnvironment $twig
* Twig environment for Drupal.
*/
public
function
__construct
(
StateInterface
$state
,
TwigEnvironment
$twig
)
{
public
function
__construct
(
StateInterface
$state
)
{
$this
->
state
=
$state
;
$this
->
twig
=
$twig
;
}
/**
...
...
@@ -50,43 +41,54 @@ class XmlSitemapController extends ControllerBase {
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'state'
),
$container
->
get
(
'twig'
)
$container
->
get
(
'state'
)
);
}
/**
* Provides the sitemap in XML format.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @throws NotFoundHttpException
*
* @return \Symfony\Component\HttpFoundation\Response
* The sitemap in XML format or plain text if xmlsitemap_developer_mode flag
* is set.
*/
public
function
renderSitemapXml
()
{
public
function
renderSitemapXml
(
Request
$request
)
{
$headers
=
[];
if
(
$this
->
state
->
get
(
'xmlsitemap_developer_mode'
))
{
$headers
[
'X-XmlSitemap-Current-Context'
]
=
Json
::
encode
(
xmlsitemap_get_current_context
());
$headers
[
'X-XmlSitemap'
]
=
'NOT FOUND'
;
}
$sitemap
=
XmlSitemap
::
loadByContext
();
if
(
!
$sitemap
)
{
throw
new
NotFoundHttpException
();
$exception
=
new
NotFoundHttpException
();
$exception
->
setHeaders
(
$headers
);
throw
$exception
;
}
$chunk
=
xmlsitemap_get_current_chunk
(
$sitemap
);
$chunk
=
xmlsitemap_get_current_chunk
(
$sitemap
,
$request
);
$file
=
xmlsitemap_sitemap_get_file
(
$sitemap
,
$chunk
);
// Provide debugging information
if enabled
.
// Provide debugging information
via headers
.
if
(
$this
->
state
->
get
(
'xmlsitemap_developer_mode'
))
{
$module_path
=
drupal_get_path
(
'module'
,
'xmlsitemap'
);
$template
=
$this
->
twig
->
loadTemplate
(
$module_path
.
'/templates/sitemap-developer-mode.html.twig'
);
$elements
=
[
'current_context'
=>
print_r
(
xmlsitemap_get_current_context
(),
TRUE
),
'sitemap'
=>
print_r
(
$sitemap
,
TRUE
),
'chunk'
=>
$chunk
,
'cache_file_location'
=>
$file
,
'cache_file_exists'
=>
file_exists
(
$file
)
?
'Yes'
:
'No'
,
];
return
new
Response
(
$template
->
render
(
$elements
));
$headers
[
'X-XmlSitemap'
]
=
Json
::
encode
(
$sitemap
->
toArray
());
$headers
[
'X-XmlSitemap-Cache-File'
]
=
$file
;
$headers
[
'X-XmlSitemap-Cache-Hit'
]
=
file_exists
(
$file
)
?
'HIT'
:
'MISS'
;
}
$response
=
new
Response
();
return
xmlsitemap_output_file
(
$response
,
$file
);
if
(
!
is_file
(
$file
)
||
!
is_readable
(
$file
))
{
$exception
=
new
NotFoundHttpException
();
$exception
->
setHeaders
(
$headers
);
throw
$exception
;
}
return
xmlsitemap_output_file
(
new
Response
(),
$file
,
$headers
);
}
/**
...
...
@@ -122,7 +124,7 @@ class XmlSitemapController extends ControllerBase {
// Output the XSL content.
$response
=
new
Response
(
$xsl_content
);
$response
->
headers
->
set
(
'Content-type'
,
'application/xml; charset=utf-8'
);
$response
->
headers
->
set
(
'X-Robots-Tag'
,
'noindex, follow'
);
$response
->
headers
->
set
(
'X-Robots-Tag'
,
'noindex,
no
follow'
);
return
$response
;
}
...
...
templates/sitemap-developer-mode.html.twig
deleted
100644 → 0
View file @
b8e9ed2a
{#
/**
* @file
* Sitemap template output when developer_mode flag is set.
*
* Available variables:
* - current_context: The current context.
* - language: The langcode of the context.
* - sitemap: The sitemap object to be displayed.
* - uri: Sitemap uri.
* - id: Entity id.
* - label: Entity label.
* - chunks: Number of chunks of the sitemap.
* - max_filesize: Maximum filesize allowed for sitemap XML file.
* - context: Context of the sitemap.
* - updated: Last time when sitemap was updated.
* - originalId: The original ID of the configuration entity.
* - pluginConfigKey: The name of the property that is used to store plugin
* configuration.
* - status: The enabled/disabled status of the configuration entity.
* - isSyncing: Whether the config is being created, updated or deleted
* through the import process.
* - isUninstalling: Whether the config is being deleted by the uninstall
* process.
* - uuid: Unique identified for the sitemap entity.
* - langcode: The language code of the entity's default language.
* - entityTypeId: The entity type.
* - enforceIsNew: Boolean indicating whether the entity should be forced to
* be new.
* - _serviceIds: Services that are used for this sitemap entity.
* - dependencies: Dependencies for the sitemap.
* - chunk: Current chunk of the sitemap.
* - cache_file_location: Path for the sitemap cache file.
* - cache_file_exists: Boolean indicating if the sitemap cache file exists.
*
* @see Drupal\xmlsitemap\Controller\XmlSitemapController::renderSitemapXml()
*/
#}
Current context:
{{
current_context
}}
<br
/>
Sitemap:
{{
sitemap
}}
<br
/>
Chunk:
{{
chunk
}}
<br
/>
Cache file location:
{{
cache_file_location
}}
<br
/>
Cache file exists:
{{
cache_file_exists
}}
<br
/>
xmlsitemap.module
View file @
79cfd857
...
...
@@ -28,6 +28,7 @@ use Drupal\Core\Url;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
use
Drupal\xmlsitemap\XmlSitemapInterface
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/**
...
...
@@ -2198,13 +2199,19 @@ function xmlsitemap_get_status_options($default = NULL) {
*
* @param \Drupal\xmlsitemap\XmlSitemapInterface $sitemap
* Sitemap entity.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request to use if provided, otherwise \Drupal::request() will be used.
*
* @return int|string
* Returns current chunk of the sitemap.
*/
function
xmlsitemap_get_current_chunk
(
XmlSitemapInterface
$sitemap
)
{
// Check if we should be displaing the index.
$query
=
\
Drupal
::
request
()
->
query
;
function
xmlsitemap_get_current_chunk
(
XmlSitemapInterface
$sitemap
,
Request
$request
=
NULL
)
{
if
(
!
isset
(
$request
))
{
$request
=
\
Drupal
::
request
();
}
// Check if we should display the index.
$query
=
$request
->
query
;
$query_page
=
$query
->
get
(
'page'
);
if
(
!
isset
(
$query_page
)
||
!
is_numeric
(
$query_page
))
{
if
(
$sitemap
->
getChunks
()
>
1
)
{
...
...
@@ -2237,8 +2244,11 @@ function xmlsitemap_get_current_chunk(XmlSitemapInterface $sitemap) {
*/
function
xmlsitemap_output_file
(
Response
$response
,
$file
,
array
$headers
=
[])
{
if
(
!
file_exists
(
$file
)
||
!
is_readable
(
$file
))
{
throw
new
NotFoundHttpException
();
$exception
=
new
NotFoundHttpException
();
$exception
->
setHeaders
(
$headers
);
throw
$exception
;
}
$mtime
=
filemtime
(
$file
);
$last_modified
=
gmdate
(
DATE_RFC1123
,
$mtime
);
$etag
=
'"'
.
md5
(
$last_modified
)
.
'"'
;
...
...
@@ -2248,6 +2258,7 @@ function xmlsitemap_output_file(Response $response, $file, array $headers = [])
$if_modified_since
=
$request
->
server
->
has
(
'HTTP_IF_MODIFIED_SINCE'
)
?
stripslashes
(
$request
->
server
->
get
(
'HTTP_IF_MODIFIED_SINCE'
))
:
FALSE
;
$if_none_match
=
$request
->
server
->
has
(
'HTTP_IF_NONE_MATCH'
)
?
stripslashes
(
$request
->
server
->
get
(
'HTTP_IF_NONE_MATCH'
))
:
FALSE
;
if
(
$if_modified_since
&&
$if_none_match
&&
$if_none_match
==
$etag
&&
$if_modified_since
==
$last_modified
)
{
$response
->
headers
->
add
(
$headers
);
$response
->
setNotModified
();
// All 304 responses must send an etag if the 200 response for the same
// object contained an etag.
...
...
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