Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
file.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Controller
;
4
5
use
Bitrix\Main
;
6
use
Bitrix\Main\Engine\Response\BFile
;
7
use
Bitrix\Main\Error
;
8
9
class
File
extends
Base
10
{
11
private
const
TOKEN_SALT =
'bizproc.file.show'
;
12
13
public
function
configureActions
(): array
14
{
15
$configureActions = parent::configureActions();
16
$configureActions[
'show'
] = [
17
'-prefilters'
=> [
18
Main\Engine\ActionFilter\Csrf::class,
19
Main\Engine\ActionFilter\Authentication::class,
20
],
21
'+prefilters'
=> [
22
new
Main\Engine\ActionFilter\CloseSession
(),
23
]
24
];
25
26
return
$configureActions;
27
}
28
29
public
function
showAction
($token)
30
{
31
[$fileId] = self::extractToken($token);
32
$file =
null
;
33
34
if
($fileId)
35
{
36
$file = \CFile::getFileArray($fileId);
37
}
38
39
if
(!$file)
40
{
41
$this->
addError
(
new
Error
(
'No file'
));
42
return
null
;
43
}
44
45
return
BFile::createByFileData($file);
46
}
47
48
public
static
function
getPublicLink
(
int
$fileId): string
49
{
50
return
Main\Engine\UrlManager::getInstance()->create(
51
'bizproc.file.show'
,
52
[
53
'token'
=> static::generateToken($fileId),
54
],
55
true
56
)->getUri();
57
}
58
59
private
static
function
generateToken(
int
$fileId)
60
{
61
$signer =
new
Main\Security\Sign\Signer
;
62
return
$signer->
sign
((
string
) $fileId, self::TOKEN_SALT);
63
}
64
65
private
static
function
extractToken(
string
$token): array
66
{
67
$signer =
new
Main\Security\Sign\Signer
;
68
69
try
70
{
71
$unsigned = $signer->
unsign
($token, self::TOKEN_SALT);
72
$result = [$unsigned];
73
}
74
catch
(\Exception $e)
75
{
76
$result = [
null
];
77
}
78
79
return
$result;
80
}
81
}
Bitrix\Bizproc\BaseType\Base
Definition
base.php:14
Bitrix\Bizproc\BaseType\Base\addError
static addError($error)
Definition
base.php:278
Bitrix\Bizproc\Controller\File
Definition
file.php:10
Bitrix\Bizproc\Controller\File\getPublicLink
static getPublicLink(int $fileId)
Definition
file.php:48
Bitrix\Bizproc\Controller\File\showAction
showAction($token)
Definition
file.php:29
Bitrix\Bizproc\Controller\File\configureActions
configureActions()
Definition
file.php:13
Bitrix\Bizproc\Error
Definition
error.php:8
Bitrix\Main\Engine\ActionFilter\CloseSession
Definition
closesession.php:13
Bitrix\Main\Engine\Response\BFile
Definition
bfile.php:9
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Security\Sign\Signer
Definition
signer.php:13
Bitrix\Main\Security\Sign\Signer\sign
sign($value, $salt=null)
Definition
signer.php:111
Bitrix\Main\Security\Sign\Signer\unsign
unsign($signedValue, $salt=null)
Definition
signer.php:153
Bitrix\Bizproc\Controller
Definition
activity.php:3
Bitrix\Main
modules
bizproc
lib
controller
file.php
Создано системой
1.10.0