Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
service.php
1<?php
10
11use Bitrix\Bitrix24\Feature;
20use Bitrix\Sender\Integration\Seo;
24
30{
36 public static function isPortal()
37 {
39 }
40
46 public static function isAvailable()
47 {
48 return
49 self::isRcAvailable()
50 ||
51 self::isMailingsAvailable()
52 ||
53 self::isAdAvailable()
54 ||
55 self::isEmailAvailable()
56 ||
57 self::isTolokaAvailable()
58 ||
59 self::isFbAdAvailable()
60 ;
61 }
62
68 public static function isAdAvailable()
69 {
70 return !self::isCloud() || Feature::isFeatureEnabled('sender_ad');
71 }
72
78 public static function isFbAdAvailable()
79 {
80 return !self::isCloud() || Feature::isFeatureEnabled('sender_fb_ads');
81 }
82
88 public static function isTolokaAvailable()
89 {
90 return !self::isCloud() || Feature::isFeatureEnabled('sender_toloka');
91 }
92
98 public static function isRcAvailable()
99 {
100 return !self::isCloud() || Feature::isFeatureEnabled('sender_rc');
101 }
102
108 public static function isPermissionEnabled()
109 {
110 return !self::isCloud() || Feature::isFeatureEnabled('sender_security');
111 }
112
118 public static function isCampaignsAvailable()
119 {
120 return !self::isCloud() && !self::isPortal();
121 }
122
129 public static function isRegionRussian(bool $onlyRu = false): bool
130 {
131 $regions = $onlyRu ? ['ru'] : ['ru', 'kz', 'by'];
132
133 $region = \Bitrix\Main\Application::getInstance()->getLicense()->getRegion() ?: 'ru';
134 return in_array($region, $regions);
135 }
136
143 public static function isCloudRegionRussian(bool $onlyRu = false): bool
144 {
145 $regions = $onlyRu ? ['ru'] : ['ru', 'kz', 'by'];
146 return self::isCloud() && in_array(\CBitrix24::getPortalZone(), $regions);
147 }
148
154 public static function isCloudRegionMayTrackMails()
155 {
156 return self::isCloud() && in_array(
157 \CBitrix24::getPortalZone(), [
158 'de',
159 'eu',
160 'it',
161 'pl',
162 'fr',
163 ]
164 );
165 }
166
173 public static function isAdVisibleInRegion($code)
174 {
175 $codes = [
176 Seo\Ads\MessageBase::CODE_ADS_VK,
177 Seo\Ads\MessageBase::CODE_ADS_YA,
178 Seo\Ads\MessageBase::CODE_ADS_LOOKALIKE_VK,
179 Seo\Ads\MessageBase::CODE_ADS_LOOKALIKE_YANDEX
180 ];
181
182 if (in_array($code, $codes))
183 {
184 if (self::isCloud())
185 {
186 return self::isCloudRegionRussian();
187 }
188 elseif (Loader::includeModule('intranet'))
189 {
190 return in_array(\CIntranetUtils::getPortalZone(), ['ru', 'kz', 'by']);
191 }
192
193 return true;
194 }
195
196 if (in_array(
197 $code,
198 [
199 Seo\Ads\MessageBase::CODE_ADS_FB,
200 Seo\Ads\MessageBase::CODE_ADS_LOOKALIKE_FB,
201 Message\iMarketing::CODE_FACEBOOK,
202 Message\iMarketing::CODE_INSTAGRAM,
203 ]
204 ))
205 {
206 return !self::isRegionRussian(true);
207 }
208
209 return true;
210 }
211
217 public static function isMasterYandexVisibleInRegion(): bool
218 {
219 $isLanguageAcceptable = (LANGUAGE_ID ?? 'ru') === 'ru';
220
221 if (!self::isCloud())
222 {
223 return false;
224 }
225 return self::isCloudRegionRussian(true) && $isLanguageAcceptable;
226 }
227
234 public static function isTolokaVisibleInRegion(): bool
235 {
236 $isLanguageAcceptable = (LANGUAGE_ID ?? 'ru') === 'ru';
237
238 if (self::isCloud())
239 {
240 return self::isCloudRegionRussian() && $isLanguageAcceptable ;
241 }
242 elseif (Loader::includeModule('intranet'))
243 {
244 return in_array(\CIntranetUtils::getPortalZone(), ['ru', 'kz', 'by']) && $isLanguageAcceptable;
245 }
246
247 return $isLanguageAcceptable;
248 }
249
255 public static function isMailingsAvailable()
256 {
257 return !self::isCloud() || Feature::isFeatureEnabled('sender_mailing');
258 }
259
265 public static function isEmailAvailable()
266 {
267 $dateCreate = Option::get("main", "~controller_date_create", "");
268
269 return !self::isCloud()
270 ||
271 Feature::isFeatureEnabled('sender_email')
272 ||
273 (
274 empty($dateCreate)
275 ||
276 $dateCreate <= mktime(
277 0, 0, 0,
278 1, 9, 2019
279 )
280 );
281 }
282
288 public static function getAvailableMailingCodes()
289 {
290 if (self::isMailingsAvailable())
291 {
292 return Message\Factory::getMailingMessageCodes();
293 }
294
295 if (self::isEmailAvailable())
296 {
297 return [Message\iBase::CODE_MAIL];
298 }
299
300 return [];
301 }
302
308 public static function isCloud()
309 {
310 return Loader::includeModule('bitrix24');
311 }
312
321 public static function getTrackingUri(int $type, ?string $siteId = null): ?string
322 {
323 switch ($type)
324 {
325 case Tracker::TYPE_READ:
326 $code = 'read';
327 break;
328
329 case Tracker::TYPE_CLICK:
330 $code = 'click';
331 break;
332
333 case Tracker::TYPE_UNSUB:
334 default:
335 $code = 'unsubscribe';
336 break;
337 }
338
339 $uri = "/pub/mail/$code.php";
340 if ($siteId)
341 {
342 if (!File::isFileExists(SiteTable::getDocumentRoot($siteId) . DIRECTORY_SEPARATOR . $uri))
343 {
344 return null;
345 }
346 }
347
348 // exclude com.br & com.de domains
349 if (
350 self::isCloud()
351 && defined('BX24_HOST_NAME')
352 && !in_array(mb_substr(BX24_HOST_NAME, -7), ['.com.br', '.com.de'])
353 )
354 {
355 $domain = BX24_HOST_NAME;
356
357 if (!\CBitrix24::isCustomDomain())
358 {
359 $domain = preg_replace('/^([-\.\w]+)\.bitrix24\.([-\.\w]+)/', '$2.$1', $domain);
360 $domain = "mailinternetsub.com/" . $domain;
361 }
362
363 $uri = "https://$domain$uri";
364 }
365
366 return $uri;
367 }
368
374 public static function initLicensePopup()
375 {
376 if (!self::isCloud())
377 {
378 return;
379 }
380
381 \CBitrix24::initLicenseInfoPopupJS();
382 \CJSCore::init('sender_b24_license');
383 }
384
390 public static function isLicenceTop()
391 {
392 if (!self::isCloud())
393 {
394 return true;
395 }
396
397 return \CBitrix24::getLicenseType() === 'company';
398 }
399
405 public static function lockServices()
406 {
407 if (!self::isCloud())
408 {
409 return;
410 }
411
412 $letters = Model\LetterTable::getList(array(
413 'select' => array('ID'),
414 'filter' => array(
415 '=STATUS' => Semantics::getWorkStates(),
416 '!MESSAGE_CODE' => Message\iBase::CODE_MAIL
417 )
418 ));
419
420 $letter = new Entity\Letter();
421 foreach ($letters as $letterData)
422 {
423 $letter->load($letterData['ID']);
424 if (!$letter->getId())
425 {
426 continue;
427 }
428
429 $state = $letter->getState();
430 if ($state->canReady())
431 {
432 $state->ready();
433 }
434 else if ($state->canStop())
435 {
436 $state->stop();
437 }
438 }
439 }
440
441 public static function isMasterYandexAvailable(): bool
442 {
443 return static::isCloud();
444 }
445}
static includeModule($moduleName)
Definition loader.php:69
static isModuleInstalled($moduleName)
static getDocumentRoot($siteId=null)
Definition site.php:37
static isRegionRussian(bool $onlyRu=false)
Definition service.php:129
static getTrackingUri(int $type, ?string $siteId=null)
Definition service.php:321
static isCloudRegionRussian(bool $onlyRu=false)
Definition service.php:143