Elgg
Version 6.1
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
Controllers
SecurityTxt.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Controllers
;
4
5
use
Elgg\Exceptions\Http\EntityNotFoundException
;
6
use
Elgg\Http\ResponseBuilder
;
7
use
Elgg\Values
;
8
14
class
SecurityTxt
{
15
24
public
function
__invoke
(\
Elgg
\
Request
$request
):
ResponseBuilder
{
25
$contact =
elgg_get_config
(
'security_txt_contact'
);
26
$expires
=
elgg_get_config
(
'security_txt_expires'
);
27
if
(empty($contact) || empty(
$expires
)) {
28
throw
new
EntityNotFoundException
();
29
}
30
31
$lines = [
32
"Contact: {$contact}"
,
33
'Expires: '
.
Values::normalizeTime
(
$expires
)->format(DATE_ATOM),
34
];
35
36
$fields
= [
37
'encryption'
=>
'Encryption'
,
38
'acknowledgments'
=>
'Acknowledgments'
,
39
'language'
=>
'Preferred-Languages'
,
40
'canonical'
=>
'Canonical'
,
41
'policy'
=>
'Policy'
,
42
'hiring'
=>
'Hiring'
,
43
'csaf'
=>
'CSAF'
,
44
];
45
foreach
(
$fields
as
$name
=>
$output
) {
46
$value
=
elgg_get_config
(
"security_txt_{$name}"
);
47
if
(empty(
$value
)) {
48
continue
;
49
}
50
51
$lines[] =
"{$output}: {$value}"
;
52
}
53
54
$response
=
elgg_ok_response
(
implode
(PHP_EOL, $lines));
55
$response
->setHeaders([
56
'Content-Type'
=>
'text/plain; charset=utf-8'
,
57
]);
58
59
return
$response
;
60
}
61
}
implode
ResponseBuilder
Elgg\Http\ResponseBuilder
HTTP response builder interface.
Definition:
ResponseBuilder.php:13
elgg_get_config
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
Definition:
configuration.php:136
Elgg\Controllers\SecurityTxt\__invoke
__invoke(\Elgg\Request $request)
Handle the request.
Definition:
SecurityTxt.php:24
Values
Saves user notification settings.
$name
if(!$user||!$user->canDelete()) $name
Definition:
delete.php:22
elgg_ok_response
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
Definition:
pagehandler.php:224
$response
$response
Definition:
content.php:10
$request
$request
Definition:
livesearch.php:12
$value
$value
Definition:
generic.php:51
Elgg
Definition:
ActionsService.php:3
Elgg\Controllers
Definition:
CommentEntityRedirector.php:3
$fields
$fields
Save the configuration of the security.txt contents.
Definition:
security_txt.php:6
$expires
$expires
Definition:
security_txt.php:19
Elgg\Controllers\SecurityTxt
Controller for the /security.txt resource.
Definition:
SecurityTxt.php:14
Elgg\Request
Request container.
Definition:
Request.php:12
EntityNotFoundException
Aggregate action for saving settings.
Elgg\Values\normalizeTime
static normalizeTime($time)
Returns DateTime object based on time representation.
Definition:
Values.php:75
Elgg\Exceptions\Http\EntityNotFoundException
Thrown when entity can not be found.
Definition:
EntityNotFoundException.php:12
$output
$output
Definition:
download.php:9
Generated on Wed Dec 4 2024 00:00:20 for Elgg by
1.8.11