22 private const ONLY_CODES = [
28 private const PAGE_CODE =
'store-chats-dark/order';
30 private static function getExistsPageId(
int $siteId,
string $code): ?
int
42 if ($page = $res->fetch())
48 private static function getLandingHooks(
string $pageId): ?array
50 $res = Internals\HookDataTable::getList([
52 'ID',
'HOOK',
'CODE',
'VALUE',
'PUBLIC'
55 '=ENTITY_TYPE' =>
'L',
56 'ENTITY_ID' => $pageId,
59 if ($rows = $res->fetchAll())
66 private static function getLandingBlocks(
string $pageId): ?array
68 $res = Internals\BlockTable::getList([
70 'ID',
'CODE',
'CONTENT'
76 if ($rows = $res->fetchAll())
83 private static function getNewLandingBlocksData(): array
86 'store.salescenter.order.details' => [
87 'COMPONENT_PARAMS' => [
88 'TEMPLATE_MODE' =>
'graymode',
91 '61.1.phone_w_btn_rght' => [
92 'COMPONENT_PARAMS' => [
93 'TEMPLATE_MODE' =>
'graymode',
94 'BUTTON_CLASSES' =>
'btn g-rounded-50 g-btn-type-outline g-btn-px-l g-btn-size-md g-btn-darkgray text-uppercase',
97 'landing-block g-pt-20 g-pb-0 g-bg-transparent u-block-border-none',
101 'CONTENT' =>
'<section class="landing-block g-bg-transparent g-pt-20 g-pb-10" style="">'
102 . PHP_EOL .
'<hr class="landing-block-line g-brd-gray-dark-v2 my-0" style="" />'
103 . PHP_EOL .
'</section>',
108 private static function prepareLandingBlocks($currentBlocksData, $newBlocksData):
void
110 $newBlocksDataFiltered = array_filter($newBlocksData,
static function($newBlockData) {
111 return isset($newBlockData[
'CONTENT']) || isset($newBlockData[
'COMPONENT_PARAMS']) || isset($newBlockData[
'CLASSES']);
114 $currentBlocksDataProcessed = array_map(
static function($currentBlockData) use ($newBlocksDataFiltered) {
115 foreach ($newBlocksDataFiltered as $codeBlock => $newBlockData)
117 if ($codeBlock === $currentBlockData[
'CODE'])
119 if (isset($newBlockData[
'CONTENT']))
121 $currentBlockData[
'CONTENT'] = $newBlockData[
'CONTENT'];
123 if (isset($newBlockData[
'COMPONENT_PARAMS']))
125 foreach ($newBlockData[
'COMPONENT_PARAMS'] as $nameParam => $valueParam)
127 $newParamsString = PHP_EOL .
'"' . $nameParam .
'" => "' . $valueParam .
'",';
128 $pattern =
'/["\']' . $nameParam .
'["\'][\s=>]*[^,]*[,?]/';
129 if (preg_match($pattern, $currentBlockData[
'CONTENT']) === 1)
131 $currentBlockData[
'CONTENT'] = preg_replace($pattern, $newParamsString, $currentBlockData[
'CONTENT']);
135 $pattern =
'/(["\'].*["\']\s*=>\s*[^,]*[,?])/';
136 $currentBlockData[
'CONTENT'] = preg_replace($pattern,
'${1}' . $newParamsString, $currentBlockData[
'CONTENT'], 1);
140 if (isset($newBlockData[
'CLASSES']))
142 $pos = strpos($newBlockData[
'CLASSES'][0],
' ');
143 $string = substr($newBlockData[
'CLASSES'][0], 0, $pos + 1);
144 $pattern =
'/class="'. $string .
'.*"/';
145 $replacement =
'class="' . $newBlockData[
'CLASSES'][0] .
'"';
146 $currentBlockData[
'CONTENT'] = preg_replace($pattern, $replacement, $currentBlockData[
'CONTENT']);
148 return $currentBlockData;
151 return $currentBlockData;
152 }, $currentBlocksData);
154 $preparedBlocksData = array_filter($currentBlocksDataProcessed);
157 foreach ($preparedBlocksData as $preparedBlockData)
159 Internals\BlockTable::update(
160 $preparedBlockData[
'ID'],
161 [
'CONTENT' => $preparedBlockData[
'CONTENT']]
166 private static function getNewLandingHooks(): array
170 'HOOK' =>
'BACKGROUND',
175 'HOOK' =>
'BACKGROUND',
177 'VALUE' =>
'#1c1c22',
180 'HOOK' =>
'BACKGROUND',
182 'VALUE' =>
'https://cdn.bitrix24.site/bitrix/images/landing/bg/store-chat-gray.jpg',
185 'HOOK' =>
'BACKGROUND',
186 'CODE' =>
'POSITION',
187 'VALUE' =>
'no_repeat',
190 'HOOK' =>
'CSSBLOCK',
195 'HOOK' =>
'CSSBLOCK',
197 'VALUE' =>
'.landing-viewtype--mobile .landing-public-mode {outline: none;}',
202 private static function prepareLandingHooks($currentHooks, $newHooks, $pageId):
void
204 $isUpdateBgHooks =
true;
205 foreach ($currentHooks as $currentHookData)
208 $currentHookData[
'HOOK'] ===
'BACKGROUND'
209 && $currentHookData[
'CODE'] ===
'USE'
210 && $currentHookData[
'VALUE'] ===
'Y'
213 $isUpdateBgHooks =
false;
217 $updateHooksData = [];
218 $createHooksData = [];
219 foreach ($newHooks as $hookData)
221 if ($hookData[
'HOOK'] ===
'BACKGROUND' && $isUpdateBgHooks ===
false)
226 $isExistPublicHook =
false;
227 $isExistUnPublicHook =
false;
228 foreach ($currentHooks as $currentHookData)
231 $hookData[
'HOOK'] === $currentHookData[
'HOOK']
232 && $hookData[
'CODE'] === $currentHookData[
'CODE']
235 if ($hookData[
'VALUE'] !== $currentHookData[
'VALUE'])
237 $updateHooksData[] = [
238 'ID' => $currentHookData[
'ID'],
239 'VALUE' => $hookData[
'VALUE'],
242 $isPublicHook = $currentHookData[
'PUBLIC'];
243 if ($isPublicHook ===
'Y')
245 $isExistPublicHook =
true;
247 if ($isPublicHook ===
'N')
249 $isExistUnPublicHook =
true;
253 $isNeedCreateHook =
false;
254 if (!$isExistPublicHook)
256 $isNeedCreateHook =
true;
259 if (!$isExistUnPublicHook)
261 $isNeedCreateHook =
true;
264 if ($isNeedCreateHook ===
true && isset($isPublic))
266 $createHooksData[] = [
267 'ENTITY_ID' => $pageId,
268 'ENTITY_TYPE' =>
'L',
269 'HOOK' => $hookData[
'HOOK'],
270 'CODE' => $hookData[
'CODE'],
271 'VALUE' => $hookData[
'VALUE'],
272 'PUBLIC' => $isPublic,
278 foreach ($updateHooksData as $updateHookData)
280 Internals\HookDataTable::update(
281 $updateHookData[
'ID'],
282 [
'VALUE' => $updateHookData[
'VALUE']]
286 foreach ($createHooksData as $createHookData)
288 Internals\HookDataTable::add([
289 'ENTITY_ID' => $createHookData[
'ENTITY_ID'],
290 'ENTITY_TYPE' => $createHookData[
'ENTITY_TYPE'],
291 'HOOK' => $createHookData[
'HOOK'],
292 'CODE' => $createHookData[
'CODE'],
293 'VALUE' => $createHookData[
'VALUE'],
294 'PUBLIC' => $createHookData[
'PUBLIC'],
304 public static function update(
int $siteId): bool
308 if (!$site || !in_array($site[
'TPL_CODE'], self::ONLY_CODES,
true))
313 $orderPageId = self::getExistsPageId($siteId, self::PAGE_CODE);
316 $currentHooks = self::getLandingHooks($orderPageId);
317 $newHooks = self::getNewLandingHooks();
318 self::prepareLandingHooks($currentHooks, $newHooks, $orderPageId);
320 $currentBlocks = self::getLandingBlocks($orderPageId);
321 $newBlocksData = self::getNewLandingBlocksData();
322 self::prepareLandingBlocks($currentBlocks, $newBlocksData);
static loadMessages($file)
static getList(array $parameters=array())