2namespace Bitrix\Rest\Marketplace;
4use Bitrix\Main\Application;
5use Bitrix\Main\Config\Option;
7use Bitrix\Main\EventManager;
9use Bitrix\Main\Localization\Loc;
10use Bitrix\Main\ModuleManager;
11use Bitrix\Main\SystemException;
12use Bitrix\Main\Type\Date;
13use Bitrix\Rest\AppTable;
14use Bitrix\Rest\Engine\Access;
15use Bitrix\Bitrix24\Feature;
17if(!defined(
'REST_MP_CATEGORIES_CACHE_TTL'))
19 define(
'REST_MP_CATEGORIES_CACHE_TTL', 86400);
25 private const SUBSCRIPTION_REGION = [
30 private const SUBSCRIPTION_DEFAULT_START_TIME = [
36 'bitrix24' =>
'/settings/order/make.php?limit=#NUM#&module=#CODE#',
37 'ru' =>
'https://marketplace.1c-bitrix.ru/tobasket.php?ID=#CODE#&limit=#NUM#&b24=y',
38 'en' =>
'https://store.bitrix24.com/tobasket.php?ID=#CODE#&limit=#NUM#&b24=y',
39 'de' =>
'https://store.bitrix24.de/tobasket.php?ID=#CODE#&limit=#NUM#&b24=y',
42 private static $appTop =
null;
43 private static $isPayApplicationAvailable;
47 $allowedActions =
array(
54 if(in_array(
$action, $allowedActions))
56 if(!is_array(self::$appTop))
59 foreach($allowedActions as
$method)
75 public static function getBuy($codeList)
80 "code" => implode(
",", $codeList)
91 if (!is_array($immuneAppList))
93 if ($immuneAppList !==
false) {
95 'message' =>
'Wrong answer from service',
96 'data' => print_r($immuneAppList,
true),
102 return $immuneAppList;
110 "code" => serialize($codeList)
119 if(!is_array($updateList) ||
count($updateList) <= 0)
126 $cnt =
count($updateList);
129 foreach($updateList as $update)
131 if(is_array($update[
'VERSIONS']) &&
count($update[
'VERSIONS']) > 0)
133 $optionValue[$update[
"CODE"]] = max(array_keys($update[
"VERSIONS"]));
140 Option::set(
"rest",
"mp_num_updates", $cnt);
146 $updates = Option::get(
"rest",
"mp_updates",
"");
147 $updates = $updates ==
"" ?
array() : unserialize($updates, [
'allowed_classes' =>
false]);
151 return array_key_exists(
$code, $updates) ? $updates[
$code] :
false;
161 return intval(Option::get(
"rest",
"mp_num_updates", 0));
172 $managedCache = Application::getInstance()->getManagedCache();
174 $cacheId =
'rest|marketplace|categories|full|'.LANGUAGE_ID;
176 $requestNeeded =
true;
179 $forceReload ===
false
180 && static::CATEGORIES_CACHE_TTL > 0
181 && $managedCache->read(static::CATEGORIES_CACHE_TTL, $cacheId)
184 $result = $managedCache->get($cacheId);
187 $requestNeeded =
false;
191 $requestNeeded =
false;
204 if (static::CATEGORIES_CACHE_TTL > 0)
206 $managedCache->set($cacheId,
$result);
221 $categories = static::getCategoriesFull($forceReload);
222 return (is_array($categories[
'ITEMS']) ? $categories[
'ITEMS'] : []);
233 $queryFields[
"page"] =
$page;
242 $queryFields[
'_market_'] =
'Y';
243 if (is_string(
$code))
245 $queryFields[
'category'] =
$code;
250 $queryFields[
'code'] =
$code;
261 $queryFields = Array(
267 $queryFields[
"page"] =
$page;
283 $queryFields = Array(
285 "sort" =>
"date_public"
291 $queryFields[
"page"] =
$page;
302 public static function getApp(
$code, $version =
false, $checkHash =
false, $installHash =
false)
304 $queryFields = Array(
308 $version = intval($version);
311 $queryFields[
"ver"] = $version;
314 if($checkHash !==
false)
316 $queryFields[
"check_hash"] = $checkHash;
317 $queryFields[
"install_hash"] = $installHash;
362 public static function getAppPublic(
$code, $version =
false, $checkHash =
false, $installHash =
false)
368 $version = intval($version);
371 $queryFields[
"ver"] = $version;
374 if($checkHash !==
false)
376 $queryFields[
"check_hash"] = $checkHash;
377 $queryFields[
"install_hash"] = $installHash;
396 $queryFields[
"page"] =
$page;
409 $queryFields = Array(
416 $queryFields[
"page"] =
$page;
425 public static function getInstall(
$code, $version =
false, $checkHash =
false, $installHash =
false)
427 $queryFields = Array(
430 "member_id" => \CRestUtil::getMemberId(),
433 $version = intval($version);
436 $queryFields[
"ver"] = $version;
439 if($checkHash !==
false)
441 $queryFields[
"check_hash"] = $checkHash;
442 $queryFields[
"install_hash"] = $installHash;
450 $linkTpl = static::$buyLinkList[
'en'];
454 $linkTpl = static::$buyLinkList[
'bitrix24'];
458 if(array_key_exists(LANGUAGE_ID, static::$buyLinkList))
460 $linkTpl = static::$buyLinkList[LANGUAGE_ID];
462 elseif(array_key_exists(Loc::getDefaultLang(LANGUAGE_ID), static::$buyLinkList))
464 $linkTpl = static::$buyLinkList[Loc::getDefaultLang(LANGUAGE_ID)];
469 array(
'#NUM#',
'#CODE#'),
470 array(intval($num), urlencode($appCode)),
478 $dbApps = AppTable::getList(
array(
483 'select' =>
array(
'CODE',
'VERSION')
485 while(
$app = $dbApps->fetch())
487 $appCodes[
$app[
"CODE"]] =
$app[
"VERSION"];
490 if(!empty($appCodes))
492 $updateList = static::getUpdates($appCodes);
494 if (is_array($updateList) && isset($updateList[
'ITEMS']))
504 return __CLASS__.
"::getNumUpdates();";
512 if(mb_substr($placement, 0, 4) ===
'CRM_' || $placement === \
Bitrix\
Rest\
Api\UserFieldType::PLACEMENT_UF_TYPE)
514 if($placement !==
'CRM_ROBOT_TRIGGERS')
516 $tag[] =
'placement';
520 $tag[] =
'automation';
525 elseif(mb_substr($placement, 0, 5) ===
'CALL_')
527 $tag[] =
'placement';
528 $tag[] =
'telephony';
544 $status = Option::get(
'bitrix24',
'~mp24_paid',
'N');
548 $status = Option::get(
'main',
'~mp24_paid',
'N');
549 if (
$status ===
'T' && Option::get(
'main',
'~mp24_used_trial',
'N') !==
'Y')
551 Option::set(
'main',
'~mp24_used_trial',
'Y');
560 && Loader::includeModule(
'bitrix24')
561 && \CBitrix24::getLicenseFamily() ===
'project'
562 && Option::get(
'rest',
'can_use_subscription_project',
'N') ===
'N'
569 $date = static::getSubscriptionFinalDate();
572 $now = new \Bitrix\Main\Type\Date();
587 return Option::get(
'bitrix24',
'~mp24_paid',
'N') ===
'T'
588 && Option::get(
'bitrix24',
'~mp24_used_trial',
'N') ===
'Y';
600 $timestamp = (int)Option::get(
'bitrix24',
'~mp24_paid_date');
604 $timestamp = (int)Option::get(
'main',
'~mp24_paid_date');
609 $result = Date::createFromTimestamp($timestamp);
624 $status = Option::get(
'bitrix24',
'~mp24_paid',
'N');
628 $status = Option::get(
'main',
'~mp24_paid',
'N');
634 private static function checkSubscriptionAccessStart(
$region): bool
637 if (!empty(static::SUBSCRIPTION_DEFAULT_START_TIME[
$region]))
641 'subscription_region_start_time_' .
$region,
642 static::SUBSCRIPTION_DEFAULT_START_TIME[
$region]
644 $canStart =
$time < time();
647 return $canStart && in_array(
$region, static::SUBSCRIPTION_REGION,
true);
654 $result = static::checkSubscriptionAccessStart(\CBitrix24::getLicensePrefix());
658 $result = Option::get(Access::MODULE_ID, Access::OPTION_SUBSCRIPTION_AVAILABLE,
'N') ===
'Y';
668 static::isSubscriptionAccess()
669 && Access::isFeatureEnabled()
672 && Loader::includeModule(
'bitrix24')
673 && !Feature::isFeatureEnabled(
'rest_can_buy_subscription')
687 $used = Option::get(
'bitrix24',
'~mp24_used_trial',
'N') ===
'Y';
691 $used = Option::get(
'main',
'~mp24_used_trial',
'N') ===
'Y';
694 return !$used && static::isSubscriptionAccess();
703 if (is_null(static::$isPayApplicationAvailable))
705 static::$isPayApplicationAvailable =
true;
706 $time = (int) Option::get(
'rest',
'time_pay_application_off', 1621029600);
709 if (Loader::includeModule(
'bitrix24'))
711 $region = \CBitrix24::getLicensePrefix();
715 $region = Option::get(
'main',
'~PARAM_CLIENT_LANG',
'');
720 static::$isPayApplicationAvailable =
false;
725 return static::$isPayApplicationAvailable;
733 if (static::isSubscriptionAvailable())
737 'onSubscriptionRenew',
740 EventManager::getInstance()->send(
$event);
static isModuleInstalled($moduleName)
static searchApp($q, $page=false)
static getTop($action, $fields=array())
static getAvailableUpdate($code=false)
static setAvailableUpdate($updateList=array())
static getBuyLink($num, $appCode)
static getCategories($forceReload=false)
static getUpdates($codeList)
static canBuySubscription()
static isSubscriptionDemoAvailable()
static getApp($code, $version=false, $checkHash=false, $installHash=false)
static getCategory($code, $page=false, $pageSize=false, bool $isMarket=false)
static isStartDemoSubscription()
static getByTag($tag, $page=false, $pageSize=false)
static getAppPublic($code, $version=false, $checkHash=false, $installHash=false)
static filterApp($fields, $page=false)
static getTagByPlacement($placement)
static isSubscriptionDemo()
static isSubscriptionAvailable()
static getAvailableUpdateNum()
static getSubscriptionFinalDate()
static isPayApplicationAvailable()
static onChangeSubscriptionDate(Event $event)
static getSiteList(array $query=[])
static getInstall($code, $version=false, $checkHash=false, $installHash=false)
const CATEGORIES_CACHE_TTL
static isSubscriptionAccess()
static getLastByTag($tag, $page=false, $pageSize=false)
static getCategoriesFull($forceReload=false)
const DICTIONARY_IMMUNE_LIST
const METHOD_GET_SITE_LIST
const METHOD_GET_SALE_OUT
const METHOD_GET_CATEGORY
const METHOD_GET_APP_PUBLIC
const METHOD_GET_SITE_ITEM
const METHOD_GET_CATEGORIES
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</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."%"