4use \Bitrix\Landing\Manager;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Rest\Marketplace\Client;
7use \Bitrix\Rest\PlacementTable;
8use \Bitrix\Landing\Placement;
10use \Bitrix\Landing\Repo as RepoCore;
11use \Bitrix\Landing\PublicActionResult;
12use \Bitrix\Landing\Node\StyleImg;
24 public static function checkContent($content, $splitter =
'#SANITIZE#')
32 $result->setResult(array(
46 public static function register(
string $code, array $fields, array $manifest = []):
PublicActionResult
49 $error = new \Bitrix\Landing\Error;
52 $notAllowed = array(
'callbacks');
53 foreach ($notAllowed as $key)
55 if (isset($manifest[$key]))
57 unset($manifest[$key]);
61 if (!is_array($fields))
67 $fields[
'XML_ID'] = trim($code);
70 if (is_array($manifest[
'nodes'] ??
null))
72 foreach ($manifest[
'nodes'] as $selector => $manifestItem)
76 if (isset($manifest[
'style'][$selector]))
78 $styleItem = $manifest[
'style'][$selector];
80 if (isset($manifest[
'style'][
'nodes'][$selector]))
82 $styleItem = $manifest[
'style'][
'nodes'][$selector];
85 if ($styleItem[
'type'] ??
null)
90 'MANIFEST_INTERSECT_IMG',
91 Loc::getMessage(
'LANDING_APP_MANIFEST_INTERSECT_IMG', [
'#selector#' => $selector])
93 $result->setError($error);
100 if (isset($fields[
'CONTENT']))
113 $result->setError($error);
118 isset($manifest[
'cards']) &&
119 is_array($manifest[
'cards'])
122 foreach ($manifest[
'cards'] as $cardCode => &$card)
125 isset($card[
'presets']) &&
126 is_array($card[
'presets'])
129 foreach ($card[
'presets'] as $presetCode => &$preset)
131 foreach ([
'html',
'name',
'values'] as $code)
133 if (isset($preset[$code]))
142 'PRESET_CONTENT_IS_BAD',
144 'LANDING_APP_PRESET_CONTENT_IS_BAD',
146 '#preset#' => $presetCode,
147 '#card#' => $cardCode
150 $result->setError($error);
163 $fields[
'MANIFEST'] = serialize($manifest);
168 $fields[
'APP_CODE'] = $app[
'CODE'];
172 if ($fields[
'XML_ID'])
174 $check = RepoCore::getList(array(
179 isset($fields[
'APP_CODE'])
181 '=XML_ID' => $fields[
'XML_ID'],
182 '=APP_CODE' => $fields[
'APP_CODE']
185 '=XML_ID' => $fields[
'XML_ID']
199 if ($res->isSuccess())
202 isset($fields[
'RESET']) &&
203 $fields[
'RESET'] ==
'Y'
206 \Bitrix\Landing\Update\Block::register(
207 'repo_' . $res->getId()
210 $result->setResult($res->getId());
214 $error->addFromResult($res);
215 $result->setError($error);
229 $error = new \Bitrix\Landing\Error;
231 $result->setResult(
false);
233 if (!is_string($code))
242 $app = \Bitrix\Landing\PublicAction::restApplication();
244 $row = RepoCore::getList(array(
252 '=APP_CODE' => $app[
'CODE']
261 $codeToDelete = array();
262 $res = RepoCore::getList(array(
270 '=APP_CODE' => $app[
'CODE']
276 while ($rowRepo = $res->fetch())
278 $codeToDelete[] =
'repo_' . $rowRepo[
'ID'];
280 if (!empty($codeToDelete))
282 BlockCore::deleteByCode($codeToDelete);
286 if ($res->isSuccess())
288 $result->setResult(
true);
292 $error->addFromResult($res);
297 $result->setError($error);
310 $error = new \Bitrix\Landing\Error;
313 if (!is_string($code))
321 'CODE' => $appLocal[
'CODE'],
322 'NAME' => $appLocal[
'APP_NAME'],
323 'DATE_FINISH' => (
string)$appLocal[
'DATE_FINISH'],
324 'PAYMENT_ALLOW' => $appLocal[
'PAYMENT_ALLOW'],
329 if (\
Bitrix\Main\Loader::includeModule(
'rest'))
332 if (isset($appRemote[
'ITEMS']))
334 $data = $appRemote[
'ITEMS'];
335 if (isset($data[
'ICON']))
337 $app[
'ICON'] = $data[
'ICON'];
339 if (isset($data[
'PRICE']) && !empty($data[
'PRICE']))
341 $app[
'PRICE'] = $data[
'PRICE'];
345 $code => $appLocal[
'VERSION']
348 isset($updates[
'ITEMS'][0][
'VERSIONS']) &&
349 is_array($updates[
'ITEMS'][0][
'VERSIONS'])
352 $app[
'UPDATES'] = count($updates[
'ITEMS'][0][
'VERSIONS']);
355 $result->setResult($app);
366 $result->setError($error);
376 public static function bind(array $fields)
379 $error = new \Bitrix\Landing\Error;
384 $fields[
'APP_ID'] = $app[
'ID'];
387 $res = Placement::getList(array(
392 'APP_ID' => isset($fields[
'APP_ID'])
395 'PLACEMENT' => isset($fields[
'PLACEMENT'])
396 ? $fields[
'PLACEMENT']
398 'PLACEMENT_HANDLER' => isset($fields[
'PLACEMENT_HANDLER'])
399 ? $fields[
'PLACEMENT_HANDLER']
406 if (\
Bitrix\Main\Loader::includeModule(
'rest'))
409 $resLocal = Placement::add($fields);
410 if ($resLocal->isSuccess())
413 $resRest = PlacementTable::add(
416 if ($resRest->isSuccess())
418 $result->setResult(
true);
422 $error->addFromResult($resRest);
423 Placement::delete($resLocal->getId());
428 $error->addFromResult($resLocal);
440 $result->setError($error);
451 public static function unbind($code, $handler =
null)
454 $error = new \Bitrix\Landing\Error;
456 if (!is_string($code))
466 $fields[
'APP_ID'] = $app[
'ID'];
469 !isset($fields[
'APP_ID']) ||
482 'APP_ID' => $fields[
'APP_ID'],
483 '=PLACEMENT' => $code
488 $params[
'filter'][
'=PLACEMENT_HANDLER'] = trim($handler);
492 $res = Placement::getList($params);
493 while ($row = $res->fetch())
496 Placement::delete($row[
'ID']);
501 if (\
Bitrix\Main\Loader::includeModule(
'rest'))
503 $res = PlacementTable::getList($params);
504 while ($row = $res->fetch())
506 PlacementTable::delete($row[
'ID']);
514 $result->setResult(
true);
519 'PLACEMENT_NO_EXIST',
522 $result->setError($error);
533 public static function getList(array $params = array())
536 $params = $result->sanitizeKeys($params);
538 if (!is_array($params))
543 !isset($params[
'filter']) ||
544 !is_array($params[
'filter'])
547 $params[
'filter'] = array();
552 $params[
'filter'][
'APP_CODE'] = $app[
'CODE'];
556 $params[
'filter'][
'APP_CODE'] =
false;
560 $res = RepoCore::getList($params);
561 while ($row = $res->fetch())
563 if (isset($row[
'DATE_CREATE']))
565 $row[
'DATE_CREATE'] = (string) $row[
'DATE_CREATE'];
567 if (isset($row[
'DATE_MODIFY']))
569 $row[
'DATE_MODIFY'] = (string) $row[
'DATE_MODIFY'];
571 $row[
'MANIFEST'] = unserialize($row[
'MANIFEST'], [
'allowed_classes' =>
false]);
574 $result->setResult($data);
static sanitize($value, &$bad=false, $splitter=' ')
static getList(array $params=array())
static bind(array $fields)
static unbind($code, $handler=null)
static checkContent($content, $splitter='#SANITIZE#')
static update($id, $fields=array())
static getAppByCode($code)
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getUpdates($codeList)
static getApp($code, $version=false, $checkHash=false, $installHash=false)