1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
service.php
См. документацию.
1<?php
8
9namespace Bitrix\Sender\Integration\Bitrix24;
10
11use Bitrix\Bitrix24\Feature;
12use Bitrix\Main\Config\Option;
13use Bitrix\Main\IO\File;
14use Bitrix\Main\Loader;
15use Bitrix\Main\Context;
16use Bitrix\Main\ModuleManager;
17use Bitrix\Main\SiteTable;
18use Bitrix\Sender\Dispatch\Semantics;
19use Bitrix\Sender\Entity;
20use Bitrix\Sender\Integration\Seo;
21use Bitrix\Sender\Internals\Model;
22use Bitrix\Sender\Message;
23use Bitrix\Sender\Message\Tracker;
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 = [
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,
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 {
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 {
326 $code = 'read';
327 break;
328
330 $code = 'click';
331 break;
332
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 return static::replaceTrackingDomainIfNeed($uri);
349 }
350
351 public static function replaceTrackingDomainIfNeed(string $uri): string
352 {
353 // exclude com.br & com.de domains
354 if (
355 self::isCloud()
356 && defined('BX24_HOST_NAME')
357 && !in_array(mb_substr(BX24_HOST_NAME, -7), ['.com.br', '.com.de'])
358 )
359 {
360 $domain = BX24_HOST_NAME;
361
362 if (!\CBitrix24::isCustomDomain())
363 {
364 $queryDomain = preg_replace('/^([-\.\w]+)\.bitrix24\.([-\.\w]+)/', '$2.$1', $domain);
365 $subdomain = rtrim(mb_substr(str_replace('.','-', $queryDomain), 0, 63), '-');
366 $domain = "$subdomain.mailinetservice.com/$queryDomain";
367 }
368
369 $uri = "https://$domain$uri";
370 }
371
372 return $uri;
373 }
374
380 public static function initLicensePopup()
381 {
382 if (!self::isCloud())
383 {
384 return;
385 }
386
387 \CBitrix24::initLicenseInfoPopupJS();
388 \CJSCore::init('sender_b24_license');
389 }
390
396 public static function isLicenceTop()
397 {
398 if (!self::isCloud())
399 {
400 return true;
401 }
402
403 return \CBitrix24::getLicenseType() === 'company';
404 }
405
411 public static function lockServices()
412 {
413 if (!self::isCloud())
414 {
415 return;
416 }
417
418 $letters = Model\LetterTable::getList(array(
419 'select' => array('ID'),
420 'filter' => array(
421 '=STATUS' => Semantics::getWorkStates(),
422 '!MESSAGE_CODE' => Message\iBase::CODE_MAIL
423 )
424 ));
425
426 $letter = new Entity\Letter();
427 foreach ($letters as $letterData)
428 {
429 $letter->load($letterData['ID']);
430 if (!$letter->getId())
431 {
432 continue;
433 }
434
435 $state = $letter->getState();
436 if ($state->canReady())
437 {
438 $state->ready();
439 }
440 else if ($state->canStop())
441 {
442 $state->stop();
443 }
444 }
445 }
446
447 public static function isMasterYandexAvailable(): bool
448 {
449 return static::isCloud();
450 }
451}
$type
Определения options.php:106
static getInstance()
Определения application.php:98
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getDocumentRoot($siteId=null)
Определения site.php:36
static isRegionRussian(bool $onlyRu=false)
Определения service.php:129
static isTolokaVisibleInRegion()
Определения service.php:234
static replaceTrackingDomainIfNeed(string $uri)
Определения service.php:351
static isCampaignsAvailable()
Определения service.php:118
static getTrackingUri(int $type, ?string $siteId=null)
Определения service.php:321
static isCloudRegionRussian(bool $onlyRu=false)
Определения service.php:143
static getAvailableMailingCodes()
Определения service.php:288
static isMasterYandexAvailable()
Определения service.php:447
static isMasterYandexVisibleInRegion()
Определения service.php:217
static isCloudRegionMayTrackMails()
Определения service.php:154
static isAdVisibleInRegion($code)
Определения service.php:173
const TYPE_READ
Определения tracker.php:18
const TYPE_UNSUB
Определения tracker.php:20
const TYPE_CLICK
Определения tracker.php:19
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$region
Определения .description.php:13
const CODE_MAIL
Определения ibase.php:17
const CODE_FACEBOOK
Определения imarketing.php:17
const CODE_INSTAGRAM
Определения imarketing.php:18
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$siteId
Определения ajax.php:8
Определения adapter.php:9
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393