Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
CheckAvatarId.php
1<?php
2
4
5use Bitrix\Disk\Driver;
6use Bitrix\Disk\File;
7use Bitrix\Disk\Security\DiskSecurityContext;
14
15class CheckAvatarId extends Base
16{
17 public function onBeforeAction(Event $event)
18 {
19 $avatarId = $this->getAction()->getArguments()['avatarId'];
20 $avatarResult = \CFile::GetByID($avatarId);
21 $avatar = (isset($avatarResult) && $avatarResult) ? $avatarResult->Fetch() : null;
22 $info = (new Image($_SERVER["DOCUMENT_ROOT"] . $avatar['SRC']))->getInfo();
23 if (!$info)
24 {
25 $this->addError(new Error(
26 'Wrong file type',
28 ));
29 return new EventResult(EventResult::ERROR, null, null, $this);
30 }
31
32 $currentUser = $this->getAction()->getCurrentUser();
33 $userId = isset($currentUser) ? $currentUser->getId() : null;
34 $securityContext = new DiskSecurityContext((int)$userId);
35 $parameters = [
36 'filter' => ['FILE_ID' => $avatarId],
37 'with' => ['CREATE_USER']
38 ];
39 $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, ['ID', 'CREATED_BY']);
40
41 $fileCollection = File::getModelList($parameters);
42 if (!$fileCollection)
43 {
44 $this->addError(new Error(
45 'File is not accessible',
47 ));
48 return new EventResult(EventResult::ERROR, null, null, $this);
49 }
50
51 return null;
52 }
53}