Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fontfix.php
1<?php
2
4
7
8final class FontFix extends Stepper
9{
10 protected const FONT_PARAMS = ':wght@300;400;500;600;700;900';
11 protected const PART_FONT_PATH = 'css2';
12 protected const STEP_PORTION = 10;
13 protected const CONTINUE_EXECUTING = true;
14 protected const STOP_EXECUTING = false;
15
21 public function execute(array &$result): bool
22 {
23 $res = HookDataTable::getList(
24 [
25 'select' => [
26 'ID', 'VALUE'
27 ],
28 'filter' => [
29 'HOOK' => 'FONTS',
30 ],
31 ]
32 );
33 if (!$result['count'])
34 {
35 $result['count'] = count($res);
36 }
37 if (!$result['steps'])
38 {
39 $result['steps'] = 0;
40 }
41
42 if (!$result['checkedRows'])
43 {
44 $result['checkedRows'] = 0;
45 }
46
47 $countFixedRows = 0;
48 $countRows = 0;
49 while ($row = $res->fetch())
50 {
51 $result["steps"] = $result["steps"]++;
52 if ($countRows > $result['checkedRows'])
53 {
54 $result['checkedRows']++;
55 preg_match_all(
56 '#(<noscript>.*?<style.*?data-id="([^"]+)"[^>]*>[^<]+</style>)#is',
57 $row['VALUE'],
58 $matches
59 );
60 $matchesNew = preg_replace(
61 '/(href="[^"]*)(css)([?]family=)([\w+]+)[^"]*(")/i',
62 '${1}'.self::PART_FONT_PATH.'$3$4'.self::FONT_PARAMS.'$5',
63 $matches[1]
64 );
65 if ($matches[1] !== $matchesNew)
66 {
67 $countFixedRows++;
68 $value = str_replace($matches[1], $matchesNew, $row['VALUE']);
69 HookDataTable::update(
70 $row['ID'],
71 ['VALUE' => $value]
72 );
73 if ($countFixedRows === self::STEP_PORTION)
74 {
75 $result['checkedRows'] = $countRows;
77 }
78 }
79 }
80 $countRows++;
81 }
82
84 }
85}