1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CheckAvatarId.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
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}
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