1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
fonts.php
См. документацию.
1<?php
2namespace Bitrix\Landing\Hook\Page;
3
4use Bitrix\Landing\Field;
5use Bitrix\Landing\Manager;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\UI;
9
11{
15 public const DEFAULT_FONTS = [
16 'g-font-open-sans' => [
17 'name' => 'Open Sans',
18 'family' => '"Open Sans", Helvetica, Arial, sans-serif',
19 'url' => 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic',
20 ],
21 'g-font-roboto' => [
22 'name' => 'Roboto',
23 'family' => '"Roboto", Arial, sans-serif',
24 'url' => 'https://fonts.googleapis.com/css2?family=Roboto:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic,cyrillic-ext,latin-ext',
25 ],
26 'g-font-roboto-slab' => [
27 'name' => 'Roboto Slab',
28 'family' => '"Roboto Slab", Helvetica, Arial, sans-serif',
29 'url' => 'https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic,cyrillic-ext,latin-ext',
30 ],
31 'g-font-montserrat' => [
32 'name' => 'Montserrat',
33 'family' => '"Montserrat", Helvetica, Arial, sans-serif',
34 'url' => 'https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic',
35 ],
36 'g-font-alegreya-sans' => [
37 'name' => 'Alegreya Sans',
38 'family' => '"Alegreya Sans", sans-serif',
39 'url' => 'https://fonts.googleapis.com/css2?family=Alegreya+Sans:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
40 ],
41 'g-font-cormorant-infant' => [
42 'name' => 'Cormorant Infant',
43 'family' => '"Cormorant Infant", serif',
44 'url' => 'https://fonts.googleapis.com/css2?family=Cormorant+Infant:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
45 ],
46 'g-font-pt-sans-caption' => [
47 'name' => 'PT Sans Caption',
48 'family' => '"PT Sans Caption", sans-serif',
49 'url' => 'https://fonts.googleapis.com/css2?family=PT+Sans+Caption:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
50 ],
51 'g-font-pt-sans-narrow' => [
52 'name' => 'PT Sans Narrow',
53 'family' => '"PT Sans Narrow", sans-serif',
54 'url' => 'https://fonts.googleapis.com/css2?family=PT+Sans+Narrow:wght@100;200;300;400;500;600;700;800;900&PT+Sans:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
55 ],
56 'g-font-pt-sans' => [
57 'name' => 'PT Sans',
58 'family' => '"PT Sans", sans-serif',
59 'url' => 'https://fonts.googleapis.com/css2?family=PT+Sans:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
60 ],
61 'g-font-lobster' => [
62 'name' => 'Lobster',
63 'family' => '"Lobster", cursive',
64 'url' => 'https://fonts.googleapis.com/css2?family=Lobster:wght@100;200;300;400;500;600;700;800;900&subset=cyrillic-ext,latin-ext',
65 ],
66 ];
67
72 protected static $setFonts = [];
73
78 protected function getMap()
79 {
80 return [
81 'CODE' => new Field\Textarea(
82 'CODE', [
83 'title' => Loc::getMessage('LNDNGHOOK_FONTS_FONT_BASE'),
84 ]),
85 ];
86 }
87
92 public function enabled()
93 {
94 return true;
95 }
96
102 public static function setFontCode(string $fontCode): void
103 {
104 if (!array_key_exists($fontCode, self::$setFonts))
105 {
106 self::$setFonts[$fontCode] = [];
107 }
108 }
109
114 public function exec()
115 {
116 if (!self::$setFonts)
117 {
118 return;
119 }
120 // @fix for #101643
121
122 $this->fields['CODE'] = str_replace(
123 ['st yle', 'onl oad', 'li nk'],
124 ['style', 'onload', 'link'],
125 $this->fields['CODE']
126 );
127 $styleFound = preg_match_all(
128 '#(<noscript>.*?<style.*?data-id="([^"]+)"[^>]*>[^<]+</style>)#is',
129 $this->fields['CODE'],
131 );
132
133 $fonts = [];
134 if ($styleFound)
135 {
136 $fonts = array_combine($matches[2], $matches[1]);
137 }
138 $this->outputFonts($fonts);
139 }
140
146 protected function outputFonts(array $fonts): void
147 {
148 $setFonts = [];
149
150 foreach (self::$setFonts as $fontCode => $foo)
151 {
152 if (isset($fonts[$fontCode]))
153 {
154 unset(self::$setFonts[$fontCode]);
155 $setFonts[] = self::proxyFontUrl($fonts[$fontCode]);
156 }
157 }
158
159 // set default fonts
160 foreach (self::$setFonts as $fontCode => $foo)
161 {
162 $setFonts[] = self::outputDefaultFont($fontCode);
163 }
164
165 if ($setFonts)
166 {
168 'BeforeHeadClose',
169 implode('', $setFonts)
170 );
171 }
172 }
173
179 public static function outputDefaultFont(string $code): string
180 {
181 if (isset(self::DEFAULT_FONTS[$code]))
182 {
183 $fontUrl = self::DEFAULT_FONTS[$code]['url'];
184 $fontUrl = self::proxyFontUrl($fontUrl);
185
186 return '<link
187 rel="preload"
188 as="style"
189 onload="this.removeAttribute(\'onload\');this.rel=\'stylesheet\'"
190 data-font="' . $code . '"
191 data-protected="true"
192 href="' . $fontUrl . '">
193 <noscript>
194 <link
195 rel="stylesheet"
196 data-font="' . $code . '"
197 data-protected="true"
198 href="' . $fontUrl . '">
199 </noscript>';
200 }
201
202 return '';
203 }
204
212 public static function generateFontTags(string $fontName): string
213 {
214 $fontUrl = "https://fonts.bitrix24.ru/css2?family="
215 . str_replace(' ', '+', $fontName)
216 . ":wght@100;200;300;400;500;600;700;800;900";
217 $fontClass = strtolower(str_replace(' ', '-', $fontName));
218
219 return <<<HTML
220 <noscript><link rel="stylesheet" href="$fontUrl" data-font="g-font-$fontClass"></noscript>
221 <link rel="preload" href="$fontUrl" data-font="g-font-$fontClass" onload="this.removeAttribute('onload');this.rel='stylesheet'" as="style">
222 <style data-id="g-font-$fontClass">.g-font-$fontClass { font-family: "$fontName", sans-serif; }</style>
223 HTML;
224}
225
231 protected static function proxyFontUrl(string $fontString): string
232 {
233 $defaultDomain = 'fonts.googleapis.com';
234 $proxyDomain = $defaultDomain;
235 if (Loader::includeModule('ui'))
236 {
238 }
239
240 return ($defaultDomain !== $proxyDomain)
241 ? str_replace($defaultDomain, $proxyDomain, $fontString)
242 : $fontString
243 ;
244 }
245}
static $setFonts
Определения fonts.php:72
static outputDefaultFont(string $code)
Определения fonts.php:179
const DEFAULT_FONTS
Определения fonts.php:15
static setFontCode(string $fontCode)
Определения fonts.php:102
outputFonts(array $fonts)
Определения fonts.php:146
static generateFontTags(string $fontName)
Определения fonts.php:212
static getZone()
Определения manager.php:930
static setPageView(string $marker, string $content, bool $skipTrim=false)
Определения manager.php:470
static includeModule($moduleName)
Определения loader.php:67
static resolveDomain(?string $region=null)
Определения Proxy.php:63
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
Определения Proxy.php:2
font style
Определения invoice.php:442
$matches
Определения index.php:22