This commit is contained in:
root
2025-11-13 19:52:28 +03:00
parent 8aeeb05b7d
commit 807dec3b6c
4646 changed files with 163445 additions and 626017 deletions

View File

@@ -1114,33 +1114,4 @@ class Block
return $result;
}
/**
* Get extensions configs, load relations, load lang phrases
*
* @param array $extCodes - array of extensions codes
* @param array $tplCodes - array of site templates
* @return PublicActionResult - array of assets by type
*/
public static function getAssetsConfig(array $extCodes, array $tplCodes = []): PublicActionResult
{
$result = new PublicActionResult();
$assetsManager = (new Assets\Manager())
->enableSandbox()
->addAsset($extCodes)
;
foreach ($tplCodes as $tpl)
{
$siteTemplatePath =
(defined('SITE_TEMPLATE_PATH') ? SITE_TEMPLATE_PATH : '/bitrix/templates/.default');
$style = $siteTemplatePath . "/template_styles.css";
$assetsManager->addAsset($style);
}
$result->setResult($assetsManager->getOutput());
return $result;
}
}

View File

@@ -239,33 +239,10 @@ class Domain
$siteController = Manager::getExternalSiteController();
if ($siteController)
{
//todo: revert changes after change .by domain
$domainName = $return['domain'];
$byDomainName = '';
$isOnlineSite = str_ends_with($domainName, '.b24site.online');
$isOnlineShop = str_ends_with($domainName, '.b24shop.online');
if ($isOnlineSite)
{
$byDomainName = str_replace('.b24site.online', '.bitrix24site.by', $domainName);
}
if ($isOnlineShop)
{
$byDomainName = str_replace('.b24shop.online', '.bitrix24shop.by', $domainName);
}
$checkResult = $siteController::isDomainExists(
$domainName
$checkResult = $siteController::isDomainExists(
$return['domain']
);
if ($byDomainName === '')
{
$return['available'] = $checkResult < 2;
}
else
{
$checkResultBy = $siteController::isDomainExists(
$byDomainName
);
$return['available'] = $checkResult < 2 && $checkResultBy < 2;
}
$return['available'] = $checkResult < 2;
}
}
catch (SystemException $ex)

View File

