Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bitrix24manager.php
1<?php
3
9use \Bitrix\Main\Config\Option;
10
18{
19 const ICAL_EVENT_LIMIT_OPTION = "event_with_email_guest_amount";
20 const EVENT_AMOUNT = "event_with_planner_amount";
21
22 //region Members
24 private static ?bool $hasPurchasedLicense = null;
26 private static ?bool $hasDemoLicense = null;
28 private static ?bool $hasNfrLicense = null;
30 private static ?bool $hasPurchasedUsers = null;
32 private static ?bool $hasPurchasedDiskSpace = null;
34 private static ?bool $isPaidAccount = null;
36 private static ?bool $enableRestBizProc = null;
37 //endregion
38
39 //region Methods
44 public static function isEnabled()
45 {
46 return ModuleManager::isModuleInstalled('bitrix24');
47 }
48
54 public static function isPaidAccount()
55 {
56 if (self::$isPaidAccount !== null)
57 {
58 return self::$isPaidAccount;
59 }
60
61 self::$isPaidAccount = self::hasPurchasedLicense()
64
65 if (!self::$isPaidAccount)
66 {
67 //Phone number check: voximplant::account_payed
68 //SIP connector check: main::~PARAM_PHONE_SIP
69 self::$isPaidAccount = \COption::GetOptionString('voximplant', 'account_payed', 'N') === 'Y'
70 || \COption::GetOptionString('main', '~PARAM_PHONE_SIP', 'N') === 'Y';
71 }
72
73 return self::$isPaidAccount;
74 }
80 public static function hasPurchasedLicense()
81 {
82 if (self::$hasPurchasedLicense !== null)
83 {
84 return self::$hasPurchasedLicense;
85 }
86
87 if (
89 && Loader::includeModule('bitrix24'))
90 && method_exists('CBitrix24', 'IsLicensePaid')
91 )
92 {
93 return (self::$hasPurchasedLicense = false);
94 }
95
96 return (self::$hasPurchasedLicense = \CBitrix24::IsLicensePaid());
97 }
103 public static function hasDemoLicense()
104 {
105 if(self::$hasDemoLicense !== null)
106 {
107 return self::$hasDemoLicense;
108 }
109
110 if (
112 && Loader::includeModule('bitrix24'))
113 && method_exists('CBitrix24', 'IsDemoLicense')
114 )
115 {
116 return (self::$hasDemoLicense = false);
117 }
118
119 return (self::$hasDemoLicense = \CBitrix24::IsDemoLicense());
120 }
126 public static function hasNfrLicense()
127 {
128 if (self::$hasNfrLicense !== null)
129 {
130 return self::$hasNfrLicense;
131 }
132
133 if (
135 && Loader::includeModule('bitrix24'))
136 && method_exists('CBitrix24', 'IsNfrLicense')
137 )
138 {
139 return (self::$hasNfrLicense = false);
140 }
141
142 return (self::$hasNfrLicense = \CBitrix24::IsNfrLicense());
143 }
149 public static function hasPurchasedUsers()
150 {
151 if(self::$hasPurchasedUsers !== null)
152 {
153 return self::$hasPurchasedUsers;
154 }
155
156 if(
158 && Loader::includeModule('bitrix24'))
159 && method_exists('CBitrix24', 'IsExtraUsers')
160 )
161 {
162 return (self::$hasPurchasedUsers = false);
163 }
164
165 return (self::$hasPurchasedUsers = \CBitrix24::IsExtraUsers());
166 }
172 public static function hasPurchasedDiskSpace()
173 {
174 if(self::$hasPurchasedDiskSpace !== null)
175 {
176 return self::$hasPurchasedDiskSpace;
177 }
178
179 if(
181 && Loader::includeModule('bitrix24'))
182 && method_exists('CBitrix24', 'IsExtraDiskSpace')
183 )
184 {
185 return (self::$hasPurchasedDiskSpace = false);
186 }
187
188 return (self::$hasPurchasedDiskSpace = \CBitrix24::IsExtraDiskSpace());
189 }
190
196 public static function isRestBizProcEnabled()
197 {
198 return self::$enableRestBizProc ?? (self::$enableRestBizProc = (self::hasPurchasedLicense() || self::hasNfrLicense() || self::hasDemoLicense()));
199 }
200
206 public static function prepareStubInfo(array $params)
207 {
208 if (
210 && Loader::includeModule('bitrix24')
211 && method_exists('CBitrix24', 'prepareStubInfo')
212 )
213 {
214 $title = $params['TITLE'] ?? '';
215 $content = $params['CONTENT'] ?? '';
216
217 $replacements = isset($params['REPLACEMENTS']) && is_array($params['REPLACEMENTS'])
218 ? $params['REPLACEMENTS'] : array();
219
220 if (!empty($replacements))
221 {
222 $search = array_keys($replacements);
223 $replace = array_values($replacements);
224
225 $title = str_replace($search, $replace, $title);
226 $content = str_replace($search, $replace, $content);
227 }
228
229 $licenseAllButtonClass = ($params['GLOBAL_SEARCH']? 'ui-btn ui-btn-xs ui-btn-light-border' : 'success');
230 $licenseDemoButtonClass = ($params['GLOBAL_SEARCH']? 'ui-btn ui-btn-xs ui-btn-light' : '');
231
232 $options = [];
233 if (isset($params['ANALYTICS_LABEL']) && $params['ANALYTICS_LABEL'] != '')
234 {
235 $options['ANALYTICS_LABEL'] = $params['ANALYTICS_LABEL'];
236 }
237
238 return \CBitrix24::prepareStubInfo(
239 $title,
240 $content,
241 array(
242 array('ID' => \CBitrix24::BUTTON_LICENSE_ALL, 'CLASS_NAME' => $licenseAllButtonClass),
243 array('ID' => \CBitrix24::BUTTON_LICENSE_DEMO, 'CLASS_NAME' => $licenseDemoButtonClass),
244 ),
245 $options
246 );
247 }
248
249 return null;
250 }
251
258 public static function prepareLicenseInfoPopupScript(array $params)
259 {
260 if (
262 && Loader::includeModule('bitrix24')
263 && method_exists('CBitrix24', 'initLicenseInfoPopupJS')
264 )
265 {
266 \CBitrix24::initLicenseInfoPopupJS();
267
268 $popupID = isset($params['ID']) ? \CUtil::JSEscape($params['ID']) : '';
269 $title = isset($params['TITLE']) ? \CUtil::JSEscape($params['TITLE']) : '';
270 $content = '';
271 if(isset($params['CONTENT']))
272 {
273 $content = \CUtil::JSEscape(
274 str_replace(
275 '#TF_PRICE#',
276 \CBitrix24::getLicensePrice('tf'),
277 $params['CONTENT']
278 )
279 );
280 }
281
282 return "if(typeof(B24.licenseInfoPopup) !== 'undefined'){ B24.licenseInfoPopup.show('{$popupID}', '{$title}', '{$content}'); }";
283 }
284
285 return '';
286 }
293 public static function prepareLicenseInfoHelperScript(array $params)
294 {
295 $script = '';
296
297 if (
298 (is_string($params['ID']) && $params['ID'] !== '')
300 && Loader::includeModule('bitrix24')
302 && Loader::includeModule('ui')
303 )
304 {
305 $script = 'if (top.hasOwnProperty("BX") && top.BX !== null && typeof(top.BX) === "function"'.
306 ' && top.BX.hasOwnProperty("UI") && top.BX.UI !== null && typeof(top.BX.UI) === "object"'.
307 ' && top.BX.UI.hasOwnProperty("InfoHelper") && top.BX.UI.InfoHelper !== null'.
308 ' && typeof(top.BX.UI.InfoHelper) === "object" && top.BX.UI.InfoHelper.hasOwnProperty("show")'.
309 ' && typeof(top.BX.UI.InfoHelper.show) === "function"){top.BX.UI.InfoHelper.show("'.
310 \CUtil::JSEscape($params['ID']).'");}';
311 }
312
313 return $script;
314 }
315
321 public static function getLicenseListPageUrl()
322 {
323 if (
325 && Loader::includeModule('bitrix24')
326 )
327 {
328 return \CBitrix24::PATH_LICENSE_ALL;
329 }
330
331 return '';
332 }
338 public static function getDemoLicensePageUrl()
339 {
340 if (
342 && Loader::includeModule('bitrix24')
343 )
344 {
345 return \CBitrix24::PATH_LICENSE_DEMO;
346 }
347
348 return '';
349 }
350
357 public static function isFeatureEnabled($releaseName)
358 {
359 if (!(ModuleManager::isModuleInstalled('bitrix24') && Loader::includeModule('bitrix24')))
360 {
361 return true;
362 }
363
364 return \Bitrix\Bitrix24\Feature::isFeatureEnabled($releaseName);
365 }
366
373 public static function getVariable($name)
374 {
375 if (!(ModuleManager::isModuleInstalled('bitrix24') && Loader::includeModule('bitrix24')))
376 {
377 return null;
378 }
379
380 return \Bitrix\Bitrix24\Feature::getVariable($name);
381 }
382
387 public static function isPlannerFeatureEnabled()
388 {
389 $eventsLimit = self::getEventWithPlannerLimit();
390
391 return $eventsLimit === -1 || self::getEventsAmount() <= $eventsLimit;
392 }
393
399 public static function getEventWithPlannerLimit()
400 {
401 $limit = self::getVariable('calendar_events_with_planner');
402 if (is_null($limit))
403 {
404 $limit = -1;
405 }
406 return $limit;
407 }
408
413 public static function getEventsAmount()
414 {
415 return Option::get('calendar', self::EVENT_AMOUNT, 0);
416 }
417
424 public static function setEventsAmount($value = 0)
425 {
426 if (ModuleManager::isModuleInstalled('bitrix24'))
427 {
428 Option::set('calendar', self::EVENT_AMOUNT, $value);
429 }
430 }
431
437 public static function increaseEventsAmount()
438 {
439 self::setEventsAmount(self::getEventsAmount() + 1);
440 }
441
447 public static function getEventWithEmailGuestLimit()
448 {
449 $limit = self::getVariable('calendar_events_with_email_guests');
450 if (is_null($limit))
451 {
452 $limit = (
454 && Loader::includeModule('bitrix24')
455 && !\CBitrix24::IsLicensePaid()
456 && !\CBitrix24::IsNfrLicense()
457 && !\CBitrix24::IsDemoLicense()
458 )
459 ? 10
460 : -1;
461 }
462
463 return $limit;
464 }
465
466 public static function getCountEventWithEmailGuestAmount()
467 {
468 return \COption::GetOptionInt('calendar', self::ICAL_EVENT_LIMIT_OPTION, 0);
469 }
470
471 public static function setCountEventWithEmailGuestAmount($value = 0)
472 {
473 return \COption::SetOptionInt('calendar', self::ICAL_EVENT_LIMIT_OPTION, $value);
474 }
475
476 public static function increaseEventWithEmailGuestAmount()
477 {
478 return \COption::SetOptionInt(
479 'calendar',
480 self::ICAL_EVENT_LIMIT_OPTION,
481 self::getCountEventWithEmailGuestAmount() + 1
482 );
483 }
484
485 public static function isEventWithEmailGuestAllowed()
486 {
488 return $limit === -1 || self::getCountEventWithEmailGuestAmount() < $limit;
489 }
490}
491?>
static isModuleInstalled($moduleName)