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

@@ -11,7 +11,6 @@ use Bitrix\Landing\Manager;
use Bitrix\Landing\Repo;
use Bitrix\Landing\Internals;
use Bitrix\Landing\Site\Type;
use Bitrix\Main\Application;
use Bitrix\Main\Event;
use Bitrix\Main\EventResult;
use Bitrix\Main\Loader;
@@ -46,6 +45,7 @@ class BlockRepo
* Sections with special conditions
*/
private const SECTION_LAST = 'last';
private const SECTION_FAVOURITE = 'favourite';
/**
* Section or block type with special conditions
@@ -264,7 +264,7 @@ class BlockRepo
if ($cache->initCache($cacheTime, $cacheId, $cachePath))
{
$this->repository = $cache->getVars();
if (is_array($this->repository) && !empty($this->repository))
if (!empty($this->repository))
{
return $this->fillLastUsedBlocks();
}
@@ -582,8 +582,7 @@ class BlockRepo
private function fillLastUsedBlocks(): static
{
$request = Application::getInstance()->getContext()->getRequest();
if ($request->get('landing_mode') !== 'edit')
if (Landing::getEditMode() === false)
{
return $this;
}
@@ -609,9 +608,9 @@ class BlockRepo
foreach ($cat['items'] as $code => &$block)
{
if (
in_array($code, $lastUsed)
&& $catCode != self::SECTION_LAST
$catCode !== self::SECTION_LAST
&& !empty($block)
&& in_array($code, $lastUsed, true)
)
{
$block['section'][] = self::SECTION_LAST;
@@ -676,17 +675,17 @@ class BlockRepo
* @param string|array $item
* @return array|null
*/
$prepareType = function (string|array $item): ?array
$prepareType = static function (string|array $item): ?array
{
$type = (array)$item;
$type = array_map('strtoupper', $type);
if (in_array('PAGE', $type))
if (in_array('PAGE', $type, true))
{
$type[] = 'SMN';
}
if (
in_array('NULL', $type)
|| in_array('', $type)
in_array('NULL', $type, true)
|| in_array('', $type, true)
)
{
return null;
@@ -706,17 +705,17 @@ class BlockRepo
$sectionTypes = $prepareType($section['type'] ?? []);
if (
$this->isFilterActive(self::FILTER_SKIP_COMMON_BLOCKS)
&& empty($sectionTypes)
&& $sectionCode !== self::SECTION_LAST
empty($sectionTypes)
&& $this->isFilterActive(self::FILTER_SKIP_COMMON_BLOCKS)
&& !in_array($sectionCode, [self::SECTION_LAST, self::SECTION_FAVOURITE], true)
)
{
continue;
}
if (
$this->isFilterActive(self::FILTER_SKIP_HIDDEN_BLOCKS)
&& $sectionTypes === null
$sectionTypes === null
&& $this->isFilterActive(self::FILTER_SKIP_HIDDEN_BLOCKS)
)
{
continue;
@@ -743,16 +742,16 @@ class BlockRepo
$blockTypes = $prepareType($block['type'] ?? []);
if (
$this->isFilterActive(self::FILTER_SKIP_COMMON_BLOCKS)
&& empty($blockTypes)
empty($blockTypes)
&& $this->isFilterActive(self::FILTER_SKIP_COMMON_BLOCKS)
)
{
continue;
}
if (
$this->isFilterActive(self::FILTER_SKIP_HIDDEN_BLOCKS)
&& $blockTypes === null
$blockTypes === null
&& $this->isFilterActive(self::FILTER_SKIP_HIDDEN_BLOCKS)
)
{
continue;
@@ -773,9 +772,9 @@ class BlockRepo
}
if (
$this->isFilterActive(self::FILTER_SKIP_SYSTEM_BLOCKS)
&& isset($block['system'])
isset($block['system'])
&& $block['system'] === true
&& $this->isFilterActive(self::FILTER_SKIP_SYSTEM_BLOCKS)
)
{
continue;
@@ -788,13 +787,40 @@ class BlockRepo
$filtered[$sectionCode]['items'][$blockCode] = $block;
}
if (empty($filtered[$sectionCode]['items']))
if (empty($filtered[$sectionCode]['items']) && $sectionCode !== self::SECTION_FAVOURITE)
{
unset($filtered[$sectionCode]);
}
}
return $filtered;
return $this->filterLastUsed($filtered);
}
private function filterLastUsed(array $repository): array
{
if (!isset($repository[self::SECTION_LAST]['items']))
{
return $repository;
}
$removeLastSection = static function(array $sections)
{
return array_diff($sections, [self::SECTION_LAST]);
};
$filteredBlocks = [];
$allowableSections = $removeLastSection(array_keys($repository));
foreach ($repository[self::SECTION_LAST]['items'] as $code => $block)
{
$blockSections = $removeLastSection($block['section'] ?? []);
if (!empty(array_intersect($blockSections, $allowableSections)))
{
$filteredBlocks[$code] = $block;
}
}
$repository[self::SECTION_LAST]['items'] = $filteredBlocks;
return $repository;
}
/**