@@ -11,6 +11,7 @@ use Bitrix\Landing\Block as BlockCore;
use Bitrix\Landing\TemplateRef;
use Bitrix\Landing\Landing as LandingCore;
use Bitrix\Landing\PublicActionResult;
use Bitrix\Landing\Internals\BlockFavouriteTable;
use Bitrix\Landing\Internals\HookDataTable;
use Bitrix\Landing\History;
use Bitrix\Main\Localization\Loc;
@@ -19,6 +20,14 @@ Loc::loadMessages(__FILE__);
class Landing
{
private const ACTION_ADD = 'add';
private const ACTION_REMOVE = 'remove';
private const STATUS_ADDED = 'added';
private const STATUS_ALREADY_EXISTS = 'already_exists';
private const STATUS_DELETED = 'deleted';
private const STATUS_NOT_FOUND = 'not_found';
/**
* Clear disallow keys from add/update fields.
* @param array $fields
@@ -215,6 +224,10 @@ class Landing
$bad
);
}
if (isset($fields['CATEGORY']))
{
$data['CATEGORY'] = $fields['CATEGORY'];
}
// sort
if (isset($fields['AFTER_ID']))
{
@@ -271,6 +284,139 @@ class Landing
return $result;
}
/**
* Add or remove a block code from the user's list of favourite blocks.
*
* @param string $codeBlock The code of the block to add or remove from favourites.
* @param string $action The action to perform: 'add' to add to favourites, 'remove' to remove from favourites.
*
* @return PublicActionResult Result object with status or error information.
*/
public static function markFavouriteBlock(string $codeBlock, string $action, string $type): PublicActionResult
{
$result = new PublicActionResult();
$userId = Manager::getUserId();
if ($userId <= 0 || !$codeBlock || !in_array($action, [self::ACTION_ADD, self::ACTION_REMOVE], true))
{
$error = new \Bitrix\Landing\Error;
$error->addError('DB_ERROR_ADD','Invalid user, codeBlock or action');
$result->setError($error);
return $result;
}
$existing = BlockFavouriteTable::getList([
'filter' => [
'=USER_ID' => $userId,
'=CODE' => $codeBlock,
],
'select' => ['ID'],
])->fetch();
switch ($action) {
case self::ACTION_ADD:
if (!$existing)
{
$addResult = BlockFavouriteTable::add([
'USER_ID' => $userId,
'CODE' => $codeBlock,
'DATE_CREATE' => new \Bitrix\Main\Type\DateTime(),
]);
if ($addResult->isSuccess())
{
$result->setResult(['status' => self::STATUS_ADDED]);
}
else
{
$error = new \Bitrix\Landing\Error;
$error->addError('DB_ERROR_ADD', $addResult->getErrorMessages());
$result->setError($error);
}
}
else
{
$result->setResult(['status' => self::STATUS_ALREADY_EXISTS]);
}
$metrikaEvent = Metrika\Events::addFavourite;
break;
case self::ACTION_REMOVE:
if ($existing)
{
$deleteResult = BlockFavouriteTable::delete($existing['ID']);
if ($deleteResult->isSuccess())
{
$result->setResult(['status' => self::STATUS_DELETED]);
}
else
{
$error = new \Bitrix\Landing\Error;
$error->addError('DB_ERROR_REMOVE', $deleteResult->getErrorMessages());
$result->setError($error);
}
}
else
{
$result->setResult(['status' => self::STATUS_NOT_FOUND]);
}
$metrikaEvent = Metrika\Events::deleteFavourite;
break;
}
if (isset($metrikaEvent))
{
$metrika = new Metrika\Metrika(Metrika\Categories::getBySiteType($type), $metrikaEvent);
$metrika
->setSection(Metrika\Sections::siteEditor)
->setSubSection('code_' . $codeBlock)
->send()
;
}
return $result;
}
/**
* Returns the list of block codes marked as favourite by the current user.
*
* @return PublicActionResult Result object containing an array of favourite block codes or error information.
*/
public static function getFavouriteBlocks(): PublicActionResult
{
$result = new PublicActionResult();
$userId = Manager::getUserId();
if ($userId <= 0)
{
$error = new \Bitrix\Landing\Error;
$error->addError('INVALID_USER', 'Invalid user');
$result->setError($error);
return $result;
}
$codes = [];
$res = BlockFavouriteTable::getList([
'filter' => [
'=USER_ID' => $userId
],
'select' => ['CODE'],
'order' => ['DATE_CREATE' => 'DESC']
]);
while ($row = $res->fetch())
{
$codes[] = $row['CODE'];
}
$result->setResult($codes);
return $result;
}
/**
* Mark delete or not the block.
* @param int $lid Id of landing.

View File

@@ -74,134 +74,6 @@ class RepoWidget extends Repo
$manifest = Scope\Mainpage::prepareBlockManifest($manifest);
}
// todo: move to non-rest namespace?
/**
* @param int $blockId
* @param array $params
* @return PublicActionResult
*/
public static function fetchData(int $blockId, array $params = []): PublicActionResult
{
$result = new PublicActionResult();
$result->setResult(false);
$error = new Landing\Error;
$block = new Landing\Block($blockId);
if (!$block->getId())
{
$error->addError(
'BLOCK_NOT_FOUND',
Loc::getMessage('LANDING_WIDGET_BLOCK_NOT_FOUND')
);
$result->setError($error);
return $result;
}
if (!Loader::includeModule('rest'))
{
$error->addError(
'REST_NOT_FOUND',
Loc::getMessage('LANDING_WIDGET_REST_NOT_FOUND')
);
$result->setError($error);
return $result;
}
// check app
$repoId = $block->getRepoId();
$app = Landing\Repo::getAppInfo($repoId);
if (
!$repoId
|| empty($app)
|| !isset($app['CLIENT_ID'])
)
{
$error->addError(
'APP_NOT_FOUND',
Loc::getMessage('LANDING_WIDGET_APP_NOT_FOUND')
);
$result->setError($error);
return $result;
}
// check subtype
$manifest = $block->getManifest();
if (
!in_array(self::SUBTYPE_WIDGET, (array)$manifest['block']['subtype'], true)
|| !is_array($manifest['block']['subtype_params'])
|| !isset($manifest['block']['subtype_params']['handler'])
)
{
$error->addError(
'HANDLER_NOT_FOUND',
Loc::getMessage('LANDING_WIDGET_HANDLER_NOT_FOUND_2')
);
$result->setError($error);
return $result;
}
// get auth
$auth = Rest\Application::getAuthProvider()->get(
$app['CLIENT_ID'],
'landing',
[],
Manager::getUserId()
);
if (isset($auth['error']))
{
$error->addError(
'APP_AUTH_ERROR__' . $auth['error'],
$auth['error_description'] ?? ''
);
$result->setError($error);
return $result;
}
$params['auth'] = $auth;
// request
$url = (string)$manifest['block']['subtype_params']['handler'];
$http = new HttpClient();
$data = $http->post(
$url,
$params
);
if ($http->getStatus() !== 200)
{
$error->addError(
'HANDLER_NOT_ALLOW',
Loc::getMessage('LANDING_WIDGET_HANDLER_NOT_ALLOW')
);
$result->setError($error);
return $result;
}
$type = empty($params) ? 'fetch' : 'fetch_params';
UsageStatTable::logLandingWidget($app['CLIENT_ID'], $type);
UsageStatTable::finalize();
if (isset($data['error']))
{
$error->addError(
$data['error'],
$data['error_description'] ?? ''
);
$result->setError($error);
return $result;
}
$result->setResult($data);
return $result;
}
/**
* Enable or disable widgets debug logging
* @param string $appCode