1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
rest_util.php
См. документацию.
1<?php
2
6use Bitrix\Rest\Public;
7
9
11{
12 const GLOBAL_SCOPE = '_global';
13 const EVENTS = '_events';
14 const PLACEMENTS = '_placements';
15
17
18 const BATCH_MAX_LENGTH = 50;
19
20 const METHOD_DOWNLOAD = "download";
21 const METHOD_UPLOAD = "upload";
22
23 const TOKEN_DELIMITER = "|";
24
25 const BITRIX_1C_APP_CODE = 'bitrix.1c';
26
27 const PLACEMENT_APP_URI = 'REST_APP_URI';
28
29 public static function sendHeaders()
30 {
31 Header('Access-Control-Allow-Origin: *');
32 Header('Access-Control-Allow-Headers: origin, content-type, accept');
33 Header('X-Content-Type-Options: nosniff');
34 }
35
36 public static function getStandardParams()
37 {
38 return array(
39 "PARAMETERS" => array(
40 "VARIABLE_ALIASES" => Array(
41 "method" => Array("NAME" => GetMessage('REST_PARAM_METHOD_NAME')),
42 ),
43 "SEF_MODE" => Array(
44 "path" => array(
45 "NAME" => GetMessage('REST_PARAM_PATH'),
46 "DEFAULT" => "#method#",
47 "VARIABLES" => array("method" => "method"),
48 ),
49 ),
50 )
51 );
52 }
53
54 public static function getRequestData()
55 {
56 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
57 $server = \Bitrix\Main\Context::getCurrent()->getServer();
58
59 $query = $request->toArray();
60
61 if($request->isPost() && $request->getPostList()->isEmpty())
62 {
63 $rawPostData = trim($request->getInput());
64
65 if(isset($server['HTTP_CONTENT_TYPE']))
66 {
67 $requestContentType = $server['HTTP_CONTENT_TYPE'];
68 }
69 else
70 {
71 $requestContentType = $server['CONTENT_TYPE'];
72 }
73
74 $requestContentType = trim(preg_replace('/;.*$/', '', $requestContentType));
75
76 $postData = array();
77
78 switch($requestContentType)
79 {
80 case 'application/json':
81
82 try
83 {
85 }
86 catch(\Bitrix\Main\ArgumentException $e)
87 {
88 $postData = array();
89 }
90
91 break;
92
93 default:
94
95 if($rawPostData <> '')
96 {
97 parse_str($rawPostData, $postData);
98 }
99
100 break;
101 }
102
103 if (!is_array($postData))
104 {
105 $postData = [];
106 }
107
108 $query = array_replace($query, $postData);
109 }
110
111 return $query;
112 }
113
118 public static function isAdmin(?int $userId = null): bool
119 {
120 global $USER;
121
122 if ($userId > 0)
123 {
124 if (is_object($USER) && $USER instanceof \CUser && ModuleManager::isModuleInstalled('bitrix24'))
125 {
126 return $USER->CanDoOperation('bitrix24_config', $userId);
127 }
128
129 return in_array(1, \CUser::GetUserGroup($userId));
130 }
131
132 if(!is_object($USER) || !($USER instanceof \CUser))
133 {
134 return false;
135 }
136
137 if (ModuleManager::isModuleInstalled('bitrix24'))
138 {
139 return $USER->CanDoOperation('bitrix24_config');
140 }
141
142 return $USER->IsAdmin();
143 }
144
150 public static function canInstallApplication($appInfo = null, ?int $userId = null)
151 {
152 global $USER;
153
154 if (
155 !empty($appInfo['HOLD_INSTALL_BY_TRIAL'])
156 && $appInfo['HOLD_INSTALL_BY_TRIAL'] === 'Y'
157 && \Bitrix\Rest\Marketplace\Client::isSubscriptionDemo()
158 )
159 {
160 return false;
161 }
162
163 if (static::isAdmin($userId))
164 {
165 return true;
166 }
167
168 if (
169 is_array($appInfo)
170 && $appInfo['TYPE'] === \Bitrix\Rest\AppTable::TYPE_CONFIGURATION
171 && !empty($appInfo['MANIFEST']['CODE'])
172 )
173 {
175 \Bitrix\Rest\Configuration\Manifest::ACCESS_TYPE_IMPORT,
176 $appInfo['MANIFEST']['CODE']
177 );
178
179 return $access['result'];
180 }
181
182 $hasAccess = $USER->CanAccess(static::getInstallAccessList());
183 if ($hasAccess && is_array($appInfo))
184 {
185 return static::appCanBeInstalledByUser($appInfo);
186 }
187
188 return $hasAccess;
189 }
190
191 public static function appCanBeInstalledByUser(array $appInfo)
192 {
193 return $appInfo['USER_INSTALL'] === 'Y';
194 }
195
196 public static function getInstallAccessList()
197 {
198 $accessList = \Bitrix\Main\Config\Option::get('rest', 'install_access_list', '');
199
200 return $accessList === '' ? array() : explode(",", $accessList);
201 }
202
203 public static function setInstallAccessList($accessList)
204 {
205 if(is_array($accessList))
206 {
207 $value = implode(',', $accessList);
208 }
209 else
210 {
211 $value = '';
212 }
213
214 \Bitrix\Main\Config\Option::set('rest', 'install_access_list', $value);
215 }
216
217 public static function notifyInstall($appInfo)
218 {
219 global $USER;
220
221 if (Loader::includeModule('im'))
222 {
223 $userName = \CUser::FormatName("#NAME# #LAST_NAME#", array(
224 "NAME" => $USER->GetFirstName(),
225 "LAST_NAME" => $USER->GetLastName(),
226 "SECOND_NAME" => $USER->GetSecondName(),
227 "LOGIN" => $USER->GetLogin()
228 ));
229
230 $adminList = \CRestUtil::getAdministratorIdList();
231 foreach($adminList as $id)
232 {
234 "TO_USER_ID" => $id,
235 "FROM_USER_ID" => $USER->GetID(),
236 "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
237 "NOTIFY_MODULE" => "rest",
238 "NOTIFY_TAG" => "REST|APP_INSTALL_NOTIFY|".$USER->GetID()."|TO|".$id,
239 "NOTIFY_SUB_TAG" => "REST|APP_INSTALL_NOTIFY",
240 "NOTIFY_EVENT" => "admin_notification",
241 "NOTIFY_MESSAGE" => GetMessage(
242 "REST_APP_INSTALL_NOTIFY_TEXT",
243 array(
244 "#USER_NAME#" => $userName,
245 "#APP_NAME#" => $appInfo['APP_NAME'],
246 "#APP_CODE#" => $appInfo['CODE'],
247 "#APP_LINK#" => \Bitrix\Rest\Marketplace\Url::getApplicationDetailUrl(urlencode($appInfo['CODE'])),
248 )),
249 );
250 \CIMNotify::Add($messageFields);
251 }
252 }
253 }
254
255 public static function signLicenseRequest(array $request, $licenseKey)
256 {
257 if(Loader::includeModule('bitrix24') && defined('BX24_HOST_NAME'))
258 {
259 $request['BX_TYPE'] = 'B24';
260 $request['BX_LICENCE'] = BX24_HOST_NAME;
261 $request['BX_HASH'] = \CBitrix24::RequestSign(md5(implode("|", $request)));
262 }
263 else
264 {
265 $request['BX_TYPE'] = ModuleManager::isModuleInstalled('intranet') ? 'CP' : 'BSM';
266 $request['BX_LICENCE'] = md5("BITRIX".$licenseKey."LICENCE");
267 $request['BX_HASH'] = md5(md5(implode("|", $request)).md5($licenseKey));
268 }
269
270 return $request;
271 }
272
273 public static function ConvertDate($dt)
274 {
275 return $dt ? date('c', MakeTimeStamp($dt, FORMAT_DATE) + date("Z")) : '';
276 }
277
278
279 public static function ConvertDateTime($dt)
280 {
281 return $dt ? date('c', MakeTimeStamp($dt) - CTimeZone::GetOffset()) : '';
282 }
283
284
289 public static function unConvertDate($iso8601)
290 {
291 if(is_array($iso8601))
292 {
293 foreach($iso8601 as $key => $value)
294 {
295 $iso8601[$key] = self::unConvertDateTime($value);
296 }
297
298 return $iso8601;
299 }
300 else
301 {
302 $date = false;
303 $timestamp = strtotime($iso8601);
304
305 if ($timestamp !== false)
306 $date = ConvertTimeStamp($timestamp, 'SHORT');
307
308 return ($date);
309 }
310 }
311
319 public static function unConvertDateTime($iso8601, $enableOffset = false)
320 {
321 if(is_array($iso8601))
322 {
323 foreach($iso8601 as $key => $value)
324 {
325 $iso8601[$key] = self::unConvertDateTime($value, $enableOffset);
326 }
327
328 return $iso8601;
329 }
330 else
331 {
332 $date = false;
333 $timestamp = strtotime($iso8601);
334
335 if ($timestamp !== false)
336 {
337 if($enableOffset)
338 {
339 $timestamp += CTimeZone::GetOffset();
340 }
341 $date = ConvertTimeStamp($timestamp, 'FULL');
342 }
343
344 return ($date);
345 }
346 }
347
348 public static function getMemberId()
349 {
350 if(CModule::IncludeModule('bitrix24'))
351 {
352 return \CBitrix24::getMemberId();
353 }
354 else
355 {
356 return \Bitrix\Rest\OAuthService::getMemberId();
357 }
358 }
359
360 public static function isStatic($url)
361 {
362 return preg_match("/^http[s]{0,1}:\/\/[^\/]*?(\.apps-bitrix24\.com|\.bitrix24-cdn\.com|cdn\.bitrix24\.|app\.bitrix24\.com|upload-.*?\.s3\.amazonaws\.com\/app_local\/)/i", $url);
363 }
364
365 public static function GetFile($fileId , $resizeParam = false)
366 {
367 $fileSrc = array();
368 $bMult = false;
369
370 if(is_array($fileId))
371 {
372 $fileId = implode(',', $fileId);
373 $bMult = true;
374 }
375
376 if($fileId <> '')
377 {
378 $files = \CFile::GetList(array(), array('@ID' => $fileId));
379 while($file = $files->Fetch())
380 {
381 if($resizeParam !== false)
382 {
383 $resizeResult = \CFile::ResizeImageGet($file["ID"], $resizeParam, BX_RESIZE_IMAGE_PROPORTIONAL_ALT, false, false, false);
384 $fileSrc[$file['ID']] = \CHTTP::URN2URI($resizeResult['src']);
385 }
386 else
387 {
388 $fileSrc[$file['ID']] = \CHTTP::URN2URI(\CFile::GetFileSrc($file));
389 }
390 }
391 }
392
393 return $bMult ? $fileSrc : $fileSrc[$fileId];
394 }
395
396 protected static function processBatchElement($query, $arResult, $keysCache = '')
397 {
398 $regexp = "/\\$(".$keysCache.")([^\s]*)/i";
399
400 if(preg_match_all($regexp, $query, $arMatches, PREG_SET_ORDER))
401 {
402 foreach($arMatches as $arMatch)
403 {
404 $path = $arMatch[2];
405 if(preg_match_all("/\\[([^\\]]+)\\]/", $path, $arPath))
406 {
407 $r = $arResult[$arMatch[1]];
408
409 while(count($arPath[1]) > 0)
410 {
411 $key = array_shift($arPath[1]);
412 if(isset($r[$key]))
413 {
414 $r = $r[$key];
415 }
416 else
417 {
418 break;
419 }
420 }
421 if($arMatch[0] === $query)
422 {
423 $query = $r;
424 }
425 else
426 {
427 if (is_numeric($r))
428 {
429 $r = (string)$r;
430 }
431
432 if (!is_string($r))
433 {
434 continue;
435 }
436 $query = str_replace($arMatch[0], $r, $query);
437 }
438 }
439 }
440 }
441
442 return $query;
443 }
444
445 protected static function processBatchStructure($queryParams, $arResult, $keysCache = null)
446 {
447 $resultQueryParams = array();
448
449 if(is_array($queryParams))
450 {
451 foreach($queryParams as $key => $param)
452 {
453 if($keysCache === null)
454 {
455 $keysCache = implode('|', array_keys($arResult));
456 }
457
458 $newKey = self::processBatchElement($key, $arResult);
459 if(is_array($param))
460 {
461 $resultQueryParams[$newKey] = self::processBatchStructure($param, $arResult, $keysCache);
462 }
463 else
464 {
465 $resultQueryParams[$newKey] = self::processBatchElement($param, $arResult, $keysCache);
466 }
467 }
468 }
469
470 return $resultQueryParams;
471 }
472
473 public static function ParseBatchQuery($query, $arResult)
474 {
475 $resultQueryParams = array();
476
477 if($query)
478 {
479 $queryParams = array();
480 parse_str($query, $queryParams);
481
482 $resultQueryParams = self::processBatchStructure($queryParams, $arResult);
483 }
484
485 return $resultQueryParams;
486 }
487
489 public static function getAuthForEvent($appId, $userId, array $additionalData = array())
490 {
491 return \Bitrix\Rest\Event\Sender::getAuth($appId, $userId, $additionalData, \Bitrix\Rest\Event\Sender::getDefaultEventParams());
492 }
493
499 public static function getAuth($appId, $appSecret, $scope, $additionalParams, $user_id = 0)
500 {
501 global $USER;
502
503 if(
504 \Bitrix\Rest\Integration\OAuthModule::isSupported()
505 && CModule::IncludeModule('oauth')
506 )
507 {
508 if(is_array($scope))
509 {
510 $scope = implode(',', $scope);
511 }
512
513 $oauth = new \Bitrix\OAuth\Client\Application();
514 $authParams = $oauth->getAuthorizeParamsInternal($appId, COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE, '', '', $scope, array(), $user_id > 0 ? $user_id : $USER->GetID());
515
516 if(is_array($authParams) && isset($authParams[COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE]))
517 {
518 $res = $oauth->grantAccessTokenInternal($appId, COAuthConstants::GRANT_TYPE_AUTH_CODE, '', $authParams[COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE], $scope, $appSecret, '', $additionalParams, $user_id > 0 ? $user_id : $USER->GetID());
519
520 return $res;
521 }
522 }
523
524 return false;
525 }
526
527 public static function checkAuth($query, $scope, &$res)
528 {
529 // compatibility fix: other modules use checkAuth instead of /rest/download
530 if(!is_array($query))
531 {
532 $query = array('auth' => $query);
533 }
534
535 foreach(GetModuleEvents('rest', 'OnRestCheckAuth', true) as $eventHandler)
536 {
537 $eventResult = ExecuteModuleEventEx($eventHandler, array($query, $scope, &$res));
538 if($eventResult !== null)
539 {
540 return $eventResult;
541 }
542 }
543
544 $res = array(
545 "error" => "NO_AUTH_FOUND",
546 "error_description" => "Wrong authorization data",
547 );
548
549 return false;
550 }
551
552 public static function makeAuth($res, $application_id = null)
553 {
554 return (new Public\Command\Auth\AuthorizeUserCommand((int)($res['user_id'] ?? 0), $application_id))
555 ->run()
556 ->isSuccess()
557 ;
558 }
559
560 public static function checkAppAccess($appId, $appInfo = null)
561 {
562 global $USER;
563
564 $hasAccess = false;
565
566 if($appInfo === null)
567 {
568 $appInfo = \Bitrix\Rest\AppTable::getByClientId($appId);
569 }
570
571 if($appInfo)
572 {
573 if(!empty($appInfo["ACCESS"]))
574 {
575 $rights = explode(",", $appInfo["ACCESS"]);
576 $hasAccess = $USER->CanAccess($rights);
577 }
578 else
579 {
580 $hasAccess = true;
581 }
582 }
583
584 if(!$hasAccess)
585 {
586 $hasAccess = \CRestUtil::isAdmin();
587 }
588
589 return $hasAccess;
590 }
591
592 public static function updateAppStatus(array $tokenInfo)
593 {
594 if(array_key_exists('status', $tokenInfo) && array_key_exists('client_id', $tokenInfo))
595 {
596 $appInfo = \Bitrix\Rest\AppTable::getByClientId($tokenInfo['client_id']);
597 if($appInfo)
598 {
599 $dateFinish = $appInfo['DATE_FINISH'] ? $appInfo['DATE_FINISH']->getTimestamp() : '';
600
601 if($tokenInfo['status'] !== $appInfo['STATUS'] || $tokenInfo['date_finish'] != $dateFinish)
602 {
603 \Bitrix\Rest\AppTable::update($appInfo['ID'], array(
604 'STATUS' => $tokenInfo['status'],
605 'DATE_FINISH' => $tokenInfo['date_finish'] ? \Bitrix\Main\Type\DateTime::createFromTimestamp($tokenInfo['date_finish']) : '',
606 ));
607 }
608 }
609 }
610 }
611
612 public static function saveFile($fileContent, $fileName = "")
613 {
614 if(is_array($fileContent))
615 {
616 list($fileName, $fileContent) = array_values($fileContent);
617 }
618
619 if($fileContent <> '' && $fileContent !== 'false') // let it be >0
620 {
621 $fileContent = base64_decode($fileContent);
622 if($fileContent !== false && $fileContent <> '')
623 {
624 if($fileName == '')
625 {
627 }
628
629 $fileName = CTempFile::GetFileName($fileName);
630
632 {
633 file_put_contents($fileName, $fileContent);
634 return CFile::MakeFileArray($fileName);
635 }
636 }
637 else
638 {
639 return null; // wrong file content
640 }
641 }
642
643 return false;
644 }
645
646 public static function CleanApp($appId, $bClean)
647 {
649 'APP_ID' => $appId,
650 'CLEAN' => $bClean
651 );
652
653 foreach (GetModuleEvents("rest", "OnRestAppDelete", true) as $arEvent)
654 {
656 }
657
661
662 if($bClean)
663 {
664 $dbRes = \Bitrix\Rest\AppTable::getById($appId);
665 $arApp = $dbRes->fetch();
666 if($arApp)
667 {
668 // delete app settings
669 COption::RemoveOption("rest", "options_".$arApp['CLIENT_ID']);
670 CUserOptions::DeleteOption("app_options", "params_".$arApp['CLIENT_ID']."_".$arApp['VERSION']);
671 // delete app user settings
672 CUserOptions::DeleteOption("app_options", "options_".$arApp['CLIENT_ID'], array());
673
674 // clean app iblocks
675 CBitrixRestEntity::Clean($arApp['CLIENT_ID']);
676 }
677 }
678 }
679
687 public static function InstallApp($code)
688 {
689 $result = false;
690
691 if(!\Bitrix\Rest\OAuthService::getEngine()->isRegistered())
692 {
693 try
694 {
696 \Bitrix\Rest\OAuthService::getEngine()->getClient()->getApplicationList();
697 }
698 catch(\Bitrix\Main\SystemException $e)
699 {
700 $result = array('error' => $e->getCode(), 'error_description' => $e->getMessage());
701 }
702 }
703
704 if(\Bitrix\Rest\OAuthService::getEngine()->isRegistered())
705 {
707
708 if($appDetailInfo)
709 {
710 $appDetailInfo = $appDetailInfo['ITEMS'];
711 }
712
713 if($appDetailInfo)
714 {
715 $queryFields = array(
716 'CLIENT_ID' => $appDetailInfo['APP_CODE'],
717 'VERSION' => $appDetailInfo['VER'],
718 'BY_SUBSCRIPTION' => $appDetailInfo['BY_SUBSCRIPTION'] === 'Y' ? 'Y' : 'N',
719 );
720
721 $installResult = \Bitrix\Rest\OAuthService::getEngine()
722 ->getClient()
723 ->installApplication($queryFields);
724
725 if($installResult['result'])
726 {
727 $appFields = array(
728 'CLIENT_ID' => $installResult['result']['client_id'],
729 'CODE' => $appDetailInfo['CODE'],
730 'ACTIVE' => \Bitrix\Rest\AppTable::ACTIVE,
731 'INSTALLED' => !empty($appDetailInfo['INSTALL_URL'])
734 'URL' => $appDetailInfo['URL'],
735 'URL_DEMO' => $appDetailInfo['DEMO_URL'],
736 'URL_INSTALL' => $appDetailInfo['INSTALL_URL'],
737 'VERSION' => $installResult['result']['version'],
738 'SCOPE' => implode(',', $installResult['result']['scope']),
739 'STATUS' => $installResult['result']['status'],
740 'SHARED_KEY' => $appDetailInfo['SHARED_KEY'],
741 'CLIENT_SECRET' => '',
742 'APP_NAME' => $appDetailInfo['NAME'],
743 'MOBILE' => $appDetailInfo['BXMOBILE'] == 'Y' ? \Bitrix\Rest\AppTable::ACTIVE : \Bitrix\Rest\AppTable::INACTIVE,
744 );
745
746 if(
747 $appFields['STATUS'] === \Bitrix\Rest\AppTable::STATUS_TRIAL
748 || $appFields['STATUS'] === \Bitrix\Rest\AppTable::STATUS_PAID
749 )
750 {
751 $appFields['DATE_FINISH'] = \Bitrix\Main\Type\DateTime::createFromTimestamp($installResult['result']['date_finish']);
752 }
753 else
754 {
755 $appFields['DATE_FINISH'] = '';
756 }
757
758 $existingApp = \Bitrix\Rest\AppTable::getByClientId($appFields['CLIENT_ID']);
759
760 if($existingApp)
761 {
762 $addResult = \Bitrix\Rest\AppTable::update($existingApp['ID'], $appFields);
763 \Bitrix\Rest\AppLangTable::deleteByApp($existingApp['ID']);
764 }
765 else
766 {
767 $addResult = \Bitrix\Rest\AppTable::add($appFields);
768 }
769
770 if($addResult->isSuccess())
771 {
772 $appId = $addResult->getId();
773 if(is_array($appDetailInfo['MENU_TITLE']))
774 {
775 foreach($appDetailInfo['MENU_TITLE'] as $lang => $langName)
776 {
777 \Bitrix\Rest\AppLangTable::add(array(
778 'APP_ID' => $appId,
779 'LANGUAGE_ID' => $lang,
780 'MENU_NAME' => $langName
781 ));
782 }
783 }
784
785 if($appDetailInfo["OPEN_API"] === "Y" && !empty($appFields["URL_INSTALL"]))
786 {
787 // checkCallback is already called inside checkFields
788 $result = \Bitrix\Rest\EventTable::add(array(
789 "APP_ID" => $appId,
790 "EVENT_NAME" => "ONAPPINSTALL",
791 "EVENT_HANDLER" => $appFields["URL_INSTALL"],
792 ));
793 if($result->isSuccess())
794 {
795 \Bitrix\Rest\Event\Sender::bind('rest', 'OnRestAppInstall');
796 }
797 }
798
800
801 $result = true;
802 }
803 }
804 }
805 }
806
807 return $result;
808 }
809
815 public static function UpdateApp($appId, $oldVersion)
816 {
817 $arApp = CBitrix24App::GetByID($appId);
818
820 'APP_ID' => $appId,
821 'VERSION' => $arApp['VERSION'],
822 'PREVIOUS_VERSION' => $oldVersion,
823 );
824
825 foreach (GetModuleEvents("rest", "OnRestAppUpdate", true) as $arEvent)
826 {
828 }
829
831
832 CUserOptions::DeleteOption("app_options", "params_".$arApp['APP_ID']."_".$arApp['VERSION']);
833 }
834
838 public static function getScopeList(array $description = null)
839 {
840 return \Bitrix\Rest\Engine\ScopeManager::getInstance()->listScope();
841 }
842
843 public static function getEventList(array $description = null)
844 {
845 if($description == null)
846 {
847 $provider = new \CRestProvider();
848 $description = $provider->getDescription();
849 }
850
851 $eventList = array();
852 foreach($description as $scope => $scopeMethods)
853 {
854 if(
855 array_key_exists(\CRestUtil::EVENTS, $scopeMethods)
856 && is_array($scopeMethods[\CRestUtil::EVENTS])
857 )
858 {
859 $eventList[$scope] = array_keys($scopeMethods[\CRestUtil::EVENTS]);
860 }
861 }
862
863 return $eventList;
864 }
865
866 public static function getApplicationToken(array $application)
867 {
868 if(!empty($application['APPLICATION_TOKEN']))
869 {
870 return $application['APPLICATION_TOKEN'];
871 }
872 else
873 {
874 $secret = array_key_exists("APP_SECRET_ID", $application) ? $application["APP_SECRET_ID"] : $application["CLIENT_SECRET"];
875 return md5(\CRestUtil::getMemberId()."|".$application["ID"]."|".$secret."|".$application["SHARED_KEY"]);
876 }
877 }
878
891 public static function getDownloadUrl($query, \CRestServer $server)
892 {
893 return static::getSpecialUrl(static::METHOD_DOWNLOAD, $query, $server);
894 }
895
896 public static function getLanguage()
897 {
899 $languageId = '';
901 'select' => array('LID', 'LANGUAGE_ID'),
902 'filter' => array('=DEF' => 'Y', '=ACTIVE' => 'Y'),
903 'cache' => ['ttl' => 86400],
904 ));
905 if($site = $siteIterator->fetch())
906 {
907 $languageId = (string)$site['LANGUAGE_ID'];
908 }
909
910 if($languageId == '')
911 {
912 if(\Bitrix\Main\Loader::includeModule('bitrix24'))
913 {
914 $languageId = \CBitrix24::getLicensePrefix();
915 }
916 else
917 {
918 $languageId = LANGUAGE_ID;
919 }
920 }
921
922 if($languageId == '')
923 {
924 $languageId = 'en';
925 }
926
927 return $languageId;
928 }
929
942 public static function getUploadUrl($query, \CRestServer $server)
943 {
944 return static::getSpecialUrl(static::METHOD_UPLOAD, $query, $server);
945 }
946
947 public static function getSpecialUrl($method, $query, \CRestServer $server)
948 {
949 if(is_array($query))
950 {
951 $query = http_build_query($query);
952 }
953
954 $query = base64_encode($query."&_=".RandString(32));
955
956 $scope = $server->getScope();
957 if($scope === static::GLOBAL_SCOPE)
958 {
959 $scope = '';
960 }
961
962 $signature = $server->getTokenCheckSignature(mb_strtolower($method), $query);
963
964 $token = $scope
965 .static::TOKEN_DELIMITER.$query
966 .static::TOKEN_DELIMITER.$signature;
967
968
969 $authData = $server->getAuthData();
970
971 if($authData['password_id'])
972 {
973 $auth = $server->getAuth();
974
975 return static::getWebhookEndpoint(
976 $auth['ap'],
977 $auth['aplogin'],
978 $method
979 )."?".http_build_query(array(
980 'token' => $token,
981 ));
982 }
983 else
984 {
985 $urlParam = array_merge(
986 $server->getAuth(),
987 array(
988 'token' => $token,
989 )
990 );
991
992 return static::getEndpoint().$method.".".$server->getTransport()."?".http_build_query($urlParam);
993 }
994 }
995
996 public static function getWebhookEndpoint($ap, $userId, $method = '')
997 {
998 return static::getEndpoint().urlencode($userId).'/'.urlencode($ap).'/'.($method === '' ? '' : urlencode($method).'/');
999 }
1000
1001 public static function getEndpoint()
1002 {
1003 return \CHTTP::URN2URI(\Bitrix\Main\Config\Option::get('rest', 'rest_server_path', '/rest').'/');
1004 }
1005
1006 public static function getAdministratorIdList()
1007 {
1008 $adminList = array();
1009
1010 $dbAdminList = \CGroup::GetGroupUserEx(1);
1011 while($admin = $dbAdminList->fetch())
1012 {
1013 $adminList[] = $admin["USER_ID"];
1014 }
1015
1016 return $adminList;
1017 }
1018
1019 public static function getApplicationPage($id, $type = 'ID', $appInfo = null)
1020 {
1021 if($appInfo === null)
1022 {
1024 }
1025
1026 if($type !== 'ID' && $type !== 'CODE' && $type !== 'CLIENT_ID')
1027 {
1028 $type = 'ID';
1029 }
1030
1031 if(
1032 empty($appInfo['MENU_NAME'])
1033 && empty($appInfo['MENU_NAME_DEFAULT'])
1034 && empty($appInfo['MENU_NAME_LICENSE'])
1035 || $appInfo['ACTIVE'] === \Bitrix\Rest\AppTable::INACTIVE
1036 || (isset($appInfo['TYPE']) && $appInfo['TYPE'] === \Bitrix\Rest\AppTable::TYPE_CONFIGURATION)
1037 )
1038 {
1039 $url = \Bitrix\Rest\Marketplace\Url::getApplicationDetailUrl(urlencode($appInfo['CODE']));
1040 }
1041 elseif($appInfo['CODE'] === static::BITRIX_1C_APP_CODE)
1042 {
1043 $url = SITE_DIR.'onec/';
1044 }
1045 else
1046 {
1048 }
1049 return $url;
1050 }
1051
1052 public static function isSlider()
1053 {
1054 return (isset($_REQUEST['IFRAME']) && $_REQUEST['IFRAME'] === 'Y' && $_REQUEST['IFRAME_TYPE'] == 'SIDE_SLIDER');
1055 }
1056
1057}
$path
Определения access_edit.php:21
$type
Определения options.php:106
$messageFields
Определения callback_ednaru.php:22
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
$arResult
Определения generate_coupon.php:16
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
static getString($length, $caseSensitive=false)
Определения random.php:76
static createFromTimestamp($timestamp)
Определения datetime.php:246
static decode($data)
Определения json.php:50
static deleteByApp($appId)
Определения applang.php:78
const STATUS_PAID
Определения app.php:86
static install($appId)
Определения app.php:497
const INSTALLED
Определения app.php:71
static getByClientId($clientId)
Определения app.php:967
const TYPE_CONFIGURATION
Определения app.php:78
const STATUS_TRIAL
Определения app.php:88
const ACTIVE
Определения app.php:69
const NOT_INSTALLED
Определения app.php:72
const INACTIVE
Определения app.php:70
static checkAccess(string $type, $manifestCode='')
Определения manifest.php:111
static bind($moduleId, $eventName)
Определения sender.php:73
static deleteByApp(mixed $appId)
Определения eventoffline.php:363
static deleteAppInstaller($appId)
Определения event.php:137
static deleteByApp($appId)
Определения event.php:124
static getInstall($code, $version=false, $checkHash=false, $installHash=false)
Определения client.php:425
static getApplicationUrl($id=null)
Определения url.php:476
static getApplicationDetailUrl($id=null, $from='')
Определения url.php:472
static getEngine()
Определения oauthservice.php:49
static register()
Определения oauthservice.php:59
static deleteByApp($appId)
Определения placement.php:211
static Clean($appId)
Определения restentity.php:1243
static URN2URI($urn, $server_name='')
Определения http.php:39
Определения rest.php:24
getScope()
Определения rest.php:387
getTokenCheckSignature($method, $queryString)
Определения rest.php:402
getAuthData()
Определения rest.php:324
getTransport()
Определения rest.php:314
getAuth()
Определения rest.php:319
Определения rest_util.php:11
static saveFile($fileContent, $fileName="")
Определения rest_util.php:612
static UpdateApp($appId, $oldVersion)
Определения rest_util.php:815
static getAuth($appId, $appSecret, $scope, $additionalParams, $user_id=0)
Определения rest_util.php:499
static getApplicationToken(array $application)
Определения rest_util.php:866
static getWebhookEndpoint($ap, $userId, $method='')
Определения rest_util.php:996
static CleanApp($appId, $bClean)
Определения rest_util.php:646
static canInstallApplication($appInfo=null, ?int $userId=null)
Определения rest_util.php:150
static makeAuth($res, $application_id=null)
Определения rest_util.php:552
static checkAppAccess($appId, $appInfo=null)
Определения rest_util.php:560
static getAdministratorIdList()
Определения rest_util.php:1006
static ConvertDateTime($dt)
Определения rest_util.php:279
static signLicenseRequest(array $request, $licenseKey)
Определения rest_util.php:255
static GetFile($fileId, $resizeParam=false)
Определения rest_util.php:365
const METHOD_UPLOAD
Определения rest_util.php:21
static appCanBeInstalledByUser(array $appInfo)
Определения rest_util.php:191
static getApplicationPage($id, $type='ID', $appInfo=null)
Определения rest_util.php:1019
const GLOBAL_SCOPE
Определения rest_util.php:12
static getDownloadUrl($query, \CRestServer $server)
Определения rest_util.php:891
const BATCH_MAX_LENGTH
Определения rest_util.php:18
static unConvertDate($iso8601)
Определения rest_util.php:289
const TOKEN_DELIMITER
Определения rest_util.php:23
static getSpecialUrl($method, $query, \CRestServer $server)
Определения rest_util.php:947
static unConvertDateTime($iso8601, $enableOffset=false)
Определения rest_util.php:319
static InstallApp($code)
Определения rest_util.php:687
static getInstallAccessList()
Определения rest_util.php:196
static getEventList(array $description=null)
Определения rest_util.php:843
static ParseBatchQuery($query, $arResult)
Определения rest_util.php:473
static getMemberId()
Определения rest_util.php:348
static processBatchElement($query, $arResult, $keysCache='')
Определения rest_util.php:396
static getEndpoint()
Определения rest_util.php:1001
const PLACEMENT_APP_URI
Определения rest_util.php:27
const HANDLER_SESSION_TTL
Определения rest_util.php:16
static getAuthForEvent($appId, $userId, array $additionalData=array())
Определения rest_util.php:489
const PLACEMENTS
Определения rest_util.php:14
static ConvertDate($dt)
Определения rest_util.php:273
static setInstallAccessList($accessList)
Определения rest_util.php:203
static getScopeList(array $description=null)
Определения rest_util.php:838
static getUploadUrl($query, \CRestServer $server)
Определения rest_util.php:942
static getStandardParams()
Определения rest_util.php:36
static notifyInstall($appInfo)
Определения rest_util.php:217
static processBatchStructure($queryParams, $arResult, $keysCache=null)
Определения rest_util.php:445
const METHOD_DOWNLOAD
Определения rest_util.php:20
static updateAppStatus(array $tokenInfo)
Определения rest_util.php:592
static checkAuth($query, $scope, &$res)
Определения rest_util.php:527
const EVENTS
Определения rest_util.php:13
static getRequestData()
Определения rest_util.php:54
static getLanguage()
Определения rest_util.php:896
static sendHeaders()
Определения rest_util.php:29
static isStatic($url)
Определения rest_util.php:360
static isAdmin(?int $userId=null)
Определения rest_util.php:118
static isSlider()
Определения rest_util.php:1052
const BITRIX_1C_APP_CODE
Определения rest_util.php:25
Определения user.php:6037
$arFields
Определения dblapprove.php:5
$arPath
Определения file_edit.php:72
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileContent
Определения file_property.php:47
$res
Определения filter_act.php:7
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$auth
Определения get_user.php:29
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$adminList
Определения iblock_catalog_list.php:44
const IM_NOTIFY_SYSTEM
Определения include.php:38
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$application
Определения bitrix.php:23
const BX_RESIZE_IMAGE_PROPORTIONAL_ALT
Определения constants.php:10
const SITE_DIR(!defined('LANG'))
Определения include.php:72
if(!defined('SITE_ID')) $lang
Определения include.php:91
const FORMAT_DATE
Определения include.php:63
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
CheckDirPath($path)
Определения tools.php:2707
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$files
Определения mysql_to_pgsql.php:30
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$fileName
Определения quickway.php:305
if(empty($signedUserToken)) $key
Определения quickway.php:257
else $userName
Определения order_form.php:75
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$siteIterator
Определения options.php:48
$method
Определения index.php:27
$postData
Определения index.php:29
$rights
Определения options.php:4
$url
Определения iframe.php:7
$dbRes
Определения yandex_detail.php:168
$site
Определения yandex_run.php:614