Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
font.php
1<?php
3
4use \Bitrix\Landing\Block;
5use \Bitrix\Landing\Internals\BlockTable;
6
7class Font
8{
14 protected static function saveAssets(Block $block): void
15 {
16 $blockContent = $block->getContent();
17 if (!$blockContent)
18 {
19 return;
20 }
21
22 $fonts = [];
23 $found = preg_match_all(
24 '/[\s"](g-font-[^\s"]+)/s',
25 $blockContent,
26 $matches
27 );
28 if ($found)
29 {
30 foreach ($matches[1] as $font)
31 {
32 if (
33 strpos($font, 'g-font-size-') !== 0
34 && strpos($font, 'g-font-weight-') !== 0
35 && strpos($font, 'g-font-style-') !== 0
36 )
37 {
38 $fonts[] = $font;
39 }
40 }
41 }
42 $block->saveAssets([
43 'font' => array_unique($fonts)
44 ]);
45 }
46
52 public static function processing(Block $block): void
53 {
54 self::saveAssets($block);
55 }
56
62 public static function processingLanding(int $landingId): void
63 {
64 $res = BlockTable::getList([
65 'select' => [
66 'ID'
67 ],
68 'filter' => [
69 'LID' => $landingId,
70 '=DELETED' => 'N'
71 ]
72 ]);
73 while ($row = $res->fetch())
74 {
75 $block = new Block($row['ID']);
76 self::processing($block);
77 $block->save();
78 }
79 }
80
86 public static function view(Block $block): void
87 {
88 $blockAssets = $block->getAssets();
89 if (isset($blockAssets['font']))
90 {
91 foreach ($blockAssets['font'] as $fontCode)
92 {
93 \Bitrix\Landing\Hook\Page\Fonts::setFontCode($fontCode);
94 }
95 }
96 }
97}
static saveAssets(Block $block)
Definition font.php:14
static processingLanding(int $landingId)
Definition font.php:62
static processing(Block $block)
Definition font.php:52
saveAssets(array $assets)
Definition block.php:3067