5use Bitrix\Pull\Rest\GuestAuth;
7if(!\Bitrix\
Main\Loader::includeModule(
'rest'))
19 'pull.application.config.get' =>
array(
'callback' =>
array(__CLASS__,
'applicationConfigGet')),
20 'pull.application.event.add' =>
array(
'callback' =>
array(__CLASS__,
'applicationEventAdd')),
21 'pull.application.push.add' =>
array(
'callback' =>
array(__CLASS__,
'applicationPushAdd')),
22 'pull.watch.extend' =>
array(
'callback' =>
array(__CLASS__,
'watchExtend'),
'options' =>
array()),
24 'pull_channel' =>
array(
25 'pull.config.get' =>
array(
'callback' =>
array(__CLASS__,
'configGet'),
'options' =>
array()),
26 'pull.channel.public.get' =>
array(
'callback' =>
array(__CLASS__,
'channelPublicGet'),
'options' =>
array()),
27 'pull.channel.public.list' =>
array(
'callback' =>
array(__CLASS__,
'channelPublicList'),
'options' =>
array()),
30 'mobile.counter.types.get' =>
array(
'callback' =>
array(__CLASS__,
'counterTypesGet'),
'options' =>
array()),
31 'mobile.counter.get' =>
array(
'callback' =>
array(__CLASS__,
'counterGet'),
'options' =>
array()),
32 'mobile.counter.config.get' =>
array(
'callback' =>
array(__CLASS__,
'counterConfigGet'),
'options' =>
array()),
33 'mobile.counter.config.set' =>
array(
'callback' =>
array(__CLASS__,
'counterConfigSet'),
'options' =>
array()),
35 'mobile.push.types.get' =>
array(
'callback' =>
array(__CLASS__,
'pushTypesGet'),
'options' =>
array()),
36 'mobile.push.config.get' =>
array(
'callback' =>
array(__CLASS__,
'pushConfigGet'),
'options' =>
array()),
37 'mobile.push.config.set' =>
array(
'callback' =>
array(__CLASS__,
'pushConfigSet'),
'options' =>
array()),
38 'mobile.push.status.get' =>
array(
'callback' =>
array(__CLASS__,
'pushStatusGet'),
'options' =>
array()),
39 'mobile.push.status.set' =>
array(
'callback' =>
array(__CLASS__,
'pushStatusSet'),
'options' =>
array()),
40 'mobile.push.smartfilter.status.get' =>
array(
'callback' =>
array(__CLASS__,
'pushSmartfilterStatusGet'),
'options' =>
array()),
41 'mobile.push.smartfilter.status.set' =>
array(
'callback' =>
array(__CLASS__,
'pushSmartfilterStatusSet'),
'options' =>
array()),
51 if (
$params[
'APPLICATION'] ===
'Y')
56 throw new \Bitrix\Rest\RestException(
"Get application public channel available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_WRONG_REQUEST);
63 $configParams = Array();
64 $configParams[
'TYPE'] =
$type;
65 $configParams[
'USER_ID'] =
$userId;
66 $configParams[
'JSON'] =
true;
71 throw new \Bitrix\Rest\RestException(
"Push & Pull server is not configured",
"SERVER_ERROR", \CRestServer::STATUS_INTERNAL);
82 if (isset(
$params[
'APPLICATION']) &&
$params[
'APPLICATION'] ===
'Y')
87 throw new \Bitrix\Rest\RestException(
"Get application public channel available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_WRONG_REQUEST);
95 if (is_string(
$params[
'USERS']))
113 throw new \Bitrix\Rest\RestException(
"A wrong format for the USERS field is passed",
"INVALID_FORMAT", \CRestServer::STATUS_WRONG_REQUEST);
117 $configParams[
'TYPE'] =
$type;
118 $configParams[
'USERS'] = $users;
119 $configParams[
'JSON'] =
true;
124 throw new \Bitrix\Rest\RestException(
"Push & Pull server is not configured",
"SERVER_ERROR", \CRestServer::STATUS_INTERNAL);
137 throw new \Bitrix\Rest\RestException(
"Get access to application config available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
140 $configParams = Array();
141 $configParams[
'CACHE'] =
$params[
'CACHE'] !==
'N';
142 $configParams[
'REOPEN'] =
$params[
'REOPEN'] !==
'N';
143 $configParams[
'CUSTOM_TYPE'] =
$clientId;
144 $configParams[
'JSON'] =
true;
149 throw new \Bitrix\Rest\RestException(
"Push & Pull server is not configured",
"SERVER_ERROR", \CRestServer::STATUS_INTERNAL);
162 throw new \Bitrix\Rest\RestException(
"Get access to application config available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
170 if (is_string(
$params[
'USER_ID']))
175 if (!isset(
$params[
'USER_ID']))
179 else if (is_array(
$params[
'USER_ID']))
189 $users = array_values($users);
193 $users = (int)
$params[
'USER_ID'];
202 $users =
$USER->GetId();
206 throw new \Bitrix\Rest\RestException(
"Only admin can send notifications to other channels",
"USER_ID_ACCESS_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
215 if (isset(
$params[
'MODULE_ID']))
218 if (preg_match(
"/[^a-z0-9._]/",
$moduleId))
220 throw new \Bitrix\Rest\RestException(
"Module ID format error",
"MODULE_ID_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
229 if (!preg_match(
"/^[\d\w:_|\.\-]+$/", $command))
231 throw new \Bitrix\Rest\RestException(
"Command format error",
"COMMAND_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
236 if (is_string(
$params[
'PARAMS']))
241 $eventParams =
$params[
'PARAMS'];
242 if (!is_array($eventParams))
244 throw new \Bitrix\Rest\RestException(
"Params format error",
"PARAMS_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
254 'command' => $command,
255 'params' => $eventParams,
268 throw new \Bitrix\Rest\RestException(
"Send push notifications available only for application authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
271 if (!self::isAdmin())
273 throw new \Bitrix\Rest\RestException(
"You do not have access to send push notifications",
"ACCESS_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
277 if (is_string(
$params[
'USER_ID']))
282 if (is_array(
$params[
'USER_ID']))
292 $users = array_values($users);
296 $users = (int)
$params[
'USER_ID'];
301 throw new \Bitrix\Rest\RestException(
"Text can't be empty",
"TEXT_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
304 $result = \Bitrix\Rest\AppTable::getList(
312 'APP_NAME_DEFAULT' =>
'LANG_DEFAULT.MENU_NAME',
316 if (empty(
$result[
'APP_NAME']))
318 throw new \Bitrix\Rest\RestException(
"For send push-notification application name can't be empty",
"EMPTY_APP_NAME", \CRestServer::STATUS_WRONG_REQUEST);
321 $appName =
$result[
'APP_NAME'];
329 $params[
'AVATAR'] = $parsedUrl->getUri();
345 "avatarUrl"=> $avatar,
346 "senderName" => $appName,
347 "senderMessage" =>
$text,
361 throw new \Bitrix\Rest\RestException(
"Method not available for OAuth authorization.",
"WRONG_AUTH_TYPE", \CRestServer::STATUS_FORBIDDEN);
365 $guestMode = defined(
"PULL_USER_ID") && (int)PULL_USER_ID != 0;
370 else if (
$USER->IsAuthorized())
376 throw new \Bitrix\Rest\RestException(
"Method not available for guest session at the moment.",
"AUTHORIZE_ERROR", \CRestServer::STATUS_FORBIDDEN);
379 $configParams = Array();
380 $configParams[
'USER_ID'] =
$userId;
381 $configParams[
'CACHE'] = !isset(
$params[
'CACHE']) ||
$params[
'CACHE'] !==
'N';
382 $configParams[
'REOPEN'] = !isset(
$params[
'REOPEN']) ||
$params[
'REOPEN'] !==
'N';
383 $configParams[
'JSON'] =
true;
388 throw new \Bitrix\Rest\RestException(
"Push & Pull server is not configured",
"SERVER_ERROR", \CRestServer::STATUS_INTERNAL);
391 $config[
'serverTime'] = date(
'c', time());
408 return \CPullWatch::Extend(
$userId, array_values(
$params[
'TAGS']));
415 if (isset(
$params[
'USER_VALUES']) &&
$params[
'USER_VALUES'] ===
'Y')
418 foreach ($types as
$type => $value)
425 foreach ($types as
$type)
435 return \Bitrix\Pull\MobileCounter::get();
457 if(is_string(
$params[
'CONFIG']))
464 throw new \Bitrix\Rest\RestException(
"New config is not specified",
"CONFIG_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
477 $userConfig = Array();
478 $config = \Bitrix\Pull\Push::getTypes();
480 $withUserValues =
false;
481 if (isset(
$params[
'USER_VALUES']) &&
$params[
'USER_VALUES'] ===
'Y')
483 $withUserValues =
true;
484 $userConfig = \Bitrix\Pull\Push::getConfig();
492 foreach ($module[
'TYPES'] as $typeId => $typeConfig)
496 $typeConfig[
'VALUE'] = $userConfig[
$moduleId][$typeId];
498 $types[] = array_change_key_case($typeConfig, CASE_LOWER);
500 $module[
'TYPES'] = $types;
502 $result[] = array_change_key_case($module, CASE_LOWER);
513 $config = \Bitrix\Pull\Push::getConfig();
521 foreach ($module as $typeId => $typeValue)
526 'active' => $typeValue
537 if(is_string(
$params[
'CONFIG']))
544 throw new \Bitrix\Rest\RestException(
"New config is not specified",
"CONFIG_ERROR", \CRestServer::STATUS_WRONG_REQUEST);
547 $newConfig = Array();
562 \Bitrix\Pull\Push::setConfig($newConfig);
569 return \Bitrix\Pull\Push::getStatus();
577 \Bitrix\Pull\Push::setStatus(
$status);
584 return \Bitrix\Pull\PushSmartfilter::getStatus();
600 throw new \Bitrix\Rest\RestException(
"Method isn't implemented yet",
"NOT_IMPLEMENTED", \CRestServer::STATUS_NOT_FOUND);
603 private static function isAdmin()
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static includeModule($moduleName)
static sortByColumn(array &$array, $columns, $callbacks='', $defaultValueIfNotSetValue=null, $preserveKeys=false)
static getPublicId($params)
static getPublicIds($params=[])
static get(array $params=[])
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static setConfig($config, $userId=null)
static getConfig($userId=null)
static setStatus($status, $userId=null)
static onRestServiceBuildDescription()
static counterConfigSet($params, $n, \CRestServer $server)
static pushConfigGet($params, $n, \CRestServer $server)
static pushConfigSet($params, $n, \CRestServer $server)
static channelPublicList($params, $n, \CRestServer $server)
static channelPublicGet($params, $n, \CRestServer $server)
static counterGet($params, $n, \CRestServer $server)
static applicationEventAdd($params, $n, \CRestServer $server)
static pushSmartfilterStatusGet($params, $n, \CRestServer $server)
static notImplemented($params, $n, \CRestServer $server)
static pushSmartfilterStatusSet($params, $n, \CRestServer $server)
static pushStatusGet($params, $n, \CRestServer $server)
static configGet($params, $n, \CRestServer $server)
static pushStatusSet($params, $n, \CRestServer $server)
static pushTypesGet($params, $n, \CRestServer $server)
static counterTypesGet($params, $n, \CRestServer $server)
static watchExtend($params, $n, \CRestServer $server)
static applicationPushAdd($params, $n, \CRestServer $server)
static counterConfigGet($params, $n, \CRestServer $server)
static applicationConfigGet($params, $n, \CRestServer $server)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']