1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CheckAvatarIdInFields.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Controller\Filter;
4
5use Bitrix\Disk\Driver;
6use Bitrix\Disk\File;
7use Bitrix\Disk\Security\DiskSecurityContext;
8use Bitrix\Im\V2\Chat;
9use Bitrix\Main\Engine\ActionFilter\Base;
10use Bitrix\Main\Error;
11use Bitrix\Main\Event;
12use Bitrix\Main\EventResult;
13use Bitrix\Main\File\Image;
14
16{
17 public function onBeforeAction(Event $event)
18 {
19 $fields = $this->getAction()->getArguments()['fields'];
20 $avatarId = $fields['avatar'] ?? null;
21 if (!is_numeric($avatarId))
22 {
23 return null;
24 }
25
26 $avatarResult = \CFile::GetByID($avatarId);
27 $avatar = (isset($avatarResult) && $avatarResult) ? $avatarResult->Fetch() : null;
28 $info = (new Image($_SERVER["DOCUMENT_ROOT"] . $avatar['SRC']))->getInfo();
29 if (!$info)
30 {
31 $this->addError(new Error(
32 'Wrong file type',
34 ));
35 return new EventResult(EventResult::ERROR, null, null, $this);
36 }
37
38 $currentUser = $this->getAction()->getCurrentUser();
39 $userId = isset($currentUser) ? $currentUser->getId() : null;
40 $securityContext = new DiskSecurityContext((int)$userId);
41 $parameters = [
42 'filter' => ['FILE_ID' => $avatarId],
43 'with' => ['CREATE_USER']
44 ];
45 $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, ['ID', 'CREATED_BY']);
46
47 $fileCollection = File::getModelList($parameters);
48 if (!$fileCollection)
49 {
50 $this->addError(new Error(
51 'File is not accessible',
53 ));
54 return new EventResult(EventResult::ERROR, null, null, $this);
55 }
56
57 return null;
58 }
59}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const WRONG_PARAMETER
Определения ChatError.php:12
addError(Error $error)
Определения base.php:80
Определения error.php:15
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
Определения Color.php:9
$event
Определения prolog_after.php:141
$fields
Определения yandex_run.php:501