Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/landing/lib/assets/preprocessing/ |
Upload File : |
<?php namespace Bitrix\Landing\Assets\PreProcessing; use \Bitrix\Landing\Block; use \Bitrix\Landing\Internals\BlockTable; class Font { /** * Tries to find google fonts classes and save them assets to the block. * @param Block $block Bock instance. * @return void */ protected static function saveAssets(Block $block): void { $blockContent = $block->getContent(); if (!$blockContent) { return; } $fonts = []; $found = preg_match_all( '/[\s"](g-font-[^\s"]+)/s', $blockContent, $matches ); if ($found) { foreach ($matches[1] as $font) { if ( strpos($font, 'g-font-size-') !== 0 && strpos($font, 'g-font-weight-') !== 0 && strpos($font, 'g-font-style-') !== 0 ) { $fonts[] = $font; } } } $block->saveAssets([ 'font' => array_unique($fonts) ]); } /** * Processing fonts in the block content. * @param Block $block Block instance. * @return void */ public static function processing(Block $block): void { self::saveAssets($block); } /** * Processing entire landing. * @param int $landingId Landing id. * @return void */ public static function processingLanding(int $landingId): void { $res = BlockTable::getList([ 'select' => [ 'ID' ], 'filter' => [ 'LID' => $landingId, '=DELETED' => 'N' ] ]); while ($row = $res->fetch()) { $block = new Block($row['ID']); self::processing($block); $block->save(); } } /** * Shows fonts on the block output. * @param Block $block Block instance. * @return void */ public static function view(Block $block): void { $blockAssets = $block->getAssets(); if (isset($blockAssets['font'])) { foreach ($blockAssets['font'] as $fontCode) { \Bitrix\Landing\Hook\Page\Fonts::setFontCode($fontCode); } } } }