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/blocks/bitrix/11.three_cols_fix_tariffs/ |
Upload File : |
<?php if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die(); } use \Bitrix\Landing\Block; use \Bitrix\Main\Web\HttpClient; use \Bitrix\Main\Web\Json; class ThreeColsFixTariffsBlock extends \Bitrix\Landing\LandingBlock { /** * Url to get Bitrix24 prices. */ const B24_PRICE_URL = 'https://util.1c-bitrix.ru/b24/catalog.php?currency=RUR&area=ru'; /** * Available Bitrix24 tariffs. */ const B24_TARIFF_CODES = [ 'START_20191', 'CRM_20191', 'CRM_20191', 'TEAM_20191', 'COMPANY1' ]; /** * Returns actual Bitrix24 prices. * @return array */ protected function getPrices(): array { $data = []; $http = new HttpClient; $res = $http->get($this::B24_PRICE_URL); if ($res) { try { $res = Json::decode($res); foreach ($this::B24_TARIFF_CODES as $code) { if (isset($res[$code]['PRICE'])) { $data[] = $res[$code]['PRICE']; } else { return []; } } } catch (\Exception $e){} } return $data; } /** * Method, which executes just before block to view. * @param Block $block Block instance. * @return void */ public function beforeView(Block $block) { return; if (!\Bitrix\Main\Loader::includeModule('bitrix24')) { return; } if (\CBitrix24::getLicenseType() != 'nfr') { return; } $blockAccess = $block->getAccess(); if ($blockAccess >= $block::ACCESS_W) { return; } $prices = $this->getPrices(); if (!$prices) { return; } $content = $block->getContent(); $content = preg_replace_callback( '#<div class="landing-block-node-price[\s"]+[^"]*"><span[^>]+>([^<]+)</span></div>#is', function($item) use($prices) { static $i = 0; return str_replace( $item[1], $prices[$i++], $item[0] ); }, $content ); $block->setAccess($block::ACCESS_W); $block->saveContent($content); $block->setAccess($blockAccess); } }