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/cvetdv.ru/bitrix/modules/burlakastudio.realcommenter/lib/ |
Upload File : |
<?php /** * ����� "��������� ����������� D7" ��� ������� * �������� ���� �����: www.realcommenter.com * �������� ���� �����������: burlaka.studio * ����� � ����������: ������� ������� (AlexeyGfi) -> alexeygfi@gmail.com */ namespace Burlakastudio\Realcommenter; use Bitrix\Main\Context; use Bitrix\Main\Event; use Bitrix\Main\EventResult; use Bitrix\Main\Web\Json; class MicrodataReview { public static function publish(&$content) { if ( !mb_strpos($content, '<!--##REALCOMMENTER_MICRODATA_REVIEW##-->', 0, LANG_CHARSET) || !$nodes = Comments::nodesCollector() ) { return; } /** * { * "@context": "https://schema.org/", * "@type": "Review", * "itemReviewed": { * "@type": "SomeProducts", * "name": "Brother HL-2230 Compact Laser Printer", * "url" : "https://microsoft.com/" * }, * "name": "A good seafood place.", * "author": { * "@type": "Person", * "name": "Bob Smith" * }, * "reviewBody": "The seafood is great." * } */ global $APPLICATION; $productName = $APPLICATION->GetTitle(); $productUrl = (self::arParams())['URL'] ?? null; $server = Context::getCurrent()->getServer(); $request = Context::getCurrent()->getRequest(); $protocol = $request->isHttps() ? 'https' : 'http'; $host = $server->getHttpHost(); $microdatas = []; // �������� ���������, ��������� foreach ($nodes as $node) { $reviewNode = [ '@context' => 'https://schema.org/', '@type' => 'Review', 'itemReviewed' => [ '@type' => 'SomeProducts' ], 'author' => [ '@type' => 'Person', 'name' => $node['UF_SIGNATURE'] ], 'reviewBody' => str_replace("\r\n", ' ', HTMLToTxt($node['REVIEW_TEXT'])) ]; if ($productName) { $reviewNode['itemReviewed']['name'] = $productName; } if ($productUrl) { $reviewNode['itemReviewed']['url'] = $protocol . '://' . $host . $productUrl; } $microdatas[] = $reviewNode; } $event = new Event( TOOLS::getModuleName(), 'onBeforeMicrodataReviewPublish', [ 'microdatas' => $microdatas, ]); $event->send(); foreach ($event->getResults() as $eventResult) { if ($eventResult->getType() !== EventResult::SUCCESS) { $microdatas = false; break; } $params = $eventResult->getParameters(); $microdatas = $params['microdatas'] ?? $microdatas; if ($microdatas && !is_array($microdatas)) { $microdatas = [$microdatas]; } } if ($microdatas) { $preparedToPublish = array_reduce( $microdatas, static function ($carry, $data) { $carry .= '<script type="application/ld+json">' . Json::encode($data, JSON_UNESCAPED_UNICODE) . '</script>'; return $carry; }, '' ); if(strtolower(LANG_CHARSET) !== 'utf-8') { $preparedToPublish = \iconv('utf-8', LANG_CHARSET, $preparedToPublish); } $content = str_replace( '<!--##REALCOMMENTER_MICRODATA_REVIEW##-->', $preparedToPublish, $content ); } } public static function arParams($newData = null) { static $arParams = []; if ($newData) { $arParams = $newData; } return $arParams; } public static function inUse($arParams = []): bool { return !(empty($arParams) || !$arParams['useReviewMicrodata']); } }