- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::appUpdate
static function appUpdate($arParams, $n, CRestServer $server)
{
if ($server->getAuthType() == BitrixRestSessionAuthAuth::AUTH_TYPE)
{
throw new BitrixRestRestException("Access for this method not allowed by session authorization.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
}
$arParams = array_change_key_case($arParams, CASE_UPPER);
$clientId = $server->getClientId();
if (!$clientId)
{
if (!empty($arParams['CLIENT_ID']))
{
$clientId = 'custom'.$arParams['CLIENT_ID'];
}
else
{
throw new BitrixRestAccessException("Client ID not specified");
}
}
$apps = BitrixImApp::getListCache();
if (!isset($apps[$arParams['APP_ID']]))
{
throw new BitrixRestRestException("App not found", "CHAT_APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
if ($apps[$arParams['APP_ID']]['APP_ID'] != $clientId)
{
throw new BitrixRestRestException("App was installed by another rest application", "APP_ID_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
$updateFields = Array();
if (isset($arParams['FIELDS']['CONTEXT']) && !empty($arParams['FIELDS']['CONTEXT']))
{
$updateFields['CONTEXT'] = $arParams['FIELDS']['CONTEXT'];
}
if (isset($arParams['FIELDS']['HASH']) && !empty($arParams['FIELDS']['HASH']))
{
$updateFields['HASH'] = $arParams['FIELDS']['HASH'];
}
if (
isset($arParams['FIELDS']['JS_METHOD']) && in_array($arParams['FIELDS']['JS_METHOD'], Array('PUT', 'SEND', 'CALL', 'SUPPORT')) &&
isset($arParams['FIELDS']['JS_PARAM']) && !empty($arParams['FIELDS']['JS_PARAM'])
)
{
if ($arParams['FIELDS']['JS_METHOD'] == 'SEND')
{
if (preg_match('//([a-zA-Z0-9-_+]+)((s)?([a-zA-Z0-9-_+]+))+/im', $arParams['FIELDS']['JS_PARAM'], $matches))
{
$updateFields['JS'] = "BXIM.sendMessage('".$matches[0]."');";
}
}
else if ($arParams['FIELDS']['JS_METHOD'] == 'PUT')
{
if (preg_match('//([a-zA-Z0-9-_+]+)((s)?([a-zA-Z0-9-_+]+))+/im', $arParams['FIELDS']['JS_PARAM'], $matches))
{
$updateFields['JS'] = "BXIM.putMessage('".$matches[0]."');";
}
}
else if ($arParams['FIELDS']['JS_METHOD'] == 'CALL')
{
if (preg_match('/+?[ -d+()#]+$/im', $arParams['FIELDS']['JS_PARAM'], $matches))
{
$updateFields['JS'] = "BXIM.phoneTo('".$matches[0]."');";
}
}
else if ($arParams['FIELDS']['JS_METHOD'] == 'SUPPORT')
{
if (preg_match('/[a-f0-9]{32}$/im', $arParams['FIELDS']['JS_PARAM'], $matches))
{
$updateFields['JS'] = "BXIM.openMessenger('networkLines".$matches[0]."');";
}
}
if (isset($updateFields['JS']))
{
$updateFields['IFRAME'] = '';
}
}
else if (isset($arParams['FIELDS']['IFRAME']) && !empty($arParams['FIELDS']['IFRAME']))
{
$check = parse_url($arParams['FIELDS']['IFRAME']);
if (!isset($check['scheme']) && !isset($check['host']))
{
throw new BitrixRestRestException("Iframe params must be HTTPS site", "IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
}
else if ($check['scheme'] != 'https' || empty($check['host']))
{
throw new BitrixRestRestException("Iframe params must be HTTPS site", "IFRAME_HTTPS", CRestServer::STATUS_WRONG_REQUEST);
}
$updateFields['IFRAME'] = $arParams['FIELDS']['IFRAME'];
$updateFields['JS'] = '';
}
if (isset($arParams['FIELDS']['IFRAME_WIDTH']))
{
$updateFields['IFRAME_WIDTH'] = intval($arParams['FIELDS']['IFRAME_WIDTH']);
}
if (isset($arParams['FIELDS']['IFRAME_HEIGHT']))
{
$updateFields['IFRAME_HEIGHT'] = intval($arParams['FIELDS']['IFRAME_HEIGHT']);
}
if (isset($arParams['FIELDS']['IFRAME_POPUP']) && !empty($arParams['FIELDS']['IFRAME_POPUP']))
{
$updateFields['IFRAME_POPUP'] = $arParams['FIELDS']['IFRAME_POPUP'] == 'Y'? 'Y': 'N';
}
if (isset($arParams['FIELDS']['HIDDEN']) && !empty($arParams['FIELDS']['HIDDEN']))
{
$updateFields['HIDDEN'] = $arParams['FIELDS']['HIDDEN'] == 'Y'? 'Y': 'N';
}
if (isset($arParams['FIELDS']['EXTRANET_SUPPORT']) && !empty($arParams['FIELDS']['EXTRANET_SUPPORT']))
{
$updateFields['EXTRANET_SUPPORT'] = $arParams['FIELDS']['EXTRANET_SUPPORT'] == 'Y'? 'Y': 'N';
}
if (isset($arParams['FIELDS']['LIVECHAT_SUPPORT']) && !empty($arParams['FIELDS']['LIVECHAT_SUPPORT']))
{
$updateFields['LIVECHAT_SUPPORT'] = $arParams['FIELDS']['LIVECHAT_SUPPORT'] == 'Y'? 'Y': 'N';
}
if (isset($arParams['FIELDS']['LANG']) && !empty($arParams['FIELDS']['LANG']))
{
$updateFields['LANG'] = $arParams['FIELDS']['LANG'];
}
if (isset($arParams['FIELDS']['ICON_FILE']))
{
$iconFile = CRestUtil::saveFile($arParams['FIELDS']['ICON_FILE']);
$imageCheck = (new BitrixMainFileImage($iconFile["tmp_name"]))->getInfo();
if(
!$imageCheck
|| !$imageCheck->getWidth()
|| $imageCheck->getWidth() > 5000
|| !$imageCheck->getHeight()
|| $imageCheck->getHeight() > 5000
)
{
$iconFile = null;
}
if ($iconFile && mb_strpos($iconFile['type'], "image/") === 0)
{
$iconFile['MODULE_ID'] = 'imbot';
$updateFields['ICON_FILE_ID'] = CFile::saveFile($iconFile, 'imbot');
}
}
if (!empty($updateFields))
{
$result = BitrixImApp::update(Array('ID' => $arParams['APP_ID']), $updateFields);
if (!$result)
{
throw new BitrixRestRestException("Command can't be updated", "WRONG_REQUEST", CRestServer::STATUS_WRONG_REQUEST);
}
}
return true;
}