Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
helper.php
1<?php
2
3
5
6
10use DateTimeInterface;
11
12class Helper
13{
14 public const DEFAULT_HTTPS_PORT = 443;
15 public const GOOGLE_ACCOUNT_TYPE_CALDAV= 'caldav_google_oauth';
16 public const GOOGLE_ACCOUNT_TYPE_API = 'google_api_oauth';
17
18 public const CONNECTION_NAME = 'google';
19 public const HTTP_SCHEME_DEFAULT = 'https';
20 public const HTTP_SCHEME_SEPARATOR = '://';
21 public const GOOGLE_API_URL = 'www.googleapis.com';
22 public const GOOGLE_CALDAV_URL = 'apidata.googleusercontent.com';
23 public const GOOGLE_API_V3_URI = '/calendar/v3';
24 public const GOOGLE_API_V2_URI = '/calendar/v2/';
25 public const GOOGLE_SERVER_PATH_V3 = self::HTTP_SCHEME_DEFAULT . self::HTTP_SCHEME_SEPARATOR . self::GOOGLE_API_URL . self::GOOGLE_API_V3_URI;
26 public const GOOGLE_SERVER_PATH_V2 = self::HTTP_SCHEME_DEFAULT . self::HTTP_SCHEME_SEPARATOR . self::GOOGLE_CALDAV_URL . self::GOOGLE_API_V2_URI;
27 public const DATE_TIME_FORMAT = DateTimeInterface::ATOM;
28 public const DATE_TIME_FORMAT_WITH_MICROSECONDS = 'Y-m-d\TH:i:s\.vP';
29 public const DATE_TIME_FORMAT_RFC_3339 = 'Y-m-d\TH:i:s\Z';
30 public const DATE_TIME_FORMAT_WITH_UTC_TIMEZONE = 'Ymd\THis\Z';
31 public const EXCLUDED_DATE_TIME_FORMAT = self::DATE_TIME_FORMAT_WITH_UTC_TIMEZONE;
32 public const EXCLUDED_DATE_FORMAT = 'Ymd';
33 public const DATE_FORMAT = 'Y-m-d';
34 public const VERSION_DIFFERENCE = 1;
35 public const END_OF_TIME = "01.01.2038";
36
37 public const NEED_SCOPE = [
38 'https://www.googleapis.com/auth/calendar',
39 'https://www.googleapis.com/auth/calendar.readonly',
40 ];
41
46 public function isGoogleConnection($accountType): bool
47 {
48 return in_array($accountType, [self::GOOGLE_ACCOUNT_TYPE_CALDAV, self::GOOGLE_ACCOUNT_TYPE_API], true);
49 }
50
51 public function isDeletedResource($errorText): bool
52 {
53 return !empty($errorText) && preg_match("/^(\[410\] Resource has been deleted)/i", $errorText);
54 }
55
56 public function isNotFoundError(string $errorText = null): bool
57 {
58 return !empty($errorText) && preg_match("/^\[(404)\][a-z0-9 _]*/i", $errorText);
59 }
60
61 public function isNotValidSyncTokenError(string $errorText = null): bool
62 {
63 return !empty($errorText)
64 && (preg_match("/^(\[410\] The requested minimum modification time lies too far in the past.)/i", $errorText)
65 || preg_match("/^(\[410\] Sync token is no longer valid, a full sync is required.)/i", $errorText))
66 ;
67 }
68
69 public function isMissingRequiredAuthCredential(string $errorText = null): bool
70 {
71 return !empty($errorText)
72 && (preg_match("/^\[401\] Request is missing required authentication credential.[a-z0-9 _]*/i", $errorText)
73 || preg_match("/^\[401\] Request had invalid authentication credentials.[a-z0-9 _]*/i", $errorText))
74 ;
75 }
76
77
84 public function getApiKey(): ?string
85 {
86 if (
87 Loader::includeModule('socialservices')
88 && ($apiKey = Option::get('socialservices', 'google_api_key', null))
89 )
90 {
91 return $apiKey;
92 }
93
94 if (Loader::includeModule('fileman'))
95 {
96 $apiKey = AddressType::getApiKey();
97 if (!empty($apiKey))
98 {
99 return $apiKey;
100 }
101 }
102
103 return Option::get('fileman', 'google_map_api_key', null)
104 ?? Option::get('bitrix24', 'google_map_api_key', null)
105 ;
106 }
107}
isMissingRequiredAuthCredential(string $errorText=null)
Definition helper.php:69
isNotValidSyncTokenError(string $errorText=null)
Definition helper.php:61
isNotFoundError(string $errorText=null)
Definition helper.php:56